Kaydet (Commit) 7fa886df authored tarafından Éric Araujo's avatar Éric Araujo

Prevent ResourceWarnings in test_gettext

üst 37a89334
...@@ -64,15 +64,12 @@ class GettextBaseTest(unittest.TestCase): ...@@ -64,15 +64,12 @@ class GettextBaseTest(unittest.TestCase):
def setUp(self): def setUp(self):
if not os.path.isdir(LOCALEDIR): if not os.path.isdir(LOCALEDIR):
os.makedirs(LOCALEDIR) os.makedirs(LOCALEDIR)
fp = open(MOFILE, 'wb') with open(MOFILE, 'wb') as fp:
fp.write(base64.decodebytes(GNU_MO_DATA)) fp.write(base64.decodebytes(GNU_MO_DATA))
fp.close() with open(UMOFILE, 'wb') as fp:
fp = open(UMOFILE, 'wb') fp.write(base64.decodebytes(UMO_DATA))
fp.write(base64.decodebytes(UMO_DATA)) with open(MMOFILE, 'wb') as fp:
fp.close() fp.write(base64.decodebytes(MMO_DATA))
fp = open(MMOFILE, 'wb')
fp.write(base64.decodebytes(MMO_DATA))
fp.close()
self.env = support.EnvironmentVarGuard() self.env = support.EnvironmentVarGuard()
self.env['LANGUAGE'] = 'xx' self.env['LANGUAGE'] = 'xx'
gettext._translations.clear() gettext._translations.clear()
...@@ -135,9 +132,8 @@ trggrkg zrffntr pngnybt yvoenel.''') ...@@ -135,9 +132,8 @@ trggrkg zrffntr pngnybt yvoenel.''')
def test_the_alternative_interface(self): def test_the_alternative_interface(self):
eq = self.assertEqual eq = self.assertEqual
# test the alternative interface # test the alternative interface
fp = open(self.mofile, 'rb') with open(self.mofile, 'rb') as fp:
t = gettext.GNUTranslations(fp) t = gettext.GNUTranslations(fp)
fp.close()
# Install the translation object # Install the translation object
t.install() t.install()
eq(_('nudge nudge'), 'wink wink') eq(_('nudge nudge'), 'wink wink')
...@@ -227,9 +223,8 @@ class PluralFormsTestCase(GettextBaseTest): ...@@ -227,9 +223,8 @@ class PluralFormsTestCase(GettextBaseTest):
def test_plural_forms2(self): def test_plural_forms2(self):
eq = self.assertEqual eq = self.assertEqual
fp = open(self.mofile, 'rb') with open(self.mofile, 'rb') as fp:
t = gettext.GNUTranslations(fp) t = gettext.GNUTranslations(fp)
fp.close()
x = t.ngettext('There is %s file', 'There are %s files', 1) x = t.ngettext('There is %s file', 'There are %s files', 1)
eq(x, 'Hay %s fichero') eq(x, 'Hay %s fichero')
x = t.ngettext('There is %s file', 'There are %s files', 2) x = t.ngettext('There is %s file', 'There are %s files', 2)
...@@ -299,11 +294,8 @@ class PluralFormsTestCase(GettextBaseTest): ...@@ -299,11 +294,8 @@ class PluralFormsTestCase(GettextBaseTest):
class UnicodeTranslationsTest(GettextBaseTest): class UnicodeTranslationsTest(GettextBaseTest):
def setUp(self): def setUp(self):
GettextBaseTest.setUp(self) GettextBaseTest.setUp(self)
fp = open(UMOFILE, 'rb') with open(UMOFILE, 'rb') as fp:
try:
self.t = gettext.GNUTranslations(fp) self.t = gettext.GNUTranslations(fp)
finally:
fp.close()
self._ = self.t.gettext self._ = self.t.gettext
def test_unicode_msgid(self): def test_unicode_msgid(self):
...@@ -319,15 +311,12 @@ class UnicodeTranslationsTest(GettextBaseTest): ...@@ -319,15 +311,12 @@ class UnicodeTranslationsTest(GettextBaseTest):
class WeirdMetadataTest(GettextBaseTest): class WeirdMetadataTest(GettextBaseTest):
def setUp(self): def setUp(self):
GettextBaseTest.setUp(self) GettextBaseTest.setUp(self)
fp = open(MMOFILE, 'rb') with open(MMOFILE, 'rb') as fp:
try:
try: try:
self.t = gettext.GNUTranslations(fp) self.t = gettext.GNUTranslations(fp)
except: except:
self.tearDown() self.tearDown()
raise raise
finally:
fp.close()
def test_weird_metadata(self): def test_weird_metadata(self):
info = self.t.info() info = self.t.info()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment