Skip to content

Commit c04eae6

Browse files
committed
lock: add tests
1 parent 2f5feef commit c04eae6

File tree

1 file changed

+237
-0
lines changed

1 file changed

+237
-0
lines changed

tests/functional/test_lock.py

Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
import sys
2+
import textwrap
3+
from pathlib import Path
4+
5+
from pip._internal.utils.urls import path_to_url
6+
7+
from ..lib import PipTestEnvironment, TestData
8+
9+
if sys.version_info >= (3, 11):
10+
import tomllib
11+
else:
12+
from pip._vendor import tomli as tomllib
13+
14+
15+
def test_lock_wheel_from_findlinks(
16+
script: PipTestEnvironment, shared_data: TestData, tmp_path: Path
17+
) -> None:
18+
"""Test locking a simple wheel package, to the default pylock.toml."""
19+
result = script.pip(
20+
"lock",
21+
"simplewheel==2.0",
22+
"--no-index",
23+
"--find-links",
24+
str(shared_data.root / "packages/"),
25+
expect_stderr=True, # for the experimental warning
26+
)
27+
result.did_create(Path("scratch") / "pylock.toml")
28+
pylock = tomllib.loads(script.scratch_path.joinpath("pylock.toml").read_text())
29+
assert pylock == {
30+
"created-by": "pip",
31+
"lock-version": "1.0",
32+
"packages": [
33+
{
34+
"name": "simplewheel",
35+
"version": "2.0",
36+
"wheels": [
37+
{
38+
"name": "simplewheel-2.0-1-py2.py3-none-any.whl",
39+
"url": path_to_url(
40+
str(
41+
shared_data.root
42+
/ "packages"
43+
/ "simplewheel-2.0-1-py2.py3-none-any.whl"
44+
)
45+
),
46+
"hashes": {
47+
"sha256": (
48+
"71e1ca6b16ae3382a698c284013f6650"
49+
"4f2581099b2ce4801f60e9536236ceee"
50+
)
51+
},
52+
}
53+
],
54+
},
55+
],
56+
}
57+
58+
59+
def test_lock_sdist_from_findlinks(
60+
script: PipTestEnvironment, shared_data: TestData
61+
) -> None:
62+
"""Test locking a simple wheel package, to the default pylock.toml."""
63+
result = script.pip(
64+
"lock",
65+
"simple==2.0",
66+
"--no-binary=simple",
67+
"--quiet",
68+
"--output=-",
69+
"--no-index",
70+
"--find-links",
71+
str(shared_data.root / "packages/"),
72+
expect_stderr=True, # for the experimental warning
73+
)
74+
pylock = tomllib.loads(result.stdout)
75+
assert pylock["packages"] == [
76+
{
77+
"name": "simple",
78+
"sdist": {
79+
"hashes": {
80+
"sha256": (
81+
"3a084929238d13bcd3bb928af04f3bac"
82+
"7ca2357d419e29f01459dc848e2d69a4"
83+
),
84+
},
85+
"name": "simple-2.0.tar.gz",
86+
"url": path_to_url(
87+
str(shared_data.root / "packages" / "simple-2.0.tar.gz")
88+
),
89+
},
90+
"version": "2.0",
91+
},
92+
]
93+
94+
95+
def test_lock_local_directory(
96+
script: PipTestEnvironment, shared_data: TestData, tmp_path: Path
97+
) -> None:
98+
project_path = tmp_path / "pkga"
99+
project_path.mkdir()
100+
project_path.joinpath("pyproject.toml").write_text(
101+
textwrap.dedent(
102+
"""\
103+
[project]
104+
name = "pkga"
105+
version = "1.0"
106+
"""
107+
)
108+
)
109+
result = script.pip(
110+
"lock",
111+
".",
112+
"--quiet",
113+
"--output=-",
114+
"--no-build-isolation", # to use the pre-installed setuptools
115+
"--no-index",
116+
"--find-links",
117+
str(shared_data.root / "packages/"),
118+
cwd=project_path,
119+
expect_stderr=True, # for the experimental warning
120+
)
121+
pylock = tomllib.loads(result.stdout)
122+
assert pylock["packages"] == [
123+
{
124+
"name": "pkga",
125+
"directory": {"path": "."},
126+
},
127+
]
128+
129+
130+
def test_lock_local_editable_with_dep(
131+
script: PipTestEnvironment, shared_data: TestData, tmp_path: Path
132+
) -> None:
133+
project_path = tmp_path / "pkga"
134+
project_path.mkdir()
135+
project_path.joinpath("pyproject.toml").write_text(
136+
textwrap.dedent(
137+
"""\
138+
[project]
139+
name = "pkga"
140+
version = "1.0"
141+
dependencies = ["simplewheel==2.0"]
142+
"""
143+
)
144+
)
145+
result = script.pip(
146+
"lock",
147+
"-e",
148+
".",
149+
"--quiet",
150+
"--output=-",
151+
"--no-build-isolation", # to use the pre-installed setuptools
152+
"--no-index",
153+
"--find-links",
154+
str(shared_data.root / "packages/"),
155+
cwd=project_path,
156+
expect_stderr=True, # for the experimental warning
157+
)
158+
pylock = tomllib.loads(result.stdout)
159+
assert pylock["packages"] == [
160+
{
161+
"name": "pkga",
162+
"directory": {"editable": True, "path": "."},
163+
},
164+
{
165+
"name": "simplewheel",
166+
"version": "2.0",
167+
"wheels": [
168+
{
169+
"name": "simplewheel-2.0-1-py2.py3-none-any.whl",
170+
"url": path_to_url(
171+
str(
172+
shared_data.root
173+
/ "packages"
174+
/ "simplewheel-2.0-1-py2.py3-none-any.whl"
175+
)
176+
),
177+
"hashes": {
178+
"sha256": (
179+
"71e1ca6b16ae3382a698c284013f6650"
180+
"4f2581099b2ce4801f60e9536236ceee"
181+
)
182+
},
183+
}
184+
],
185+
},
186+
]
187+
188+
189+
def test_lock_vcs(script: PipTestEnvironment, shared_data: TestData) -> None:
190+
result = script.pip(
191+
"lock",
192+
"git+https://github.com/pypa/[email protected]",
193+
"--quiet",
194+
"--output=-",
195+
"--no-build-isolation", # to use the pre-installed setuptools
196+
"--no-index",
197+
expect_stderr=True, # for the experimental warning
198+
)
199+
pylock = tomllib.loads(result.stdout)
200+
assert pylock["packages"] == [
201+
{
202+
"name": "pip-test-package",
203+
"vcs": {
204+
"type": "git",
205+
"url": "https://github.com/pypa/pip-test-package",
206+
"requested-revision": "0.1.2",
207+
"commit-id": "f1c1020ebac81f9aeb5c766ff7a772f709e696ee",
208+
},
209+
},
210+
]
211+
212+
213+
def test_lock_archive(script: PipTestEnvironment, shared_data: TestData) -> None:
214+
result = script.pip(
215+
"lock",
216+
"https://github.com/pypa/pip-test-package/tarball/0.1.2",
217+
"--quiet",
218+
"--output=-",
219+
"--no-build-isolation", # to use the pre-installed setuptools
220+
"--no-index",
221+
expect_stderr=True, # for the experimental warning
222+
)
223+
pylock = tomllib.loads(result.stdout)
224+
assert pylock["packages"] == [
225+
{
226+
"name": "pip-test-package",
227+
"archive": {
228+
"url": "https://github.com/pypa/pip-test-package/tarball/0.1.2",
229+
"hashes": {
230+
"sha256": (
231+
"1b176298e5ecd007da367bfda91aad3c"
232+
"4a6534227faceda087b00e5b14d596bf"
233+
),
234+
},
235+
},
236+
},
237+
]

0 commit comments

Comments
 (0)