2013-02-01 15:22:32 -05:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
|
|
import os
|
2015-06-04 13:53:42 +07:00
|
|
|
import sys
|
2013-08-22 12:17:28 -04:00
|
|
|
from subprocess import Popen, STDOUT, PIPE, call
|
2013-08-12 13:17:03 -04:00
|
|
|
import filecmp
|
2013-08-21 16:19:54 -04:00
|
|
|
import glob
|
2014-02-24 17:21:48 -05:00
|
|
|
from optparse import OptionParser
|
2013-02-01 15:22:32 -05:00
|
|
|
|
2014-02-24 17:21:48 -05:00
|
|
|
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()
|
2013-02-01 15:22:32 -05:00
|
|
|
|
|
|
|
|
def test_run():
|
2014-02-24 17:21:48 -05:00
|
|
|
if opts.mpi_exec != '':
|
|
|
|
|
proc = Popen([opts.mpi_exec, '-np', opts.mpi_np, opts.exe, cwd],
|
2013-08-16 17:36:44 -04:00
|
|
|
stderr=STDOUT, stdout=PIPE)
|
|
|
|
|
else:
|
2014-02-24 17:21:48 -05:00
|
|
|
proc = Popen([opts.exe, cwd], stderr=STDOUT, stdout=PIPE)
|
2013-02-01 15:22:32 -05:00
|
|
|
print(proc.communicate()[0])
|
2013-10-16 23:03:40 -04:00
|
|
|
returncode = proc.returncode
|
2014-02-24 17:21:48 -05:00
|
|
|
assert returncode == 0, 'OpenMC did not exit successfully.'
|
2013-02-01 15:22:32 -05:00
|
|
|
|
|
|
|
|
def test_created_statepoint():
|
2014-04-08 18:39:40 -04:00
|
|
|
statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
|
2014-02-24 17:21:48 -05:00
|
|
|
assert len(statepoint) == 1, 'Either multiple or no statepoint files exist.'
|
|
|
|
|
assert statepoint[0].endswith('binary') or statepoint[0].endswith('h5'),\
|
|
|
|
|
'Statepoint file is not a binary or hdf5 file.'
|
2013-02-01 15:22:32 -05:00
|
|
|
|
2013-08-12 13:17:03 -04:00
|
|
|
def test_results():
|
2014-04-08 18:39:40 -04:00
|
|
|
statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
|
2015-06-04 13:53:42 +07:00
|
|
|
call([sys.executable, 'results.py', statepoint[0]])
|
2013-08-12 14:13:54 -04:00
|
|
|
compare = filecmp.cmp('results_test.dat', 'results_true.dat')
|
|
|
|
|
if not compare:
|
2013-08-14 20:09:27 -05:00
|
|
|
os.rename('results_test.dat', 'results_error.dat')
|
2014-02-24 17:21:48 -05:00
|
|
|
assert compare, 'Results do not agree.'
|
2013-08-12 13:17:03 -04:00
|
|
|
|
2013-02-01 15:22:32 -05:00
|
|
|
def teardown():
|
2014-04-08 18:39:40 -04:00
|
|
|
output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
|
|
|
|
|
output.append(os.path.join(cwd, 'results_test.dat'))
|
2013-02-01 15:22:32 -05:00
|
|
|
for f in output:
|
|
|
|
|
if os.path.exists(f):
|
|
|
|
|
os.remove(f)
|
2014-02-24 17:21:48 -05:00
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
|
|
|
|
|
# test for openmc executable
|
2014-04-03 08:15:54 -04:00
|
|
|
if opts.exe is None:
|
2014-02-24 17:21:48 -05:00
|
|
|
raise Exception('Must specify OpenMC executable from command line with --exe.')
|
|
|
|
|
|
|
|
|
|
# run tests
|
2014-05-27 16:51:52 -04:00
|
|
|
try:
|
|
|
|
|
test_run()
|
|
|
|
|
test_created_statepoint()
|
|
|
|
|
test_results()
|
|
|
|
|
finally:
|
|
|
|
|
teardown()
|