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):
def setUp(self):
if not os.path.isdir(LOCALEDIR):
os.makedirs(LOCALEDIR)
fp = open(MOFILE, 'wb')
fp.write(base64.decodebytes(GNU_MO_DATA))
fp.close()
fp = open(UMOFILE, 'wb')
fp.write(base64.decodebytes(UMO_DATA))
fp.close()
fp = open(MMOFILE, 'wb')
fp.write(base64.decodebytes(MMO_DATA))
fp.close()
with open(MOFILE, 'wb') as fp:
fp.write(base64.decodebytes(GNU_MO_DATA))
with open(UMOFILE, 'wb') as fp:
fp.write(base64.decodebytes(UMO_DATA))
with open(MMOFILE, 'wb') as fp:
fp.write(base64.decodebytes(MMO_DATA))
self.env = support.EnvironmentVarGuard()
self.env['LANGUAGE'] = 'xx'
gettext._translations.clear()
......@@ -135,9 +132,8 @@ trggrkg zrffntr pngnybt yvoenel.''')
def test_the_alternative_interface(self):
eq = self.assertEqual
# test the alternative interface
fp = open(self.mofile, 'rb')
t = gettext.GNUTranslations(fp)
fp.close()
with open(self.mofile, 'rb') as fp:
t = gettext.GNUTranslations(fp)
# Install the translation object
t.install()
eq(_('nudge nudge'), 'wink wink')
......@@ -227,9 +223,8 @@ class PluralFormsTestCase(GettextBaseTest):
def test_plural_forms2(self):
eq = self.assertEqual
fp = open(self.mofile, 'rb')
t = gettext.GNUTranslations(fp)
fp.close()
with open(self.mofile, 'rb') as fp:
t = gettext.GNUTranslations(fp)
x = t.ngettext('There is %s file', 'There are %s files', 1)
eq(x, 'Hay %s fichero')
x = t.ngettext('There is %s file', 'There are %s files', 2)
......@@ -299,11 +294,8 @@ class PluralFormsTestCase(GettextBaseTest):
class UnicodeTranslationsTest(GettextBaseTest):
def setUp(self):
GettextBaseTest.setUp(self)
fp = open(UMOFILE, 'rb')
try:
with open(UMOFILE, 'rb') as fp:
self.t = gettext.GNUTranslations(fp)
finally:
fp.close()
self._ = self.t.gettext
def test_unicode_msgid(self):
......@@ -319,15 +311,12 @@ class UnicodeTranslationsTest(GettextBaseTest):
class WeirdMetadataTest(GettextBaseTest):
def setUp(self):
GettextBaseTest.setUp(self)
fp = open(MMOFILE, 'rb')
try:
with open(MMOFILE, 'rb') as fp:
try:
self.t = gettext.GNUTranslations(fp)
except:
self.tearDown()
raise
finally:
fp.close()
def test_weird_metadata(self):
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