1
1
Fork 0
mirror of https://github.com/pypa/pip synced 2023-12-13 21:30:23 +01:00

Add tests for BadZipFile handling

Note that the functional test does not actually detect the behavioral
change of throwing unhandled `BadZipFile` → throwing unhandled
`InvalidWheel`, whereas the unit test does.
This commit is contained in:
Lukas Juhrich 2021-10-17 20:06:08 +02:00
parent cd3aefe7ad
commit 58996b5ddb
3 changed files with 19 additions and 2 deletions

View file

@ -0,0 +1 @@
This is a corrupt wheel which _clearly_ is not a zip file.

View file

@ -45,13 +45,20 @@ def test_install_from_future_wheel_version(script, tmpdir):
result.assert_installed("futurewheel", without_egg_link=True, editable=False)
def test_install_from_broken_wheel(script, data):
@pytest.mark.parametrize(
"wheel_name",
[
"brokenwheel-1.0-py2.py3-none-any.whl",
"corruptwheel-1.0-py2.py3-none-any.whl",
],
)
def test_install_from_broken_wheel(script, data, wheel_name):
"""
Test that installing a broken wheel fails properly
"""
from tests.lib import TestFailure
package = data.packages.joinpath("brokenwheel-1.0-py2.py3-none-any.whl")
package = data.packages.joinpath(wheel_name)
result = script.pip("install", package, "--no-index", expect_error=True)
with pytest.raises(TestFailure):
result.assert_installed("futurewheel", without_egg_link=True, editable=False)

View file

@ -252,6 +252,15 @@ def test_wheel_root_is_purelib(text: str, expected: bool) -> None:
assert wheel.wheel_root_is_purelib(message_from_string(text)) == expected
def test_dist_from_broken_wheel_fails(data) -> None:
from pip._internal.exceptions import InvalidWheel
from pip._internal.metadata import get_wheel_distribution, FilesystemWheel
package = data.packages.joinpath("corruptwheel-1.0-py2.py3-none-any.whl")
with pytest.raises(InvalidWheel):
get_wheel_distribution(FilesystemWheel(package), "brokenwheel")
class TestWheelFile:
def test_unpack_wheel_no_flatten(self, tmpdir: Path) -> None:
filepath = os.path.join(DATA_DIR, "packages", "meta-1.0-py2.py3-none-any.whl")