Skip to content

Commit e67c027

Browse files
test instrumentation: add dependency injected toml content to read_pyproject
1 parent 7570f68 commit e67c027

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/setuptools_scm/_integration/pyproject_reading.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ def read_pyproject(
174174
tool_name: str = DEFAULT_TOOL_NAME,
175175
canonical_build_package_name: str = "setuptools-scm",
176176
_given_result: _t.GivenPyProjectResult = None,
177+
_given_definition: TOML_RESULT | None = None,
177178
) -> PyProjectData:
178179
"""Read and parse pyproject configuration.
179180
@@ -195,7 +196,10 @@ def read_pyproject(
195196
if isinstance(_given_result, (InvalidTomlError, FileNotFoundError)):
196197
raise _given_result
197198

198-
defn = read_toml_content(path)
199+
if _given_definition is not None:
200+
defn = _given_definition
201+
else:
202+
defn = read_toml_content(path)
199203

200204
requires: list[str] = defn.get("build-system", {}).get("requires", [])
201205
is_required = has_build_package(requires, canonical_build_package_name)

testing/test_pyproject_reading.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
from pathlib import Path
4+
from unittest.mock import Mock
45

56
import pytest
67

@@ -108,3 +109,20 @@ def test_invalid_requirement_string(self) -> None:
108109
assert (
109110
has_build_package_with_extra(requires, "setuptools-scm", "simple") is False
110111
)
112+
113+
114+
def test_read_pyproject_with_given_definition(monkeypatch: pytest.MonkeyPatch) -> None:
115+
"""Test that read_pyproject reads existing files correctly."""
116+
monkeypatch.setattr(
117+
"setuptools_scm._integration.pyproject_reading.read_toml_content",
118+
Mock(side_effect=FileNotFoundError("this test should not read")),
119+
)
120+
121+
res = read_pyproject(
122+
_given_definition={
123+
"build-system": {"requires": ["setuptools-scm[simple]"]},
124+
"project": {"name": "test-package", "dynamic": ["version"]},
125+
}
126+
)
127+
128+
assert res.should_infer()

0 commit comments

Comments
 (0)