Skip to content

Commit c49688c

Browse files
committed
Finalize coverage testing of Python API via options in run_tests.py
1 parent c7e5600 commit c49688c

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

CMakeLists.txt

+10-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,16 @@ foreach(test ${TESTS})
1717
get_filename_component(TEST_NAME ${test} NAME)
1818
get_filename_component(TEST_PATH ${test} PATH)
1919

20-
add_test(NAME ${TEST_NAME}
21-
WORKING_DIRECTORY ${TEST_PATH}
22-
COMMAND coverage run ${TEST_NAME}
20+
if(${COVERAGE})
21+
add_test(NAME ${TEST_NAME}
22+
WORKING_DIRECTORY ${TEST_PATH}
23+
COMMAND ${PYTHON_EXECUTABLE} run --omit=${OMIT} ${TEST_NAME}
2324
)
25+
else()
26+
add_test(NAME ${TEST_NAME}
27+
WORKING_DIRECTORY ${TEST_PATH}
28+
COMMAND ${PYTHON_EXECUTABLE} ${TEST_NAME}
29+
)
30+
endif()
2431

2532
endforeach(test)

tests/run_tests.py

+15-7
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
parser = OptionParser()
1616
parser.add_option('-j', '--parallel', dest='n_procs', default='1',
1717
help="Number of parallel jobs.")
18-
parser.add_option('-v', '--verbose', action="store_true", dest="verbose",
18+
parser.add_option('-v', '--verbose', action="store_true", dest='verbose',
1919
default=False, help="Make CTest verbose.")
2020
parser.add_option('-R', '--tests-regex', dest='regex_tests',
2121
help="Run tests matching regular expression. "
@@ -26,9 +26,9 @@
2626
"Specific build configurations can be printed out with "
2727
"optional argument -p, --print. This uses standard "
2828
"regex syntax to select build configurations.")
29-
parser.add_option('-c', '--coverage', dest='coverage',
30-
help="Run tests with coverage.py to output Python code "
31-
"coverage.")
29+
parser.add_option('-c', '--coverage', action="store_true", dest='coverage',
30+
default=False, help="Run tests with coverage.py to output "
31+
"Python code coverage.")
3232
parser.add_option('-l', '--list', action="store_true",
3333
dest="list_build_configs", default=False,
3434
help="List out build configurations.")
@@ -82,6 +82,14 @@ def run_cmake(self):
8282

8383
cmake_cmd = ['cmake', '-H..', '-Bbuild']
8484

85+
# Run tests with coverage option or not
86+
if options.coverage:
87+
cmake_cmd += ['-DPYTHON_EXECUTABLE=' + shutil.which('coverage')]
88+
cmake_cmd += ['-DCOVERAGE=True']
89+
cmake_cmd += ['-DOMIT=test*']
90+
else:
91+
cmake_cmd += ['-DPYTHON_EXECUTABLE=' + sys.executable]
92+
8593
# Run CMake
8694
rc = subprocess.call(cmake_cmd)
8795

@@ -128,7 +136,7 @@ def add_test(name, cc='gcc', num_threads=1, debug=False, ):
128136
# List of all tests that may be run. User can add -C to command line to specify
129137
# a subset of these configurations
130138
add_test('normal-gcc', cc='gcc', num_threads=1)
131-
#add_test('normal-openmp-gcc', cc='gcc', num_threads=4)
139+
add_test('normal-openmp-gcc', cc='gcc', num_threads=4)
132140
#add_test('normal-icpc', cc='icpc', num_threads=1)
133141
#add_test('normal-openmp-icpc', cc='icpc', num_threads=4)
134142
#add_test('normal-clang', cc='clang', num_threads=1)
@@ -192,12 +200,12 @@ def add_test(name, cc='gcc', num_threads=1, debug=False, ):
192200
shutil.copy(logfile[0], logfilename)
193201

194202
# Combine all coverage files
195-
if coverage == True:
203+
if options.coverage:
196204
os.system('coverage combine test*/.coverage')
197205

198206
# Clear build directory and remove binary and hdf5 files
199207
shutil.rmtree('build', ignore_errors=True)
200-
if coverage == False:
208+
if not options.coverage:
201209
shutil.rmtree('openmoc', ignore_errors=True)
202210
subprocess.call(['./cleanup'])
203211

0 commit comments

Comments
 (0)