Skip to content

Commit 858e705

Browse files
Move core version scheme tests to vcs-versioning
Extract core version scheme and formatting tests from setuptools-scm/testing_scm/test_functions.py to vcs-versioning/testing_vcs/test_version_schemes.py. Moved tests: - test_next_tag: tests guess_next_version (core) - test_format_version: tests format_version (core) - test_format_version_with_build_metadata: tests format with build metadata (core) - test_tag_to_version: tests tag_to_version (core) - test_has_command: tests vcs_versioning._run_cmd.has_command (core) - test_has_command_logs_stderr: tests has_command logging (core) Kept in setuptools-scm: - All dump_version tests (setuptools-specific functionality) All tests pass: 407 passed, 10 skipped, 1 xfailed
1 parent 91c5554 commit 858e705

File tree

3 files changed

+212
-191
lines changed

3 files changed

+212
-191
lines changed

.serena/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/cache

setuptools-scm/testing_scm/test_functions.py

Lines changed: 5 additions & 191 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
"""Tests for setuptools-scm specific dump_version functionality.
2+
3+
Core version scheme tests have been moved to vcs-versioning/testing_vcs/test_version_schemes.py
4+
"""
5+
16
from __future__ import annotations
27

38
import shutil
@@ -8,178 +13,19 @@
813
import pytest
914

1015
from vcs_versioning._overrides import PRETEND_KEY
11-
from vcs_versioning._run_cmd import has_command
1216

1317
from setuptools_scm import Configuration
1418
from setuptools_scm import dump_version
1519
from setuptools_scm import get_version
16-
from setuptools_scm.version import format_version
17-
from setuptools_scm.version import guess_next_version
1820
from setuptools_scm.version import meta
19-
from setuptools_scm.version import tag_to_version
2021

2122
c = Configuration()
2223

23-
24-
@pytest.mark.parametrize(
25-
("tag", "expected"),
26-
[
27-
("1.1", "1.2"),
28-
("1.2.dev", "1.2"),
29-
("1.1a2", "1.1a3"),
30-
pytest.param(
31-
"23.24.post2+deadbeef",
32-
"23.24.post3",
33-
marks=pytest.mark.filterwarnings(
34-
"ignore:.*will be stripped of its suffix.*:UserWarning"
35-
),
36-
),
37-
],
38-
)
39-
def test_next_tag(tag: str, expected: str) -> None:
40-
version = meta(tag, config=c)
41-
assert guess_next_version(version) == expected
42-
43-
4424
VERSIONS = {
4525
"exact": meta("1.1", distance=0, dirty=False, config=c),
46-
"dirty": meta("1.1", distance=0, dirty=True, config=c),
47-
"distance-clean": meta("1.1", distance=3, dirty=False, config=c),
48-
"distance-dirty": meta("1.1", distance=3, dirty=True, config=c),
49-
}
50-
51-
# Versions with build metadata in the tag
52-
VERSIONS_WITH_BUILD_METADATA = {
53-
"exact-build": meta("1.1+build.123", distance=0, dirty=False, config=c),
54-
"dirty-build": meta("1.1+build.123", distance=0, dirty=True, config=c),
55-
"distance-clean-build": meta("1.1+build.123", distance=3, dirty=False, config=c),
56-
"distance-dirty-build": meta("1.1+build.123", distance=3, dirty=True, config=c),
57-
"exact-ci": meta("2.0.0+ci.456", distance=0, dirty=False, config=c),
58-
"dirty-ci": meta("2.0.0+ci.456", distance=0, dirty=True, config=c),
59-
"distance-clean-ci": meta("2.0.0+ci.456", distance=2, dirty=False, config=c),
60-
"distance-dirty-ci": meta("2.0.0+ci.456", distance=2, dirty=True, config=c),
6126
}
6227

6328

