Paths
paths
Path/tier/module-name helpers (no AST, no IO beyond Path inspection).
abspath(p, project_path)
Normalise a finding path (which may be relative or absolute).
file_depth_from_project(path, project_path)
Number of path parts between path's file and project_path.
For /p/tests/unit/core/test_X.py under /p, returns 4
(tests, unit, core, test_X.py). Independent of
project_path's own depth. Used to compute depth_delta when
a file is relocated, so Path(__file__).parents[N] constants
can be re-pointed to the same ancestor.
Source code in packages/axm-audit/src/axm_audit/core/fix/paths.py
module_path_for_test_file(path, project_path)
Return the dotted module path used by from imports for path.
For project/tests/integration/test_foo.py this returns
tests.integration.test_foo. Returns None if path is not under
project_path/tests/.
Source code in packages/axm-audit/src/axm_audit/core/fix/paths.py
retier(p, root, target_lvl)
Compute the destination path under tests/{target_lvl}/.
Three cases on the relative parts:
tests/<tier>/...rest...— substitute the tier component:parts[1] = target_lvl.tests/<file>.py— no tier component yet; inject one betweentestsand the file: result istests/<target_lvl>/<file>.py. Without this branch the slot-substitution path silently turnedtests/test_X.pyintotests/<target_lvl>(the.pydisappears because it was at index 1), which then surfaced asIsADirectoryErrordownstream.- anything not under
tests/— unchanged.
Source code in packages/axm-audit/src/axm_audit/core/fix/paths.py
safe_filename(name)
Make a canonical filename PEP8-importable.
Current FILE_NAMING emits test_<a>__<b>.py (__ separator,
PEP 8 compliant). This function is now a near-identity defensive
pass: it strips any legacy - separators an older audit version
could still produce, preserving forward compatibility without
changing the proto's behaviour on output of the current rule.
Source code in packages/axm-audit/src/axm_audit/core/fix/paths.py
tier_for_path(path)
Return unit/integration/e2e for a test path, or None.
Walks up the parents until a tier component is found. Tolerates
nested test layouts like tests/integration/hooks/test_x.py
where path.parent.name is hooks rather than integration.