|
11 | 11 | import traceback |
12 | 12 | import importlib.util |
13 | 13 |
|
14 | | -# Ensure the project root is in the Python path to allow for omnipkg imports |
| 14 | +# Ensure the project root is in the Python path |
15 | 15 | project_root = Path(__file__).resolve().parent.parent |
16 | 16 | sys.path.insert(0, str(project_root)) |
17 | 17 |
|
18 | 18 | # --- Test Configuration --- |
19 | 19 | MAIN_UV_VERSION = '0.6.13' |
20 | 20 | BUBBLE_VERSIONS_TO_TEST = ['0.4.30', '0.5.11'] |
21 | 21 |
|
22 | | -# --- Internationalization Setup --- |
23 | | -from omnipkg.i18n import _ |
24 | | -lang_from_env = os.environ.get('OMNIPKG_LANG') |
25 | | -if lang_from_env: |
26 | | - _.set_language(lang_from_env) |
27 | | - |
28 | 22 | # --- Omnipkg Core Imports --- |
29 | 23 | try: |
30 | 24 | from omnipkg.core import ConfigManager, omnipkg as OmnipkgCore |
31 | 25 | from omnipkg.loader import omnipkgLoader |
32 | | - from omnipkg.common_utils import run_command, print_header |
| 26 | + from omnipkg.common_utils import print_header |
| 27 | + from omnipkg.i18n import _ |
| 28 | + # Create a single, global config manager instance to be used throughout the script |
| 29 | + config_manager = ConfigManager() |
33 | 30 | except ImportError as e: |
34 | | - print(_('❌ Failed to import omnipkg modules. Is the project structure correct? Error: {}').format(e)) |
| 31 | + print(f'❌ Failed to import omnipkg modules. Is the project structure correct? Error: {e}') |
35 | 32 | sys.exit(1) |
36 | 33 |
|
37 | 34 | # --- Helper Functions --- |
38 | 35 |
|
39 | 36 | def print_header(title): |
40 | 37 | """Prints a formatted header to the console.""" |
41 | 38 | print('\n' + '=' * 80) |
42 | | - print(_(' 🚀 {}').format(title)) |
| 39 | + print(f' 🚀 {title}') |
43 | 40 | print('=' * 80) |
44 | 41 |
|
45 | 42 | def print_subheader(title): |
46 | 43 | """Prints a formatted subheader to the console.""" |
47 | | - print(_('\n--- {} ---').format(title)) |
| 44 | + print(f'\n--- {title} ---') |
48 | 45 |
|
49 | | -def set_install_strategy(config_manager, strategy): |
| 46 | +def set_install_strategy(strategy): |
50 | 47 | """Sets the omnipkg install strategy via the CLI.""" |
51 | 48 | try: |
52 | 49 | subprocess.run(['omnipkg', 'config', 'set', 'install_strategy', strategy], capture_output=True, text=True, check=True) |
53 | | - print(_(' ⚙️ Install strategy set to: {}').format(strategy)) |
| 50 | + print(f' ⚙️ Install strategy set to: {strategy}') |
54 | 51 | return True |
55 | 52 | except Exception as e: |
56 | | - print(_(' ⚠️ Failed to set install strategy: {}').format(e)) |
| 53 | + print(f' ⚠️ Failed to set install strategy: {e}') |
57 | 54 | return False |
58 | 55 |
|
59 | 56 | def pip_uninstall_uv(): |
60 | 57 | """Uses pip to uninstall uv from the main environment.""" |
61 | | - print(_(' 🧹 Using pip to uninstall uv from main environment...')) |
| 58 | + print(' 🧹 Using pip to uninstall uv from main environment...') |
62 | 59 | try: |
63 | 60 | result = subprocess.run(['pip', 'uninstall', 'uv', '-y'], capture_output=True, text=True, check=False) |
64 | | - if result.returncode == 0: |
65 | | - print(_(' ✅ pip uninstall uv completed successfully')) |
66 | | - else: |
67 | | - # It's not an error if it wasn't installed |
68 | | - print(_(' ℹ️ pip uninstall completed (uv may not have been installed)')) |
| 61 | + print(' ✅ pip uninstall uv completed successfully' if result.returncode == 0 else ' ℹ️ pip uninstall completed (uv may not have been installed)') |
69 | 62 | return True |
70 | 63 | except Exception as e: |
71 | | - print(_(' ⚠️ pip uninstall failed: {}').format(e)) |
| 64 | + print(f' ⚠️ pip uninstall failed: {e}') |
72 | 65 | return False |
73 | 66 |
|
74 | 67 | def pip_install_uv(version): |
75 | 68 | """Uses pip to install a specific version of uv.""" |
76 | | - print(_(' 📦 Using pip to install uv=={}...').format(version)) |
| 69 | + print(f' 📦 Using pip to install uv=={version}...') |
77 | 70 | try: |
78 | 71 | subprocess.run(['pip', 'install', f'uv=={version}'], capture_output=True, text=True, check=True) |
79 | | - print(_(' ✅ pip install uv=={} completed successfully').format(version)) |
| 72 | + print(f' ✅ pip install uv=={version} completed successfully') |
80 | 73 | return True |
81 | 74 | except Exception as e: |
82 | | - print(_(' ❌ pip install failed: {}').format(e)) |
| 75 | + print(f' ❌ pip install failed: {e}') |
83 | 76 | return False |
84 | 77 |
|
85 | 78 | # --- Test Workflow Steps --- |
86 | 79 |
|
87 | 80 | def setup_environment(): |
88 | 81 | """Prepares the testing environment by cleaning up and setting up a baseline.""" |
89 | 82 | print_header('STEP 1: Environment Setup & Cleanup') |
90 | | - config_manager = ConfigManager() |
91 | 83 | omnipkg_core = OmnipkgCore(config_manager) |
92 | | - print(_(' 🧹 Cleaning up existing UV installations...')) |
| 84 | + print(' 🧹 Cleaning up existing UV installations...') |
93 | 85 | pip_uninstall_uv() |
94 | | - # Clean any leftover bubbles from previous runs |
95 | 86 | for bubble in omnipkg_core.multiversion_base.glob('uv-*'): |
96 | 87 | shutil.rmtree(bubble, ignore_errors=True) |
97 | 88 |
|
98 | | - print(_(' 📦 Establishing stable main environment: uv=={}').format(MAIN_UV_VERSION)) |
| 89 | + print(f' 📦 Establishing stable main environment: uv=={MAIN_UV_VERSION}') |
99 | 90 | if not pip_install_uv(MAIN_UV_VERSION): |
100 | | - return (None, None) |
| 91 | + return None, None |
101 | 92 |
|
102 | | - # Use 'stable-main' to ensure omnipkg creates bubbles for other versions |
103 | | - set_install_strategy(config_manager, 'stable-main') |
| 93 | + original_strategy = config_manager.config.get('install_strategy', 'multiversion') |
| 94 | + set_install_strategy('stable-main') |
104 | 95 |
|
105 | | - print(_(' 🫧 Creating all required test bubbles...')) |
| 96 | + print(' 🫧 Creating all required test bubbles...') |
106 | 97 | for version in BUBBLE_VERSIONS_TO_TEST: |
107 | 98 | print(f' -> Installing bubble for uv=={version}') |
108 | 99 | omnipkg_core.smart_install([f'uv=={version}']) |
109 | 100 |
|
110 | | - print(_('✅ Environment prepared')) |
111 | | - return (ConfigManager(), 'stable-main') |
| 101 | + print('✅ Environment prepared') |
| 102 | + return config_manager, original_strategy |
112 | 103 |
|
113 | 104 | def inspect_bubble_structure(bubble_path): |
114 | 105 | """Prints a summary of the bubble's directory structure for verification.""" |
115 | | - print(_(' 🔍 Inspecting bubble structure: {}').format(bubble_path.name)) |
| 106 | + print(f' 🔍 Inspecting bubble structure: {bubble_path.name}') |
| 107 | + # ... (rest of the function is unchanged) |
116 | 108 | if not bubble_path.exists(): |
117 | | - print(_(" ❌ Bubble doesn't exist: {}").format(bubble_path)) |
| 109 | + print(f" ❌ Bubble doesn't exist: {bubble_path}") |
118 | 110 | return False |
119 | 111 |
|
120 | | - # Check for key components of a binary package bubble |
121 | 112 | dist_info = list(bubble_path.glob('uv-*.dist-info')) |
122 | | - if dist_info: |
123 | | - print(_(' ✅ Found dist-info: {}').format(dist_info[0].name)) |
124 | | - else: |
125 | | - print(_(' ⚠️ No dist-info found')) |
| 113 | + print(f' ✅ Found dist-info: {dist_info[0].name}' if dist_info else ' ⚠️ No dist-info found') |
126 | 114 |
|
127 | 115 | scripts_dir = bubble_path / 'bin' |
128 | 116 | if scripts_dir.exists(): |
129 | 117 | items = list(scripts_dir.iterdir()) |
130 | | - print(_(' ✅ Found bin directory with {} items').format(len(items))) |
| 118 | + print(f' ✅ Found bin directory with {len(items)} items') |
131 | 119 | uv_bin = scripts_dir / 'uv' |
132 | 120 | if uv_bin.exists(): |
133 | | - print(_(' ✅ Found uv binary: {}').format(uv_bin)) |
134 | | - if os.access(uv_bin, os.X_OK): |
135 | | - print(_(' ✅ Binary is executable')) |
136 | | - else: |
137 | | - print(_(' ⚠️ Binary is not executable')) |
| 121 | + print(f' ✅ Found uv binary: {uv_bin}') |
| 122 | + print(' ✅ Binary is executable' if os.access(uv_bin, os.X_OK) else ' ⚠️ Binary is not executable') |
138 | 123 | else: |
139 | | - print(_(' ⚠️ No uv binary in bin/')) |
| 124 | + print(' ⚠️ No uv binary in bin/') |
140 | 125 | else: |
141 | | - print(_(' ⚠️ No bin directory found')) |
| 126 | + print(' ⚠️ No bin directory found') |
142 | 127 |
|
143 | 128 | contents = list(bubble_path.iterdir()) |
144 | | - print(_(' 📁 Bubble contents ({} items):').format(len(contents))) |
145 | | - for item in sorted(contents)[:5]: # Print first 5 items |
146 | | - print(_(' - {}{}').format(item.name, '/' if item.is_dir() else '')) |
| 129 | + print(f' 📁 Bubble contents ({len(contents)} items):') |
| 130 | + for item in sorted(contents)[:5]: |
| 131 | + print(f" - {item.name}{'/' if item.is_dir() else ''}") |
147 | 132 | return True |
148 | 133 |
|
| 134 | +# ***** FIX IS HERE: Function signature reverted to original ***** |
149 | 135 | def test_swapped_binary_execution(expected_version): |
150 | 136 | """ |
151 | | - Tests version swapping using omnipkgLoader.context, which will |
152 | | - measure and print the activation/deactivation times. |
| 137 | + Tests version swapping using omnipkgLoader. |
153 | 138 | """ |
154 | | - print(_(' 🔧 Testing swapped binary execution via omnipkgLoader...')) |
| 139 | + print(' 🔧 Testing swapped binary execution via omnipkgLoader...') |
155 | 140 | try: |
156 | | - # This context manager activates the bubble, modifies the PATH, |
157 | | - # times the operation, and handles cleanup. |
158 | | - with omnipkgLoader(f'uv=={expected_version}'): |
159 | | - print(_(' 🎯 Executing: uv --version (within context)')) |
| 141 | + # It correctly uses the global config_manager instance now |
| 142 | + with omnipkgLoader(f'uv=={expected_version}', config=config_manager.config): |
| 143 | + print(' 🎯 Executing: uv --version (within context)') |
160 | 144 |
|
161 | | - # Inside the context, 'uv' should resolve to the bubbled version's binary |
162 | 145 | result = subprocess.run(['uv', '--version'], capture_output=True, text=True, timeout=10, check=True) |
163 | 146 | actual_version = result.stdout.strip().split()[-1] |
164 | 147 |
|
165 | | - print(_(' ✅ Swapped binary reported: {}').format(actual_version)) |
| 148 | + print(f' ✅ Swapped binary reported: {actual_version}') |
166 | 149 |
|
167 | 150 | if actual_version == expected_version: |
168 | | - print(_(' 🎯 Swapped binary test: PASSED')) |
| 151 | + print(' 🎯 Swapped binary test: PASSED') |
169 | 152 | return True |
170 | 153 | else: |
171 | | - print(_(' ❌ Version mismatch: expected {}, got {}').format(expected_version, actual_version)) |
| 154 | + print(f' ❌ Version mismatch: expected {expected_version}, got {actual_version}') |
172 | 155 | return False |
173 | 156 | except Exception as e: |
174 | | - print(_(' ❌ Swapped binary execution failed: {}').format(e)) |
| 157 | + print(f' ❌ Swapped binary execution failed: {e}') |
175 | 158 | traceback.print_exc() |
176 | 159 | return False |
177 | 160 |
|
178 | | -def test_main_environment_uv(config_manager: ConfigManager): |
| 161 | +def test_main_environment_uv(): |
179 | 162 | """Tests the main environment's uv installation as a baseline.""" |
180 | | - print_subheader(_('Testing Main Environment (uv=={})').format(MAIN_UV_VERSION)) |
| 163 | + print_subheader(f'Testing Main Environment (uv=={MAIN_UV_VERSION})') |
181 | 164 | python_exe = config_manager.config.get('python_executable', sys.executable) |
182 | 165 | uv_binary_path = Path(python_exe).parent / 'uv' |
183 | 166 | try: |
184 | 167 | result = subprocess.run([str(uv_binary_path), '--version'], capture_output=True, text=True, timeout=10, check=True) |
185 | 168 | actual_version = result.stdout.strip().split()[-1] |
186 | 169 | main_passed = actual_version == MAIN_UV_VERSION |
187 | | - print(_(' ✅ Main environment version: {}').format(actual_version)) |
188 | | - if main_passed: |
189 | | - print(_(' 🎯 Main environment test: PASSED')) |
190 | | - else: |
191 | | - print(_(f' ❌ Main environment test: FAILED (expected {MAIN_UV_VERSION}, got {actual_version})')) |
| 170 | + print(f' ✅ Main environment version: {actual_version}') |
| 171 | + print(' 🎯 Main environment test: PASSED' if main_passed else f' ❌ Main environment test: FAILED (expected {MAIN_UV_VERSION}, got {actual_version})') |
192 | 172 | return main_passed |
193 | 173 | except Exception as e: |
194 | | - print(_(' ❌ Main environment test failed: {}').format(e)) |
| 174 | + print(f' ❌ Main environment test failed: {e}') |
195 | 175 | return False |
196 | 176 |
|
197 | 177 | def run_comprehensive_test(): |
198 | 178 | """Main function to orchestrate the entire test suite.""" |
199 | 179 | print_header('🚨 OMNIPKG UV BINARY STRESS TEST 🚨') |
200 | 180 | original_strategy = 'multiversion' |
201 | 181 | try: |
202 | | - config_manager, original_strategy = setup_environment() |
203 | | - if config_manager is None: |
| 182 | + local_config_manager, original_strategy = setup_environment() |
| 183 | + if not local_config_manager: |
204 | 184 | return False |
205 | 185 |
|
206 | | - multiversion_base = Path(config_manager.config['multiversion_base']) |
| 186 | + multiversion_base = Path(local_config_manager.config['multiversion_base']) |
207 | 187 | print_header('STEP 3: Comprehensive UV Version Testing') |
208 | 188 |
|
209 | 189 | test_results = {} |
210 | 190 |
|
211 | | - # 1. Test the main, stable version |
212 | | - main_passed = test_main_environment_uv(config_manager) |
| 191 | + main_passed = test_main_environment_uv() |
213 | 192 | test_results[f'main-{MAIN_UV_VERSION}'] = main_passed |
214 | 193 |
|
215 | | - # 2. Test each bubbled version |
216 | 194 | for version in BUBBLE_VERSIONS_TO_TEST: |
217 | | - print_subheader(_('Testing Bubble (uv=={})').format(version)) |
| 195 | + print_subheader(f'Testing Bubble (uv=={version})') |
218 | 196 | bubble_path = multiversion_base / f'uv-{version}' |
219 | 197 |
|
220 | | - # First, verify the bubble structure on disk is correct |
221 | 198 | if not inspect_bubble_structure(bubble_path): |
222 | 199 | test_results[f'bubble-{version}'] = False |
223 | 200 | continue |
224 | 201 |
|
225 | | - # Second, test the dynamic swapping and version check |
| 202 | + # ***** FIX IS HERE: The call now matches the corrected function signature ***** |
226 | 203 | version_passed = test_swapped_binary_execution(version) |
227 | 204 | test_results[f'bubble-{version}'] = version_passed |
228 | 205 |
|
229 | 206 | print_header('FINAL TEST RESULTS') |
230 | | - print(_('📊 Test Summary:')) |
231 | | - all_tests_passed = True |
| 207 | + print('📊 Test Summary:') |
| 208 | + all_tests_passed = all(test_results.values()) |
| 209 | + |
232 | 210 | for version_key, passed in test_results.items(): |
233 | 211 | status = '✅ PASSED' if passed else '❌ FAILED' |
234 | 212 | print(f' {version_key:<25}: {status}') |
235 | | - if not passed: |
236 | | - all_tests_passed = False |
237 | 213 |
|
238 | 214 | if all_tests_passed: |
239 | | - print(_('\n🎉🎉🎉 ALL UV BINARY TESTS PASSED! 🎉🎉🎉')) |
240 | | - print(_('🔥 OMNIPKG UV BINARY HANDLING IS FULLY FUNCTIONAL! 🔥')) |
| 215 | + print('\n🎉🎉🎉 ALL UV BINARY TESTS PASSED! 🎉🎉🎉') |
| 216 | + print('🔥 OMNIPKG UV BINARY HANDLING IS FULLY FUNCTIONAL! 🔥') |
241 | 217 | else: |
242 | | - print(_('\n💥 SOME TESTS FAILED - UV BINARY HANDLING NEEDS WORK 💥')) |
| 218 | + print('\n💥 SOME TESTS FAILED - UV BINARY HANDLING NEEDS WORK 💥') |
243 | 219 |
|
244 | 220 | return all_tests_passed |
245 | 221 |
|
246 | 222 | except Exception as e: |
247 | | - print(_('\n❌ Critical error during testing: {}').format(e)) |
| 223 | + print(f'\n❌ Critical error during testing: {e}') |
248 | 224 | traceback.print_exc() |
249 | 225 | return False |
250 | 226 | finally: |
251 | 227 | print_header('STEP 4: Cleanup & Restoration') |
252 | 228 | try: |
253 | | - config_manager = ConfigManager() |
254 | 229 | omnipkg_core = OmnipkgCore(config_manager) |
255 | 230 | for bubble in omnipkg_core.multiversion_base.glob('uv-*'): |
256 | 231 | if bubble.is_dir(): |
257 | | - print(_(' 🧹 Removing test bubble: {}').format(bubble.name)) |
| 232 | + print(f' 🧹 Removing test bubble: {bubble.name}') |
258 | 233 | shutil.rmtree(bubble, ignore_errors=True) |
259 | 234 |
|
260 | 235 | if original_strategy and original_strategy != 'stable-main': |
261 | | - print(_(' 🔄 Restoring original install strategy: {}').format(original_strategy)) |
262 | | - set_install_strategy(config_manager, original_strategy) |
| 236 | + print(f' 🔄 Restoring original install strategy: {original_strategy}') |
| 237 | + set_install_strategy(original_strategy) |
263 | 238 | else: |
264 | | - print(_(' ℹ️ Install strategy remains at: stable-main')) |
265 | | - print(_('✅ Cleanup complete')) |
| 239 | + print(' ℹ️ Install strategy remains at: stable-main') |
| 240 | + print('✅ Cleanup complete') |
266 | 241 | except Exception as e: |
267 | | - print(_('⚠️ Cleanup failed: {}').format(e)) |
| 242 | + print(f'⚠️ Cleanup failed: {e}') |
268 | 243 |
|
269 | 244 | if __name__ == '__main__': |
270 | 245 | success = run_comprehensive_test() |
|
0 commit comments