converted new tests to ctest format

This commit is contained in:
Bryan Herman 2014-03-11 18:59:37 -04:00
parent 433b579004
commit 94535a0fbe
5 changed files with 222 additions and 148 deletions

View file

@ -3,42 +3,55 @@
import os
from subprocess import Popen, STDOUT, PIPE, call
import filecmp
from nose_mpi import NoseMPI
import glob
from optparse import OptionParser
pwd = os.path.dirname(__file__)
def setup():
os.putenv('PWD', pwd)
os.chdir(pwd)
parser = OptionParser()
parser.add_option('--mpi_exec', dest='mpi_exec', default='')
parser.add_option('--mpi_np', dest='mpi_np', default='3')
parser.add_option('--exe', dest='exe')
(opts, args) = parser.parse_args()
cwd = os.getcwd()
def test_run():
openmc_path = pwd + '/../../src/openmc'
if int(NoseMPI.mpi_np) > 0:
proc = Popen([NoseMPI.mpi_exec, '-np', NoseMPI.mpi_np, openmc_path],
if opts.mpi_exec != '':
proc = Popen([opts.mpi_exec, '-np', opts.mpi_np, opts.exe, cwd],
stderr=STDOUT, stdout=PIPE)
else:
proc = Popen([openmc_path], stderr=STDOUT, stdout=PIPE)
proc = Popen([opts.exe, cwd], stderr=STDOUT, stdout=PIPE)
print(proc.communicate()[0])
returncode = proc.returncode
assert returncode == 0
assert returncode == 0, 'OpenMC did not exit successfully.'
def test_statepoint_exists():
statepoint = glob.glob(pwd + '/statepoint.*')
assert len(statepoint) == 5
assert statepoint[0].endswith('binary') or statepoint[0].endswith('h5')
statepoint = glob.glob(cwd + '/statepoint.*')
assert len(statepoint) == 5, '5 statepoint files must exist.'
assert statepoint[0].endswith('binary') or statepoint[0].endswith('h5'),\
'Statepoint file detected that is not binary or hdf5.'
def test_results():
statepoint = glob.glob(pwd + '/statepoint.8.*')
statepoint = glob.glob(cwd + '/statepoint.8.*')
call(['python', 'results.py', statepoint[0]])
compare = filecmp.cmp('results_test.dat', 'results_true.dat')
if not compare:
os.rename('results_test.dat', 'results_error.dat')
assert compare
assert compare, 'Results do no agree.'
def teardown():
output = glob.glob(pwd + '/statepoint.*')
output.append(pwd + '/results_test.dat')
output = glob.glob(cwd + '/statepoint.*')
output.append(cwd + '/results_test.dat')
for f in output:
if os.path.exists(f):
os.remove(f)
if __name__ == '__main__':
# test for openmc executable
if opts.exe == None:
raise Exception('Must specify OpenMC executable from command line with --exe.')
# run tests
test_run()
test_statepoint_exists()
test_results()
teardown()