MCPcopy
hub / github.com/pex-tool/pex / test_header_isolation

Function test_header_isolation

tests/test_zip_utils.py:82–108  ·  view source on GitHub ↗
(
    tmpdir,  # type: Any
    header,  # type: bytes
    comment,  # type: bytes
)

Source from the content-addressed store, hash-verified

80 [pytest.param(b"", id="no comment"), pytest.param(b"Phil Katz was here.", id="comment")],
81)
82def 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
111def test_sandwich(tmpdir):

Callers

nothing calls this directly

Calls 7

create_zipappFunction · 0.85
assert_zipappFunction · 0.85
isolate_headerMethod · 0.80
isolate_zipMethod · 0.80
joinMethod · 0.45
writeMethod · 0.45
loadMethod · 0.45

Tested by

no test coverage detected