Skip to content

Commit

Permalink
Add tests for BadZipFile handling
Browse files Browse the repository at this point in the history
Note that the functional test does not actually detect the behavioral
change of throwing unhandled `BadZipFile` → throwing unhandled
`InvalidWheel`, whereas the unit test does.
  • Loading branch information
lukasjuhrich committed Oct 17, 2021
1 parent 0154511 commit 22c3c6b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions tests/data/packages/corruptwheel-1.0-py2.py3-none-any.whl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is a corrupt wheel which _clearly_ is not a zip file.
11 changes: 9 additions & 2 deletions tests/functional/test_install_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 22c3c6b

Please sign in to comment.