()
| 141 | |
| 142 | |
| 143 | def main(): |
| 144 | parser = argparse.ArgumentParser(description="Smoke-test the MITK wheel.") |
| 145 | parser.add_argument( |
| 146 | "--build-dir", |
| 147 | default=None, |
| 148 | help="Path to MITK-build directory to discover the wheel (default: CWD)", |
| 149 | ) |
| 150 | parser.add_argument( |
| 151 | "--run-tests", |
| 152 | action="store_true", |
| 153 | help=argparse.SUPPRESS, # internal: run test functions directly |
| 154 | ) |
| 155 | args = parser.parse_args() |
| 156 | |
| 157 | # Inner mode: run test functions directly (called from the venv subprocess) |
| 158 | if args.run_tests: |
| 159 | return run_tests() |
| 160 | |
| 161 | # Outer mode: discover wheel, create venv, run tests in subprocess |
| 162 | search_dir = os.path.abspath(args.build_dir) if args.build_dir else os.getcwd() |
| 163 | wheel_path = find_wheel(search_dir) |
| 164 | |
| 165 | if not wheel_path: |
| 166 | print(f"Error: no mitk_python-*.whl found in {search_dir}", file=sys.stderr) |
| 167 | return 1 |
| 168 | |
| 169 | print(f"Wheel: {wheel_path}") |
| 170 | |
| 171 | with tempfile.TemporaryDirectory() as venv_dir: |
| 172 | venv_path = os.path.join(venv_dir, "venv") |
| 173 | |
| 174 | # Create venv |
| 175 | subprocess.check_call([sys.executable, "-m", "venv", venv_path]) |
| 176 | |
| 177 | # Find the venv Python |
| 178 | if sys.platform == "win32": |
| 179 | venv_python = os.path.join(venv_path, "Scripts", "python.exe") |
| 180 | else: |
| 181 | venv_python = os.path.join(venv_path, "bin", "python") |
| 182 | |
| 183 | # Install the wheel |
| 184 | subprocess.check_call( |
| 185 | [venv_python, "-m", "pip", "install", "--quiet", wheel_path] |
| 186 | ) |
| 187 | |
| 188 | # Run tests inside the venv |
| 189 | test_script = os.path.abspath(__file__) |
| 190 | result = subprocess.run([venv_python, test_script, "--run-tests"]) |
| 191 | return result.returncode |
| 192 | |
| 193 | |
| 194 | if __name__ == "__main__": |
no test coverage detected