def test_show_with_files_from_legacy( tmp_path: pathlib.Path, script: PipTestEnvironment, data: TestData ) -> None: """ Test listing files in the show command (legacy installed-files.txt). """ # Since 'pip install' now always tries to build a wheel from sdist, it # cannot properly generate a setup. The legacy code path is basically # 'setup.py install' plus installed-files.txt, which we manually generate. source_dir = tmp_path.joinpath("unpacked-sdist") setuptools_record = tmp_path.joinpath("installed-record.txt") untar_file(data.packages.joinpath("simple-1.0.tar.gz"), str(source_dir)) script.run( "python", "setup.py", "install", "--single-version-externally-managed", "--record", str(setuptools_record), cwd=source_dir, ) write_installed_files_from_setuptools_record( setuptools_record.read_text().splitlines(), root=None, req_description="simple==1.0", ) result = script.pip("show", "--files", "simple") lines = result.stdout.splitlines() assert "Cannot locate RECORD or installed-files.txt" not in lines[6], lines[6] assert re.search(r"Files:\n( .+\n)+", result.stdout) assert f" simple{os.sep}__init__.py" in lines[6:]
def test_unpack_tar_failure(self) -> None: """ Test unpacking a *.tar with file containing .. path and expect exception """ files = ["regular_file.txt", os.path.join("..", "outside_file.txt")] test_tar = self.make_tar_file("test_tar.tar", files) with pytest.raises(InstallationError) as e: untar_file(test_tar, self.tempdir) assert "trying to install outside target directory" in str(e.value)
def test_unpack_tar_failure(self): """ Test unpacking a *.tar with file containing .. path and expect exception """ files = ['regular_file.txt', os.path.join('..', 'outside_file.txt')] test_tar = self.make_tar_file('test_tar.tar', files) with pytest.raises(InstallationError) as e: untar_file(test_tar, self.tempdir) assert 'trying to install outside target directory' in str(e.value)
def test_unpack_tgz(self, data: TestData) -> None: """ Test unpacking a *.tgz, and setting execute permissions """ test_file = data.packages.joinpath("test_tar.tgz") untar_file(os.fspath(test_file), self.tempdir) self.confirm_files() # Check the timestamp of an extracted file file_txt_path = os.path.join(self.tempdir, "file.txt") mtime = time.gmtime(os.stat(file_txt_path).st_mtime) assert mtime[0:6] == (2013, 8, 16, 5, 13, 37), mtime
def test_unpack_tar_success(self) -> None: """ Test unpacking a *.tar with regular files, no file will be installed outside target directory after unpack so no exception raised """ files = [ "regular_file1.txt", os.path.join("dir", "dir_file1.txt"), os.path.join("dir", "..", "dir_file2.txt"), ] test_tar = self.make_tar_file("test_tar.tar", files) untar_file(test_tar, self.tempdir)
def test_unpack_tar_success(self): """ Test unpacking a *.tar with regular files, no file will be installed outside target directory after unpack so no exception raised """ files = [ 'regular_file1.txt', os.path.join('dir', 'dir_file1.txt'), os.path.join('dir', '..', 'dir_file2.txt'), ] test_tar = self.make_tar_file('test_tar.tar', files) untar_file(test_tar, self.tempdir)
def test_unpack_tar_unicode(tmpdir: Path) -> None: test_tar = tmpdir / "test.tar" # tarfile tries to decode incoming with tarfile.open(test_tar, "w", format=tarfile.PAX_FORMAT, encoding="utf-8") as f: metadata = tarfile.TarInfo("dir/åäö_日本語.py") f.addfile(metadata, io.BytesIO(b"hello world")) output_dir = tmpdir / "output" output_dir.mkdir() untar_file(os.fspath(test_tar), str(output_dir)) output_dir_name = str(output_dir) contents = os.listdir(output_dir_name) assert "åäö_日本語.py" in contents