Option C Tools
Loading...
Searching...
No Matches
test_paths.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3# tests/tests_core/test_paths.py
4
5"""
6Purpose
7-------
8OI-533 regression tests — :func:`oct.core.paths.to_project_relative`
9renders filesystem paths as project-relative POSIX strings for
10user-facing output (lint findings, health reports, git status, etc.)
11so absolute machine paths never leak into CI logs or pasted errors.
12
13Responsibilities
14----------------
15- In-tree paths are rendered relative to *project_root*.
16- Out-of-tree paths fall back to the absolute POSIX form.
17- Windows-style backslashes are normalised to forward slashes on
18 every platform.
19
20Diagnostics
21-----------
22Domain: CORE-TESTS
23Levels:
24 L2 — test lifecycle
25 L3 — individual assertions
26 L4 — deep tracing
27
28Contracts
29---------
30- Tests use synthetic paths; no real filesystem reads or writes.
31"""
32
33from __future__ import annotations
34
35from pathlib import Path, PureWindowsPath
36
37from oct.core.paths import to_project_relative
38
39
41 root = tmp_path
42 target = root / "oct" / "foo.py"
43 target.parent.mkdir(parents=True)
44 target.touch()
45
46 assert to_project_relative(target, root) == "oct/foo.py"
47
48
50 root = tmp_path / "proj"
51 root.mkdir()
52 outside = tmp_path / "elsewhere" / "bar.py"
53 outside.parent.mkdir()
54 outside.touch()
55
56 result = to_project_relative(outside, root)
57
58 assert result == outside.as_posix()
59 assert "\\" not in result
60
61
63 root = tmp_path
64 target = root / "a" / "b" / "c.py"
65 target.parent.mkdir(parents=True)
66 target.touch()
67
68 rel = to_project_relative(target, root)
69
70 assert "\\" not in rel
71 assert rel == "a/b/c.py"
test_out_of_tree_path_falls_back_to_absolute_posix(tmp_path)
Definition test_paths.py:49
test_backslashes_are_normalised_to_posix(tmp_path)
Definition test_paths.py:62
test_in_tree_path_is_rendered_project_relative(tmp_path)
Definition test_paths.py:40