-
-
Notifications
You must be signed in to change notification settings - Fork 766
Expand file tree
/
Copy pathtest_path_resolution.py
More file actions
executable file
·144 lines (113 loc) · 4.84 KB
/
test_path_resolution.py
File metadata and controls
executable file
·144 lines (113 loc) · 4.84 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/env python3
"""Test script to verify path resolution works correctly on different platforms.
This script tests that pymode/utils.py patch_paths() function correctly
resolves paths for required submodules on different operating systems.
Note: This script tests the path resolution logic without requiring Vim,
since patch_paths() requires vim module at runtime.
"""
import os
import sys
import platform
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
PROJECT_ROOT = os.path.dirname(SCRIPT_DIR)
PYMODE_DIR = os.path.join(PROJECT_ROOT, 'pymode')
SUBMODULES_DIR = os.path.join(PROJECT_ROOT, 'submodules')
def test_path_resolution_logic():
"""Test the path resolution logic used by patch_paths()."""
def test_path_resolution_logic():
"""Test the path resolution logic used by patch_paths()."""
print("=" * 70)
print("Path Resolution Test")
print("=" * 70)
print(f"Platform: {platform.system()} {platform.release()}")
print(f"Python version: {sys.version.split()[0]}")
print(f"Python executable: {sys.executable}")
print()
# Simulate patch_paths() logic
print("Simulating patch_paths() logic...")
dir_script = PYMODE_DIR
dir_submodule = os.path.abspath(os.path.join(dir_script, '..', 'submodules'))
print(f"Pymode directory: {dir_script}")
print(f"Submodules directory: {dir_submodule}")
print()
# Required submodules (from patch_paths() logic)
required_submodules = ['rope', 'tomli', 'pytoolconfig']
print("Checking required submodules:")
print("-" * 70)
all_found = True
paths_to_add = []
for module in required_submodules:
module_full_path = os.path.join(dir_submodule, module)
exists = os.path.exists(module_full_path)
# Simulate the check from patch_paths()
if exists and module_full_path not in sys.path:
paths_to_add.append(module_full_path)
status = "✓"
elif exists:
status = "⚠" # Already in path
paths_to_add.append(module_full_path)
else:
status = "✗"
print(f"{status} {module:15} | Exists: {str(exists):5} | Path: {module_full_path}")
if not exists:
print(f" ERROR: Module directory not found!")
all_found = False
print()
# Check for removed submodules (should NOT exist or be added)
removed_submodules = [
'pyflakes', 'pycodestyle', 'mccabe', 'pylint',
'pydocstyle', 'pylama', 'autopep8', 'snowball_py',
'toml', 'appdirs', 'astroid'
]
print("\nChecking removed submodules (should NOT be added to paths):")
print("-" * 70)
removed_found = False
for module in removed_submodules:
module_path = os.path.join(dir_submodule, module)
exists = os.path.exists(module_path)
# Check if it would be added (it shouldn't be in required_submodules)
if module in required_submodules:
print(f"✗ {module:15} | ERROR: Still in required_submodules list!")
removed_found = True
elif exists:
print(f"⚠ {module:15} | WARNING: Directory still exists (should be removed)")
else:
print(f"✓ {module:15} | Correctly excluded")
if not removed_found:
print("\n✓ All removed submodules correctly excluded from path resolution")
print()
# Platform-specific path handling test
print("\nPlatform-specific path handling:")
print("-" * 70)
is_windows = sys.platform == 'win32' or sys.platform == 'msys'
if is_windows:
print("✓ Windows platform detected - using Windows-specific path handling")
print(" (patch_paths() only adds submodules on Windows)")
else:
print(f"✓ Unix-like platform ({sys.platform}) - using standard path handling")
print(" (patch_paths() only adds submodules on Windows)")
print(" Note: On Unix, submodules are accessed via pymode/libs")
# Test path separators
print("\nPath separator test:")
print("-" * 70)
for module in required_submodules:
path = os.path.join(dir_submodule, module)
if os.path.exists(path):
# os.path.join handles separators correctly for platform
normalized = os.path.normpath(path)
print(f"✓ {module:15} | Normalized: {normalized[:60]}...")
print()
print("=" * 70)
# Summary
if all_found and not removed_found:
print("RESULT: ✓ All path resolution tests passed!")
print(f"\nWould add {len(paths_to_add)} path(s) to sys.path:")
for p in paths_to_add:
print(f" - {p}")
return 0
else:
print("RESULT: ✗ Some path resolution tests failed!")
return 1
if __name__ == '__main__':
exit_code = test_path_resolution_logic()
sys.exit(exit_code)