Skip to content

Commit 9f247c9

Browse files
add test for hash mismatch
1 parent bfd547f commit 9f247c9

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/functional/test_fast_deps.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
import json
33
import os
44
import pathlib
5+
import re
56
from os.path import basename
67
from typing import Iterable
78

89
from pip._vendor.packaging.utils import canonicalize_name
910
from pytest import mark
1011

12+
from pip._internal.utils.misc import hash_file
1113
from tests.lib import PipTestEnvironment, TestData, TestPipResult
1214

1315

@@ -101,3 +103,31 @@ def test_hash_mismatch(script: PipTestEnvironment, tmp_path: pathlib.Path) -> No
101103
expect_error=True,
102104
)
103105
assert "DO NOT MATCH THE HASHES" in result.stderr
106+
107+
108+
@mark.network
109+
def test_hash_mismatch_existing_download(
110+
script: PipTestEnvironment, tmp_path: pathlib.Path
111+
) -> None:
112+
reqs = tmp_path / "requirements.txt"
113+
reqs.write_text("idna==2.10")
114+
dl_dir = tmp_path / "downloads"
115+
dl_dir.mkdir()
116+
idna_wheel = dl_dir / "idna-2.10-py2.py3-none-any.whl"
117+
idna_wheel.write_text("asdf")
118+
result = script.pip(
119+
"download",
120+
"--use-feature=fast-deps",
121+
"-r",
122+
str(reqs),
123+
"-d",
124+
str(dl_dir),
125+
allow_stderr_warning=True,
126+
)
127+
assert re.search(
128+
r"WARNING: Previously-downloaded file.*has bad hash", result.stderr
129+
)
130+
assert (
131+
hash_file(str(idna_wheel))[0].hexdigest()
132+
== "b97d804b1e9b523befed77c48dacec60e6dcb0b5391d57af6a65a312a90648c0"
133+
)

0 commit comments

Comments
 (0)