Skip to content
Snippets Groups Projects
Commit c909e6ac authored by Frederik Hennig's avatar Frederik Hennig
Browse files

Fix conftest. Fix deprecated usage of scipy.ndimage.gaussian_filter. Fix array...

Fix conftest. Fix deprecated usage of scipy.ndimage.gaussian_filter. Fix array data types in BoundaryOffsetInfo.
parent 55391e5b
Branches
Tags
1 merge request!409Migrate Test Suite
...@@ -3,7 +3,6 @@ import runpy ...@@ -3,7 +3,6 @@ import runpy
import sys import sys
import tempfile import tempfile
import warnings import warnings
import pathlib
import nbformat import nbformat
import pytest import pytest
...@@ -17,32 +16,38 @@ import pytest ...@@ -17,32 +16,38 @@ import pytest
# at the same time # at the same time
try: try:
import pyximport import pyximport
pyximport.install(language_level=3) pyximport.install(language_level=3)
from pystencils.boundaries.createindexlistcython import * # NOQA from pystencils.boundaries.createindexlistcython import * # NOQA
except ImportError: except ImportError:
pass pass
SCRIPT_FOLDER = os.path.dirname(os.path.realpath(__file__)) SCRIPT_FOLDER = os.path.dirname(os.path.realpath(__file__))
sys.path.insert(0, os.path.abspath('pystencils')) sys.path.insert(0, os.path.abspath("pystencils"))
# the Ubuntu pipeline uses an older version of pytest which uses deprecated functionality. # the Ubuntu pipeline uses an older version of pytest which uses deprecated functionality.
# This leads to many warinings in the test and coverage pipeline. # 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 = [int(x, 10) for x in pytest.__version__.split(".")]
pytest_numeric_version.reverse() pytest_numeric_version.reverse()
pytest_version = sum(x * (100 ** i) for i, x in enumerate(pytest_numeric_version)) pytest_version = sum(x * (100**i) for i, x in enumerate(pytest_numeric_version))
def add_path_to_ignore(path): def add_path_to_ignore(path):
if not os.path.exists(path): if not os.path.exists(path):
return return
global collect_ignore global collect_ignore
collect_ignore += [os.path.join(SCRIPT_FOLDER, path, f) for f in os.listdir(os.path.join(SCRIPT_FOLDER, path))] collect_ignore += [
os.path.join(SCRIPT_FOLDER, path, f)
for f in os.listdir(os.path.join(SCRIPT_FOLDER, path))
]
collect_ignore = [os.path.join(SCRIPT_FOLDER, "doc", "conf.py"), collect_ignore = [
os.path.join(SCRIPT_FOLDER, "src", "pystencils", "opencl", "opencl.autoinit")] os.path.join(SCRIPT_FOLDER, "doc", "conf.py"),
add_path_to_ignore('tests/benchmark') os.path.join(SCRIPT_FOLDER, "src", "pystencils", "opencl", "opencl.autoinit"),
add_path_to_ignore('_local_tmp') ]
add_path_to_ignore("tests/benchmark")
add_path_to_ignore("_local_tmp")
try: try:
...@@ -50,46 +55,60 @@ try: ...@@ -50,46 +55,60 @@ try:
except ImportError: except ImportError:
collect_ignore += [ collect_ignore += [
os.path.join(SCRIPT_FOLDER, "tests/kernelcreation/test_gpu.py"), os.path.join(SCRIPT_FOLDER, "tests/kernelcreation/test_gpu.py"),
os.path.join(SCRIPT_FOLDER, "src/pystencils/backend/jit/gpu_cupy.py") os.path.join(SCRIPT_FOLDER, "src/pystencils/backend/jit/gpu_cupy.py"),
] ]
add_path_to_ignore('src/pystencils/gpu') add_path_to_ignore("src/pystencils/gpu")
try: try:
import waLBerla import waLBerla
except ImportError: except ImportError:
collect_ignore += [os.path.join(SCRIPT_FOLDER, "docs/source/tutorials/03_tutorial_datahandling.ipynb"), collect_ignore += [
os.path.join(SCRIPT_FOLDER, "src/pystencils/datahandling/parallel_datahandling.py"), os.path.join(
os.path.join(SCRIPT_FOLDER, "tests/runtime/test_datahandling_parallel.py"), SCRIPT_FOLDER, "docs/source/tutorials/03_tutorial_datahandling.ipynb"
os.path.join(SCRIPT_FOLDER, "tests/runtime/test_small_block_benchmark.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: try:
import blitzdb import blitzdb
except ImportError: except ImportError:
add_path_to_ignore('src/pystencils/runhelper') 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_parameterstudy.py")]
collect_ignore += [os.path.join(SCRIPT_FOLDER, "tests/test_json_serializer.py")] collect_ignore += [os.path.join(SCRIPT_FOLDER, "tests/test_json_serializer.py")]
try: try:
import islpy import islpy
except ImportError: except ImportError:
collect_ignore += [os.path.join(SCRIPT_FOLDER, "src/pystencils/integer_set_analysis.py")] collect_ignore += [
os.path.join(SCRIPT_FOLDER, "src/pystencils/integer_set_analysis.py")
]
try: try:
import graphviz import graphviz
except ImportError: except ImportError:
collect_ignore += [os.path.join(SCRIPT_FOLDER, "src/pystencils/backends/dot.py")] 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")] collect_ignore += [
os.path.join(SCRIPT_FOLDER, "doc/notebooks/01_tutorial_getting_started.ipynb")
]
try: try:
import pyevtk import pyevtk
except ImportError: except ImportError:
collect_ignore += [os.path.join(SCRIPT_FOLDER, "src/pystencils/datahandling/vtk.py")] collect_ignore += [
os.path.join(SCRIPT_FOLDER, "src/pystencils/datahandling/vtk.py")
]
collect_ignore += [os.path.join(SCRIPT_FOLDER, 'setup.py')] collect_ignore += [os.path.join(SCRIPT_FOLDER, "setup.py")]
for root, sub_dirs, files in os.walk('.'): for root, sub_dirs, files in os.walk("."):
for f in files: for f in files:
if f.endswith(".ipynb") and not any(f.startswith(k) for k in ['demo', 'tutorial', 'test', 'doc']): if f.endswith(".ipynb") and not any(
f.startswith(k) for k in ["demo", "tutorial", "test", "doc"]
):
collect_ignore.append(f) collect_ignore.append(f)
...@@ -111,39 +130,50 @@ class IPyNbTest(pytest.Item): ...@@ -111,39 +130,50 @@ class IPyNbTest(pytest.Item):
def __init__(self, name, parent, code): def __init__(self, name, parent, code):
super(IPyNbTest, self).__init__(name, parent) super(IPyNbTest, self).__init__(name, parent)
self.code = code self.code = code
self.add_marker('notebook') self.add_marker("notebook")
@pytest.mark.filterwarnings("ignore:IPython.core.inputsplitter is deprecated")
def runtest(self): def runtest(self):
global_dict = {'get_ipython': lambda: IPythonMockup(), global_dict = {"get_ipython": lambda: IPythonMockup(), "is_test_run": True}
'is_test_run': True}
# disable matplotlib output # disable matplotlib output
exec("import matplotlib.pyplot as p; " exec(
"p.switch_backend('Template')", global_dict) "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 # 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 # plot is created. This warning is suppressed here
exec("import warnings;" exec(
"warnings.filterwarnings('ignore', 'Adding an axes using the same arguments as a previous.*')", "import warnings;"
global_dict) "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: with tempfile.NamedTemporaryFile() as f:
f.write(self.code.encode()) f.write(self.code.encode())
f.flush() f.flush()
runpy.run_path(f.name, init_globals=global_dict, run_name=self.name) 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): class IPyNbFile(pytest.File):
def collect(self): def collect(self):
from nbconvert import PythonExporter from nbconvert import PythonExporter
exporter = PythonExporter() exporter = PythonExporter()
exporter.exclude_markdown = True exporter.exclude_markdown = True
exporter.exclude_input_prompt = True exporter.exclude_input_prompt = True
notebook_contents = self.path.open(encoding='utf-8') notebook_contents = self.path.open(encoding="utf-8")
with warnings.catch_warnings(): with warnings.catch_warnings():
warnings.filterwarnings("ignore", "IPython.core.inputsplitter is deprecated") warnings.filterwarnings(
"ignore", "IPython.core.inputsplitter is deprecated"
)
notebook = nbformat.read(notebook_contents, 4) notebook = nbformat.read(notebook_contents, 4)
code, _ = exporter.from_notebook_node(notebook) code, _ = exporter.from_notebook_node(notebook)
if pytest_version >= 50403: if pytest_version >= 50403:
...@@ -155,10 +185,21 @@ class IPyNbFile(pytest.File): ...@@ -155,10 +185,21 @@ class IPyNbFile(pytest.File):
pass pass
def pytest_collect_file(path, parent): if pytest_version >= 70000:
glob_exprs = ["*demo*.ipynb", "*tutorial*.ipynb", "test_*.ipynb"] # Since pytest 7.0, usage of `py.path.local` is deprecated and `pathlib.Path` should be used instead
if any(path.fnmatch(g) for g in glob_exprs): import pathlib
if pytest_version >= 50403:
return IPyNbFile.from_parent(path=pathlib.Path(path), parent=parent) def pytest_collect_file(file_path: pathlib.Path, parent):
else: glob_exprs = ["*demo*.ipynb", "*tutorial*.ipynb", "test_*.ipynb"]
return IPyNbFile(path, parent) if any(file_path.match(g) for g in glob_exprs):
return IPyNbFile.from_parent(path=file_path, parent=parent)
else:
def pytest_collect_file(path, parent):
glob_exprs = ["*demo*.ipynb", "*tutorial*.ipynb", "test_*.ipynb"]
if any(path.fnmatch(g) for g in glob_exprs):
if pytest_version >= 50403:
return IPyNbFile.from_parent(fspath=path, parent=parent)
else:
return IPyNbFile(path, parent)
Source diff could not be displayed: it is too large. Options to address this: view the blob.
...@@ -410,11 +410,11 @@ class BoundaryOffsetInfo: ...@@ -410,11 +410,11 @@ class BoundaryOffsetInfo:
@staticmethod @staticmethod
def offset_from_dir(dir_idx, dim): def offset_from_dir(dir_idx, dim):
return tuple([sp.IndexedBase(symbol, shape=(1,))[dir_idx] return tuple([sp.IndexedBase(symbol, shape=(1,))[dir_idx]
for symbol in BoundaryOffsetInfo._offset_symbols(dim)]) for symbol in BoundaryOffsetInfo._untyped_offset_symbols(dim)])
@staticmethod @staticmethod
def inv_dir(dir_idx): def inv_dir(dir_idx):
return sp.IndexedBase(BoundaryOffsetInfo._inv_dir_symbol(), shape=(1,))[dir_idx] return sp.IndexedBase(BoundaryOffsetInfo._untyped_inv_dir_symbol(), shape=(1,))[dir_idx]
# ---------------------------------- Internal --------------------------------------------- # ---------------------------------- Internal ---------------------------------------------
...@@ -425,7 +425,7 @@ class BoundaryOffsetInfo: ...@@ -425,7 +425,7 @@ class BoundaryOffsetInfo:
def get_array_declarations(self) -> list[Assignment]: def get_array_declarations(self) -> list[Assignment]:
asms = [] asms = []
for i, offset_symb in enumerate(BoundaryOffsetInfo._offset_symbols(self._dim)): for i, offset_symb in enumerate(self._offset_symbols(self._dim)):
offsets = tuple(d[i] for d in self._stencil) offsets = tuple(d[i] for d in self._stencil)
asms.append(Assignment(offset_symb, offsets)) asms.append(Assignment(offset_symb, offsets))
...@@ -434,16 +434,22 @@ class BoundaryOffsetInfo: ...@@ -434,16 +434,22 @@ class BoundaryOffsetInfo:
inverse_dir = tuple([-i for i in direction]) inverse_dir = tuple([-i for i in direction])
inv_dirs.append(str(self._stencil.index(inverse_dir))) inv_dirs.append(str(self._stencil.index(inverse_dir)))
asms.append(Assignment(BoundaryOffsetInfo._inv_dir_symbol(), tuple(inv_dirs))) asms.append(Assignment(self._inv_dir_symbol(), tuple(inv_dirs)))
return asms return asms
def _offset_symbols(self, dim, dtype: PsIntegerType = SInt(32)):
return [TypedSymbol(f"c{d}", Arr(dtype, len(self._stencil))) for d in ['x', 'y', 'z'][:dim]]
@staticmethod @staticmethod
def _offset_symbols(dim, dtype: PsIntegerType = SInt(32)): def _untyped_offset_symbols(dim):
return [TypedSymbol(f"c{d}", Arr(dtype)) for d in ['x', 'y', 'z'][:dim]] return [sp.Symbol(f"c{d}") for d in ['x', 'y', 'z'][:dim]]
def _inv_dir_symbol(self, dtype: PsIntegerType = SInt(32)):
return TypedSymbol("invdir", Arr(dtype, len(self._stencil)))
@staticmethod @staticmethod
def _inv_dir_symbol(dtype: PsIntegerType = SInt(32)): def _untyped_inv_dir_symbol(dtype: PsIntegerType = SInt(32)):
return TypedSymbol("invdir", Arr(dtype)) return sp.Symbol("invdir")
def create_boundary_kernel(field, index_field, stencil, boundary_functor, target=Target.CPU, **kernel_creation_args): def create_boundary_kernel(field, index_field, stencil, boundary_functor, target=Target.CPU, **kernel_creation_args):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment