Skip to content

Commit 8f389d3

Browse files
committed
Add initial functional tests for dependency-groups
This initial suite of tests is modeled fairly closely on existing tests for requirements files. Tests cover the following cases: - installing an empty dependency group (and nothing else) - installing from a simple / straightforward group - installing from multiple groups in a single command - normalizing names from the CLI and pyproject.toml to match - applying a constraints file to a dependency-group install
1 parent 99df94a commit 8f389d3

File tree

2 files changed

+110
-0
lines changed

2 files changed

+110
-0
lines changed

tests/functional/test_install.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,21 @@ def test_install_exit_status_code_when_blank_requirements_file(
318318
script.pip("install", "-r", "blank.txt")
319319

320320

321+
def test_install_exit_status_code_when_empty_dependency_group(
322+
script: PipTestEnvironment,
323+
) -> None:
324+
"""
325+
Test install exit status code is 0 when empty dependency group specified
326+
"""
327+
script.scratch_path.joinpath("pyproject.toml").write_text(
328+
"""\
329+
[dependency-groups]
330+
empty = []
331+
"""
332+
)
333+
script.pip("install", "--group", "empty")
334+
335+
321336
@pytest.mark.network
322337
def test_basic_install_from_pypi(script: PipTestEnvironment) -> None:
323338
"""

tests/functional/test_install_reqs.py

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,75 @@ def test_requirements_file(script: PipTestEnvironment) -> None:
9393
assert result.files_created[script.site_packages / fn].dir
9494

9595

96+
@pytest.mark.network
97+
def test_dependency_group(script: PipTestEnvironment) -> None:
98+
"""
99+
Test installing from a dependency group.
100+
101+
"""
102+
pyproject = script.scratch_path / "pyproject.toml"
103+
pyproject.write_text(
104+
textwrap.dedent(
105+
"""\
106+
[dependency-groups]
107+
initools = [
108+
"INITools==0.2",
109+
"peppercorn<=0.6",
110+
]
111+
"""
112+
)
113+
)
114+
result = script.pip("install", "--group", "initools")
115+
result.did_create(script.site_packages / "INITools-0.2.dist-info")
116+
result.did_create(script.site_packages / "initools")
117+
assert result.files_created[script.site_packages / "peppercorn"].dir
118+
assert result.files_created[script.site_packages / "peppercorn-0.6.dist-info"].dir
119+
120+
121+
@pytest.mark.network
122+
def test_multiple_dependency_groups(script: PipTestEnvironment) -> None:
123+
"""
124+
Test installing from two dependency groups simultaneously.
125+
126+
"""
127+
pyproject = script.scratch_path / "pyproject.toml"
128+
pyproject.write_text(
129+
textwrap.dedent(
130+
"""\
131+
[dependency-groups]
132+
initools = ["INITools==0.2"]
133+
peppercorn = ["peppercorn<=0.6"]
134+
"""
135+
)
136+
)
137+
result = script.pip("install", "--group", "initools", "--group", "peppercorn")
138+
result.did_create(script.site_packages / "INITools-0.2.dist-info")
139+
result.did_create(script.site_packages / "initools")
140+
assert result.files_created[script.site_packages / "peppercorn"].dir
141+
assert result.files_created[script.site_packages / "peppercorn-0.6.dist-info"].dir
142+
143+
144+
@pytest.mark.network
145+
def test_dependency_group_with_non_normalized_name(script: PipTestEnvironment) -> None:
146+
"""
147+
Test installing from a dependency group with a non-normalized name, verifying that
148+
the pyproject.toml content and CLI arg are normalized to match.
149+
150+
"""
151+
pyproject = script.scratch_path / "pyproject.toml"
152+
pyproject.write_text(
153+
textwrap.dedent(
154+
"""\
155+
[dependency-groups]
156+
INITOOLS = ["INITools==0.2"]
157+
"""
158+
)
159+
)
160+
result = script.pip("install", "--group", "IniTools")
161+
result.did_create(script.site_packages / "INITools-0.2.dist-info")
162+
result.did_create(script.site_packages / "initools")
163+
164+
96165
def test_schema_check_in_requirements_file(script: PipTestEnvironment) -> None:
97166
"""
98167
Test installing from a requirements file with an invalid vcs schema..
@@ -212,6 +281,32 @@ def test_package_in_constraints_and_dependencies(
212281
assert "installed TopoRequires-0.0.1" in result.stdout
213282

214283

284+
def test_constraints_apply_to_dependency_groups(
285+
script: PipTestEnvironment, data: TestData
286+
) -> None:
287+
script.scratch_path.joinpath("constraints.txt").write_text("TopoRequires==0.0.1")
288+
pyproject = script.scratch_path / "pyproject.toml"
289+
pyproject.write_text(
290+
textwrap.dedent(
291+
"""\
292+
[dependency-groups]
293+
mylibs = ["TopoRequires2"]
294+
"""
295+
)
296+
)
297+
result = script.pip(
298+
"install",
299+
"--no-index",
300+
"-f",
301+
data.find_links,
302+
"-c",
303+
script.scratch_path / "constraints.txt",
304+
"--group",
305+
"mylibs",
306+
)
307+
assert "installed TopoRequires-0.0.1" in result.stdout
308+
309+
215310
def test_multiple_constraints_files(script: PipTestEnvironment, data: TestData) -> None:
216311
script.scratch_path.joinpath("outer.txt").write_text("-c inner.txt")
217312
script.scratch_path.joinpath("inner.txt").write_text("Upper==1.0")

0 commit comments

Comments
 (0)