File: test_demos.py

package info (click to toggle)
fenics-ffcx 1%3A0.9.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 948 kB
  • sloc: python: 8,246; ansic: 109; makefile: 58
file content (75 lines) | stat: -rw-r--r-- 2,510 bytes parent folder | download | duplicates (2)
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
"""Test demos."""

import os
import sys

import pytest

demo_dir = os.path.dirname(os.path.realpath(__file__))

ufl_files = []
for file in os.listdir(demo_dir):
    if file.endswith(".py") and not file == "test_demos.py":
        ufl_files.append(file[:-3])


@pytest.mark.parametrize("file", ufl_files)
@pytest.mark.parametrize("scalar_type", ["float64", "float32", "complex128", "complex64"])
def test_demo(file, scalar_type):
    """Test a demo."""
    if sys.platform.startswith("win32") and "complex" in scalar_type:
        # Skip complex demos on win32
        pytest.skip(reason="_Complex not supported on Windows")

    if file in [
        "MixedGradient",
        "TraceElement",  # HDiv Trace
        "MixedElasticity",  # VectorElement of BDM
        "RestrictedElement",
        "_TensorProductElement",
    ]:
        # Skip demos that use elements not yet implemented in Basix
        pytest.skip(reason="Element not yet implemented in Basix")

    if "complex" in scalar_type and file in [
        "BiharmonicHHJ",
        "BiharmonicRegge",
        "StabilisedStokes",
    ]:
        # Skip demos that are not implemented for complex scalars
        pytest.skip(reason="Not implemented for complex types")
    elif "Complex" in file and scalar_type in ["float64", "float32"]:
        # Skip demos that are only implemented for complex scalars
        pytest.skip(reason="Not implemented for real types")

    if sys.platform.startswith("win32"):
        opts = f"--scalar_type {scalar_type}"
        extra_flags = "/std:c17"
        assert os.system(f"cd {demo_dir} && ffcx {opts} {file}.py") == 0
        assert (
            os.system(
                f"cd {demo_dir} && " f'cl.exe /I "../ffcx/codegeneration" {extra_flags} /c {file}.c'
            )
        ) == 0
        assert (
            os.system(
                f"cd {demo_dir} && "
                f'clang-cl.exe /I "../ffcx/codegeneration" {extra_flags} /c {file}.c'
            )
        ) == 0
    else:
        cc = os.environ.get("CC", "cc")
        opts = f"--scalar_type {scalar_type}"
        extra_flags = (
            "-std=c17 -Wunused-variable -Werror -fPIC -Wno-error=implicit-function-declaration"
        )
        assert os.system(f"cd {demo_dir} && ffcx {opts} {file}.py") == 0
        assert (
            os.system(
                f"cd {demo_dir} && "
                f"{cc} -I../ffcx/codegeneration "
                f"{extra_flags} "
                f"-c {file}.c"
            )
            == 0
        )