Skip to content

Commit 58996b5

Browse files
committed
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.
1 parent cd3aefe commit 58996b5

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is a corrupt wheel which _clearly_ is not a zip file.

tests/functional/test_install_wheel.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,20 @@ def test_install_from_future_wheel_version(script, tmpdir):
4545
result.assert_installed("futurewheel", without_egg_link=True, editable=False)
4646

4747

48-
def test_install_from_broken_wheel(script, data):
48+
@pytest.mark.parametrize(
49+
"wheel_name",
50+
[
51+
"brokenwheel-1.0-py2.py3-none-any.whl",
52+
"corruptwheel-1.0-py2.py3-none-any.whl",
53+
],
54+
)
55+
def test_install_from_broken_wheel(script, data, wheel_name):
4956
"""
5057
Test that installing a broken wheel fails properly
5158
"""
5259
from tests.lib import TestFailure
5360

54-
package = data.packages.joinpath("brokenwheel-1.0-py2.py3-none-any.whl")
61+
package = data.packages.joinpath(wheel_name)
5562
result = script.pip("install", package, "--no-index", expect_error=True)
5663
with pytest.raises(TestFailure):
5764
result.assert_installed("futurewheel", without_egg_link=True, editable=False)

tests/unit/test_wheel.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,15 @@ def test_wheel_root_is_purelib(text: str, expected: bool) -> None:
252252
assert wheel.wheel_root_is_purelib(message_from_string(text)) == expected
253253

254254

255+
def test_dist_from_broken_wheel_fails(data) -> None:
256+
from pip._internal.exceptions import InvalidWheel
257+
from pip._internal.metadata import get_wheel_distribution, FilesystemWheel
258+
259+
package = data.packages.joinpath("corruptwheel-1.0-py2.py3-none-any.whl")
260+
with pytest.raises(InvalidWheel):
261+
get_wheel_distribution(FilesystemWheel(package), "brokenwheel")
262+
263+
255264
class TestWheelFile:
256265
def test_unpack_wheel_no_flatten(self, tmpdir: Path) -> None:
257266
filepath = os.path.join(DATA_DIR, "packages", "meta-1.0-py2.py3-none-any.whl")

0 commit comments

Comments
 (0)