Skip to content

Commit 895376d

Browse files
fix 879: expand windows case handling
1 parent 99f0d2a commit 895376d

File tree

4 files changed

+87
-3
lines changed

4 files changed

+87
-3
lines changed

.cursor/rules/test-running.mdc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
description: run tests wit uv tooling
3+
globs:
4+
alwaysApply: true
5+
---
6+
7+
use `uv run pytest` to run tests
8+
use uv to manage dependencies

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
- fix #1136: update customizing.md to fix missing import
2828
- fix #1001: document the missing version schemes and add examples in the docs
2929
- fix #1115: explicitly document file finder behaviour
30+
- fix #879: add test that validates caswe differenct behavior
3031

3132
## v8.3.1
3233

testing/test_regressions.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,81 @@ def test_case_mismatch_on_windows_git(tmp_path: Path) -> None:
101101
assert res is not None
102102

103103

104+
@pytest.mark.skipif(sys.platform != "win32", reason="this bug is only valid on windows")
105+
def test_case_mismatch_nested_dir_windows_git(tmp_path: Path) -> None:
106+
"""Test case where we have a nested directory with different casing"""
107+
# Create git repo in my_repo
108+
repo_path = tmp_path / "my_repo"
109+
repo_path.mkdir()
110+
run("git init", repo_path)
111+
112+
# Create a nested directory with specific casing
113+
nested_dir = repo_path / "CasedDir"
114+
nested_dir.mkdir()
115+
116+
# Create a pyproject.toml in the nested directory
117+
(nested_dir / "pyproject.toml").write_text("""
118+
[build-system]
119+
requires = ["setuptools>=64", "setuptools-scm"]
120+
build-backend = "setuptools.build_meta"
121+
122+
[project]
123+
name = "test-project"
124+
dynamic = ["version"]
125+
126+
[tool.setuptools_scm]
127+
""")
128+
129+
# Add and commit the file
130+
run("git add .", repo_path)
131+
run("git commit -m 'Initial commit'", repo_path)
132+
133+
# Now try to parse from the nested directory with lowercase path
134+
# This simulates: cd my_repo/caseddir (lowercase) when actual dir is CasedDir
135+
lowercase_nested_path = str(nested_dir).replace("CasedDir", "caseddir")
136+
137+
# This should trigger the assertion error in _git_toplevel
138+
try:
139+
res = parse(lowercase_nested_path, Configuration())
140+
# If we get here without assertion error, the bug is already fixed or not triggered
141+
print(f"Parse succeeded with result: {res}")
142+
except AssertionError as e:
143+
print(f"AssertionError caught as expected: {e}")
144+
# Re-raise so the test fails, showing we reproduced the bug
145+
raise
146+
147+
148+
def test_case_mismatch_force_assertion_failure(tmp_path: Path) -> None:
149+
"""Force the assertion failure by directly calling _git_toplevel with mismatched paths"""
150+
from setuptools_scm._file_finders.git import _git_toplevel
151+
152+
# Create git repo structure
153+
repo_path = tmp_path / "my_repo"
154+
repo_path.mkdir()
155+
run("git init", repo_path)
156+
157+
# Create nested directory
158+
nested_dir = repo_path / "CasedDir"
159+
nested_dir.mkdir()
160+
161+
# Add and commit something to make it a valid repo
162+
(nested_dir / "test.txt").write_text("test")
163+
run("git add .", repo_path)
164+
run("git commit -m 'Initial commit'", repo_path)
165+
166+
# Now call _git_toplevel with a path that has different casing
167+
# This should cause the assertion to fail
168+
lowercase_nested_path = str(nested_dir).replace("CasedDir", "caseddir")
169+
170+
try:
171+
result = _git_toplevel(lowercase_nested_path)
172+
print(f"_git_toplevel returned: {result}")
173+
# If no assertion error, either the bug is fixed or we didn't trigger it properly
174+
except AssertionError as e:
175+
print(f"AssertionError as expected: {e}")
176+
raise # Let the test fail to show we reproduced the issue
177+
178+
104179
def test_entrypoints_load() -> None:
105180
d = distribution("setuptools-scm")
106181

testing/test_version.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ def test_regex_match_but_no_version() -> None:
233233
" however the matched group has no value"
234234
),
235235
):
236-
meta("v1", config=replace(c, tag_regex=re.compile("(?P<version>).*")))
236+
meta("v1", config=replace(c, tag_regex=re.compile(r"(?P<version>).*")))
237237

238238

239239
@pytest.mark.issue("https://github.com/pypa/setuptools-scm/issues/471")
@@ -482,7 +482,7 @@ def __repr__(self) -> str:
482482
def test_no_matching_entrypoints(config_key: str) -> None:
483483
version = meta(
484484
"1.0",
485-
config=replace(c, **{config_key: "nonexistant"}), # type: ignore
485+
config=replace(c, **{config_key: "nonexistant"}), # type: ignore[arg-type]
486486
)
487487
with pytest.raises(
488488
ValueError,
@@ -499,7 +499,7 @@ def test_all_entrypoints_return_none() -> None:
499499
"1.0",
500500
config=replace(
501501
c,
502-
version_scheme=lambda v: None, # type: ignore
502+
version_scheme=lambda v: None, # type: ignore[arg-type,return-value]
503503
),
504504
)
505505
with pytest.raises(

0 commit comments

Comments
 (0)