diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2021-04-14 11:50:15 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2021-04-14 12:52:39 -0400 |
commit | 50cc68846f9b78a4d0984c5a9475203b3c87c1e0 (patch) | |
tree | cad38e5b57c4eebab80ad99c645396200a3b824c /igor.py | |
parent | 52e5088a39b4d47e124a79c357dd04233658c583 (diff) | |
download | python-coveragepy-git-50cc68846f9b78a4d0984c5a9475203b3c87c1e0.tar.gz |
test: improve zipfile test
Before this commit, the GetZipBytesTest.test_get_encoded_zip_files test
was flaky on Python 3.10.0a7. Since I had just added new files to the
common zip file, I tried splitting the newly added stuff into its own
file, and that seemed to fix the problem.
Diffstat (limited to 'igor.py')
-rw-r--r-- | igor.py | 70 |
1 files changed, 35 insertions, 35 deletions
@@ -217,41 +217,41 @@ def do_test_with_tracer(tracer, *runner_args): def do_zip_mods(): - """Build the zipmods.zip file.""" - zf = zipfile.ZipFile("tests/zipmods.zip", "w") - - # Take some files from disk. - zf.write("tests/covmodzip1.py", "covmodzip1.py") - zf.write("tests/zipsrc/zip1/__init__.py", "zip1/__init__.py") - zf.write("tests/zipsrc/zip1/zip1.py", "zip1/zip1.py") - - # The others will be various encodings. - source = textwrap.dedent(u"""\ - # coding: {encoding} - text = u"{text}" - ords = {ords} - assert [ord(c) for c in text] == ords - print(u"All OK with {encoding}") - """) - # These encodings should match the list in tests/test_python.py - details = [ - (u'utf8', u'ⓗⓔⓛⓛⓞ, ⓦⓞⓡⓛⓓ'), - (u'gb2312', u'你好,世界'), - (u'hebrew', u'שלום, עולם'), - (u'shift_jis', u'こんにちは世界'), - (u'cp1252', u'“hi”'), - ] - for encoding, text in details: - filename = 'encoded_{}.py'.format(encoding) - ords = [ord(c) for c in text] - source_text = source.format(encoding=encoding, text=text, ords=ords) - zf.writestr(filename, source_text.encode(encoding)) - - zf.close() - - zf = zipfile.ZipFile("tests/covmain.zip", "w") - zf.write("coverage/__main__.py", "__main__.py") - zf.close() + """Build the zip files needed for tests.""" + with zipfile.ZipFile("tests/zipmods.zip", "w") as zf: + + # Take some files from disk. + zf.write("tests/covmodzip1.py", "covmodzip1.py") + + # The others will be various encodings. + source = textwrap.dedent(u"""\ + # coding: {encoding} + text = u"{text}" + ords = {ords} + assert [ord(c) for c in text] == ords + print(u"All OK with {encoding}") + encoding = "{encoding}" + """) + # These encodings should match the list in tests/test_python.py + details = [ + (u'utf8', u'ⓗⓔⓛⓛⓞ, ⓦⓞⓡⓛⓓ'), + (u'gb2312', u'你好,世界'), + (u'hebrew', u'שלום, עולם'), + (u'shift_jis', u'こんにちは世界'), + (u'cp1252', u'“hi”'), + ] + for encoding, text in details: + filename = 'encoded_{}.py'.format(encoding) + ords = [ord(c) for c in text] + source_text = source.format(encoding=encoding, text=text, ords=ords) + zf.writestr(filename, source_text.encode(encoding)) + + with zipfile.ZipFile("tests/zip1.zip", "w") as zf: + zf.write("tests/zipsrc/zip1/__init__.py", "zip1/__init__.py") + zf.write("tests/zipsrc/zip1/zip1.py", "zip1/zip1.py") + + with zipfile.ZipFile("tests/covmain.zip", "w") as zf: + zf.write("coverage/__main__.py", "__main__.py") def do_check_eol(): |