@@ -1178,32 +1178,18 @@ def test_version_keyword_no_scm_dependency_works(
1178
1178
assert dist .metadata .version == "1.0.0"
1179
1179
1180
1180
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 :
1184
1182
"""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
+ )
1207
1193
1208
1194
# should_infer should raise a ValueError when dynamic=['version'] is missing
1209
1195
with pytest .raises (
@@ -1212,67 +1198,39 @@ def test_verify_dynamic_version_when_required_missing_dynamic(
1212
1198
pyproject_data .should_infer ()
1213
1199
1214
1200
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 :
1218
1202
"""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
+ )
1240
1213
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 )
1243
1214
assert pyproject_data .is_required is True
1244
1215
assert pyproject_data .section_present is True
1245
1216
1246
1217
# should_infer should return True because tool section exists
1247
1218
assert pyproject_data .should_infer () is True
1248
1219
1249
1220
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 :
1253
1222
"""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
+ )
1273
1233
1274
- # This should not raise an error because dynamic=['version'] is set
1275
- pyproject_data = read_pyproject (Path ("pyproject.toml" ), missing_section_ok = True )
1276
1234
assert pyproject_data .is_required is True
1277
1235
assert pyproject_data .section_present is False
1278
1236
0 commit comments