-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathtestutils.py
More file actions
67 lines (56 loc) · 1.77 KB
/
testutils.py
File metadata and controls
67 lines (56 loc) · 1.77 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
"""
Test suite utilities.
"""
from pathlib import Path
import subprocess
import sys
from itertools import chain
ROOT = Path(__file__).parents[2] # repo root
examples_dir = ROOT / "examples" / "desktop"
screenshots_dir = examples_dir / "screenshots"
diffs_dir = examples_dir / "diffs"
# examples live in themed sub-folders
example_globs = [
"image/*.py",
"heatmap/*.py",
"scatter/*.py",
"line/*.py",
"line_collection/*.py",
"gridplot/*.py"
]
def get_wgpu_backend():
"""
Query the configured wgpu backend driver.
"""
code = "import wgpu.utils; info = wgpu.utils.get_default_device().adapter.request_adapter_info(); print(info['adapter_type'], info['backend_type'])"
result = subprocess.run(
[
sys.executable,
"-c",
code,
],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True,
cwd=ROOT,
)
out = result.stdout.strip()
err = result.stderr.strip()
return err if "traceback" in err.lower() else out
wgpu_backend = get_wgpu_backend()
is_lavapipe = wgpu_backend.lower() == "cpu vulkan"
def find_examples(query=None, negative_query=None, return_stems=False):
"""Finds all modules to be tested."""
result = []
for example_path in chain(*(examples_dir.glob(x) for x in example_globs)):
example_code = example_path.read_text(encoding="UTF-8")
query_match = query is None or query in example_code
negative_query_match = (
negative_query is None or negative_query not in example_code
)
if query_match and negative_query_match:
result.append(example_path)
result = list(sorted(result))
if return_stems:
result = [r.stem for r in result]
return result