Coverage for tests / docker_compose.py: 29%
34 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-02 09:48 +0100
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-02 09:48 +0100
1"""
2Docker compose management for Superset integration tests.
3"""
5import subprocess
6import time
7from pathlib import Path
9import requests
12class SupersetDockerCompose:
13 """Manage a Superset docker-compose stack for integration tests."""
15 def __init__(self, compose_file: Path, project_name: str = "superset_test"):
16 self.compose_file = compose_file
17 self.project_name = project_name
18 self._process = None
20 def start(self, timeout: int = 120):
21 """Start the docker-compose stack and wait for Superset to be ready."""
22 # Start containers
23 cmd = [
24 "docker-compose",
25 "-f",
26 str(self.compose_file),
27 "-p",
28 self.project_name,
29 "up",
30 "-d",
31 ]
32 subprocess.run(cmd, check=True, capture_output=True)
34 # Wait for Superset health check
35 start_time = time.time()
36 while time.time() - start_time < timeout:
37 try:
38 resp = requests.get("http://localhost:8088/health", timeout=5)
39 if resp.status_code == 200:
40 # Also wait for API to be fully ready
41 time.sleep(10) # Extra time for initialization
42 return
43 except requests.exceptions.ConnectionError:
44 pass
45 time.sleep(5)
47 raise TimeoutError(f"Superset not ready after {timeout} seconds")
49 def stop(self):
50 """Stop and remove the docker-compose stack."""
51 cmd = [
52 "docker-compose",
53 "-f",
54 str(self.compose_file),
55 "-p",
56 self.project_name,
57 "down",
58 "-v",
59 "--remove-orphans",
60 ]
61 subprocess.run(cmd, capture_output=True)
63 def is_running(self) -> bool:
64 """Check if the Superset stack is running and healthy."""
65 try:
66 resp = requests.get("http://localhost:8088/health", timeout=5)
67 return resp.status_code == 200
68 except requests.exceptions.ConnectionError:
69 return False
72def get_docker_compose_path() -> Path:
73 """Return the path to the docker-compose.yml file."""
74 return Path(__file__).parent / "docker-compose.yml"