-
-
Notifications
You must be signed in to change notification settings - Fork 600
/
test_repository_local.py
90 lines (70 loc) · 3.11 KB
/
test_repository_local.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import copy
import pytest
from piptools.repositories.local import LocalRequirementsRepository
from piptools.utils import name_from_req
from tests.conftest import FakeRepository
EXPECTED = {"sha256:5e6071ee6e4c59e0d0408d366fe9b66781d2cf01be9a6e19a2433bb3c5336330"}
def test_get_hashes_local_repository_cache_miss(
capfd, pip_conf, from_line, pypi_repository
):
existing_pins = {}
local_repository = LocalRequirementsRepository(existing_pins, pypi_repository)
with local_repository.allow_all_wheels():
hashes = local_repository.get_hashes(from_line("small-fake-a==0.1"))
assert hashes == EXPECTED
captured = capfd.readouterr()
assert captured.out == ""
assert (
captured.err.strip()
== "Couldn't get hashes from PyPI, fallback to hashing files"
)
def test_get_hashes_local_repository_cache_hit(from_line, repository):
# Create an install requirement with the hashes included in its options
options = {"hashes": {"sha256": [entry.split(":")[1] for entry in EXPECTED]}}
req = from_line("small-fake-a==0.1", options=options)
existing_pins = {name_from_req(req): req}
# Use fake repository so that we know the hashes are coming from cache
local_repository = LocalRequirementsRepository(existing_pins, repository)
with local_repository.allow_all_wheels():
hashes = local_repository.get_hashes(from_line("small-fake-a==0.1"))
assert hashes == EXPECTED
NONSENSE = {"sha256:NONSENSE"}
@pytest.mark.parametrize(
("reuse_hashes", "expected"), ((True, NONSENSE), (False, EXPECTED))
)
def test_toggle_reuse_hashes_local_repository(
capfd, pip_conf, from_line, pypi_repository, reuse_hashes, expected
):
# Create an install requirement with the hashes included in its options
options = {"hashes": {"sha256": [entry.split(":")[1] for entry in NONSENSE]}}
req = from_line("small-fake-a==0.1", options=options)
existing_pins = {name_from_req(req): req}
local_repository = LocalRequirementsRepository(
existing_pins, pypi_repository, reuse_hashes=reuse_hashes
)
with local_repository.allow_all_wheels():
assert local_repository.get_hashes(from_line("small-fake-a==0.1")) == expected
captured = capfd.readouterr()
assert captured.out == ""
if reuse_hashes:
assert captured.err == ""
else:
assert (
captured.err.strip()
== "Couldn't get hashes from PyPI, fallback to hashing files"
)
class FakeRepositoryChecksForCopy(FakeRepository):
def __init__(self):
super(FakeRepositoryChecksForCopy, self).__init__()
self.copied = []
def copy_ireq_dependencies(self, source, dest):
self.copied.append(source)
def test_local_repository_copy_ireq_dependencies(from_line):
# Ensure that local repository forwards any messages to update its state
# of ireq dependencies.
checker = FakeRepositoryChecksForCopy()
local_repository = LocalRequirementsRepository({}, checker)
src = from_line("small-fake-a==0.1")
dest = copy.deepcopy(src)
local_repository.copy_ireq_dependencies(src, dest)
assert src in checker.copied