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
"""
6
Purpose
7
-------
8
OI-533 regression tests — :func:`oct.core.paths.to_project_relative`
9
renders filesystem paths as project-relative POSIX strings for
10
user-facing output (lint findings, health reports, git status, etc.)
11
so absolute machine paths never leak into CI logs or pasted errors.
12
13
Responsibilities
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
20
Diagnostics
21
-----------
22
Domain: CORE-TESTS
23
Levels:
24
L2 — test lifecycle
25
L3 — individual assertions
26
L4 — deep tracing
27
28
Contracts
29
---------
30
- Tests use synthetic paths; no real filesystem reads or writes.
31
"""
32
33
from
__future__
import
annotations
34
35
from
pathlib
import
Path, PureWindowsPath
36
37
from
oct.core.paths
import
to_project_relative
38
39
40
def
test_in_tree_path_is_rendered_project_relative
(tmp_path):
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
49
def
test_out_of_tree_path_falls_back_to_absolute_posix
(tmp_path):
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
62
def
test_backslashes_are_normalised_to_posix
(tmp_path):
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"
tests_core.test_paths.test_out_of_tree_path_falls_back_to_absolute_posix
test_out_of_tree_path_falls_back_to_absolute_posix(tmp_path)
Definition
test_paths.py:49
tests_core.test_paths.test_backslashes_are_normalised_to_posix
test_backslashes_are_normalised_to_posix(tmp_path)
Definition
test_paths.py:62
tests_core.test_paths.test_in_tree_path_is_rendered_project_relative
test_in_tree_path_is_rendered_project_relative(tmp_path)
Definition
test_paths.py:40
tests
tests_core
test_paths.py
Generated by
1.15.0