Skip to content

Commit 179ccbe

Browse files
committed
Add tests for empty hash intersection
1 parent 753ad4d commit 179ccbe

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

tests/functional/test_new_resolver_hashes.py

+88
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,91 @@ def test_new_resolver_hash_intersect_from_constraint(script):
123123
"(1 matches, 0 no digest): discarding 1 non-matches"
124124
).format(name=u"base")
125125
assert message in result.stdout, str(result)
126+
127+
128+
@pytest.mark.parametrize(
129+
"requirements_template, constraints_template",
130+
[
131+
(
132+
"""
133+
base==0.1.0 --hash=sha256:{sdist_hash}
134+
base==0.1.0 --hash=sha256:{wheel_hash}
135+
""",
136+
"",
137+
),
138+
(
139+
"base==0.1.0 --hash=sha256:{sdist_hash}",
140+
"base==0.1.0 --hash=sha256:{wheel_hash}",
141+
),
142+
],
143+
ids=["both-requirements", "one-each"],
144+
)
145+
def test_new_resolver_hash_intersect_empty(
146+
script, requirements_template, constraints_template,
147+
):
148+
find_links = _create_find_links(script)
149+
150+
constraints_txt = script.scratch_path / "constraints.txt"
151+
constraints_txt.write_text(
152+
constraints_template.format(
153+
sdist_hash=find_links.sdist_hash,
154+
wheel_hash=find_links.wheel_hash,
155+
),
156+
)
157+
158+
requirements_txt = script.scratch_path / "requirements.txt"
159+
requirements_txt.write_text(
160+
requirements_template.format(
161+
sdist_hash=find_links.sdist_hash,
162+
wheel_hash=find_links.wheel_hash,
163+
),
164+
)
165+
166+
result = script.pip(
167+
"install",
168+
"--use-feature=2020-resolver",
169+
"--no-cache-dir",
170+
"--no-deps",
171+
"--no-index",
172+
"--find-links", find_links.index_html,
173+
"--constraint", constraints_txt,
174+
"--requirement", requirements_txt,
175+
expect_error=True,
176+
)
177+
178+
assert (
179+
"THESE PACKAGES DO NOT MATCH THE HASHES FROM THE REQUIREMENTS FILE."
180+
) in result.stderr, str(result)
181+
182+
183+
def test_new_resolver_hash_intersect_empty_from_constraint(script):
184+
find_links = _create_find_links(script)
185+
186+
constraints_txt = script.scratch_path / "constraints.txt"
187+
constraints_txt.write_text(
188+
"""
189+
base==0.1.0 --hash=sha256:{sdist_hash}
190+
base==0.1.0 --hash=sha256:{wheel_hash}
191+
""".format(
192+
sdist_hash=find_links.sdist_hash,
193+
wheel_hash=find_links.wheel_hash,
194+
),
195+
)
196+
197+
result = script.pip(
198+
"install",
199+
"--use-feature=2020-resolver",
200+
"--no-cache-dir",
201+
"--no-deps",
202+
"--no-index",
203+
"--find-links", find_links.index_html,
204+
"--constraint", constraints_txt,
205+
"base==0.1.0",
206+
expect_error=True,
207+
)
208+
209+
message = (
210+
"Hashes are required in --require-hashes mode, but they are missing "
211+
"from some requirements."
212+
)
213+
assert message in result.stderr, str(result)

0 commit comments

Comments
 (0)