-
-
Notifications
You must be signed in to change notification settings - Fork 347
Expand file tree
/
Copy pathtest_path_normalization.py
More file actions
66 lines (55 loc) · 2.27 KB
/
test_path_normalization.py
File metadata and controls
66 lines (55 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python3
"""Quick test to verify path normalization logic."""
# Test the regex-based normalization
def test_normalize_path():
import re
test_cases = [
# (input_path, expected_output)
("C:\\Program Files\\game.exe", "C:\\Program Files\\game.exe"), # Already Windows
("/var/home/user/.local/share/bottles/bottles/MyBottle/drive_c/Program Files/game.exe", "C:\\Program Files\\game.exe"),
("/path/to/bottle/drive_d/Games/game.exe", "D:\\Games\\game.exe"),
("/path/dosdevices/c:/windows/system32/cmd.exe", "C:\\windows\\system32\\cmd.exe"),
("/path/dosdevices/e:/data/file.txt", "E:\\data\\file.txt"),
]
def normalize(program_path: str) -> str:
"""Simplified version of _normalize_path_to_windows."""
# Already Windows format?
if ":" in program_path and "\\" in program_path:
return program_path
# Convert Unix path to Windows format
if "/drive_" in program_path:
match = re.search(r"drive_([a-z])/(.+)", program_path)
if match:
drive = match.group(1).upper()
rest = match.group(2).replace("/", "\\")
return f"{drive}:\\{rest}"
elif "/dosdevices/" in program_path:
match = re.search(r"dosdevices/([a-z]):/(.+)", program_path)
if match:
drive = match.group(1).upper()
rest = match.group(2).replace("/", "\\")
return f"{drive}:\\{rest}"
return program_path
print("Testing path normalization:")
print("-" * 80)
all_passed = True
for input_path, expected in test_cases:
result = normalize(input_path)
passed = result == expected
all_passed = all_passed and passed
status = "✓ PASS" if passed else "✗ FAIL"
print(f"{status}")
print(f" Input: {input_path}")
print(f" Expected: {expected}")
print(f" Got: {result}")
print()
print("-" * 80)
if all_passed:
print("✓ All tests passed!")
else:
print("✗ Some tests failed!")
return all_passed
if __name__ == "__main__":
import sys
success = test_normalize_path()
sys.exit(0 if success else 1)