Repository navigation
Expand file tree
/
Copy pathrun_examples_as_tests.py
More file actions
executable file
·89 lines (73 loc) · 2.69 KB
/
Copy pathrun_examples_as_tests.py
File metadata and controls
executable file
·89 lines (73 loc) · 2.69 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
#!/usr/bin/env python
##Copyright 2009-2019 Thomas Paviot (tpaviot@gmail.com)
##
##This file is part of pythonOCC.
##
##pythonOCC is free software: you can redistribute it and/or modify
##it under the terms of the GNU Lesser General Public License as published by
##the Free Software Foundation, either version 3 of the License, or
##(at your option) any later version.
##
##pythonOCC is distributed in the hope that it will be useful,
##but WITHOUT ANY WARRANTY; without even the implied warranty of
##MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
##GNU Lesser General Public License for more details.
##
##You should have received a copy of the GNU Lesser General Public License
##along with pythonOCC. If not, see <http://www.gnu.org/licenses/>.
# look for all example names
import glob
import os
import subprocess
import sys
import time
def worker(example_name):
# += operation is not atomic, so we need to get a lock:
print(f"running {example_name} ...", end="")
try:
subprocess.check_output(
[sys.executable, example_name],
stderr=subprocess.STDOUT,
universal_newlines=True,
)
print("[passed]")
return True
except subprocess.CalledProcessError as cpe:
print(f"{cpe.output}")
print("[failed]")
return False
if __name__ == "__main__":
init_time = time.time()
# find examplessubdir from current file
path = os.path.abspath(__file__)
test_dirname = os.path.dirname(path)
examples_directory = os.path.join(test_dirname, "examples")
os.chdir(examples_directory)
all_examples_file_names = glob.glob("core_*.py")
# some tests have to be excluded from the automatic
# run. For instance, qt based examples
tests_to_exclude = [
"core_display_signal_slots.py",
"core_visualization_overpaint_viewer.py",
]
# remove examples to excludes
for test_name in tests_to_exclude:
all_examples_file_names.remove(test_name)
nbr_examples = len(all_examples_file_names)
os.environ["PYTHONOCC_OFFSCREEN_RENDERER"] = "1"
os.environ["PYTHONOCC_OFFSCREEN_RENDERER_DUMP_IMAGE"] = "1"
os.environ["PYTHONOCC_SHUNT_WEB_SERVER"] = "1"
# loop over each example
failed = 0
for example_file_name in all_examples_file_names:
test_result = worker(example_file_name)
if not test_result:
failed += 1
print("Test examples results :")
print(f"\t {nbr_examples - failed}/{nbr_examples} tests passed")
if failed > 0:
print(f"{failed} tests failed")
print("Total time to run all examples: %fs" % (time.time() - init_time))
# if failed, exit with error
if failed > 0:
sys.exit(1)