def test_zipbuild_symlink_simple(tmp_path): """Symlinks are supported.""" testfile1 = tmp_path / 'real.txt' testfile1.write_bytes(b"123\x00456") testfile2 = tmp_path / 'link.txt' testfile2.symlink_to(testfile1) zip_filepath = tmp_path / 'testresult.zip' build_zip(zip_filepath, tmp_path, [testfile1, testfile2]) zf = zipfile.ZipFile(str(zip_filepath)) # str() for Py3.5 support assert sorted(x.filename for x in zf.infolist()) == ['link.txt', 'real.txt'] assert zf.read('real.txt') == b"123\x00456" assert zf.read('link.txt') == b"123\x00456"
def test_zipbuild_symlink_simple(tmp_path): """Symlinks are supported.""" testfile1 = tmp_path / "real.txt" testfile1.write_bytes(b"123\x00456") testfile2 = tmp_path / "link.txt" testfile2.symlink_to(testfile1) zip_filepath = tmp_path / "testresult.zip" build_zip(zip_filepath, tmp_path, [testfile1, testfile2]) zf = zipfile.ZipFile(zip_filepath) assert sorted(x.filename for x in zf.infolist()) == ["link.txt", "real.txt"] assert zf.read("real.txt") == b"123\x00456" assert zf.read("link.txt") == b"123\x00456"
def test_zipbuild_simple(tmp_path): """Build a bunch of files in the zip.""" testfile1 = tmp_path / 'foo.txt' testfile1.write_bytes(b"123\x00456") subdir = tmp_path / 'bar' subdir.mkdir() testfile2 = subdir / 'baz.txt' testfile2.write_bytes(b"mo\xc3\xb1o") zip_filepath = tmp_path / 'testresult.zip' build_zip(zip_filepath, tmp_path, [testfile1, testfile2]) zf = zipfile.ZipFile(str(zip_filepath)) # str() for Py3.5 support assert sorted(x.filename for x in zf.infolist()) == ['bar/baz.txt', 'foo.txt'] assert zf.read('foo.txt') == b"123\x00456" assert zf.read('bar/baz.txt') == b"mo\xc3\xb1o"
def test_zipbuild_simple(tmp_path): """Build a bunch of files in the zip.""" testfile1 = tmp_path / "foo.txt" testfile1.write_bytes(b"123\x00456") subdir = tmp_path / "bar" subdir.mkdir() testfile2 = subdir / "baz.txt" testfile2.write_bytes(b"mo\xc3\xb1o") zip_filepath = tmp_path / "testresult.zip" build_zip(zip_filepath, tmp_path, [testfile1, testfile2]) zf = zipfile.ZipFile(zip_filepath) assert sorted(x.filename for x in zf.infolist()) == ["bar/baz.txt", "foo.txt"] assert zf.read("foo.txt") == b"123\x00456" assert zf.read("bar/baz.txt") == b"mo\xc3\xb1o"
def test_zipbuild_symlink_outside(tmp_path): """No matter where the symlink points to.""" # outside the build dir testfile1 = tmp_path / "real.txt" testfile1.write_bytes(b"123\x00456") # inside the build dir build_dir = tmp_path / "somedir" build_dir.mkdir() testfile2 = build_dir / "link.txt" testfile2.symlink_to(testfile1) zip_filepath = tmp_path / "testresult.zip" build_zip(zip_filepath, build_dir) zf = zipfile.ZipFile(zip_filepath) assert sorted(x.filename for x in zf.infolist()) == ["link.txt"] assert zf.read("link.txt") == b"123\x00456"
def test_zipbuild_symlink_outside(tmp_path): """No matter where the symlink points to.""" # outside the build dir testfile1 = tmp_path / 'real.txt' testfile1.write_bytes(b"123\x00456") # inside the build dir build_dir = tmp_path / 'somedir' build_dir.mkdir() testfile2 = build_dir / 'link.txt' testfile2.symlink_to(testfile1) zip_filepath = tmp_path / 'testresult.zip' build_zip(zip_filepath, build_dir, [testfile2]) zf = zipfile.ZipFile(str(zip_filepath)) # str() for Py3.5 support assert sorted(x.filename for x in zf.infolist()) == ['link.txt'] assert zf.read('link.txt') == b"123\x00456"