Skip to content

Commit deda9a4

Browse files
committed
Simplify run_examples_as_tests script, single process
1 parent 47b22d4 commit deda9a4

File tree

1 file changed

+15
-27
lines changed

1 file changed

+15
-27
lines changed

run_examples_as_tests.py

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,26 @@
1717
##You should have received a copy of the GNU Lesser General Public License
1818
##along with pythonOCC. If not, see <http://www.gnu.org/licenses/>.
1919

20-
from __future__ import print_function
2120
# look for all example names
2221
import os
2322
import glob
2423
import sys
2524
import subprocess
26-
import multiprocessing as mp
2725
import time
28-
try:
29-
from threading import TIMEOUT_MAX
30-
except ImportError:
31-
TIMEOUT_MAX = 60 * 60 * 24 * 49
32-
33-
def init(args):
34-
''' store the counter for later use '''
35-
global failed
36-
failed = args
3726

3827
def worker(example_name):
39-
global failed
4028
# += operation is not atomic, so we need to get a lock:
4129
print("running %s ..." % example_name, end="")
4230
try:
4331
subprocess.check_output([sys.executable, example_name],
4432
stderr=subprocess.STDOUT,
4533
universal_newlines=True)
4634
print("[passed]")
35+
return True
4736
except subprocess.CalledProcessError as cpe:
4837
print("%s" % cpe.output)
49-
with failed.get_lock():
50-
failed.value += 1
5138
print("[failed]")
39+
return False
5240

5341
if __name__ == "__main__":
5442
init_time = time.time()
@@ -59,7 +47,7 @@ def worker(example_name):
5947
examples_directory = os.path.join(test_dirname, 'examples')
6048
os.chdir(examples_directory)
6149
all_examples_file_names = glob.glob('core_*.py')
62-
print(all_examples_file_names)
50+
6351
# some tests have to be excluded from the automatic
6452
# run. For instance, qt based examples
6553
tests_to_exclude = ['core_display_signal_slots.py',
@@ -76,20 +64,20 @@ def worker(example_name):
7664
os.environ["PYTHONOCC_OFFSCREEN_RENDERER_DUMP_IMAGE"] = "1"
7765
os.environ["PYTHONOCC_SHUNT_WEB_SERVER"] = "1"
7866

79-
failed = mp.Value('i', 0)
80-
81-
pool = mp.Pool(initializer = init, initargs = (failed, ))
82-
pool.map_async(worker, all_examples_file_names).get(TIMEOUT_MAX)
83-
pool.close()
84-
pool.join()
67+
# loop over each example
68+
failed = 0
69+
for example_file_name in all_examples_file_names:
70+
test_result = worker(example_file_name)
71+
if not test_result:
72+
failed += 1
8573

8674
print("Test examples results :")
87-
print("\t %i/%i tests passed" % ((nbr_examples - failed.value), nbr_examples))
75+
print("\t %i/%i tests passed" % ((nbr_examples - failed), nbr_examples))
8876

89-
del os.environ["PYTHONOCC_OFFSCREEN_RENDERER"]
90-
del os.environ["PYTHONOCC_SHUNT_WEB_SERVER"]
91-
92-
if failed.value > 0:
93-
print("%i tests failed" % (failed.value))
77+
if failed > 0:
78+
print("%i tests failed" % failed)
9479

9580
print("Total time to run all examples: %fs" %(time.time() - init_time))
81+
82+
del os.environ["PYTHONOCC_OFFSCREEN_RENDERER"]
83+
del os.environ["PYTHONOCC_SHUNT_WEB_SERVER"]

0 commit comments

Comments
 (0)