-
Notifications
You must be signed in to change notification settings - Fork 98
/
Copy pathtest_examples.py
87 lines (74 loc) · 2.36 KB
/
test_examples.py
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
import os
import unittest
from time import time
import runpy
all_scripts = [
'01_turbine_model',
'02_ccblade',
'03_tune_controller',
'04_simple_sim',
'05_openfast_sim',
'06_peak_shaving',
'07_openfast_outputs',
'08_run_turbsim',
'09_distributed_aero',
'10_linear_params',
'11_robust_tuning',
'12_tune_ipc',
'14_open_loop_control',
'15_pass_through',
'16_external_dll',
'17a_zeromq_simple', # only runs on unix in CI
'17b_zeromq_multi_openfast', # only runs on unix in CI
'18_pitch_offsets',
'19_update_discon_version',
'20_active_wake_control',
'21_optional_inputs',
'22_cable_control',
'23_structural_control',
'24_floating_feedback',
'25_rotor_position_control',
'26_marine_hydro',
'27_power_ref_control',
'28_tower_resonance',
'update_rosco_discons',
]
def execute_script(fscript):
this_dir = os.path.dirname(os.path.abspath(__file__))
rosco_dir = os.path.dirname( os.path.dirname(this_dir) )
examples_dir = os.path.join(rosco_dir,'Examples')
test_case_dir = os.path.join(examples_dir,'Test_Cases')
# Go to location due to relative path use for airfoil files
print("\n\n")
print("NOW RUNNING:", fscript)
print()
if fscript in ['update_rosco_discons']:
run_dir = test_case_dir
else:
run_dir = examples_dir
fullpath = os.path.join(run_dir, fscript + ".py")
basepath = os.path.dirname(os.path.realpath(fullpath))
os.chdir(basepath)
# Use runpy to execute examples
s = time()
runpy.run_path(os.path.realpath(fullpath), run_name='__main__')
print(f"{fscript} took {time() - s} seconds to run")
class TestExamples(unittest.TestCase):
def test_all_scripts(self):
for ks, s in enumerate(all_scripts):
with self.subTest(f"Running: {s}", i=ks):
try:
execute_script(s)
self.assertTrue(True)
except:
self.assertEqual(s, "Success")
def suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestExamples))
return suite
if __name__ == "__main__":
result = unittest.TextTestRunner().run(suite())
if result.wasSuccessful():
exit(0)
else:
exit(1)