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
This commit is contained in:
Joshua Harlow 2016-03-24 11:39:22 -07:00
parent 9f0a3c3df9
commit 1dc7cb7992
2 changed files with 8 additions and 5 deletions

View File

@ -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)

View File

@ -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))