-
Notifications
You must be signed in to change notification settings - Fork 4
/
noxfile.py
81 lines (67 loc) · 2.17 KB
/
noxfile.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
70
71
72
73
74
75
76
77
78
79
80
81
import os
import platform
import shlex
import nox
from dotenv import load_dotenv
SUPPORTED_PYTHON_VERSIONS = ["3.10", "3.11", "3.12"]
VENV_BACKEND = "uv|conda|venv"
REUSE_VENV = True
# specify tests under a single session, otherwise "compatibility" and "unit_tests" will use different venvs
VENV_NAME = "tests_session"
nox.options.reuse_existing_virtualenvs = True
def get_install_cmd():
system = platform.system().lower()
if system == "linux":
return shlex.split(
"-e .[test] --find-links https://download.pytorch.org/whl/torch_stable.html"
)
elif system == "darwin":
return shlex.split("-e .[test]")
else:
raise ValueError(f"Unsupported platform: {system}")
@nox.session(
python=SUPPORTED_PYTHON_VERSIONS,
venv_backend=VENV_BACKEND,
reuse_venv=REUSE_VENV,
name=VENV_NAME,
)
def compatibility(session):
session.install(
*get_install_cmd(),
silent=False,
)
pip_show_output = session.run("pip", "show", "dojo", silent=True)
if "not found" in pip_show_output:
raise Exception(
"Missing dojo package, this means installation probably failed."
)
@nox.session(
python=SUPPORTED_PYTHON_VERSIONS,
venv_backend=VENV_BACKEND,
reuse_venv=REUSE_VENV,
name=VENV_NAME,
)
def unit_tests(session):
session.install(
*get_install_cmd(),
silent=False,
)
def run_tests_with_env(env_file, test_file):
load_dotenv(env_file)
# inject environment variables into the session
for key, value in os.environ.items():
session.env[key] = value
session.run("pytest", "-s", "-v", f"tests/unit_testing/{test_file}")
# run miner tests with .env.miner
run_tests_with_env(".env.miner", "test_miner.py")
# run validator tests with .env.validator
run_tests_with_env(".env.validator", "test_validator.py")
other_tests = [
f
for f in os.listdir("tests/unit_testing")
if f.startswith("test_") and f not in ["test_miner.py", "test_validator.py"]
]
if other_tests:
session.run(
"pytest", "-s", "-v", *[f"tests/unit_testing/{f}" for f in other_tests]
)