diff --git a/.cursor/rules/test-running.mdc b/.cursor/rules/test-running.mdc new file mode 100644 index 00000000..8c6875c9 --- /dev/null +++ b/.cursor/rules/test-running.mdc @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 08d838f4..c16454c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/testing/test_regressions.py b/testing/test_regressions.py index 21f52711..679365e6 100644 --- a/testing/test_regressions.py +++ b/testing/test_regressions.py @@ -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") diff --git a/testing/test_version.py b/testing/test_version.py index 7dce433d..eb31cc1e 100644 --- a/testing/test_version.py +++ b/testing/test_version.py @@ -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).*"))) + meta("v1", config=replace(c, tag_regex=re.compile(r"(?P).*"))) @pytest.mark.issue("https://github.com/pypa/setuptools-scm/issues/471") @@ -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, @@ -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(