forked from CrayLabs/SmartSim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
119 lines (99 loc) · 3.24 KB
/
conftest.py
File metadata and controls
119 lines (99 loc) · 3.24 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import os
import shutil
import pytest
import smartsim
from smartsim.settings import SrunSettings, AprunSettings
from smartsim.settings import RunSettings
from smartsim.config import CONFIG
# Globals, yes, but its a testing file
test_path = os.path.dirname(os.path.abspath(__file__))
test_dir = os.path.join(test_path, "tests", "test_output")
test_launcher = "local"
def get_launcher():
global test_launcher
test_launcher = CONFIG.test_launcher
return test_launcher
def print_test_configuration():
global test_path
global test_dir
global test_launcher
print("TEST_SMARTSIM_LOCATION: ", smartsim.__path__)
print("TEST_PATH:", test_path)
print("TEST_LAUNCHER", test_launcher)
print("TEST_DIR:", test_dir)
print("Test output will be located in TEST_DIR if there is a failure")
def pytest_configure():
launcher = get_launcher()
pytest.test_launcher = launcher
pytest.wlm_options = ["slurm", "pbs", "cobalt"]
def pytest_sessionstart(session):
"""
Called after the Session object has been created and
before performing collection and entering the run test loop.
"""
get_launcher()
if os.path.isdir(test_dir):
shutil.rmtree(test_dir)
os.mkdir(test_dir)
print_test_configuration()
def pytest_sessionfinish(session, exitstatus):
"""
Called after whole test run finished, right before
returning the exit status to the system.
"""
if exitstatus == 0:
shutil.rmtree(test_dir)
@pytest.fixture
def wlmutils():
return WLMUtils
class WLMUtils:
@staticmethod
def get_test_launcher():
global test_launcher
return test_launcher
@staticmethod
def get_run_settings(exe, args, nodes=1, ntasks=1, **kwargs):
if test_launcher == "slurm":
run_args = {"nodes": nodes,
"ntasks": ntasks,
"time": "00:10:00"}
run_args.update(kwargs)
settings = SrunSettings(exe, args, run_args=run_args)
return settings
elif test_launcher == "pbs":
run_args = {"pes": ntasks}
run_args.update(kwargs)
settings = AprunSettings(exe, args, run_args=run_args)
return settings
# TODO allow user to pick aprun vs MPIrun
elif test_launcher == "cobalt":
run_args = {"pes": ntasks}
run_args.update(kwargs)
settings = AprunSettings(exe, args, run_args=run_args)
return settings
else:
return RunSettings(exe, args)
@pytest.fixture
def fileutils():
return FileUtils
class FileUtils:
@staticmethod
def get_test_dir(dir_name):
dir_path = os.path.join(test_dir, dir_name)
return dir_path
@staticmethod
def make_test_dir(dir_name):
dir_path = os.path.join(test_dir, dir_name)
try:
os.mkdir(dir_path)
except Exception:
return dir_path
return dir_path
@staticmethod
def get_test_conf_path(filename):
file_path = os.path.join(test_path, "tests", "test_configs", filename)
return file_path
@staticmethod
def get_test_dir_path(dirname):
dir_path = os.path.join(test_path, "tests", "test_configs", dirname)
return dir_path