-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathconftest.py
69 lines (48 loc) · 1.68 KB
/
conftest.py
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
import json
from pathlib import Path
import pytest
import requests
from requests.exceptions import ConnectionError
def is_responsive(url):
try:
response = requests.get(url)
if response.status_code == 200:
return True
except ConnectionError:
return False
@pytest.fixture(scope="session", params=["lab", "base-with-services"])
def variant(request):
return request.param
@pytest.fixture(scope="session")
def docker_compose_file(pytestconfig, variant):
return f"docker-compose.{variant}.yml"
@pytest.fixture(scope="session")
def notebook_service(docker_ip, docker_services):
"""Ensure that HTTP service is up and responsive."""
port = docker_services.port_for("aiidalab", 8888)
url = f"http://{docker_ip}:{port}"
docker_services.wait_until_responsive(
timeout=30.0, pause=0.1, check=lambda: is_responsive(url)
)
return url
@pytest.fixture(scope="session")
def docker_compose(docker_services):
return docker_services._docker_compose
@pytest.fixture
def aiidalab_exec(docker_compose):
def execute(command, user=None, **kwargs):
if user:
command = f"exec -T --user={user} aiidalab {command}"
else:
command = f"exec -T aiidalab {command}"
return docker_compose.execute(command, **kwargs)
return execute
@pytest.fixture
def nb_user(aiidalab_exec):
return aiidalab_exec("bash -c 'echo \"${NB_USER}\"'").decode().strip()
@pytest.fixture(scope="session")
def _build_config():
return json.loads(Path("build.json").read_text())["variable"]
@pytest.fixture(scope="session")
def aiida_version(_build_config):
return _build_config["AIIDA_VERSION"]["default"]