Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .cursor/rules/test-running.mdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
description: run tests wit uv tooling
globs:
alwaysApply: true
---

use `uv run pytest` to run tests
use uv to manage dependencies
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
- fix #1136: update customizing.md to fix missing import
- fix #1001: document the missing version schemes and add examples in the docs
- fix #1115: explicitly document file finder behaviour
- fix #879: add test that validates caswe differenct behavior

## v8.3.1

Expand Down
75 changes: 75 additions & 0 deletions testing/test_regressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,81 @@ def test_case_mismatch_on_windows_git(tmp_path: Path) -> None:
assert res is not None


@pytest.mark.skipif(sys.platform != "win32", reason="this bug is only valid on windows")
def test_case_mismatch_nested_dir_windows_git(tmp_path: Path) -> None:
"""Test case where we have a nested directory with different casing"""
# Create git repo in my_repo
repo_path = tmp_path / "my_repo"
repo_path.mkdir()
run("git init", repo_path)

# Create a nested directory with specific casing
nested_dir = repo_path / "CasedDir"
nested_dir.mkdir()

# Create a pyproject.toml in the nested directory
(nested_dir / "pyproject.toml").write_text("""
[build-system]
requires = ["setuptools>=64", "setuptools-scm"]
build-backend = "setuptools.build_meta"

[project]
name = "test-project"
dynamic = ["version"]

[tool.setuptools_scm]
""")

# Add and commit the file
run("git add .", repo_path)
run("git commit -m 'Initial commit'", repo_path)

# Now try to parse from the nested directory with lowercase path
# This simulates: cd my_repo/caseddir (lowercase) when actual dir is CasedDir
lowercase_nested_path = str(nested_dir).replace("CasedDir", "caseddir")

# This should trigger the assertion error in _git_toplevel
try:
res = parse(lowercase_nested_path, Configuration())
# If we get here without assertion error, the bug is already fixed or not triggered
print(f"Parse succeeded with result: {res}")
except AssertionError as e:
print(f"AssertionError caught as expected: {e}")
# Re-raise so the test fails, showing we reproduced the bug
raise


def test_case_mismatch_force_assertion_failure(tmp_path: Path) -> None:
"""Force the assertion failure by directly calling _git_toplevel with mismatched paths"""
from setuptools_scm._file_finders.git import _git_toplevel

# Create git repo structure
repo_path = tmp_path / "my_repo"
repo_path.mkdir()
run("git init", repo_path)

# Create nested directory
nested_dir = repo_path / "CasedDir"
nested_dir.mkdir()

# Add and commit something to make it a valid repo
(nested_dir / "test.txt").write_text("test")
run("git add .", repo_path)
run("git commit -m 'Initial commit'", repo_path)

# Now call _git_toplevel with a path that has different casing
# This should cause the assertion to fail
lowercase_nested_path = str(nested_dir).replace("CasedDir", "caseddir")

try:
result = _git_toplevel(lowercase_nested_path)
print(f"_git_toplevel returned: {result}")
# If no assertion error, either the bug is fixed or we didn't trigger it properly
except AssertionError as e:
print(f"AssertionError as expected: {e}")
raise # Let the test fail to show we reproduced the issue


def test_entrypoints_load() -> None:
d = distribution("setuptools-scm")

Expand Down
6 changes: 3 additions & 3 deletions testing/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def test_regex_match_but_no_version() -> None:
" however the matched group has no value"
),
):
meta("v1", config=replace(c, tag_regex=re.compile("(?P<version>).*")))
meta("v1", config=replace(c, tag_regex=re.compile(r"(?P<version>).*")))


@pytest.mark.issue("https://github.com/pypa/setuptools-scm/issues/471")
Expand Down Expand Up @@ -482,7 +482,7 @@ def __repr__(self) -> str:
def test_no_matching_entrypoints(config_key: str) -> None:
version = meta(
"1.0",
config=replace(c, **{config_key: "nonexistant"}), # type: ignore
config=replace(c, **{config_key: "nonexistant"}), # type: ignore[arg-type]
)
with pytest.raises(
ValueError,
Expand All @@ -499,7 +499,7 @@ def test_all_entrypoints_return_none() -> None:
"1.0",
config=replace(
c,
version_scheme=lambda v: None, # type: ignore
version_scheme=lambda v: None, # type: ignore[arg-type,return-value]
),
)
with pytest.raises(
Expand Down
Loading