(
tmpdir, # type: Any
header, # type: bytes
comment, # type: bytes
)
| 80 | [pytest.param(b"", id="no comment"), pytest.param(b"Phil Katz was here.", id="comment")], |
| 81 | ) |
| 82 | def test_header_isolation( |
| 83 | tmpdir, # type: Any |
| 84 | header, # type: bytes |
| 85 | comment, # type: bytes |
| 86 | ): |
| 87 | # type: (...) -> None |
| 88 | |
| 89 | zip_file = create_zipapp(tmpdir, comment=comment) |
| 90 | |
| 91 | zip_file_with_header = os.path.join(str(tmpdir), "zip_file_with_header") |
| 92 | with open(zip_file, "rb") as in_fp, open(zip_file_with_header, "wb") as out_fp: |
| 93 | out_fp.write(header) |
| 94 | shutil.copyfileobj(in_fp, out_fp) |
| 95 | |
| 96 | zf = Zip.load(zip_file_with_header) |
| 97 | assert bool(header) == zf.has_header |
| 98 | |
| 99 | with BytesIO() as out_fp: |
| 100 | assert b"" == zf.isolate_header(out_fp) |
| 101 | assert header == out_fp.getvalue() |
| 102 | |
| 103 | out_zip = os.path.join(str(tmpdir), "out.zip") |
| 104 | with open(out_zip, "wb") as out_fp: |
| 105 | zf.isolate_zip(out_fp) |
| 106 | |
| 107 | assert filecmp.cmp(zip_file, out_zip, shallow=False) |
| 108 | assert_zipapp(out_zip, expected_comment=comment) |
| 109 | |
| 110 | |
| 111 | def test_sandwich(tmpdir): |
nothing calls this directly
no test coverage detected