Skip to content

Commit 78cda9c

Browse files
Split regression tests by architectural layer
Create vcs-versioning/testing_vcs/test_regressions.py with core VCS regression tests moved from setuptools-scm/testing_scm/test_regressions.py. Moved to vcs-versioning (core VCS): - test_case_mismatch_on_windows_git: tests core git parse with case sensitivity - test_case_mismatch_nested_dir_windows_git: tests core git parse with nested dirs - test_write_to_absolute_path_passes_when_subdir_of_root: tests vcs_versioning.write_version_files - test_version_as_tuple: tests vcs_versioning._version_cls._version_as_tuple Kept in setuptools-scm (setuptools integration): - test_data_from_mime_ignores_body: setuptools integration - test_pkginfo_noscmroot: setup.py integration - test_pip_download: pip integration - test_use_scm_version_callable: use_scm_version callable - test_case_mismatch_force_assertion_failure: setuptools_scm._file_finders (setuptools) - test_entrypoints_load: setuptools-scm entry points All tests pass: 407 passed, 10 skipped, 1 xfailed
1 parent 331a323 commit 78cda9c

File tree

2 files changed

+110
-97
lines changed

2 files changed

+110
-97
lines changed

setuptools-scm/testing_scm/test_regressions.py

Lines changed: 6 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
1+
"""Setuptools-scm specific regression tests.
2+
3+
Core VCS regression tests have been moved to vcs-versioning/testing_vcs/test_regressions.py
4+
"""
5+
16
from __future__ import annotations
27

38
import pprint
49
import subprocess
510
import sys
611

7-
from collections.abc import Sequence
8-
from dataclasses import replace
912
from importlib.metadata import EntryPoint
1013
from importlib.metadata import distribution
1114
from pathlib import Path
1215

1316
import pytest
1417

1518
from vcs_versioning._run_cmd import run
19+
from vcs_versioning.test_api import WorkDir
1620

17-
from setuptools_scm import Configuration
18-
from setuptools_scm.git import parse
1921
from setuptools_scm.integration import data_from_mime
20-
from setuptools_scm.version import meta
2122

2223

2324
def test_data_from_mime_ignores_body() -> None:
@@ -92,67 +93,8 @@ def vs(v):
9293
assert res.stdout == "1.0"
9394

9495

95-
@pytest.mark.skipif(sys.platform != "win32", reason="this bug is only valid on windows")
96-
def test_case_mismatch_on_windows_git(tmp_path: Path) -> None:
97-
"""Case insensitive path checks on Windows"""
98-
camel_case_path = tmp_path / "CapitalizedDir"
99-
camel_case_path.mkdir()
100-
run("git init", camel_case_path)
101-
res = parse(str(camel_case_path).lower(), Configuration())
102-
assert res is not None
103-
104-
105-
@pytest.mark.skipif(sys.platform != "win32", reason="this bug is only valid on windows")
106-
def test_case_mismatch_nested_dir_windows_git(tmp_path: Path) -> None:
107-
"""Test case where we have a nested directory with different casing"""
108-
from vcs_versioning.test_api import WorkDir
109-
110-
# Create git repo in my_repo
111-
repo_path = tmp_path / "my_repo"
112-
repo_path.mkdir()
113-
wd = WorkDir(repo_path).setup_git()
114-
115-
# Create a nested directory with specific casing
116-
nested_dir = repo_path / "CasedDir"
117-
nested_dir.mkdir()
118-
119-
# Create a pyproject.toml in the nested directory
120-
wd.write(
121-
"CasedDir/pyproject.toml",
122-
"""
123-
[build-system]
124-
requires = ["setuptools>=64", "setuptools-scm"]
125-
build-backend = "setuptools.build_meta"
126-
127-
[project]
128-
name = "test-project"
129-
dynamic = ["version"]
130-
131-
[tool.setuptools_scm]
132-
""",
133-
)
134-
135-
# Add and commit the file
136-
wd.add_and_commit("Initial commit")
137-
138-
# Now try to parse from the nested directory with lowercase path
139-
# This simulates: cd my_repo/caseddir (lowercase) when actual dir is CasedDir
140-
lowercase_nested_path = str(nested_dir).replace("CasedDir", "caseddir")
141-
142-
# This should trigger the assertion error in _git_toplevel
143-
try:
144-
res = parse(lowercase_nested_path, Configuration())
145-
# If we get here without assertion error, the bug is already fixed or not triggered
146-
print(f"Parse succeeded with result: {res}")
147-
except AssertionError as e:
148-
print(f"AssertionError caught as expected: {e}")
149-
# Re-raise so the test fails, showing we reproduced the bug
150-
raise
151-
152-
15396
def test_case_mismatch_force_assertion_failure(tmp_path: Path) -> None:
15497
"""Force the assertion failure by directly calling _git_toplevel with mismatched paths"""
155-
from vcs_versioning.test_api import WorkDir
15698

15799
from setuptools_scm._file_finders.git import _git_toplevel
158100

