Debian Codegraph @

dev/continuous-integration/run_test_suite.py

raw
1 """
2 Script to run the test suite during automatic testing (easier than putting all
3 the logic into Windows batch/bash statements)
4 """
5
6 # Importing multiprocessing here seems to fix hangs in the test suite on OS X
7 # see https://github.com/scipy/scipy/issues/11835
8 import multiprocessing
9
10 # Prevent potential issues on multi-threaded execution
11 multiprocessing.set_start_method("spawn", force=True)
12 import os
13 import sys
14
15 import numpy as np
16
17 import brian2
18
19 if __name__ == "__main__":
20 split_run = os.environ.get("SPLIT_RUN", None)
21 standalone = os.environ.get("STANDALONE", "no").lower() in ["yes", "true"]
22 python_version = os.environ.get("PYTHON_VERSION", os.environ.get("PYTHON"))
23 # If TRAVIS_OS_NAME is not defined, we are testing on appveyor
24 operating_system = os.environ.get("AGENT_OS", "unknown").lower()
25 cross_compiled = os.environ.get("CROSS_COMPILED", "FALSE").lower() in [
26 "yes",
27 "true",
28 ]
29 do_not_reset_preferences = os.environ.get(
30 "DO_NOT_RESET_PREFERENCES", "false"
31 ).lower() in ["yes", "true"]
32 dtype_32_bit = os.environ.get("FLOAT_DTYPE_32", "no").lower() in ["yes", "true"]
33 sphinx_dir = os.environ.get("SPHINX_DIR")
34 src_dir = os.environ.get("SRCDIR")
35 deprecation_error = os.environ.get("DEPRECATION_ERROR", "false").lower() in [
36 "yes",
37 "true",
38 ]
39 if split_run == "1":
40 targets = ["numpy"]
41 independent = True
42 elif split_run == "2":
43 targets = ["cython"]
44 independent = False
45 else:
46 targets = None
47 independent = True
48
49 if operating_system == "windows" or standalone:
50 in_parallel = []
51 else:
52 in_parallel = ["codegen_independent", "numpy", "cpp_standalone"]
53
54 if operating_system in ["linux", "windows_nt"]:
55 openmp = True
56 else:
57 openmp = False
58
59 reset_preferences = not (cross_compiled or do_not_reset_preferences)
60 if dtype_32_bit:
61 float_dtype = np.float32
62 else:
63 float_dtype = None
64
65 if deprecation_error:
66 args = ["-W", "error::DeprecationWarning", "--tb=short"]
67 else:
68 # Use coverage and test time duration when running on GitHub
69 if "GITHUB_WORKSPACE" in os.environ:
70 args = [
71 "--durations=10", # print a list of the 10 slowest tests
72 "--cov",
73 "--cov-append",
74 "--cov-report",
75 "xml",
76 "--cov-config",
77 os.path.join(os.environ["GITHUB_WORKSPACE"], ".coveragerc"),
78 ]
79 else:
80 args = []
81
82 if standalone:
83 result = brian2.test(
84 [],
85 test_codegen_independent=False,
86 test_standalone="cpp_standalone",
87 test_openmp=openmp,
88 test_in_parallel=in_parallel,
89 reset_preferences=reset_preferences,
90 float_dtype=float_dtype,
91 test_GSL=True,
92 sphinx_dir=sphinx_dir,
93 additional_args=args,
94 )
95 else:
96 result = brian2.test(
97 targets,
98 test_codegen_independent=independent,
99 test_standalone=None,
100 test_in_parallel=in_parallel,
101 reset_preferences=reset_preferences,
102 float_dtype=float_dtype,
103 test_GSL=True,
104 sphinx_dir=sphinx_dir,
105 additional_args=args,
106 )
107
108 if not result:
109 sys.exit(1)