mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 22:26:08 -04:00
Updated tests to use Python TestHarness
This commit is contained in:
parent
13744b1f8b
commit
e610f0147d
216 changed files with 1197 additions and 8530 deletions
|
|
@ -1,32 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
|
||||
sys.path.insert(0, '../..')
|
||||
from openmc.statepoint import StatePoint
|
||||
|
||||
# read in statepoint file
|
||||
if len(sys.argv) > 1:
|
||||
sp = StatePoint(sys.argv[1])
|
||||
else:
|
||||
sp = StatePoint('statepoint.08.binary')
|
||||
|
||||
sp.read_results()
|
||||
sp.read_source()
|
||||
|
||||
# set up output string
|
||||
outstr = ''
|
||||
|
||||
# write out k-combined
|
||||
outstr += 'k-combined:\n'
|
||||
outstr += "{0:12.6E} {1:12.6E}\n".format(sp._k_combined[0], sp._k_combined[1])
|
||||
|
||||
# write out xyz
|
||||
xyz = sp._source[0]._xyz
|
||||
for i in xyz:
|
||||
outstr += "{0:12.6E} ".format(i)
|
||||
outstr += "\n"
|
||||
|
||||
# write results to file
|
||||
with open('results_test.dat','w') as fh:
|
||||
fh.write(outstr)
|
||||
|
|
@ -1,3 +1,3 @@
|
|||
k-combined:
|
||||
0.000000E+00 0.000000E+00
|
||||
1.892327E+00 -3.385257E+00 6.702634E-01
|
||||
1.892327E+00 -3.385257E+00 6.702634E-01
|
||||
|
|
|
|||
|
|
@ -1,60 +1,42 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import os
|
||||
import sys
|
||||
from subprocess import Popen, STDOUT, PIPE, call
|
||||
import filecmp
|
||||
import glob
|
||||
from optparse import OptionParser
|
||||
sys.path.insert(0, '..')
|
||||
from testing_harness import *
|
||||
|
||||
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():
|
||||
if opts.mpi_exec != '':
|
||||
proc = Popen([opts.mpi_exec, '-np', opts.mpi_np, opts.exe, cwd],
|
||||
stderr=STDOUT, stdout=PIPE)
|
||||
else:
|
||||
proc = Popen([opts.exe, cwd], stderr=STDOUT, stdout=PIPE)
|
||||
print(proc.communicate()[0])
|
||||
returncode = proc.returncode
|
||||
assert returncode == 0, 'OpenMC did not exit successfully.'
|
||||
class SourcepointTestHarness(TestHarness):
|
||||
def _test_output_created(self):
|
||||
"""Make sure statepoint.* files have been created."""
|
||||
statepoint = glob.glob(os.path.join(os.getcwd(), 'statepoint.*'))
|
||||
assert len(statepoint) == 5, '5 statepoint files must exist.'
|
||||
assert statepoint[0].endswith('binary') \
|
||||
or statepoint[0].endswith('h5'), \
|
||||
'Statepoint file is not a binary or hdf5 file.'
|
||||
|
||||
def test_statepoint_exists():
|
||||
statepoint = glob.glob(os.path.join(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(os.path.join(cwd, 'statepoint.08.*'))
|
||||
call([sys.executable, '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, 'Results do no agree.'
|
||||
def _get_results(self):
|
||||
"""Digest info in the statepoint and create a simpler ASCII file."""
|
||||
# Read the statepoint file.
|
||||
statepoint = glob.glob(os.path.join(os.getcwd(), self._sp_name))[0]
|
||||
sp = StatePoint(statepoint)
|
||||
sp.read_results()
|
||||
sp.read_source()
|
||||
|
||||
# Write out k-combined.
|
||||
outstr = 'k-combined:\n'
|
||||
form = '{0:12.6E} {1:12.6E}\n'
|
||||
outstr += form.format(sp.k_combined[0], sp.k_combined[1])
|
||||
|
||||
xyz = sp._source[0]._xyz
|
||||
outstr += ' '.join(['{0:12.6E}'.format(x) for x in xyz])
|
||||
outstr += "\n"
|
||||
|
||||
# Write results to a file.
|
||||
with open('results_test.dat','w') as fh:
|
||||
fh.write(outstr)
|
||||
|
||||
def teardown():
|
||||
output = glob.glob(os.path.join(cwd, 'statepoint.*'))
|
||||
output.append(os.path.join(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 is None:
|
||||
raise Exception('Must specify OpenMC executable from command line with --exe.')
|
||||
|
||||
# run tests
|
||||
try:
|
||||
test_run()
|
||||
test_statepoint_exists()
|
||||
test_results()
|
||||
finally:
|
||||
teardown()
|
||||
harness = SourcepointTestHarness('statepoint.08.*')
|
||||
harness.execute_test()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue