From d49cfaac72e57195876a0da43462f69835f5afea Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Fri, 1 May 2015 19:37:55 +0000 Subject: [PATCH] Remove oslo namespace package Blueprint remove-namespace-packages Depends-on: I5bd1cdc35d2ecaf98a0802fff589d8c37aaa8028 for openstack/django_openstack_auth Depends-on: I5da7ca7a8a909eb12a4417e7d5f5b6bd33da4de8 for openstack/horizon Depends-on: Ib17a74ada3122ce45c52fdd7dcf8d27fafbb1d70 for openstack/openstack-doc-tools Depends-on: I1f539cf9f5d6f48e10cac381c13eeb5fa314abd4 for openstack/python-ceilometerclient Depends-on: Ic21066211a071591854280a93a53bb2255cb8ad3 for openstack/python-ironicclient Depends-on: I387a7a1a817058a4daca313fe6df60612cb84864 for openstack/python-keystoneclient Depends-on: I32767615b2d678b6ce545722b6b9d1704cb1ffb4 for openstack/python-keystoneclient-saml2 Depends-on: Id26264ad0b002ab21e60431a2fd39fcecf76c490 for openstack/python-magnumclient Depends-on: Ib86c36f81f6fdbee64d88dd0b1d126bcc16649ac for openstack/python-manilaclient Depends-on: If5e8257085b5fd0a26a34705505fc0077adbabb2 for openstack/python-novaclient Depends-on: I37ce99d8c9a2ba5b97a12a0c2666f6340dbc7f42 for openstack/python-saharaclient Depends-on: I2a8caa859830b3416bfe54e4261dd3415ac5a76a for openstack/python-troveclient Depends-on: I324a3bd0c468a3e84f633497ad5c0d59c5ccc455 for openstack/python-tuskarclient Depends-on: Id54b2381f00d9905c4bb07821f54c5aaaa48d970 for openstack/python-zaqarclient Depends-on: I9d3e80d94795060d375aae30ce249513aae3fd97 for openstack/trove Change-Id: I1b100a426f84b91f9c5a9a857f420e36c209cbb4 --- oslo/__init__.py | 13 ---- oslo/i18n/__init__.py | 31 ---------- oslo/i18n/fixture.py | 13 ---- oslo/i18n/log.py | 13 ---- oslo_i18n/fixture.py | 2 +- oslo_i18n/tests/test_fixture.py | 15 ++--- setup.cfg | 4 -- tests/__init__.py | 0 tests/test_fixture.py | 38 ------------ tests/test_handler.py | 106 -------------------------------- tests/test_public_api.py | 44 ------------- tests/test_warning.py | 61 ------------------ 12 files changed, 6 insertions(+), 334 deletions(-) delete mode 100644 oslo/__init__.py delete mode 100644 oslo/i18n/__init__.py delete mode 100644 oslo/i18n/fixture.py delete mode 100644 oslo/i18n/log.py delete mode 100644 tests/__init__.py delete mode 100644 tests/test_fixture.py delete mode 100644 tests/test_handler.py delete mode 100644 tests/test_public_api.py delete mode 100644 tests/test_warning.py diff --git a/oslo/__init__.py b/oslo/__init__.py deleted file mode 100644 index dc130d6..0000000 --- a/oslo/__init__.py +++ /dev/null @@ -1,13 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -__import__('pkg_resources').declare_namespace(__name__) diff --git a/oslo/i18n/__init__.py b/oslo/i18n/__init__.py deleted file mode 100644 index e43c963..0000000 --- a/oslo/i18n/__init__.py +++ /dev/null @@ -1,31 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import warnings - -from oslo_i18n._factory import * -from oslo_i18n._gettextutils import * -from oslo_i18n._lazy import * -from oslo_i18n._translate import * - - -def deprecated(): - new_name = __name__.replace('.', '_') - warnings.warn( - ('The oslo namespace package is deprecated. Please use %s instead.' % - new_name), - DeprecationWarning, - stacklevel=3, - ) - - -deprecated() diff --git a/oslo/i18n/fixture.py b/oslo/i18n/fixture.py deleted file mode 100644 index eb08773..0000000 --- a/oslo/i18n/fixture.py +++ /dev/null @@ -1,13 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from oslo_i18n.fixture import * # noqa diff --git a/oslo/i18n/log.py b/oslo/i18n/log.py deleted file mode 100644 index ac18766..0000000 --- a/oslo/i18n/log.py +++ /dev/null @@ -1,13 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from oslo_i18n.log import * # noqa diff --git a/oslo_i18n/fixture.py b/oslo_i18n/fixture.py index 6dd2ee0..4352c79 100644 --- a/oslo_i18n/fixture.py +++ b/oslo_i18n/fixture.py @@ -156,7 +156,7 @@ class PrefixLazyTranslation(fixtures.Fixture): 'oslo_i18n._gettextutils.get_available_languages', lambda *x, **y: self.languages)) self.useFixture(fixtures.MonkeyPatch( - 'oslo.i18n.get_available_languages', + 'oslo_i18n.get_available_languages', lambda *x, **y: self.languages)) self.useFixture(fixtures.MonkeyPatch( 'oslo_i18n.get_available_languages', diff --git a/oslo_i18n/tests/test_fixture.py b/oslo_i18n/tests/test_fixture.py index 7bc29d1..db67033 100644 --- a/oslo_i18n/tests/test_fixture.py +++ b/oslo_i18n/tests/test_fixture.py @@ -15,8 +15,7 @@ from oslotest import base as test_base import six -from oslo import i18n as old_i18n -import oslo_i18n as new_i18n +import oslo_i18n from oslo_i18n import _gettextutils from oslo_i18n._i18n import _ from oslo_i18n import _lazy @@ -95,11 +94,9 @@ class PrefixLazyTranslationTest(test_base.BaseTestCase): expected_msg = 'oslo.i18n/' + default_lang + ': ' + raw_id1 msg1 = _(raw_id1) # noqa self.assertEqual([default_lang], - _gettextutils.get_available_languages('oslo')) + _gettextutils.get_available_languages('oslo.i18n')) self.assertEqual([default_lang], - old_i18n.get_available_languages('oslo')) - self.assertEqual([default_lang], - new_i18n.get_available_languages('oslo')) + oslo_i18n.get_available_languages('oslo.i18n')) self.assertEqual(expected_msg, _translate.translate(msg1)) def test_extra_lang(self): @@ -113,11 +110,9 @@ class PrefixLazyTranslationTest(test_base.BaseTestCase): expected_msg_en_ZZ = 'oslo.i18n/' + _FAKE_LANG + ': ' + raw_id1 msg1 = _(raw_id1) # noqa self.assertEqual(languages, - _gettextutils.get_available_languages('oslo')) + _gettextutils.get_available_languages('oslo.i18n')) self.assertEqual(languages, - old_i18n.get_available_languages('oslo')) - self.assertEqual(languages, - new_i18n.get_available_languages('oslo')) + oslo_i18n.get_available_languages('oslo.i18n')) self.assertEqual(expected_msg_en_US, _translate.translate(msg1)) self.assertEqual(expected_msg_en_ZZ, _translate.translate(msg1, diff --git a/setup.cfg b/setup.cfg index 8361b08..f949a6b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -21,11 +21,7 @@ classifier = [files] packages = - oslo - oslo.i18n oslo_i18n -namespace_packages = - oslo [build_sphinx] source-dir = doc/source diff --git a/tests/__init__.py b/tests/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/test_fixture.py b/tests/test_fixture.py deleted file mode 100644 index ece05ee..0000000 --- a/tests/test_fixture.py +++ /dev/null @@ -1,38 +0,0 @@ -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from oslotest import base as test_base -import six - -from oslo.i18n import fixture -from oslo_i18n import _message - - -class FixtureTest(test_base.BaseTestCase): - - def setUp(self): - super(FixtureTest, self).setUp() - self.trans_fixture = self.useFixture(fixture.Translation()) - - def test_lazy(self): - msg = self.trans_fixture.lazy('this is a lazy message') - self.assertIsInstance(msg, _message.Message) - self.assertEqual(msg.msgid, 'this is a lazy message') - - def test_immediate(self): - msg = self.trans_fixture.immediate('this is a lazy message') - # Python 2.6 does not have assertNotIsInstance - self.assertFalse(isinstance(msg, _message.Message)) - self.assertIsInstance(msg, six.text_type) - self.assertEqual(msg, u'this is a lazy message') diff --git a/tests/test_handler.py b/tests/test_handler.py deleted file mode 100644 index 539eb72..0000000 --- a/tests/test_handler.py +++ /dev/null @@ -1,106 +0,0 @@ -# Copyright 2012 Red Hat, Inc. -# Copyright 2013 IBM Corp. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import logging - -import mock -from oslotest import base as test_base -import six - -from oslo.i18n import log as i18n_log -from oslo_i18n import _message -from oslo_i18n.tests import fakes - -LOG = logging.getLogger(__name__) - - -class TranslationHandlerTestCase(test_base.BaseTestCase): - - def setUp(self): - super(TranslationHandlerTestCase, self).setUp() - - self.stream = six.StringIO() - self.destination_handler = logging.StreamHandler(self.stream) - self.translation_handler = i18n_log.TranslationHandler('zh_CN') - self.translation_handler.setTarget(self.destination_handler) - - self.logger = logging.getLogger('localehander_logger') - self.logger.setLevel(logging.DEBUG) - self.logger.addHandler(self.translation_handler) - - def test_set_formatter(self): - formatter = 'some formatter' - self.translation_handler.setFormatter(formatter) - self.assertEqual(formatter, self.translation_handler.target.formatter) - - @mock.patch('gettext.translation') - def test_emit_translated_message(self, mock_translation): - log_message = 'A message to be logged' - log_message_translation = 'A message to be logged in Chinese' - translations = {log_message: log_message_translation} - translations_map = {'zh_CN': translations} - translator = fakes.FakeTranslations.translator(translations_map) - mock_translation.side_effect = translator - - msg = _message.Message(log_message) - - self.logger.info(msg) - self.assertIn(log_message_translation, self.stream.getvalue()) - - @mock.patch('gettext.translation') - def test_emit_translated_message_with_args(self, mock_translation): - log_message = 'A message to be logged %s' - log_message_translation = 'A message to be logged in Chinese %s' - log_arg = 'Arg to be logged' - log_arg_translation = 'An arg to be logged in Chinese' - - translations = {log_message: log_message_translation, - log_arg: log_arg_translation} - translations_map = {'zh_CN': translations} - translator = fakes.FakeTranslations.translator(translations_map) - mock_translation.side_effect = translator - - msg = _message.Message(log_message) - arg = _message.Message(log_arg) - - self.logger.info(msg, arg) - self.assertIn(log_message_translation % log_arg_translation, - self.stream.getvalue()) - - @mock.patch('gettext.translation') - def test_emit_translated_message_with_named_args(self, mock_translation): - log_message = 'A message to be logged %(arg1)s $(arg2)s' - log_message_translation = 'Chinese msg to be logged %(arg1)s $(arg2)s' - log_arg_1 = 'Arg1 to be logged' - log_arg_1_translation = 'Arg1 to be logged in Chinese' - log_arg_2 = 'Arg2 to be logged' - log_arg_2_translation = 'Arg2 to be logged in Chinese' - - translations = {log_message: log_message_translation, - log_arg_1: log_arg_1_translation, - log_arg_2: log_arg_2_translation} - translations_map = {'zh_CN': translations} - translator = fakes.FakeTranslations.translator(translations_map) - mock_translation.side_effect = translator - - msg = _message.Message(log_message) - arg_1 = _message.Message(log_arg_1) - arg_2 = _message.Message(log_arg_2) - - self.logger.info(msg, {'arg1': arg_1, 'arg2': arg_2}) - translation = log_message_translation % {'arg1': log_arg_1_translation, - 'arg2': log_arg_2_translation} - self.assertIn(translation, self.stream.getvalue()) diff --git a/tests/test_public_api.py b/tests/test_public_api.py deleted file mode 100644 index afe9d34..0000000 --- a/tests/test_public_api.py +++ /dev/null @@ -1,44 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -"""A few tests that use the public API to ensure the imports work. -""" - -import unittest - -import mock - -from oslo import i18n -from oslo_i18n import _lazy - - -class PublicAPITest(unittest.TestCase): - - def test_create_factory(self): - i18n.TranslatorFactory('domain') - - def test_install(self): - with mock.patch('six.moves.builtins'): - i18n.install('domain') - - def test_get_available_languages(self): - i18n.get_available_languages('domains') - - def test_toggle_lazy(self): - original = _lazy.USE_LAZY - try: - i18n.enable_lazy(True) - i18n.enable_lazy(False) - finally: - i18n.enable_lazy(original) - - def test_translate(self): - i18n.translate(u'string') diff --git a/tests/test_warning.py b/tests/test_warning.py deleted file mode 100644 index f9aa54f..0000000 --- a/tests/test_warning.py +++ /dev/null @@ -1,61 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import imp -import os -import warnings - -import mock -from oslotest import base as test_base -import six - - -class DeprecationWarningTest(test_base.BaseTestCase): - - @mock.patch('warnings.warn') - def test_warning(self, mock_warn): - import oslo.i18n - imp.reload(oslo.i18n) - self.assertTrue(mock_warn.called) - args = mock_warn.call_args - self.assertIn('oslo_i18n', args[0][0]) - self.assertIn('deprecated', args[0][0]) - self.assertTrue(issubclass(args[0][1], DeprecationWarning)) - - def test_real_warning(self): - with warnings.catch_warnings(record=True) as warning_msgs: - warnings.resetwarnings() - warnings.simplefilter('always', DeprecationWarning) - import oslo.i18n - - # Use a separate function to get the stack level correct - # so we know the message points back to this file. This - # corresponds to an import or reload, which isn't working - # inside the test under Python 3.3. That may be due to a - # difference in the import implementation not triggering - # warnings properly when the module is reloaded, or - # because the warnings module is mostly implemented in C - # and something isn't cleanly resetting the global state - # used to track whether a warning needs to be - # emitted. Whatever the cause, we definitely see the - # warnings.warn() being invoked on a reload (see the test - # above) and warnings are reported on the console when we - # run the tests. A simpler test script run outside of - # testr does correctly report the warnings. - def foo(): - oslo.i18n.deprecated() - - foo() - self.assertEqual(1, len(warning_msgs)) - msg = warning_msgs[0] - self.assertIn('oslo_i18n', six.text_type(msg.message)) - self.assertEqual('test_warning.py', os.path.basename(msg.filename))