64-
@pytest.mark.parametrize(
65-
("version", "version_scheme", "local_scheme", "expected"),
66-
[
67-
("exact", "guess-next-dev", "node-and-date", "1.1"),
68-
("dirty", "guess-next-dev", "node-and-date", "1.2.dev0+d20090213"),
69-
("dirty", "guess-next-dev", "no-local-version", "1.2.dev0"),
70-
("distance-clean", "guess-next-dev", "node-and-date", "1.2.dev3"),
71-
("distance-dirty", "guess-next-dev", "node-and-date", "1.2.dev3+d20090213"),
72-
("exact", "post-release", "node-and-date", "1.1"),
73-
("dirty", "post-release", "node-and-date", "1.1.post0+d20090213"),
74-
("distance-clean", "post-release", "node-and-date", "1.1.post3"),
75-
("distance-dirty", "post-release", "node-and-date", "1.1.post3+d20090213"),
76-
],
77-
)
78-
def test_format_version(
79-
version: str, version_scheme: str, local_scheme: str, expected: str
80-
) -> None:
81-
from dataclasses import replace
82-
83-
scm_version = VERSIONS[version]
84-
configured_version = replace(
85-
scm_version,
86-
config=replace(
87-
scm_version.config, version_scheme=version_scheme, local_scheme=local_scheme
88-
),
89-
)
90-
assert format_version(configured_version) == expected
91-
92-
93-
@pytest.mark.parametrize(
94-
("version", "version_scheme", "local_scheme", "expected"),
95-
[
96-
# Exact matches should preserve build metadata from tag
97-
("exact-build", "guess-next-dev", "node-and-date", "1.1+build.123"),
98-
("exact-build", "guess-next-dev", "no-local-version", "1.1+build.123"),
99-
("exact-ci", "guess-next-dev", "node-and-date", "2.0.0+ci.456"),
100-
("exact-ci", "guess-next-dev", "no-local-version", "2.0.0+ci.456"),
101-
# Dirty exact matches - version scheme treats dirty as non-exact, build metadata preserved
102-
(
103-
"dirty-build",
104-
"guess-next-dev",
105-
"node-and-date",
106-
"1.2.dev0+build.123.d20090213",
107-
),
108-
("dirty-build", "guess-next-dev", "no-local-version", "1.2.dev0+build.123"),
109-
("dirty-ci", "guess-next-dev", "node-and-date", "2.0.1.dev0+ci.456.d20090213"),
110-
# Distance cases - build metadata should be preserved and combined with SCM data
111-
(
112-
"distance-clean-build",
113-
"guess-next-dev",
114-
"node-and-date",
115-
"1.2.dev3+build.123",
116-
),
117-
(
118-
"distance-clean-build",
119-
"guess-next-dev",
120-
"no-local-version",
121-
"1.2.dev3+build.123",
122-
),
123-
("distance-clean-ci", "guess-next-dev", "node-and-date", "2.0.1.dev2+ci.456"),
124-
# Distance + dirty cases - build metadata should be preserved and combined with SCM data
125-
(
126-
"distance-dirty-build",
127-
"guess-next-dev",
128-
"node-and-date",
129-
"1.2.dev3+build.123.d20090213",
130-
),
131-
(
132-
"distance-dirty-ci",
133-
"guess-next-dev",
134-
"node-and-date",
135-
"2.0.1.dev2+ci.456.d20090213",
136-
),
137-
# Post-release scheme tests
138-
("exact-build", "post-release", "node-and-date", "1.1+build.123"),
139-
(
140-
"dirty-build",
141-
"post-release",
142-
"node-and-date",
143-
"1.1.post0+build.123.d20090213",
144-
),
145-
(
146-
"distance-clean-build",
147-
"post-release",
148-
"node-and-date",
149-
"1.1.post3+build.123",
150-
),
151-
(
152-
"distance-dirty-build",
153-
"post-release",
154-
"node-and-date",
155-
"1.1.post3+build.123.d20090213",
156-
),
157-
],
158-
)
159-
def test_format_version_with_build_metadata(
160-
version: str, version_scheme: str, local_scheme: str, expected: str
161-
) -> None:
162-
"""Test format_version with tags that contain build metadata."""
163-
from dataclasses import replace
164-
165-
from packaging.version import Version
166-
167-
scm_version = VERSIONS_WITH_BUILD_METADATA[version]
168-
configured_version = replace(
169-
scm_version,
170-
config=replace(
171-
scm_version.config, version_scheme=version_scheme, local_scheme=local_scheme
172-
),
173-
)
174-
result = format_version(configured_version)
175-
176-
# Validate result is a valid PEP 440 version
177-
parsed = Version(result)
178-
assert str(parsed) == result, f"Result should be valid PEP 440: {result}"
179-
180-
assert result == expected, f"Expected {expected}, got {result}"
181-
182-
18329
def test_dump_version_doesnt_bail_on_value_error(tmp_path: Path) -> None:
18430
write_to = "VERSION"
18531
version = str(VERSIONS["exact"].tag)
@@ -264,38 +110,6 @@ def test_dump_version_ruff(tmp_path: Path) -> None:
264110
subprocess.run([ruff, "check", "--no-fix", "VERSION.py"], cwd=tmp_path, check=True)
265111

266112

267-
def test_has_command() -> None:
268-
with pytest.warns(RuntimeWarning, match="yadayada"):
269-
assert not has_command("yadayada_setuptools_aint_ne")
270-
271-
272-
def test_has_command_logs_stderr(caplog: pytest.LogCaptureFixture) -> None:
273-
"""
274-
If the name provided to has_command() exists as a command, but gives a non-zero
275-
return code, there should be a log message generated.
276-
"""
277-
with pytest.warns(RuntimeWarning, match="ls"):
278-
has_command("ls", ["--a-flag-that-doesnt-exist-should-give-output-on-stderr"])
279-
found_it = False
280-
for record in caplog.records:
281-
if "returned non-zero. This is stderr" in record.message:
282-
found_it = True
283-
assert found_it, "Did not find expected log record for "
284-
285-
286-
@pytest.mark.parametrize(
287-
("tag", "expected_version"),
288-
[
289-
("1.1", "1.1"),
290-
("release-1.1", "1.1"),
291-
pytest.param("3.3.1-rc26", "3.3.1rc26", marks=pytest.mark.issue(266)),
292-
],
293-
)
294-
def test_tag_to_version(tag: str, expected_version: str) -> None:
295-
version = str(tag_to_version(tag, c))
296-
assert version == expected_version
297-
298-
299113
def test_write_version_to_path_deprecation_warning_none(tmp_path: Path) -> None:
300114
"""Test that write_version_to_path warns when scm_version=None is passed."""
301115
from vcs_versioning._dump_version import write_version_to_path

0 commit comments

Comments
 (0)