Debian Codegraph @

python/demo/test.py

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 import os
2 import pathlib
3 import subprocess
4 import sys
5 import pytest
6
7
8 # Get directory of this file
9 dir_path = pathlib.Path(__file__).resolve().parent
10
11 # Build list of demo programs
12 demos = []
13 for subdir in ['documented', 'undocumented']:
14 p = pathlib.Path(dir_path, subdir)
15 demo_files = list(p.glob('**/*.py'))
16 for f in demo_files:
17 demos.append((f.parent, f.name))
18
19
20 # FIXME: fix cases that break pattern
21 # Remove 'tensor-weighted-poisson'
22 demos = [d for d in demos if d[0].stem != 'tensor-weighted-poisson']
23
24 # Testing
25 #demos = [d for d in demos if d[0].stem == 'stokes-taylor-hood']
26 #print("------------------------------")
27 #print(demos)
28
29
30 @pytest.mark.parametrize("path,name", demos)
31 def test_demos(mpiexec, num_proc, path, name):
32
33 if mpiexec is None:
34 # Run in serial
35 ret = subprocess.run([sys.executable, name],
36 cwd=str(path),
37 env={**os.environ, 'MPLBACKEND': 'agg'},
38 check=True)
39 else:
40 # Run with MPI
41
42 # FIXME: non-MPI demos should exit gracefully
43 # Demos that don't work in parallel
44 broken = ["demo_subdomains.py",
45 "demo_auto-adaptive-poisson.py",
46 "demo_nonmatching-interpolation.py",
47 'demo_adaptive-poisson.py',
48 'demo_auto-adaptive-navier-stokes.py',
49 'demo_eval.py',
50 'demo_extrapolation.py',
51 'demo_nonmatching-interpolation.py',
52 'demo_nonmatching-projection.py',
53 'demo_poisson-disc.py',
54 'demo_smoothing.py',
55 'demo_subdomains.py',
56 'demo_submesh.py',
57 'demo_time-series.py',
58 'demo_poisson1D-in-2D.py',
59 'demo_coordinates.py',
60 'demo_block-assembly-2D2D-nonlinear.py',
61 'demo_block-assembly-3D1D.py',
62 ]
63 if name in broken:
64 return
65
66 assert int(num_proc) > 0 and int(num_proc) < 32
67 cmd = mpiexec + " -np " + str(num_proc) + " " + sys.executable + " " + name
68 ret = subprocess.run(cmd,
69 cwd=str(path),
70 shell=True,
71 #stdin=subprocess.DEVNULL,
72 env={**os.environ, 'MPLBACKEND': 'agg'},
73 check=True
74 )