@@ -194,36 +136,3 @@ def test_entrypoints_load() -> None:
194136
failed.append((ep, e))
195137
if failed:
196138
pytest.fail(pprint.pformat(failed))
197-
198-
199-
def test_write_to_absolute_path_passes_when_subdir_of_root(tmp_path: Path) -> None:
200-
c = Configuration(root=tmp_path, write_to=tmp_path / "VERSION.py")
201-
v = meta("1.0", config=c)
202-
from vcs_versioning._get_version_impl import write_version_files
203-
204-
with pytest.warns(DeprecationWarning, match=".*write_to=.* is a absolute.*"):
205-
write_version_files(c, "1.0", v)
206-
write_version_files(replace(c, write_to="VERSION.py"), "1.0", v)
207-
subdir = tmp_path / "subdir"
208-
subdir.mkdir()
209-
with pytest.raises(
210-
# todo: python version specific error list
211-
ValueError,
212-
match=r".*VERSION.py' .* .*subdir.*",
213-
):
214-
write_version_files(replace(c, root=subdir), "1.0", v)
215-
216-
217-
@pytest.mark.parametrize(
218-
("input", "expected"),
219-
[
220-
("1.0", (1, 0)),
221-
("1.0a2", (1, 0, "a2")),
222-
("1.0.b2dev1", (1, 0, "b2", "dev1")),
223-
("1.0.dev1", (1, 0, "dev1")),
224-
],
225-
)
226-
def test_version_as_tuple(input: str, expected: Sequence[int | str]) -> None:
227-
from vcs_versioning._version_cls import _version_as_tuple
228-
229-
assert _version_as_tuple(input) == expected
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
"""Core VCS regression tests."""
2+
3+
from __future__ import annotations
4+
5+
import sys
6+
from collections.abc import Sequence
7+
from dataclasses import replace
8+
from pathlib import Path
9+
10+
import pytest
11+
from setuptools_scm import Configuration
12+
from setuptools_scm.git import parse
13+
from setuptools_scm.version import meta
14+
from vcs_versioning._run_cmd import run
15+
from vcs_versioning.test_api import WorkDir
16+
17+
18+
@pytest.mark.skipif(sys.platform != "win32", reason="this bug is only valid on windows")
19+
def test_case_mismatch_on_windows_git(tmp_path: Path) -> None:
20+
"""Case insensitive path checks on Windows"""
21+
camel_case_path = tmp_path / "CapitalizedDir"
22+
camel_case_path.mkdir()
23+
run("git init", camel_case_path)
24+
res = parse(str(camel_case_path).lower(), Configuration())
25+
assert res is not None
26+
27+
28+
@pytest.mark.skipif(sys.platform != "win32", reason="this bug is only valid on windows")
29+
def test_case_mismatch_nested_dir_windows_git(tmp_path: Path) -> None:
30+
"""Test case where we have a nested directory with different casing"""
31+
# Create git repo in my_repo
32+
repo_path = tmp_path / "my_repo"
33+
repo_path.mkdir()
34+
wd = WorkDir(repo_path).setup_git()
35+
36+
# Create a nested directory with specific casing
37+
nested_dir = repo_path / "CasedDir"
38+
nested_dir.mkdir()
39+
40+
# Create a pyproject.toml in the nested directory
41+
wd.write(
42+
"CasedDir/pyproject.toml",
43+
"""
44+
[build-system]
45+
requires = ["setuptools>=64", "setuptools-scm"]
46+
build-backend = "setuptools.build_meta"
47+
48+
[project]
49+
name = "test-project"
50+
dynamic = ["version"]
51+
52+
[tool.setuptools_scm]
53+
""",
54+
)
55+
56+
# Add and commit the file
57+
wd.add_and_commit("Initial commit")
58+
59+
# Now try to parse from the nested directory with lowercase path
60+
# This simulates: cd my_repo/caseddir (lowercase) when actual dir is CasedDir
61+
lowercase_nested_path = str(nested_dir).replace("CasedDir", "caseddir")
62+
63+
# This should trigger the assertion error in _git_toplevel
64+
try:
65+
res = parse(lowercase_nested_path, Configuration())
66+
# If we get here without assertion error, the bug is already fixed or not triggered
67+
print(f"Parse succeeded with result: {res}")
68+
except AssertionError as e:
69+
print(f"AssertionError caught as expected: {e}")
70+
# Re-raise so the test fails, showing we reproduced the bug
71+
raise
72+
73+
74+
def test_write_to_absolute_path_passes_when_subdir_of_root(tmp_path: Path) -> None:
75+
c = Configuration(root=tmp_path, write_to=tmp_path / "VERSION.py")
76+
v = meta("1.0", config=c)
77+
from vcs_versioning._get_version_impl import write_version_files
78+
79+
with pytest.warns(DeprecationWarning, match=".*write_to=.* is a absolute.*"):
80+
write_version_files(c, "1.0", v)
81+
write_version_files(replace(c, write_to="VERSION.py"), "1.0", v)
82+
subdir = tmp_path / "subdir"
83+
subdir.mkdir()
84+
with pytest.raises(
85+
# todo: python version specific error list
86+
ValueError,
87+
match=r".*VERSION.py' .* .*subdir.*",
88+
):
89+
write_version_files(replace(c, root=subdir), "1.0", v)
90+
91+
92+
@pytest.mark.parametrize(
93+
("input", "expected"),
94+
[
95+
("1.0", (1, 0)),
96+
("1.0a2", (1, 0, "a2")),
97+
("1.0.b2dev1", (1, 0, "b2", "dev1")),
98+
("1.0.dev1", (1, 0, "dev1")),
99+
],
100+
)
101+
def test_version_as_tuple(input: str, expected: Sequence[int | str]) -> None:
102+
from vcs_versioning._version_cls import _version_as_tuple
103+
104+
assert _version_as_tuple(input) == expected

0 commit comments

Comments
 (0)