Make tests clean up after themselves better. This means:
* call tearDown when Setup is called * shutil.rmtree the root of the created directory instead of just the leaf directory * set the LANGUAGE environment variable to what it was originally and not assume 'en'.
This commit is contained in:
parent
caf1c9dfe7
commit
4aebbb0449
@ -46,6 +46,10 @@ ZC1CeTogbWFudWFsbHkKAMKkeXoA
|
|||||||
LOCALEDIR = os.path.join('xx', 'LC_MESSAGES')
|
LOCALEDIR = os.path.join('xx', 'LC_MESSAGES')
|
||||||
MOFILE = os.path.join(LOCALEDIR, 'gettext.mo')
|
MOFILE = os.path.join(LOCALEDIR, 'gettext.mo')
|
||||||
UMOFILE = os.path.join(LOCALEDIR, 'ugettext.mo')
|
UMOFILE = os.path.join(LOCALEDIR, 'ugettext.mo')
|
||||||
|
try:
|
||||||
|
LANG = os.environ['LANGUAGE']
|
||||||
|
except:
|
||||||
|
LANG = 'en'
|
||||||
|
|
||||||
|
|
||||||
class GettextBaseTest(unittest.TestCase):
|
class GettextBaseTest(unittest.TestCase):
|
||||||
@ -60,8 +64,8 @@ class GettextBaseTest(unittest.TestCase):
|
|||||||
os.environ['LANGUAGE'] = 'xx'
|
os.environ['LANGUAGE'] = 'xx'
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
os.environ['LANGUAGE'] = 'en'
|
os.environ['LANGUAGE'] = LANG
|
||||||
shutil.rmtree(LOCALEDIR)
|
shutil.rmtree(os.path.split(LOCALEDIR)[0])
|
||||||
|
|
||||||
|
|
||||||
class GettextTestCase1(GettextBaseTest):
|
class GettextTestCase1(GettextBaseTest):
|
||||||
@ -71,6 +75,9 @@ class GettextTestCase1(GettextBaseTest):
|
|||||||
self.mofile = MOFILE
|
self.mofile = MOFILE
|
||||||
gettext.install('gettext', self.localedir)
|
gettext.install('gettext', self.localedir)
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
GettextBaseTest.tearDown(self)
|
||||||
|
|
||||||
def test_some_translations(self):
|
def test_some_translations(self):
|
||||||
eq = self.assertEqual
|
eq = self.assertEqual
|
||||||
# test some translations
|
# test some translations
|
||||||
@ -137,6 +144,9 @@ class GettextTestCase2(GettextBaseTest):
|
|||||||
# For convenience
|
# For convenience
|
||||||
self._ = gettext.gettext
|
self._ = gettext.gettext
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
GettextBaseTest.tearDown(self)
|
||||||
|
|
||||||
def test_bindtextdomain(self):
|
def test_bindtextdomain(self):
|
||||||
self.assertEqual(gettext.bindtextdomain('gettext'), self.localedir)
|
self.assertEqual(gettext.bindtextdomain('gettext'), self.localedir)
|
||||||
|
|
||||||
@ -191,6 +201,9 @@ class PluralFormsTestCase(GettextBaseTest):
|
|||||||
GettextBaseTest.setUp(self)
|
GettextBaseTest.setUp(self)
|
||||||
self.mofile = MOFILE
|
self.mofile = MOFILE
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
GettextBaseTest.tearDown(self)
|
||||||
|
|
||||||
def test_plural_forms1(self):
|
def test_plural_forms1(self):
|
||||||
eq = self.assertEqual
|
eq = self.assertEqual
|
||||||
x = gettext.ngettext('There is %s file', 'There are %s files', 1)
|
x = gettext.ngettext('There is %s file', 'There are %s files', 1)
|
||||||
@ -279,6 +292,9 @@ class UnicodeTranslationsTest(GettextBaseTest):
|
|||||||
fp.close()
|
fp.close()
|
||||||
self._ = self.t.ugettext
|
self._ = self.t.ugettext
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
GettextBaseTest.tearDown(self)
|
||||||
|
|
||||||
def test_unicode_msgid(self):
|
def test_unicode_msgid(self):
|
||||||
unless = self.failUnless
|
unless = self.failUnless
|
||||||
unless(isinstance(self._(''), unicode))
|
unless(isinstance(self._(''), unicode))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user