Skip to content

Commit 2319a9d

Browse files
migrate test_integration_function_call_order to direct pyproject data injection
1 parent 9d4e67e commit 2319a9d

File tree

1 file changed

+45
-39
lines changed

1 file changed

+45
-39
lines changed

testing/test_integration.py

Lines changed: 45 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from packaging.version import Version
1818

1919
from setuptools_scm._integration import setuptools as setuptools_integration
20+
from setuptools_scm._integration.pyproject_reading import PyProjectData
2021
from setuptools_scm._requirement_cls import extract_package_name
2122

2223
if TYPE_CHECKING:
@@ -939,33 +940,35 @@ def create_clean_distribution(name: str) -> setuptools.Distribution:
939940
return dist
940941

941942

942-
def version_keyword_default(dist: setuptools.Distribution) -> None:
943+
def version_keyword_default(
944+
dist: setuptools.Distribution, pyproject_data: PyProjectData | None = None
945+
) -> None:
943946
"""Helper to call version_keyword with default config and return the result."""
944947

945-
setuptools_integration.version_keyword(dist, "use_scm_version", True)
948+
setuptools_integration.version_keyword(
949+
dist, "use_scm_version", True, _given_pyproject_data=pyproject_data
950+
)
946951

947952

948-
def version_keyword_calver(dist: setuptools.Distribution) -> None:
953+
def version_keyword_calver(
954+
dist: setuptools.Distribution, pyproject_data: PyProjectData | None = None
955+
) -> None:
949956
"""Helper to call version_keyword with calver-by-date scheme and return the result."""
950957

951958
setuptools_integration.version_keyword(
952-
dist, "use_scm_version", {"version_scheme": "calver-by-date"}
959+
dist,
960+
"use_scm_version",
961+
{"version_scheme": "calver-by-date"},
962+
_given_pyproject_data=pyproject_data,
953963
)
954964

955965

956-
# Test cases: (first_func, second_func, expected_final_version)
957-
# We use a controlled date to make calver deterministic
958-
TEST_CASES = [
959-
# Real-world scenarios: infer_version and version_keyword can be called in either order
960-
(setuptools_integration.infer_version, version_keyword_default, "1.0.1.dev1"),
961-
(
962-
setuptools_integration.infer_version,
963-
version_keyword_calver,
964-
"9.2.13.0.dev1",
965-
), # calver should win but doesn't
966-
(version_keyword_default, setuptools_integration.infer_version, "1.0.1.dev1"),
967-
(version_keyword_calver, setuptools_integration.infer_version, "9.2.13.0.dev1"),
968-
]
966+
def infer_version_with_data(
967+
dist: setuptools.Distribution, pyproject_data: PyProjectData | None = None
968+
) -> None:
969+
"""Helper to call infer_version with pyproject data."""
970+
971+
setuptools_integration.infer_version(dist, _given_pyproject_data=pyproject_data)
969972

970973

971974
@pytest.mark.issue("https://github.com/pypa/setuptools_scm/issues/1022")
@@ -975,7 +978,13 @@ def version_keyword_calver(dist: setuptools.Distribution) -> None:
975978
)
976979
@pytest.mark.parametrize(
977980
("first_integration", "second_integration", "expected_final_version"),
978-
TEST_CASES,
981+
[
982+
# infer_version and version_keyword can be called in either order
983+
(infer_version_with_data, version_keyword_default, "1.0.1.dev1"),
984+
(infer_version_with_data, version_keyword_calver, "9.2.13.0.dev1"),
985+
(version_keyword_default, infer_version_with_data, "1.0.1.dev1"),
986+
(version_keyword_calver, infer_version_with_data, "9.2.13.0.dev1"),
987+
],
979988
)
980989
def test_integration_function_call_order(
981990
wd: WorkDir,
@@ -992,36 +1001,33 @@ def test_integration_function_call_order(
9921001
# Set up controlled environment for deterministic versions
9931002
monkeypatch.setenv("SOURCE_DATE_EPOCH", "1234567890") # 2009-02-13T23:31:30+00:00
9941003
# Override node_date to get consistent calver versions
995-
monkeypatch.setenv("SETUPTOOLS_SCM_PRETEND_METADATA", "{node_date=2009-02-13}")
1004+
monkeypatch.setenv(
1005+
"SETUPTOOLS_SCM_PRETEND_METADATA_FOR_TEST_CALL_ORDER", "{node_date=2009-02-13}"
1006+
)
9961007

9971008
# Set up a git repository with a tag and known commit hash
9981009
wd.commit_testfile("test")
9991010
wd("git tag 1.0.0")
10001011
wd.commit_testfile("test2") # Add another commit to get distance
10011012
monkeypatch.chdir(wd.cwd)
10021013

1003-
# Create a pyproject.toml file
1004-
pyproject_content = f"""
1005-
[build-system]
1006-
requires = ["setuptools", "setuptools_scm"]
1007-
build-backend = "setuptools.build_meta"
1008-
1009-
[project]
1010-
name = "test-pkg-{first_integration.__name__}-{second_integration.__name__}"
1011-
dynamic = ["version"]
1012-
1013-
[tool.setuptools_scm]
1014-
local_scheme = "no-local-version"
1015-
"""
1016-
wd.write("pyproject.toml", pyproject_content)
1017-
1018-
dist = create_clean_distribution(
1019-
f"test-pkg-{first_integration.__name__}-{second_integration.__name__}"
1014+
# Create PyProjectData with equivalent configuration - no file I/O!
1015+
project_name = "test-call-order"
1016+
pyproject_data = PyProjectData(
1017+
path=Path("pyproject.toml"),
1018+
tool_name="setuptools_scm",
1019+
project={"name": project_name, "dynamic": ["version"]},
1020+
section={"local_scheme": "no-local-version"}, # [tool.setuptools_scm] config
1021+
is_required=True, # setuptools_scm in build-system.requires
1022+
section_present=True, # [tool.setuptools_scm] section exists
1023+
project_present=True, # [project] section exists
10201024
)
10211025

1022-
# Call both integration functions in order
1023-
first_integration(dist)
1024-
second_integration(dist)
1026+
dist = create_clean_distribution(project_name)
1027+
1028+
# Call both integration functions in order with direct data injection
1029+
first_integration(dist, pyproject_data)
1030+
second_integration(dist, pyproject_data)
10251031

10261032
# Get the final version directly from the distribution
10271033
final_version = dist.metadata.version

0 commit comments

Comments
 (0)