Skip to content

Commit 5b57ac9

Browse files
committed
Use jaraco.path.build in test_pyprojecttoml_dynamic_deps
1 parent be01680 commit 5b57ac9

File tree

1 file changed

+58
-53
lines changed

1 file changed

+58
-53
lines changed

setuptools/tests/config/test_pyprojecttoml_dynamic_deps.py

Lines changed: 58 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,59 @@
1+
from inspect import cleandoc
2+
13
import pytest
4+
from jaraco import path
25

36
from setuptools.config.pyprojecttoml import apply_configuration
47
from setuptools.dist import Distribution
5-
from setuptools.tests.textwrap import DALS
68

79

810
def test_dynamic_dependencies(tmp_path):
9-
(tmp_path / "requirements.txt").write_text("six\n # comment\n")
10-
pyproject = tmp_path / "pyproject.toml"
11-
pyproject.write_text(
12-
DALS(
11+
files = {
12+
"requirements.txt": "six\n # comment\n",
13+
"pyproject.toml": cleandoc(
1314
"""
14-
[project]
15-
name = "myproj"
16-
version = "1.0"
17-
dynamic = ["dependencies"]
15+
[project]
16+
name = "myproj"
17+
version = "1.0"
18+
dynamic = ["dependencies"]
1819
19-
[build-system]
20-
requires = ["setuptools", "wheel"]
21-
build-backend = "setuptools.build_meta"
20+
[build-system]
21+
requires = ["setuptools", "wheel"]
22+
build-backend = "setuptools.build_meta"
2223
23-
[tool.setuptools.dynamic.dependencies]
24-
file = ["requirements.txt"]
25-
"""
26-
)
27-
)
24+
[tool.setuptools.dynamic.dependencies]
25+
file = ["requirements.txt"]
26+
"""
27+
),
28+
}
29+
path.build(files, prefix=tmp_path)
2830
dist = Distribution()
29-
dist = apply_configuration(dist, pyproject)
31+
dist = apply_configuration(dist, tmp_path / "pyproject.toml")
3032
assert dist.install_requires == ["six"]
3133

3234

3335
def test_dynamic_optional_dependencies(tmp_path):
34-
(tmp_path / "requirements-docs.txt").write_text("sphinx\n # comment\n")
35-
pyproject = tmp_path / "pyproject.toml"
36-
pyproject.write_text(
37-
DALS(
36+
files = {
37+
"requirements-docs.txt": "sphinx\n # comment\n",
38+
"pyproject.toml": cleandoc(
3839
"""
39-
[project]
40-
name = "myproj"
41-
version = "1.0"
42-
dynamic = ["optional-dependencies"]
40+
[project]
41+
name = "myproj"
42+
version = "1.0"
43+
dynamic = ["optional-dependencies"]
4344
44-
[tool.setuptools.dynamic.optional-dependencies.docs]
45-
file = ["requirements-docs.txt"]
45+
[tool.setuptools.dynamic.optional-dependencies.docs]
46+
file = ["requirements-docs.txt"]
4647
47-
[build-system]
48-
requires = ["setuptools", "wheel"]
49-
build-backend = "setuptools.build_meta"
50-
"""
51-
)
52-
)
48+
[build-system]
49+
requires = ["setuptools", "wheel"]
50+
build-backend = "setuptools.build_meta"
51+
"""
52+
),
53+
}
54+
path.build(files, prefix=tmp_path)
5355
dist = Distribution()
54-
dist = apply_configuration(dist, pyproject)
56+
dist = apply_configuration(dist, tmp_path / "pyproject.toml")
5557
assert dist.extras_require == {"docs": ["sphinx"]}
5658

5759

@@ -61,29 +63,32 @@ def test_mixed_dynamic_optional_dependencies(tmp_path):
6163
configurations in the case of fields containing sub-fields (groups),
6264
things would work out.
6365
"""
64-
(tmp_path / "requirements-images.txt").write_text("pillow~=42.0\n # comment\n")
65-
pyproject = tmp_path / "pyproject.toml"
66-
pyproject.write_text(
67-
DALS(
66+
files = {
67+
"requirements-images.txt": "pillow~=42.0\n # comment\n",
68+
"pyproject.toml": cleandoc(
6869
"""
69-
[project]
70-
name = "myproj"
71-
version = "1.0"
72-
dynamic = ["optional-dependencies"]
70+
[project]
71+
name = "myproj"
72+
version = "1.0"
73+
dynamic = ["optional-dependencies"]
7374
74-
[project.optional-dependencies]
75-
docs = ["sphinx"]
75+
[project.optional-dependencies]
76+
docs = ["sphinx"]
7677
77-
[tool.setuptools.dynamic.optional-dependencies.images]
78-
file = ["requirements-images.txt"]
78+
[tool.setuptools.dynamic.optional-dependencies.images]
79+
file = ["requirements-images.txt"]
80+
81+
[build-system]
82+
requires = ["setuptools", "wheel"]
83+
build-backend = "setuptools.build_meta"
84+
"""
85+
),
86+
}
87+
88+
path.build(files, prefix=tmp_path)
7989

80-
[build-system]
81-
requires = ["setuptools", "wheel"]
82-
build-backend = "setuptools.build_meta"
83-
"""
84-
)
85-
)
8690
# Test that the mix-and-match doesn't currently validate.
91+
pyproject = tmp_path / "pyproject.toml"
8792
with pytest.raises(ValueError, match="project.optional-dependencies"):
8893
apply_configuration(Distribution(), pyproject)
8994

0 commit comments

Comments
 (0)