Repository navigation
Expand file tree
/
Copy pathconftest.py
More file actions
218 lines (172 loc) · 6.37 KB
/
Copy pathconftest.py
File metadata and controls
218 lines (172 loc) · 6.37 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
import atexit
import functools
import logging
import os
import sys
CIMEROOT = os.path.abspath(os.path.join(os.path.dirname(__file__)))
sys.path.insert(0, CIMEROOT)
import pytest
from CIME import utils
from CIME.config import Config
from CIME.utils import get_current_commit, get_model
from CIME.XML.machines import Machines
from CIME.tests.base import BaseTestCase
os.environ["CIME_GLOBAL_WALLTIME"] = "0:05:00"
TEST_RESULT = None
def pytest_addoption(parser):
# set addoption as add_argument to use common argument setup
# pytest's addoption has same signature as add_argument
setattr(parser, "add_argument", parser.addoption)
setup_arguments(parser)
# verbose and debug flags already exist
parser.addoption("--silent", action="store_true", help="Disable all logging")
def pytest_configure(config):
kwargs = vars(config.option)
utils.configure_logging(kwargs["verbose"], kwargs["debug"], kwargs["silent"])
configure_tests(**kwargs)
@pytest.fixture(scope="module", autouse=True)
def setup(pytestconfig):
# ensure we start from CIMEROOT for each module
os.chdir(CIMEROOT)
srcroot = utils.get_src_root()
customize_path = os.path.join(srcroot, "cime_config", "customize")
if os.path.exists(customize_path):
Config.instance().load(customize_path)
# ensure GLOABL is reset
utils.GLOBAL = {}
def setup_arguments(parser):
parser.add_argument(
"--fast",
action="store_true",
help="Skip full system tests, which saves a lot of time",
)
parser.add_argument(
"--no-batch",
action="store_true",
help="Do not submit jobs to batch system, run locally."
" If false, will default to machine setting.",
)
parser.add_argument(
"--no-fortran-run",
action="store_true",
help="Do not run any fortran jobs. Implies --fast" " Used for github actions",
)
parser.add_argument(
"--no-cmake", action="store_true", help="Do not run cmake tests"
)
parser.add_argument(
"--no-teardown",
action="store_true",
help="Do not delete directories left behind by testing",
)
parser.add_argument(
"--machine", help="Select a specific machine setting for cime", default=None
)
parser.add_argument(
"--compiler", help="Select a specific compiler setting for cime", default=None
)
parser.add_argument(
"--mpilib", help="Select a specific compiler setting for cime", default=None
)
parser.add_argument(
"--test-root",
help="Select a specific test root for all cases created by the testing",
default=None,
)
parser.add_argument(
"--timeout",
type=int,
help="Select a specific timeout for all tests",
default=None,
)
def configure_tests(
timeout,
no_fortran_run,
fast,
no_batch,
no_cmake,
no_teardown,
machine,
compiler,
mpilib,
test_root,
**kwargs
):
config = utils.get_cime_config()
customize_path = os.path.join(utils.get_src_root(), "cime_config", "customize")
Config.load(customize_path)
if timeout:
BaseTestCase.GLOBAL_TIMEOUT = str(timeout)
BaseTestCase.NO_FORTRAN_RUN = no_fortran_run or False
BaseTestCase.FAST_ONLY = fast or no_fortran_run
BaseTestCase.NO_BATCH = no_batch or False
BaseTestCase.NO_CMAKE = no_cmake or False
BaseTestCase.NO_TEARDOWN = no_teardown or False
# make sure we have default values
MACHINE = None
TEST_COMPILER = None
TEST_MPILIB = None
if machine is not None:
MACHINE = Machines(machine=machine)
os.environ["CIME_MACHINE"] = machine
elif "CIME_MACHINE" in os.environ:
MACHINE = Machines(machine=os.environ["CIME_MACHINE"])
elif config.has_option("create_test", "MACHINE"):
MACHINE = Machines(machine=config.get("create_test", "MACHINE"))
elif config.has_option("main", "MACHINE"):
MACHINE = Machines(machine=config.get("main", "MACHINE"))
else:
MACHINE = Machines()
BaseTestCase.MACHINE = MACHINE
if compiler is not None:
TEST_COMPILER = compiler
elif config.has_option("create_test", "COMPILER"):
TEST_COMPILER = config.get("create_test", "COMPILER")
elif config.has_option("main", "COMPILER"):
TEST_COMPILER = config.get("main", "COMPILER")
BaseTestCase.TEST_COMPILER = TEST_COMPILER
if mpilib is not None:
TEST_MPILIB = mpilib
elif config.has_option("create_test", "MPILIB"):
TEST_MPILIB = config.get("create_test", "MPILIB")
elif config.has_option("main", "MPILIB"):
TEST_MPILIB = config.get("main", "MPILIB")
BaseTestCase.TEST_MPILIB = TEST_MPILIB
if test_root is not None:
TEST_ROOT = test_root
elif config.has_option("create_test", "TEST_ROOT"):
TEST_ROOT = config.get("create_test", "TEST_ROOT")
else:
TEST_ROOT = os.path.join(
MACHINE.get_value("CIME_OUTPUT_ROOT"),
"scripts_regression_test.%s" % utils.get_timestamp(),
)
BaseTestCase.TEST_ROOT = TEST_ROOT
write_provenance_info(MACHINE, TEST_COMPILER, TEST_MPILIB, TEST_ROOT)
atexit.register(functools.partial(cleanup, TEST_ROOT))
def write_provenance_info(machine, test_compiler, test_mpilib, test_root):
curr_commit = get_current_commit(repo=CIMEROOT)
logging.info("Testing commit %s" % ("unknown" if curr_commit is None else curr_commit))
cime_model = get_model()
logging.info("Using cime_model = %s" % cime_model)
logging.info("Testing machine = %s" % machine.get_machine_name())
if test_compiler is not None:
logging.info("Testing compiler = %s" % test_compiler)
if test_mpilib is not None:
logging.info("Testing mpilib = %s" % test_mpilib)
logging.info("Test root: %s" % test_root)
logging.info("Test driver: %s" % utils.get_cime_default_driver())
logging.info("Python version {}\n".format(sys.version))
def cleanup(test_root):
if (
os.path.exists(test_root)
and TEST_RESULT is not None
and TEST_RESULT.wasSuccessful()
):
testreporter = os.path.join(test_root, "testreporter")
files = os.listdir(test_root)
if len(files) == 1 and os.path.isfile(testreporter):
os.unlink(testreporter)
if not os.listdir(test_root):
print("All pass, removing directory:", test_root)
os.rmdir(test_root)