summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_gettext.py
diff options
context:
space:
mode:
authorÉric Araujo <merwok@netwok.org>2010-11-06 04:11:59 (GMT)
committerÉric Araujo <merwok@netwok.org>2010-11-06 04:11:59 (GMT)
commit7fa886df3622bbedbeb9c2486a8af5f05334a928 (patch)
tree375fa9f259c7893cb0dea26ce920f42f35cdc104 /Lib/test/test_gettext.py
parent37a89334da1fbe5b30f5a03a97b8f8c2a59adc1b (diff)
downloadcpython-7fa886df3622bbedbeb9c2486a8af5f05334a928.zip
cpython-7fa886df3622bbedbeb9c2486a8af5f05334a928.tar.gz
cpython-7fa886df3622bbedbeb9c2486a8af5f05334a928.tar.bz2
Prevent ResourceWarnings in test_gettext
Diffstat (limited to 'Lib/test/test_gettext.py')
-rw-r--r--Lib/test/test_gettext.py35
1 files changed, 12 insertions, 23 deletions
diff --git a/Lib/test/test_gettext.py b/Lib/test/test_gettext.py
index 634c607..5456948 100644
--- a/Lib/test/test_gettext.py
+++ b/Lib/test/test_gettext.py
@@ -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()