diff --git a/tests/test_packaging.py b/tests/test_packaging.py index 899e15a..6c7510d 100644 --- a/tests/test_packaging.py +++ b/tests/test_packaging.py @@ -32,24 +32,39 @@ def _get_version() -> str: return get_version() +def _get_container_runtime() -> str: + """Get available container runtime (podman or docker).""" + for cmd in ["podman", "docker"]: + try: + r = subprocess.run([cmd, "info"], capture_output=True, timeout=10) + if r.returncode == 0: + return cmd + except (FileNotFoundError, subprocess.TimeoutExpired): + continue + return "docker" # fallback + + def _docker_available() -> bool: - """Check if Docker daemon is reachable.""" - try: - r = subprocess.run( - ["docker", "info"], capture_output=True, timeout=10 - ) - return r.returncode == 0 - except (FileNotFoundError, subprocess.TimeoutExpired): - return False + """Check if Docker or Podman daemon is reachable.""" + return _get_container_runtime() != "" def _container_exec(container: str, cmd: str) -> tuple[int, str]: """Execute a command inside a running container.""" - r = subprocess.run( - ["docker", "exec", container, "sh", "-c", cmd], - capture_output=True, text=True, timeout=120, - ) - return r.returncode, r.stdout + r.stderr + runtime = _get_container_runtime() + try: + r = subprocess.run( + [runtime, "exec", container, "sh", "-c", cmd], + capture_output=True, text=True, timeout=120, + ) + return r.returncode, r.stdout + r.stderr + except (FileNotFoundError, subprocess.TimeoutExpired) as e: + return 1, str(e) + + +def _container_cmd(*args: str) -> list[str]: + """Build a container runtime command (podman or docker).""" + return [_get_container_runtime()] + list(args) def _find_package(fmt: str) -> Path: