-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconftest.py
More file actions
220 lines (176 loc) · 6.59 KB
/
Copy pathconftest.py
File metadata and controls
220 lines (176 loc) · 6.59 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
219
import os
import runpy
import sys
import tempfile
import warnings
import pathlib
import pytest
# Trigger config file reading / creation once - to avoid race conditions when multiple instances are creating it
# at the same time
# TODO: replace with new backend
# from pystencils.cpu import cpujit
# trigger cython imports - there seems to be a problem when multiple processes try to compile the same cython file
# at the same time
try:
import pyximport
pyximport.install(language_level=3)
from pystencils.boundaries.createindexlistcython import * # NOQA
except ImportError:
pass
SCRIPT_FOLDER = os.path.dirname(os.path.realpath(__file__))
sys.path.insert(0, os.path.abspath("pystencils"))
# the Ubuntu pipeline uses an older version of pytest which uses deprecated functionality.
# This leads to many warinings in the test and coverage pipeline.
pytest_numeric_version = [int(x, 10) for x in pytest.__version__.split(".")]
pytest_numeric_version.reverse()
pytest_version = sum(x * (100**i) for i, x in enumerate(pytest_numeric_version))
def add_path_to_ignore(path):
if not os.path.exists(path):
return
global collect_ignore
collect_ignore += [
os.path.join(SCRIPT_FOLDER, path, f)
for f in os.listdir(os.path.join(SCRIPT_FOLDER, path))
]
def ignore_file(fp):
global collect_ignore
collect_ignore += [os.path.join(SCRIPT_FOLDER, fp)]
collect_ignore = []
ignore_file("noxfile.py")
ignore_file("docs/source/conf.py")
ignore_file(("tests/dpctl_compat.py"))
add_path_to_ignore("docs/build")
add_path_to_ignore("tests/benchmark")
add_path_to_ignore("_local_tmp")
try:
import cupy
except ImportError:
collect_ignore += [
os.path.join(SCRIPT_FOLDER, "src/pystencils/backend/jit/gpu_cupy.py"),
]
add_path_to_ignore("src/pystencils/gpu")
try:
import waLBerla
except ImportError:
collect_ignore += [
os.path.join(
SCRIPT_FOLDER, "docs/source/tutorials/03_tutorial_datahandling.ipynb"
),
os.path.join(
SCRIPT_FOLDER, "src/pystencils/datahandling/parallel_datahandling.py"
),
os.path.join(SCRIPT_FOLDER, "tests/runtime/test_datahandling_parallel.py"),
os.path.join(SCRIPT_FOLDER, "tests/runtime/test_small_block_benchmark.ipynb"),
]
try:
import blitzdb
except ImportError:
add_path_to_ignore("src/pystencils/runhelper")
collect_ignore += [os.path.join(SCRIPT_FOLDER, "tests/test_parameterstudy.py")]
collect_ignore += [os.path.join(SCRIPT_FOLDER, "tests/test_json_serializer.py")]
try:
import islpy
except ImportError:
collect_ignore += [
os.path.join(SCRIPT_FOLDER, "src/pystencils/integer_set_analysis.py")
]
try:
import graphviz
except ImportError:
collect_ignore += [os.path.join(SCRIPT_FOLDER, "src/pystencils/backends/dot.py")]
collect_ignore += [
os.path.join(SCRIPT_FOLDER, "doc/notebooks/01_tutorial_getting_started.ipynb")
]
try:
import pyevtk
except ImportError:
collect_ignore += [
os.path.join(SCRIPT_FOLDER, "src/pystencils/datahandling/vtk.py")
]
collect_ignore += [os.path.join(SCRIPT_FOLDER, "setup.py")]
try:
import dpctl
except ImportError:
collect_ignore += [
os.path.join(SCRIPT_FOLDER, "src/pystencils/jit/sycl/sycljit.py"),
os.path.join(SCRIPT_FOLDER, "src/pystencils/jit/sycl/sycl_module_builder.py"),
os.path.join(SCRIPT_FOLDER, "src/pystencils/backend/platforms/sycl.py"),
]
for root, sub_dirs, files in os.walk("."):
for f in files:
if f.endswith(".ipynb") and not any(
f.startswith(k) for k in ["demo", "tutorial", "test", "doc"]
):
collect_ignore.append(f)
try:
import nbformat
from nbconvert import PythonExporter
jupyter_support = True
except ImportError:
jupyter_support = False
if jupyter_support:
class IPythonMockup:
def run_line_magic(self, *args, **kwargs):
pass
def run_cell_magic(self, *args, **kwargs):
pass
def magic(self, *args, **kwargs):
pass
def __bool__(self):
return False
class IPyNbTest(pytest.Item):
def __init__(self, name, parent, code):
super(IPyNbTest, self).__init__(name, parent)
self.code = code
self.add_marker("notebook")
def runtest(self):
global_dict = {"get_ipython": lambda: IPythonMockup(), "is_test_run": True}
# disable matplotlib output
exec(
"import matplotlib.pyplot as p; "
"p.close('all'); "
"p.switch_backend('Template')",
global_dict,
)
# in notebooks there is an implicit plt.show() - if this is not called a warning is shown when the next
# plot is created. This warning is suppressed here
exec(
"import warnings;"
"warnings.filterwarnings('ignore', 'Adding an axes using the same arguments as a previous.*');"
"warnings.filterwarnings('ignore', 'Animation was deleted without rendering anything.*');",
global_dict,
)
with tempfile.NamedTemporaryFile() as f:
f.write(self.code.encode())
f.flush()
runpy.run_path(f.name, init_globals=global_dict, run_name=self.name)
# Close any open figures
exec("import matplotlib.pyplot as p; p.close('all')", global_dict)
class IPyNbFile(pytest.File):
def collect(self):
exporter = PythonExporter()
exporter.exclude_markdown = True
exporter.exclude_input_prompt = True
notebook_contents = self.path.open(encoding="utf-8")
with warnings.catch_warnings():
warnings.filterwarnings(
"ignore", "IPython.core.inputsplitter is deprecated"
)
notebook = nbformat.read(notebook_contents, 4)
code, _ = exporter.from_notebook_node(notebook)
if pytest_version >= 50403:
yield IPyNbTest.from_parent(name=self.name, parent=self, code=code)
else:
yield IPyNbTest(self.name, self, code)
def teardown(self):
pass
def pytest_collect_file(file_path: pathlib.Path, parent):
glob_exprs = ["*demo*.ipynb", "*tutorial*.ipynb", "test_*.ipynb"]
if any(file_path.match(g) for g in glob_exprs):
return IPyNbFile.from_parent(path=file_path, parent=parent)
# Fixtures
from tests.fixtures import *
try:
from override_fixtures import *
except ImportError:
pass