Refactoring testcases to reduce ResourceWarning (refs: #1409)

This commit is contained in:
Takeshi KOMIYA 2016-01-10 01:04:38 +09:00
parent 7894f0bd9c
commit 053d7806fe
2 changed files with 13 additions and 7 deletions

View File

@ -41,6 +41,11 @@ def gen_with_intl_app(builder, confoverrides={}, *args, **kw):
return gen_with_app(builder, *args, **default_kw)
def read_po(pathname):
with pathname.open() as f:
return pofile.read_po(f)
def setup_module():
if not root.exists():
(rootdir / 'roots' / 'test-intl').copytree(root)
@ -310,22 +315,22 @@ def test_gettext_builder(app, status, warning):
app.builder.build_all()
# --- definition terms: regression test for #2198, #2205
expect = pofile.read_po((app.srcdir / 'definition_terms.po').open())
actual = pofile.read_po((app.outdir / 'definition_terms.pot').open())
expect = read_po(app.srcdir / 'definition_terms.po')
actual = read_po(app.outdir / 'definition_terms.pot')
for expect_msg in [m for m in expect if m.id]:
yield assert_in, expect_msg.id, [m.id for m in actual if m.id]
# --- glossary terms: regression test for #1090
expect = pofile.read_po((app.srcdir / 'glossary_terms.po').open())
actual = pofile.read_po((app.outdir / 'glossary_terms.pot').open())
expect = read_po(app.srcdir / 'glossary_terms.po')
actual = read_po(app.outdir / 'glossary_terms.pot')
for expect_msg in [m for m in expect if m.id]:
yield assert_in, expect_msg.id, [m.id for m in actual if m.id]
warnings = warning.getvalue().replace(os.sep, '/')
yield assert_not_in, 'term not in glossary', warnings
# --- glossary term inconsistencies: regression test for #1090
expect = pofile.read_po((app.srcdir / 'glossary_terms_inconsistency.po').open())
actual = pofile.read_po((app.outdir / 'glossary_terms_inconsistency.pot').open())
expect = read_po(app.srcdir / 'glossary_terms_inconsistency.po')
actual = read_po(app.outdir / 'glossary_terms_inconsistency.pot')
for expect_msg in [m for m in expect if m.id]:
yield assert_in, expect_msg.id, [m.id for m in actual if m.id]

View File

@ -55,7 +55,8 @@ def test_catalog_write_mo(dir):
cat = i18n.CatalogInfo(dir, 'test', 'utf-8')
cat.write_mo('en')
assert path.exists(cat.mo_path)
assert read_mo(open(cat.mo_path, 'rb')) is not None
with open(cat.mo_path, 'rb') as f:
assert read_mo(f) is not None
@with_tempdir