Skip to content

Commit 5cd6d2b

Browse files
use PyProjectData.for_testing instead of writing to files in tests where appropiate
1 parent dfadacc commit 5cd6d2b

File tree

1 file changed

+33
-75
lines changed

1 file changed

+33
-75
lines changed

testing/test_integration.py

Lines changed: 33 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,32 +1178,18 @@ def test_version_keyword_no_scm_dependency_works(
11781178
assert dist.metadata.version == "1.0.0"
11791179

11801180

1181-
def test_verify_dynamic_version_when_required_missing_dynamic(
1182-
wd: WorkDir, monkeypatch: pytest.MonkeyPatch
1183-
) -> None:
1181+
def test_verify_dynamic_version_when_required_missing_dynamic() -> None:
11841182
"""Test that should_infer raises ValueError when setuptools-scm is in build-system.requires but dynamic=['version'] is missing"""
1185-
if sys.version_info < (3, 11):
1186-
pytest.importorskip("tomli")
1187-
1188-
# Change to the test directory
1189-
monkeypatch.chdir(wd.cwd)
1190-
1191-
# Create a pyproject.toml file with setuptools-scm in build-system.requires but NO dynamic=['version']
1192-
pyproject_content = """
1193-
[build-system]
1194-
requires = ["setuptools>=80", "setuptools-scm>=8"]
1195-
build-backend = "setuptools.build_meta"
1196-
1197-
[project]
1198-
name = "test-package-missing-dynamic"
1199-
# Missing: dynamic = ["version"]
1200-
"""
1201-
wd.write("pyproject.toml", pyproject_content)
1202-
1203-
from setuptools_scm._integration.pyproject_reading import read_pyproject
1204-
1205-
# Read pyproject data first
1206-
pyproject_data = read_pyproject(Path("pyproject.toml"), missing_section_ok=True)
1183+
from setuptools_scm._integration.pyproject_reading import PyProjectData
1184+
1185+
# Create pyproject data: setuptools-scm required, project present, but no dynamic=['version']
1186+
pyproject_data = PyProjectData.for_testing(
1187+
is_required=True,
1188+
section_present=False,
1189+
project_present=True,
1190+
project_name="test-package-missing-dynamic",
1191+
has_dynamic_version=False, # This is the key: no dynamic=['version']
1192+
)
12071193

12081194
# should_infer should raise a ValueError when dynamic=['version'] is missing
12091195
with pytest.raises(
@@ -1212,67 +1198,39 @@ def test_verify_dynamic_version_when_required_missing_dynamic(
12121198
pyproject_data.should_infer()
12131199

12141200

1215-
def test_verify_dynamic_version_when_required_with_tool_section(
1216-
wd: WorkDir, monkeypatch: pytest.MonkeyPatch
1217-
) -> None:
1201+
def test_verify_dynamic_version_when_required_with_tool_section() -> None:
12181202
"""Test that verification passes when setuptools-scm is in build-system.requires and [tool.setuptools_scm] section exists"""
1219-
if sys.version_info < (3, 11):
1220-
pytest.importorskip("tomli")
1221-
1222-
# Change to the test directory
1223-
monkeypatch.chdir(wd.cwd)
1224-
1225-
# Create a pyproject.toml file with setuptools-scm in build-system.requires and [tool.setuptools_scm] section
1226-
pyproject_content = """
1227-
[build-system]
1228-
requires = ["setuptools>=80", "setuptools-scm>=8"]
1229-
build-backend = "setuptools.build_meta"
1230-
1231-
[project]
1232-
name = "test-package-with-tool-section"
1233-
# Missing: dynamic = ["version"]
1234-
1235-
[tool.setuptools_scm]
1236-
"""
1237-
wd.write("pyproject.toml", pyproject_content)
1238-
1239-
from setuptools_scm._integration.pyproject_reading import read_pyproject
1203+
from setuptools_scm._integration.pyproject_reading import PyProjectData
1204+
1205+
# Create pyproject data: setuptools-scm required, tool section present
1206+
pyproject_data = PyProjectData.for_testing(
1207+
is_required=True,
1208+
section_present=True, # This is the key: tool section exists
1209+
project_present=True,
1210+
project_name="test-package-with-tool-section",
1211+
has_dynamic_version=False, # dynamic=['version'] not needed when tool section exists
1212+
)
12401213

1241-
# This should not raise an error because [tool.setuptools_scm] section exists
1242-
pyproject_data = read_pyproject(Path("pyproject.toml"), missing_section_ok=True)
12431214
assert pyproject_data.is_required is True
12441215
assert pyproject_data.section_present is True
12451216

12461217
# should_infer should return True because tool section exists
12471218
assert pyproject_data.should_infer() is True
12481219

12491220

1250-
def test_verify_dynamic_version_when_required_with_dynamic(
1251-
wd: WorkDir, monkeypatch: pytest.MonkeyPatch
1252-
) -> None:
1221+
def test_verify_dynamic_version_when_required_with_dynamic() -> None:
12531222
"""Test that verification passes when setuptools-scm is in build-system.requires and dynamic=['version'] is set"""
1254-
if sys.version_info < (3, 11):
1255-
pytest.importorskip("tomli")
1256-
1257-
# Change to the test directory
1258-
monkeypatch.chdir(wd.cwd)
1259-
1260-
# Create a pyproject.toml file with setuptools-scm in build-system.requires and dynamic=['version']
1261-
pyproject_content = """
1262-
[build-system]
1263-
requires = ["setuptools>=80", "setuptools-scm>=8"]
1264-
build-backend = "setuptools.build_meta"
1265-
1266-
[project]
1267-
name = "test-package-with-dynamic"
1268-
dynamic = ["version"]
1269-
"""
1270-
wd.write("pyproject.toml", pyproject_content)
1271-
1272-
from setuptools_scm._integration.pyproject_reading import read_pyproject
1223+
from setuptools_scm._integration.pyproject_reading import PyProjectData
1224+
1225+
# Create pyproject data: setuptools-scm required, no tool section, but dynamic=['version'] set
1226+
pyproject_data = PyProjectData.for_testing(
1227+
is_required=True,
1228+
section_present=False,
1229+
project_present=True,
1230+
project_name="test-package-with-dynamic",
1231+
has_dynamic_version=True, # This is the key: dynamic=['version'] is set
1232+
)
12731233

1274-
# This should not raise an error because dynamic=['version'] is set
1275-
pyproject_data = read_pyproject(Path("pyproject.toml"), missing_section_ok=True)
12761234
assert pyproject_data.is_required is True
12771235
assert pyproject_data.section_present is False
12781236

0 commit comments

Comments
 (0)