diff options
author | Joshua Harlow <harlowja@gmail.com> | 2016-03-24 11:39:22 -0700 |
---|---|---|
committer | Davanum Srinivas (dims) <davanum@gmail.com> | 2016-03-24 21:48:18 +0000 |
commit | 2672fa283a2bf5d49899e8f527c30cbf7dd1524b (patch) | |
tree | c4fec7787ba6699733dfd876a4116e9ba865fb52 | |
parent | aaa60997dc2b7414d4b1369dae32d2625f60d9e3 (diff) | |
download | oslo-i18n-2672fa283a2bf5d49899e8f527c30cbf7dd1524b.tar.gz |
Better isolate tests and fixtures from environment
Remove a duplicate monkey patch as well as ensure that the
environment the test is running in does not influence the
test results (especially in regard to locale settings).
Change-Id: I2451240148bb329e0ff9aa01f279bde9711e599f
-rw-r--r-- | oslo_i18n/_message.py | 5 | ||||
-rw-r--r-- | oslo_i18n/fixture.py | 8 |
2 files changed, 8 insertions, 5 deletions
diff --git a/oslo_i18n/_message.py b/oslo_i18n/_message.py index d03337d..0bd83c5 100644 --- a/oslo_i18n/_message.py +++ b/oslo_i18n/_message.py @@ -103,7 +103,10 @@ class Message(six.text_type): if not desired_locale: system_locale = locale.getdefaultlocale() # If the system locale is not available to the runtime use English - desired_locale = system_locale[0] or 'en_US' + if not system_locale or not system_locale[0]: + desired_locale = 'en_US' + else: + desired_locale = system_locale[0] locale_dir = os.environ.get( _locale.get_locale_dir_variable_name(domain) diff --git a/oslo_i18n/fixture.py b/oslo_i18n/fixture.py index 4352c79..35dc694 100644 --- a/oslo_i18n/fixture.py +++ b/oslo_i18n/fixture.py @@ -145,9 +145,10 @@ class PrefixLazyTranslation(fixtures.Fixture): _DEFAULT_LANG = 'en_US' - def __init__(self, languages=None): + def __init__(self, languages=None, locale=None): super(PrefixLazyTranslation, self).__init__() self.languages = languages or [PrefixLazyTranslation._DEFAULT_LANG] + self.locale = locale def setUp(self): super(PrefixLazyTranslation, self).setUp() @@ -158,8 +159,7 @@ class PrefixLazyTranslation(fixtures.Fixture): self.useFixture(fixtures.MonkeyPatch( 'oslo_i18n.get_available_languages', lambda *x, **y: self.languages)) - self.useFixture(fixtures.MonkeyPatch( - 'oslo_i18n.get_available_languages', - lambda *x, **y: self.languages)) self.useFixture(fixtures.MonkeyPatch('gettext.translation', _prefix_translations)) + self.useFixture(fixtures.MonkeyPatch('locale.getdefaultlocale', + lambda *x, **y: self.locale)) |