-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_build.py
More file actions
222 lines (190 loc) · 7.3 KB
/
test_build.py
File metadata and controls
222 lines (190 loc) · 7.3 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#!/usr/bin/env python3
"""
Test script to verify build environment and dependencies
This script checks if all required components are available for building
"""
import sys
import os
import shutil
import subprocess
from pathlib import Path
def test_python():
"""Test Python installation"""
print("Testing Python installation...")
try:
version = sys.version_info
print(f" ✓ Python {version.major}.{version.minor}.{version.micro} found")
if version.major < 3 or (version.major == 3 and version.minor < 8):
print(" ⚠ Warning: Python 3.8+ recommended for PyInstaller")
return False
return True
except Exception as e:
print(f" ✗ Python test failed: {e}")
return False
def test_pip():
"""Test pip installation"""
print("Testing pip...")
try:
result = subprocess.run([sys.executable, '-m', 'pip', '--version'],
capture_output=True, text=True, check=True)
print(f" ✓ {result.stdout.strip()}")
return True
except Exception as e:
print(f" ✗ pip test failed: {e}")
return False
def test_required_files():
"""Test that required files exist"""
print("Testing required files...")
required_files = [
'menu.py',
'font_manager.py',
'config.yml',
'logo.png',
'smallicon.png',
'requirements_build.txt',
'build.py',
'build.sh'
]
missing = []
for file in required_files:
if os.path.exists(file):
print(f" ✓ {file}")
else:
print(f" ✗ {file} (missing)")
missing.append(file)
return len(missing) == 0
def test_build_dependencies():
"""Test if build dependencies can be installed"""
print("Testing build dependencies installation...")
# Create a temporary virtual environment
test_venv = "test_venv"
try:
print(f" Creating test virtual environment: {test_venv}")
subprocess.run([sys.executable, '-m', 'venv', test_venv],
check=True, capture_output=True)
# Get Python path in venv
if os.name == 'nt': # Windows
venv_python = os.path.join(test_venv, 'Scripts', 'python.exe')
else:
venv_python = os.path.join(test_venv, 'bin', 'python')
print(" Installing build requirements...")
subprocess.run([venv_python, '-m', 'pip', 'install', '-r', 'requirements_build.txt'],
check=True, capture_output=True)
print(" Testing PyInstaller import...")
subprocess.run([venv_python, '-c', 'import PyInstaller; print("PyInstaller OK")'],
check=True, capture_output=True)
print(" Testing PyQt5 import...")
subprocess.run([venv_python, '-c', 'import PyQt5.QtWidgets; print("PyQt5 OK")'],
check=True, capture_output=True)
print(" Testing PyYAML import...")
subprocess.run([venv_python, '-c', 'import yaml; print("PyYAML OK")'],
check=True, capture_output=True)
print(" ✓ All build dependencies can be installed and imported")
return True
except subprocess.CalledProcessError as e:
print(f" ✗ Build dependency test failed: {e}")
return False
except Exception as e:
print(f" ✗ Unexpected error: {e}")
return False
finally:
# Clean up test environment
if os.path.exists(test_venv):
shutil.rmtree(test_venv)
print(f" Cleaned up {test_venv}")
def test_yaml_config():
"""Test that the current config file is valid"""
print("Testing YAML configuration...")
try:
import yaml
with open('config.yml', 'r') as f:
config = yaml.safe_load(f)
# Check basic structure
required_keys = ['menu_title', 'menu_items']
for key in required_keys:
if key not in config:
print(f" ⚠ Warning: Missing key '{key}' in config.yml")
else:
print(f" ✓ Found {key}: {config[key] if key == 'menu_title' else f'{len(config[key])} items'}")
print(" ✓ YAML configuration is valid")
return True
except ImportError:
print(" ⚠ PyYAML not installed, installing temporarily...")
try:
subprocess.run([sys.executable, '-m', 'pip', 'install', 'PyYAML'],
check=True, capture_output=True)
return test_yaml_config() # Retry
except Exception as e:
print(f" ✗ Could not install PyYAML: {e}")
return False
except Exception as e:
print(f" ✗ YAML test failed: {e}")
return False
def test_build_scripts():
"""Test that build scripts are executable"""
print("Testing build scripts...")
scripts = [
('build.py', 'Python build script'),
('build.sh', 'Shell build script (Unix/Linux/macOS)'),
('build.bat', 'Batch build script (Windows)')
]
all_good = True
for script, description in scripts:
if os.path.exists(script):
if script.endswith('.sh'):
if os.access(script, os.X_OK):
print(f" ✓ {script} - {description} (executable)")
else:
print(f" ⚠ {script} - {description} (not executable)")
print(f" Run: chmod +x {script}")
else:
print(f" ✓ {script} - {description}")
else:
print(f" ✗ {script} - {description} (missing)")
all_good = False
return all_good
def main():
"""Run all tests"""
print("=" * 50)
print("Python GUI Menu - Build Environment Test")
print("=" * 50)
print()
tests = [
("Python Installation", test_python),
("Pip Package Manager", test_pip),
("Required Files", test_required_files),
("YAML Configuration", test_yaml_config),
("Build Scripts", test_build_scripts),
("Build Dependencies", test_build_dependencies),
]
results = []
for test_name, test_func in tests:
print(f"\n{test_name}:")
print("-" * len(test_name))
try:
success = test_func()
results.append((test_name, success))
except Exception as e:
print(f" ✗ Test failed with exception: {e}")
results.append((test_name, False))
# Summary
print("\n" + "=" * 50)
print("TEST SUMMARY")
print("=" * 50)
passed = 0
for test_name, success in results:
status = "PASS" if success else "FAIL"
symbol = "✓" if success else "✗"
print(f"{symbol} {test_name}: {status}")
if success:
passed += 1
print(f"\nTotal: {passed}/{len(results)} tests passed")
if passed == len(results):
print("\n🎉 All tests passed! Your build environment is ready.")
print(" Run 'python build.py' to create a standalone executable.")
else:
print(f"\n⚠ {len(results) - passed} test(s) failed. Check the errors above.")
print(" Fix the issues before building.")
return 0 if passed == len(results) else 1
if __name__ == "__main__":
sys.exit(main())