Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.
Python aicode-complexitycode-healthcode-intelligencecode-qualitydead-codedeveloper-toolsdocumentationgit-analyticsmcpopen-sourcepythonrefactoringstatic-analysistechnical-debt
fix(test-paths): classify Perl-style t/ as a Python test tree (#3046)
Soumojit Das6f833c7fef74
diff --git a/packages/core/src/repowise/core/ingestion/languages/spec.py b/packages/core/src/repowise/core/ingestion/languages/spec.pyindex 383f40807..7ff4d26f8 100644--- a/packages/core/src/repowise/core/ingestion/languages/spec.py+++ b/packages/core/src/repowise/core/ingestion/languages/spec.py@@ -105,9 +105,11 @@ class LanguageSpec:# Single-segment test-dir tokens that are UNAMBIGUOUS for this# language's files. The generic table treats "spec(s)/" as ambiguous- # (OpenAPI specs, language specs) and demands a test-shaped filename —- # but a Ruby file under spec/ is RSpec material whatever its name- # (support helpers, vendored fixtures like okjson.rb included).+ # (OpenAPI specs, language specs) and "t/" as ambiguous (a single+ # letter) and demands a test-shaped filename — but a Ruby file under+ # spec/ is RSpec material whatever its name (support helpers, vendored+ # fixtures like okjson.rb included), and a Python file under t/ is test+ # material whatever its name.test_dir_tokens: tuple[str, ...] = ()# Case-sensitive directory-segment suffixes that mark a test projectdiff --git a/packages/core/src/repowise/core/ingestion/languages/specs/python.py b/packages/core/src/repowise/core/ingestion/languages/specs/python.pyindex 0b8bc99c5..923471e8e 100644--- a/packages/core/src/repowise/core/ingestion/languages/specs/python.py+++ b/packages/core/src/repowise/core/ingestion/languages/specs/python.py@@ -11,6 +11,9 @@ SPEC = LanguageSpec(test_stem_prefixes=("test_",),test_fixture_stems=("conftest",),suite_anchor_stems=("conftest",),+ # Perl-style t/: a Python file under t/ is test material whatever its+ # name (fixtures, helpers, task modules) — no filename corroboration.+ test_dir_tokens=("t",),extensions=frozenset({".py", ".pyi"}),grammar_package="tree_sitter_python",scm_file="python.scm",diff --git a/packages/core/src/repowise/core/test_paths.py b/packages/core/src/repowise/core/test_paths.pyindex 92d62955f..92f84bdf0 100644--- a/packages/core/src/repowise/core/test_paths.py+++ b/packages/core/src/repowise/core/test_paths.py@@ -99,11 +99,13 @@ _REPO_METADATA_DIR = ".github"_SEGMENT_WORD_SEPARATORS = re.compile(r"[-_.]+")# Tokens that also name non-test directories in the wild: "spec(s)" is as often-# OpenAPI/language specifications as it is RSpec. These count only when the+# OpenAPI/language specifications as it is RSpec, and "t" is a single letter+# that shows up in real directory names. These count only when the# filename corroborates, or when the file's own language declares the token# (Ruby's spec/ needs no corroboration - a Ruby file under spec/ is RSpec-# material whatever its name).-_AMBIGUOUS_TEST_DIR_TOKENS: frozenset[str] = frozenset({"spec", "specs"})+# material whatever its name; Python's t/ likewise - a Python file under t/+# is test material whatever its name).+_AMBIGUOUS_TEST_DIR_TOKENS: frozenset[str] = frozenset({"spec", "specs", "t"})# A whole module named for testing and nothing else: Django's per-app# ``myapp/tests.py`` and Rust's ``#[cfg(test)] mod tests;`` in ``tests.rs``,@@ -405,8 +407,9 @@ def is_test_path(path: str, language: str | None = None) -> bool:Test *support* (``conftest.py``, ``tests/factories/user.py``) isdeliberately not a test here - see :func:`is_test_support_path`. Pass- *language* when it is known: it decides the ambiguous ``spec/`` case, which- is RSpec for Ruby and a specification folder for everything else.+ *language* when it is known: it decides the ambiguous ``spec/``/``t/``+ cases, which are RSpec for Ruby and a Perl-style test tree for Python,+ and specification or miscellaneous folders for everything else."""return _classify(path, language) == "test"diff --git a/tests/unit/test_test_paths.py b/tests/unit/test_test_paths.pyindex 9c4ffde21..b95414c4c 100644--- a/tests/unit/test_test_paths.py+++ b/tests/unit/test_test_paths.py@@ -81,6 +81,26 @@ _CORPUS: tuple[tuple[str, str | None, str], ...] = (("spec/models/user.rb", None, ""),("spec/openapi/users.yaml", None, ""),("spec/support/helper.rb", None, "support"),+ # perl-style t/: `t/` is a test tree for python whatever the filename+ # (celery layout), and needs a test-shaped filename otherwise — same+ # ambiguous-token mechanism as `spec/` above (#2962)+ ("t/unit/app/test_app.py", "python", "test"),+ ("t/unit/conftest.py", "python", "support"),+ ("t/unit/tasks/task_config.py", "python", "test"),+ ("t/integration/tasks.py", "python", "test"),+ ("t/smoke/tasks.py", "python", "test"),+ ("t/unit/contrib/proj/foo/tasks.py", "python", "test"),+ # ...so without the language, only a corroborating filename counts+ ("t/unit/app/test_app.py", None, "test"),+ ("t/unit/tasks/task_config.py", None, ""),+ # ...a non-source file under t/ stays as it is without corroboration+ ("t/data/expected.json", None, ""),+ ("t/assets/image.png", None, ""),+ # ...and a bare `t` that is not a directory segment stays production+ ("src/t.py", None, ""),+ ("src/t.py", "python", ""),+ ("latest/x.py", None, ""),+ ("contest/x.py", None, ""),# e2e suites("e2e/login.ts", None, "test"),# production code that merely contains the word: the unanchored