diff --git a/tests/test_basic/results.py b/tests/test_basic/results.py
deleted file mode 100644
index 03f3e4b439..0000000000
--- a/tests/test_basic/results.py
+++ /dev/null
@@ -1,24 +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.10.binary')
-sp.read_results()
-
-# 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 results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_basic/test_basic.py b/tests/test_basic/test_basic.py
old mode 100644
new mode 100755
index ab227e2ba3..390e6d832e
--- a/tests/test_basic/test_basic.py
+++ b/tests/test_basic/test_basic.py
@@ -1,60 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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_created_statepoint()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*')
+ harness.execute_test()
diff --git a/tests/test_cmfd_feed/results.py b/tests/test_cmfd_feed/results.py
deleted file mode 100644
index fe38537b32..0000000000
--- a/tests/test_cmfd_feed/results.py
+++ /dev/null
@@ -1,92 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-import numpy as np
-
-sys.path.insert(0, '../..')
-import openmc
-from openmc.statepoint import StatePoint
-
-# read in statepoint file
-if len(sys.argv) > 1:
- sp = StatePoint(sys.argv[1])
-else:
- sp = StatePoint('statepoint.20.binary')
-
-sp.read_results()
-
-# extract tally results and convert to vector
-tally1 = sp.get_tally(scores=['flux'], filters=[openmc.Filter('mesh', [1])], \
- estimator='tracklength')
-tally2 = sp.get_tally(scores=['flux'], filters=[openmc.Filter('mesh', [2])], \
- estimator='analog')
-tally3 = sp.get_tally(scores=['nu-fission'], \
- filters=[openmc.Filter('mesh', [2])], estimator='analog')
-tally4 = sp.get_tally(scores=['current'], filters=[openmc.Filter('mesh', [2]), \
- openmc.Filter('surface', [1,2,3,4,5,6])], \
- estimator='analog')
-
-results1 = np.zeros((tally1.sum.size + tally1.sum.size, ))
-results1[0::2] = tally1.sum.ravel()
-results1[1::2] = tally1.sum_sq.ravel()
-
-results2 = np.zeros((tally2.sum.size + tally2.sum.size, ))
-results2[0::2] = tally2.sum.ravel()
-results2[1::2] = tally2.sum_sq.ravel()
-
-results3 = np.zeros((tally3.sum.size + tally3.sum.size, ))
-results3[0::2] = tally3.sum.ravel()
-results3[1::2] = tally3.sum_sq.ravel()
-
-results4 = np.zeros((tally4.sum.size + tally4.sum.size, ))
-results4[0::2] = tally4.sum.ravel()
-results4[1::2] = tally4.sum_sq.ravel()
-
-# 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 tally results
-outstr += 'tally 1:\n'
-for item in results1:
- outstr += "{0:12.6E}\n".format(item)
-outstr += 'tally 2:\n'
-for item in results2:
- outstr += "{0:12.6E}\n".format(item)
-outstr += 'tally 3:\n'
-for item in results3:
- outstr += "{0:12.6E}\n".format(item)
-outstr += 'tally 4:\n'
-for item in results4:
- outstr += "{0:12.6E}\n".format(item)
-
-# write out cmfd answers
-outstr += 'cmfd indices\n'
-for item in sp._cmfd_indices:
- outstr += "{0:12.6E}\n".format(item)
-outstr += 'k cmfd\n'
-for item in sp._k_cmfd:
- outstr += "{0:12.6E}\n".format(item)
-outstr += 'cmfd entropy\n'
-for item in sp._cmfd_entropy:
- outstr += "{0:12.6E}\n".format(item)
-outstr += 'cmfd balance\n'
-for item in sp._cmfd_balance:
- outstr += "{0:12.6E}\n".format(item)
-outstr += 'cmfd dominance ratio\n'
-for item in sp._cmfd_dominance:
- outstr += "{0:10.3E}\n".format(item)
-outstr += 'cmfd openmc source comparison\n'
-for item in sp._cmfd_srccmp:
- outstr += "{0:12.6E}\n".format(item)
-outstr += 'cmfd source\n'
-cmfdsrc = np.reshape(sp._cmfd_src, np.product(sp._cmfd_indices), order='F')
-for item in cmfdsrc:
- outstr += "{0:12.6E}\n".format(item)
-
-# write results to file
-with open('results_test.dat', 'w') as fh:
- fh.write(outstr)
diff --git a/tests/test_cmfd_feed/test_cmfd_feed.py b/tests/test_cmfd_feed/test_cmfd_feed.py
index 0a51dd6f80..51456c0b28 100644
--- a/tests/test_cmfd_feed/test_cmfd_feed.py
+++ b/tests/test_cmfd_feed/test_cmfd_feed.py
@@ -1,68 +1,61 @@
#!/usr/bin/env python
-import os
import sys
-from subprocess import Popen, STDOUT, PIPE, call
-import filecmp
-import glob
-from optparse import OptionParser
-
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.20.*'))
- 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.'
+sys.path.insert(0, '..')
+from testing_harness import *
-def test_output_exists():
- assert os.path.exists(os.path.join(cwd, 'tallies.out')), 'Tally output file does not exist.'
+class CMFDTestHarness(TestHarness):
+ 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()
+ # 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])
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.20.*'))
- 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 not agree.'
+ # Write out tally data.
+ if self._tallies:
+ tally_num = 1
+ for tally_ind in sp._tallies:
+ tally = sp._tallies[tally_ind]
+ results = np.zeros((tally._sum.size*2, ))
+ results[0::2] = tally._sum.ravel()
+ results[1::2] = tally._sum_sq.ravel()
+ results = ['{0:12.6E}'.format(x) for x in results]
+ outstr += 'tally ' + str(tally_num) + ':\n'
+ outstr += '\n'.join(results) + '\n'
+ tally_num += 1
+
+ # Write out CMFD data.
+ outstr += 'cmfd indices\n'
+ outstr += '\n'.join(['{0:12.6E}'.format(x) for x in sp._cmfd_indices])
+ outstr += '\nk cmfd\n'
+ outstr += '\n'.join(['{0:12.6E}'.format(x) for x in sp._k_cmfd])
+ outstr += '\ncmfd entropy\n'
+ outstr += '\n'.join(['{0:12.6E}'.format(x) for x in sp._cmfd_entropy])
+ outstr += '\ncmfd balance\n'
+ outstr += '\n'.join(['{0:12.6E}'.format(x) for x in sp._cmfd_balance])
+ outstr += '\ncmfd dominance ratio\n'
+ outstr += '\n'.join(['{0:10.3E}'.format(x) for x in sp._cmfd_dominance])
+ outstr += '\ncmfd openmc source comparison\n'
+ outstr += '\n'.join(['{0:12.6E}'.format(x) for x in sp._cmfd_srccmp])
+ outstr += '\ncmfd source\n'
+ cmfdsrc = np.reshape(sp._cmfd_src, np.product(sp._cmfd_indices),
+ order='F')
+ outstr += '\n'.join(['{0:12.6E}'.format(x) for x in cmfdsrc])
+ 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.20.*'))
- output.append(os.path.join(cwd, 'tallies.out'))
- 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_created_statepoint()
- test_output_exists()
- test_results()
- finally:
- teardown()
+ harness = CMFDTestHarness('statepoint.20.*', True)
+ harness.execute_test()
diff --git a/tests/test_cmfd_nofeed/results.py b/tests/test_cmfd_nofeed/results.py
deleted file mode 100644
index 0ba4d2c98e..0000000000
--- a/tests/test_cmfd_nofeed/results.py
+++ /dev/null
@@ -1,92 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-import numpy as np
-
-sys.path.insert(0, '../..')
-import openmc
-from openmc.statepoint import StatePoint
-
-# read in statepoint file
-if len(sys.argv) > 1:
- sp = StatePoint(sys.argv[1])
-else:
- sp = StatePoint('statepoint.20.binary')
-
-sp.read_results()
-
-# extract tally results and convert to vector
-tally1 = sp.get_tally(scores=['flux'], filters=[openmc.Filter('mesh', [1])], \
- estimator='tracklength')
-tally2 = sp.get_tally(scores=['flux'], filters=[openmc.Filter('mesh', [2])], \
- estimator='analog')
-tally3 = sp.get_tally(scores=['nu-fission'], \
- filters=[openmc.Filter('mesh', [2])], estimator='analog')
-tally4 = sp.get_tally(scores=['current'], filters=[openmc.Filter('mesh', [2]), \
- openmc.Filter('surface', [1,2,3,4,5,6])], \
- estimator='analog')
-
-results1 = np.zeros((tally1.sum.size + tally1.sum.size, ))
-results1[0::2] = tally1.sum.ravel()
-results1[1::2] = tally1.sum_sq.ravel()
-
-results2 = np.zeros((tally2.sum.size + tally2.sum.size, ))
-results2[0::2] = tally2.sum.ravel()
-results2[1::2] = tally2.sum_sq.ravel()
-
-results3 = np.zeros((tally3.sum.size + tally3.sum.size, ))
-results3[0::2] = tally3.sum.ravel()
-results3[1::2] = tally3.sum_sq.ravel()
-
-results4 = np.zeros((tally4.sum.size + tally4.sum.size, ))
-results4[0::2] = tally4.sum.ravel()
-results4[1::2] = tally4.sum_sq.ravel()
-
-# 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 tally results
-outstr += 'tally 1:\n'
-for item in results1:
- outstr += "{0:12.6E}\n".format(item)
-outstr += 'tally 2:\n'
-for item in results2:
- outstr += "{0:12.6E}\n".format(item)
-outstr += 'tally 3:\n'
-for item in results3:
- outstr += "{0:12.6E}\n".format(item)
-outstr += 'tally 4:\n'
-for item in results4:
- outstr += "{0:12.6E}\n".format(item)
-
-# write out cmfd answers
-outstr += 'cmfd indices\n'
-for item in sp._cmfd_indices:
- outstr += "{0:12.6E}\n".format(item)
-outstr += 'k cmfd\n'
-for item in sp._k_cmfd:
- outstr += "{0:12.6E}\n".format(item)
-outstr += 'cmfd entropy\n'
-for item in sp._cmfd_entropy:
- outstr += "{0:12.6E}\n".format(item)
-outstr += 'cmfd balance\n'
-for item in sp._cmfd_balance:
- outstr += "{0:12.6E}\n".format(item)
-outstr += 'cmfd dominance ratio\n'
-for item in sp._cmfd_dominance:
- outstr += "{0:10.3E}\n".format(item)
-outstr += 'cmfd openmc source comparison\n'
-for item in sp._cmfd_srccmp:
- outstr += "{0:12.6E}\n".format(item)
-outstr += 'cmfd source\n'
-cmfdsrc = np.reshape(sp._cmfd_src, np.product(sp._cmfd_indices), order='F')
-for item in cmfdsrc:
- outstr += "{0:12.6E}\n".format(item)
-
-# write results to file
-with open('results_test.dat', 'w') as fh:
- fh.write(outstr)
diff --git a/tests/test_cmfd_nofeed/test_cmfd_nofeed.py b/tests/test_cmfd_nofeed/test_cmfd_nofeed.py
index 3a1b233ff2..51456c0b28 100644
--- a/tests/test_cmfd_nofeed/test_cmfd_nofeed.py
+++ b/tests/test_cmfd_nofeed/test_cmfd_nofeed.py
@@ -1,69 +1,61 @@
#!/usr/bin/env python
-import os
import sys
-from subprocess import Popen, STDOUT, PIPE, call
-import filecmp
-import glob
-from optparse import OptionParser
-
-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.'
+sys.path.insert(0, '..')
+from testing_harness import *
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.20.*'))
- 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.'
+class CMFDTestHarness(TestHarness):
+ 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()
+ # 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])
-def test_output_exists():
- assert os.path.exists(os.path.join(cwd, 'tallies.out')), 'Tally output file does not exist.'
+ # Write out tally data.
+ if self._tallies:
+ tally_num = 1
+ for tally_ind in sp._tallies:
+ tally = sp._tallies[tally_ind]
+ results = np.zeros((tally._sum.size*2, ))
+ results[0::2] = tally._sum.ravel()
+ results[1::2] = tally._sum_sq.ravel()
+ results = ['{0:12.6E}'.format(x) for x in results]
+ outstr += 'tally ' + str(tally_num) + ':\n'
+ outstr += '\n'.join(results) + '\n'
+ tally_num += 1
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.20.*'))
- 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 not agree.'
+ # Write out CMFD data.
+ outstr += 'cmfd indices\n'
+ outstr += '\n'.join(['{0:12.6E}'.format(x) for x in sp._cmfd_indices])
+ outstr += '\nk cmfd\n'
+ outstr += '\n'.join(['{0:12.6E}'.format(x) for x in sp._k_cmfd])
+ outstr += '\ncmfd entropy\n'
+ outstr += '\n'.join(['{0:12.6E}'.format(x) for x in sp._cmfd_entropy])
+ outstr += '\ncmfd balance\n'
+ outstr += '\n'.join(['{0:12.6E}'.format(x) for x in sp._cmfd_balance])
+ outstr += '\ncmfd dominance ratio\n'
+ outstr += '\n'.join(['{0:10.3E}'.format(x) for x in sp._cmfd_dominance])
+ outstr += '\ncmfd openmc source comparison\n'
+ outstr += '\n'.join(['{0:12.6E}'.format(x) for x in sp._cmfd_srccmp])
+ outstr += '\ncmfd source\n'
+ cmfdsrc = np.reshape(sp._cmfd_src, np.product(sp._cmfd_indices),
+ order='F')
+ outstr += '\n'.join(['{0:12.6E}'.format(x) for x in cmfdsrc])
+ 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.20.*'))
- output.append(os.path.join(cwd, 'tallies.out'))
- 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_created_statepoint()
- test_output_exists()
- test_results()
- finally:
- teardown()
+ harness = CMFDTestHarness('statepoint.20.*', True)
+ harness.execute_test()
diff --git a/tests/test_confidence_intervals/results.py b/tests/test_confidence_intervals/results.py
deleted file mode 100644
index 3f215b2870..0000000000
--- a/tests/test_confidence_intervals/results.py
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-import numpy as np
-
-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.10.binary')
-
-sp.read_results()
-
-# extract tally results and convert to vector
-tally = sp._tallies[1]
-results = np.zeros((tally._sum.size + tally._sum.size, ))
-results[0::2] = tally._sum.ravel()
-results[1::2] = tally._sum_sq.ravel()
-
-# 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 tally results
-outstr += 'tallies:\n'
-for item in results:
- outstr += "{0:12.6E}\n".format(item)
-
-# write results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_confidence_intervals/results_true.dat b/tests/test_confidence_intervals/results_true.dat
index 8468614dbc..fb13bdad29 100644
--- a/tests/test_confidence_intervals/results_true.dat
+++ b/tests/test_confidence_intervals/results_true.dat
@@ -1,5 +1,5 @@
k-combined:
2.913599E-01 6.738749E-03
-tallies:
+tally 1:
6.420923E+01
5.190738E+02
diff --git a/tests/test_confidence_intervals/test_confidence_intervals.py b/tests/test_confidence_intervals/test_confidence_intervals.py
old mode 100644
new mode 100755
index 5c61e70d28..8f3b0785a8
--- a/tests/test_confidence_intervals/test_confidence_intervals.py
+++ b/tests/test_confidence_intervals/test_confidence_intervals.py
@@ -1,65 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_created_output():
- assert os.path.exists(os.path.join(cwd, 'tallies.out')), 'Tally output file does not exist.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- output.append(os.path.join(cwd, 'results_test.dat'))
- output.append(os.path.join(cwd, 'tallies.out'))
- 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_created_statepoint()
- test_created_output()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*', True)
+ harness.execute_test()
diff --git a/tests/test_density_atombcm/results.py b/tests/test_density_atombcm/results.py
deleted file mode 100644
index fc1b491c6c..0000000000
--- a/tests/test_density_atombcm/results.py
+++ /dev/null
@@ -1,25 +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.10.binary')
-
-sp.read_results()
-
-# 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 results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_density_atombcm/test_density_atombcm.py b/tests/test_density_atombcm/test_density_atombcm.py
index ab227e2ba3..390e6d832e 100644
--- a/tests/test_density_atombcm/test_density_atombcm.py
+++ b/tests/test_density_atombcm/test_density_atombcm.py
@@ -1,60 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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_created_statepoint()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*')
+ harness.execute_test()
diff --git a/tests/test_density_atomcm3/results.py b/tests/test_density_atomcm3/results.py
deleted file mode 100644
index fc1b491c6c..0000000000
--- a/tests/test_density_atomcm3/results.py
+++ /dev/null
@@ -1,25 +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.10.binary')
-
-sp.read_results()
-
-# 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 results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_density_atomcm3/test_density_atomcm3.py b/tests/test_density_atomcm3/test_density_atomcm3.py
index 571f311994..390e6d832e 100644
--- a/tests/test_density_atomcm3/test_density_atomcm3.py
+++ b/tests/test_density_atomcm3/test_density_atomcm3.py
@@ -1,60 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob('statepoint.10.*')
- 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_created_statepoint()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*')
+ harness.execute_test()
diff --git a/tests/test_density_kgm3/results.py b/tests/test_density_kgm3/results.py
deleted file mode 100644
index fc1b491c6c..0000000000
--- a/tests/test_density_kgm3/results.py
+++ /dev/null
@@ -1,25 +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.10.binary')
-
-sp.read_results()
-
-# 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 results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_density_kgm3/test_density_kgm3.py b/tests/test_density_kgm3/test_density_kgm3.py
index ab227e2ba3..390e6d832e 100644
--- a/tests/test_density_kgm3/test_density_kgm3.py
+++ b/tests/test_density_kgm3/test_density_kgm3.py
@@ -1,60 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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_created_statepoint()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*')
+ harness.execute_test()
diff --git a/tests/test_density_sum/results.py b/tests/test_density_sum/results.py
deleted file mode 100644
index fc1b491c6c..0000000000
--- a/tests/test_density_sum/results.py
+++ /dev/null
@@ -1,25 +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.10.binary')
-
-sp.read_results()
-
-# 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 results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_density_sum/test_density_sum.py b/tests/test_density_sum/test_density_sum.py
index 6363a2374c..390e6d832e 100644
--- a/tests/test_density_sum/test_density_sum.py
+++ b/tests/test_density_sum/test_density_sum.py
@@ -1,60 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_results():
- statepoint = glob.glob('statepoint.10.*')
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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_created_statepoint()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*')
+ harness.execute_test()
diff --git a/tests/test_eigenvalue_genperbatch/results.py b/tests/test_eigenvalue_genperbatch/results.py
deleted file mode 100644
index a84a6f6524..0000000000
--- a/tests/test_eigenvalue_genperbatch/results.py
+++ /dev/null
@@ -1,25 +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.7.binary')
-
-sp.read_results()
-
-# 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 results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_eigenvalue_genperbatch/test_eigenvalue_genperbatch.py b/tests/test_eigenvalue_genperbatch/test_eigenvalue_genperbatch.py
index 2898e8bbc3..745c9e706d 100644
--- a/tests/test_eigenvalue_genperbatch/test_eigenvalue_genperbatch.py
+++ b/tests/test_eigenvalue_genperbatch/test_eigenvalue_genperbatch.py
@@ -1,60 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.7.*'))
- 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.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.7.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.7.*'))
- 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_created_statepoint()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.7.*')
+ harness.execute_test()
diff --git a/tests/test_eigenvalue_no_inactive/results.py b/tests/test_eigenvalue_no_inactive/results.py
deleted file mode 100644
index fc1b491c6c..0000000000
--- a/tests/test_eigenvalue_no_inactive/results.py
+++ /dev/null
@@ -1,25 +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.10.binary')
-
-sp.read_results()
-
-# 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 results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_eigenvalue_no_inactive/test_eigenvalue_no_inactive.py b/tests/test_eigenvalue_no_inactive/test_eigenvalue_no_inactive.py
index ab227e2ba3..390e6d832e 100644
--- a/tests/test_eigenvalue_no_inactive/test_eigenvalue_no_inactive.py
+++ b/tests/test_eigenvalue_no_inactive/test_eigenvalue_no_inactive.py
@@ -1,60 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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_created_statepoint()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*')
+ harness.execute_test()
diff --git a/tests/test_energy_grid/results.py b/tests/test_energy_grid/results.py
deleted file mode 100644
index fc1b491c6c..0000000000
--- a/tests/test_energy_grid/results.py
+++ /dev/null
@@ -1,25 +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.10.binary')
-
-sp.read_results()
-
-# 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 results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_energy_grid/test_energy_grid.py b/tests/test_energy_grid/test_energy_grid.py
index ab227e2ba3..390e6d832e 100644
--- a/tests/test_energy_grid/test_energy_grid.py
+++ b/tests/test_energy_grid/test_energy_grid.py
@@ -1,60 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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_created_statepoint()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*')
+ harness.execute_test()
diff --git a/tests/test_entropy/results.py b/tests/test_entropy/results.py
deleted file mode 100644
index e0d0d97c55..0000000000
--- a/tests/test_entropy/results.py
+++ /dev/null
@@ -1,31 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-import numpy as np
-
-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.10.binary')
-
-sp.read_results()
-
-# 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 tally results
-outstr += 'entropy:\n'
-for item in sp._entropy:
- outstr += "{0:12.6E}\n".format(item)
-
-# write results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_entropy/test_entropy.py b/tests/test_entropy/test_entropy.py
index cc153c832f..08d8db6aac 100644
--- a/tests/test_entropy/test_entropy.py
+++ b/tests/test_entropy/test_entropy.py
@@ -1,61 +1,33 @@
#!/usr/bin/env python
-import os
import sys
-from subprocess import Popen, STDOUT, PIPE, call
-import filecmp
-import glob
-from optparse import OptionParser
-
-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()
+sys.path.insert(0, '..')
+from testing_harness import *
-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 EntropyTestHarness(TestHarness):
+ 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()
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
+ # 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])
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
+ # Write out entropy data.
+ outstr += 'entropy:\n'
+ results = ['{0:12.6E}'.format(x) for x in sp._entropy]
+ outstr += '\n'.join(results) + '\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.10.*'))
- 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_created_statepoint()
- test_results()
- finally:
- teardown()
+ harness = EntropyTestHarness('statepoint.10.*')
+ harness.execute_test()
diff --git a/tests/test_filter_cell/results.py b/tests/test_filter_cell/results.py
deleted file mode 100644
index e8ee1d2d51..0000000000
--- a/tests/test_filter_cell/results.py
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-import numpy as np
-
-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.10.binary')
-
-sp.read_results()
-
-# extract tally results and convert to vector
-tally = sp._tallies[1]
-results = np.empty((tally._sum.size + tally._sum.size, ), dtype=np.float64)
-results[0::2] = tally._sum.ravel()
-results[1::2] = tally._sum_sq.ravel()
-
-# 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 tally results
-outstr += 'tallies:\n'
-for item in results:
- outstr += "{0:12.6E}\n".format(item)
-
-# write results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_filter_cell/results_true.dat b/tests/test_filter_cell/results_true.dat
index 0a1924c5d7..0838e7baed 100644
--- a/tests/test_filter_cell/results_true.dat
+++ b/tests/test_filter_cell/results_true.dat
@@ -1,6 +1,6 @@
k-combined:
1.093844E+00 1.626801E-02
-tallies:
+tally 1:
0.000000E+00
0.000000E+00
1.517577E+01
diff --git a/tests/test_filter_cell/test_filter_cell.py b/tests/test_filter_cell/test_filter_cell.py
index 0130cd7a06..8f3b0785a8 100644
--- a/tests/test_filter_cell/test_filter_cell.py
+++ b/tests/test_filter_cell/test_filter_cell.py
@@ -1,65 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_output_exists():
- assert os.path.exists(os.path.join(cwd, 'tallies.out')), 'Tally output file does not exist.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- output.append(os.path.join(cwd, 'tallies.out'))
- 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_created_statepoint()
- test_output_exists()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*', True)
+ harness.execute_test()
diff --git a/tests/test_filter_cellborn/results.py b/tests/test_filter_cellborn/results.py
deleted file mode 100644
index e8ee1d2d51..0000000000
--- a/tests/test_filter_cellborn/results.py
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-import numpy as np
-
-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.10.binary')
-
-sp.read_results()
-
-# extract tally results and convert to vector
-tally = sp._tallies[1]
-results = np.empty((tally._sum.size + tally._sum.size, ), dtype=np.float64)
-results[0::2] = tally._sum.ravel()
-results[1::2] = tally._sum_sq.ravel()
-
-# 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 tally results
-outstr += 'tallies:\n'
-for item in results:
- outstr += "{0:12.6E}\n".format(item)
-
-# write results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_filter_cellborn/results_true.dat b/tests/test_filter_cellborn/results_true.dat
index ad682dab5d..d2fa7f7004 100644
--- a/tests/test_filter_cellborn/results_true.dat
+++ b/tests/test_filter_cellborn/results_true.dat
@@ -1,6 +1,6 @@
k-combined:
1.093844E+00 1.626801E-02
-tallies:
+tally 1:
0.000000E+00
0.000000E+00
7.449502E+01
diff --git a/tests/test_filter_cellborn/test_filter_cellborn.py b/tests/test_filter_cellborn/test_filter_cellborn.py
index 76b1b433e7..8f3b0785a8 100644
--- a/tests/test_filter_cellborn/test_filter_cellborn.py
+++ b/tests/test_filter_cellborn/test_filter_cellborn.py
@@ -1,62 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
-
-def test_output_exists():
- assert os.path.exists(os.path.join(cwd, 'tallies.out')), 'Tally output file does not exist.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- output.append(os.path.join(cwd, 'tallies.out'))
- 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_created_statepoint()
- test_output_exists()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*', True)
+ harness.execute_test()
diff --git a/tests/test_filter_distribcell/case-1/results_true.dat b/tests/test_filter_distribcell/case-1/results_true.dat
new file mode 100644
index 0000000000..fb68a38f9e
--- /dev/null
+++ b/tests/test_filter_distribcell/case-1/results_true.dat
@@ -0,0 +1,14 @@
+k-combined:
+0.000000E+00 0.000000E+00
+tally 1:
+8.565980E-03
+7.337601E-05
+8.045879E-03
+6.473617E-05
+9.027116E-03
+8.148882E-05
+7.326285E-03
+5.367445E-05
+tally 2:
+3.296526E-02
+1.086708E-03
diff --git a/tests/test_filter_distribcell/case-2/results_true.dat b/tests/test_filter_distribcell/case-2/results_true.dat
new file mode 100644
index 0000000000..bb2f498cbf
--- /dev/null
+++ b/tests/test_filter_distribcell/case-2/results_true.dat
@@ -0,0 +1,11 @@
+k-combined:
+0.000000E+00 0.000000E+00
+tally 1:
+7.326285E-03
+5.367445E-05
+8.565980E-03
+7.337601E-05
+9.027116E-03
+8.148882E-05
+8.045879E-03
+6.473617E-05
diff --git a/tests/test_filter_distribcell/case-3/results_true.dat b/tests/test_filter_distribcell/case-3/results_true.dat
new file mode 100644
index 0000000000..1378f9cf75
--- /dev/null
+++ b/tests/test_filter_distribcell/case-3/results_true.dat
@@ -0,0 +1 @@
+f5873c6ca03a2c75f5094b7297059285788bb93c450466606914805cdb24fd2664c3872ed42a8c6665a272070ab6b08b0a53b02612bcd993e10329aec2f1d313
\ No newline at end of file
diff --git a/tests/test_filter_distribcell/results.py b/tests/test_filter_distribcell/results.py
deleted file mode 100644
index 90a5572cf3..0000000000
--- a/tests/test_filter_distribcell/results.py
+++ /dev/null
@@ -1,95 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-import numpy as np
-
-sys.path.insert(0, '../..')
-from openmc.statepoint import StatePoint
-from openmc import Filter
-
-# read in statepoint file
-sp3 = StatePoint(sys.argv[1])
-sp2 = StatePoint(sys.argv[2])
-sp1 = StatePoint(sys.argv[3])
-sp1.read_results()
-sp2.read_results()
-sp3.read_results()
-sp1.compute_stdev()
-sp2.compute_stdev()
-sp3.compute_stdev()
-
-# analyze sp1
-# compare distrib sum to cell
-sp1_t1 = sp1.tallies[1]
-sp1_t2 = sp1.tallies[2]
-
-sp1_t1_d1 = sp1_t1.get_values(scores=['total'], filters=['distribcell'],
- filter_bins=[(0,)], value='mean')
-sp1_t1_d2 = sp1_t1.get_values(scores=['total'], filters=['distribcell'],
- filter_bins=[(1,)], value='mean')
-sp1_t1_d3 = sp1_t1.get_values(scores=['total'], filters=['distribcell'],
- filter_bins=[(2,)], value='mean')
-sp1_t1_d4 = sp1_t1.get_values(scores=['total'], filters=['distribcell'],
- filter_bins=[(3,)], value='mean')
-sp1_t1_sum = sp1_t1_d1 + sp1_t1_d2 + sp1_t1_d3 + sp1_t1_d4
-
-cell_filter = sp1_t2.find_filter(filter_type='cell')
-sp1_t2_c201 = sp1_t2.get_values(scores=['total'], value='mean')
-
-
-# analyze sp2
-sp2_t1 = sp2.tallies[1]
-sp2_t1_c201 = sp2_t1.get_values(scores=['total'], filters=['cell'],
- filter_bins=[(2,)], value='mean')
-sp2_t1_c203 = sp2_t1.get_values(scores=['total'], filters=['cell'],
- filter_bins=[(4,)], value='mean')
-sp2_t1_c205 = sp2_t1.get_values(scores=['total'], filters=['cell'],
- filter_bins=[(6,)], value='mean')
-sp2_t1_c207 = sp2_t1.get_values(scores=['total'], filters=['cell'],
- filter_bins=[(8,)], value='mean')
-
-
-# analyze sp3
-sp3_t1 = sp3.tallies[1]
-sp3_t2 = sp3.tallies[2]
-sp3_t3 = sp3.tallies[3]
-sp3_t4 = sp3.tallies[4]
-sp3_t5 = sp3.tallies[5]
-sp3_t6 = sp3.tallies[6]
-
-sp3_t1_c1 = sp3_t1.get_values(scores=['total'], filters=['cell'],
- filter_bins=[(1,)], value='mean')
-sp3_t2_d1 = sp3_t2.get_values(scores=['total'], filters=['distribcell'],
- filter_bins=[(0,)], value='mean')
-
-sp3_t3_c60 = sp3_t3.get_values(scores=['total'], filters=['cell'],
- filter_bins=[(26,)], value='mean')
-sp3_t4_d = sum(sp3_t4.get_values(scores=['total'], value='mean'))
-
-sp3_t5_c27 = sp3_t5.get_values(scores=['total'], filters=['cell'],
- filter_bins=[(19,)], value='mean')
-sp3_t6_d = sum(sp3_t6.get_values(scores=['total'], value='mean'))
-
-# set up output string
-outstr = ''
-
-outstr += "{0:12.6E}\n".format(sp1_t1_sum)
-outstr += "{0:12.6E}\n".format(sp1_t2_c201[()])
-outstr += "{0:12.6E}\n".format(sp2_t1_c201[()])
-outstr += "{0:12.6E}\n".format(sp1_t1_d4[()])
-outstr += "{0:12.6E}\n".format(sp2_t1_c203[()])
-outstr += "{0:12.6E}\n".format(sp1_t1_d1[()])
-outstr += "{0:12.6E}\n".format(sp2_t1_c205[()])
-outstr += "{0:12.6E}\n".format(sp1_t1_d3[()])
-outstr += "{0:12.6E}\n".format(sp2_t1_c207[()])
-outstr += "{0:12.6E}\n".format(sp1_t1_d2[()])
-outstr += "{0:12.6E}\n".format(sp3_t1_c1[()])
-outstr += "{0:12.6E}\n".format(sp3_t2_d1[()])
-outstr += "{0:12.6E}\n".format(sp3_t3_c60[()])
-outstr += "{0:12.6E}\n".format(sp3_t4_d)
-outstr += "{0:12.6E}\n".format(sp3_t5_c27[()])
-outstr += "{0:12.6E}\n".format(sp3_t6_d)
-
-# write results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_filter_distribcell/results_true.dat b/tests/test_filter_distribcell/results_true.dat
deleted file mode 100644
index dcece1a5cd..0000000000
--- a/tests/test_filter_distribcell/results_true.dat
+++ /dev/null
@@ -1,16 +0,0 @@
-3.296526E-02
-3.296526E-02
-7.326285E-03
-7.326285E-03
-8.565980E-03
-8.565980E-03
-9.027116E-03
-9.027116E-03
-8.045879E-03
-8.045879E-03
-1.820738E+01
-1.820738E+01
-1.770306E+01
-1.770306E+01
-2.109466E+00
-2.109466E+00
diff --git a/tests/test_filter_distribcell/test_filter_distribcell.py b/tests/test_filter_distribcell/test_filter_distribcell.py
index d389bb5a65..40f8dd69b5 100644
--- a/tests/test_filter_distribcell/test_filter_distribcell.py
+++ b/tests/test_filter_distribcell/test_filter_distribcell.py
@@ -1,109 +1,119 @@
#!/usr/bin/env python
-import os
+import hashlib
import sys
-from subprocess import Popen, STDOUT, PIPE, call
-import filecmp
-import glob
-from optparse import OptionParser
-from shutil import copyfile
-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()
+sys.path.insert(0, '..')
+from testing_harness import *
-def test_run():
- if opts.mpi_exec != '':
- opts.mpi_exe = os.path.abspath(opts.mpi_exec)
+class DistribcellTestHarness(TestHarness):
+ def __init__(self):
+ self._sp_name = None
+ self._tallies = True
+ self._opts = None
+ self._args = None
- opts.exe = os.path.abspath(opts.exe)
- # Call 1
- os.chdir('case-1')
- cwd = os.getcwd()
- 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
+ def execute_test(self):
+ self._parse_args()
+ base_dir = os.getcwd()
+ try:
+ self._run_openmc()
+ os.chdir(base_dir)
+ self._test_output_created()
+ os.chdir(base_dir)
+ self._get_results()
+ os.chdir(base_dir)
+ self._compare_results()
+ finally:
+ os.chdir(base_dir)
+ self._cleanup()
- # Call 2
- os.chdir('../case-2')
- cwd = os.getcwd()
- 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
- # Call 3
- os.chdir('../case-3')
- cwd = os.getcwd()
- 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
+ def _run_openmc(self):
+ dirs = ('case-1', '../case-2', '../case-3')
+ for d in dirs:
+ os.chdir(d)
+ if self._opts.mpi_exec != '':
+ proc = Popen([self._opts.mpi_exec, '-np', self._opts.mpi_np,
+ self._opts.exe, os.getcwd()],
+ stderr=STDOUT, stdout=PIPE)
+ else:
+ proc = Popen([self._opts.exe, os.getcwd()],
+ stderr=STDOUT, stdout=PIPE)
+ print(proc.communicate()[0])
+ returncode = proc.returncode
+ assert returncode == 0, 'OpenMC did not exit successfully.'
- os.chdir('..')
-def test_created_statepoint():
- cwd = os.getcwd()
- statepoint1 = glob.glob(cwd + '/case-1/statepoint.1.*')
- statepoint2 = glob.glob(cwd + '/case-2/statepoint.1.*')
- statepoint3 = glob.glob(cwd + '/case-3/statepoint.3.*')
- assert len(statepoint1) == 1
- assert len(statepoint2) == 1
- assert len(statepoint3) == 1
- string1 = statepoint1.pop()
- string2 = statepoint2.pop()
- string3 = statepoint3.pop()
- assert string1.endswith('binary') or string1.endswith('h5')
- assert string2.endswith('binary') or string2.endswith('h5')
- assert string3.endswith('binary') or string3.endswith('h5')
+ def _test_output_created(self):
+ """Make sure statepoint files have been created."""
+ dirs = ('case-1', '../case-2', '../case-3')
+ sps = ('statepoint.1.*', 'statepoint.1.*', 'statepoint.3.*')
+ tallies_present = (True, True, False)
+ for i in range(len(dirs)):
+ os.chdir(dirs[i])
+ self._tallies = tallies_present[i]
+ self._sp_name = sps[i]
+ TestHarness._test_output_created(self)
+ self._tallies = True
-def test_results():
- cwd = os.getcwd()
- statepoint = list()
- statepoint.append(glob.glob(cwd + '/case-1/statepoint.1.*'))
- statepoint.append(glob.glob(cwd + '/case-2/statepoint.1.*'))
- statepoint.append(glob.glob(cwd + '/case-3/statepoint.3.*'))
- call([sys.executable, 'results.py', statepoint.pop()[0], statepoint.pop()[0], statepoint.pop()[0]])
- compare = filecmp.cmp('results_test.dat', 'results_true.dat')
- if not compare:
- os.rename('results_test.dat', 'results_error.dat')
- assert compare
-def teardown():
- cwd = os.getcwd()
- output = glob.glob(cwd + '/statepoint.*')
- output.append(cwd + '/results_test.dat')
- for f in output:
- if os.path.exists(str(f)):
- os.remove(str(f))
+ def _get_results(self):
+ dirs = ('case-1', '../case-2', '../case-3')
+ sps = ('statepoint.1.*', 'statepoint.1.*', 'statepoint.3.*')
+ for i in range(len(dirs)):
+ os.chdir(dirs[i])
+ self._sp_name = sps[i]
+
+ # Read the statepoint file.
+ statepoint = glob.glob(os.path.join(os.getcwd(), self._sp_name))[0]
+ sp = StatePoint(statepoint)
+ sp.read_results()
+
+ # 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])
+
+ # Write out tally data.
+ if self._tallies:
+ tally_num = 1
+ for tally_ind in sp._tallies:
+ tally = sp._tallies[tally_ind]
+ results = np.zeros((tally._sum.size*2, ))
+ results[0::2] = tally._sum.ravel()
+ results[1::2] = tally._sum_sq.ravel()
+ results = ['{0:12.6E}'.format(x) for x in results]
+
+ outstr += 'tally ' + str(tally_num) + ':\n'
+ outstr += '\n'.join(results) + '\n'
+ tally_num += 1
+
+ if i == 2:
+ sha512 = hashlib.sha512()
+ sha512.update(outstr)
+ outstr = sha512.hexdigest()
+
+ # Write results to a file.
+ with open('results_test.dat','w') as fh:
+ fh.write(outstr)
+
+
+ def _compare_results(self):
+ dirs = ('case-1', '../case-2', '../case-3')
+ for d in dirs:
+ os.chdir(d)
+ TestHarness._compare_results(self)
+
+ def _cleanup(self):
+ dirs = ('case-1', '../case-2', '../case-3')
+ for d in dirs:
+ os.chdir(d)
+ TestHarness._cleanup(self)
+
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_created_statepoint()
- test_results()
- finally:
- teardown()
+ harness = DistribcellTestHarness()
+ harness.execute_test()
diff --git a/tests/test_filter_energy/results.py b/tests/test_filter_energy/results.py
deleted file mode 100644
index 3f215b2870..0000000000
--- a/tests/test_filter_energy/results.py
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-import numpy as np
-
-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.10.binary')
-
-sp.read_results()
-
-# extract tally results and convert to vector
-tally = sp._tallies[1]
-results = np.zeros((tally._sum.size + tally._sum.size, ))
-results[0::2] = tally._sum.ravel()
-results[1::2] = tally._sum_sq.ravel()
-
-# 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 tally results
-outstr += 'tallies:\n'
-for item in results:
- outstr += "{0:12.6E}\n".format(item)
-
-# write results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_filter_energy/results_true.dat b/tests/test_filter_energy/results_true.dat
index 81702c8140..9e3ab7965b 100644
--- a/tests/test_filter_energy/results_true.dat
+++ b/tests/test_filter_energy/results_true.dat
@@ -1,6 +1,6 @@
k-combined:
1.093844E+00 1.626801E-02
-tallies:
+tally 1:
2.687671E+01
1.475192E+02
4.148025E+01
diff --git a/tests/test_filter_energy/test_filter_energy.py b/tests/test_filter_energy/test_filter_energy.py
index 0130cd7a06..8f3b0785a8 100644
--- a/tests/test_filter_energy/test_filter_energy.py
+++ b/tests/test_filter_energy/test_filter_energy.py
@@ -1,65 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_output_exists():
- assert os.path.exists(os.path.join(cwd, 'tallies.out')), 'Tally output file does not exist.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- output.append(os.path.join(cwd, 'tallies.out'))
- 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_created_statepoint()
- test_output_exists()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*', True)
+ harness.execute_test()
diff --git a/tests/test_filter_energyout/results.py b/tests/test_filter_energyout/results.py
deleted file mode 100644
index 1574bbc25f..0000000000
--- a/tests/test_filter_energyout/results.py
+++ /dev/null
@@ -1,36 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-import numpy as np
-
-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.10.binary')
-sp.read_results()
-
-# extract tally results and convert to vector
-tally = sp._tallies[1]
-results = np.zeros((tally._sum.size + tally._sum.size, ))
-results[0::2] = tally._sum.ravel()
-results[1::2] = tally._sum_sq.ravel()
-
-# 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 tally results
-outstr += 'tallies:\n'
-for item in results:
- outstr += "{0:12.6E}\n".format(item)
-
-# write results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_filter_energyout/results_true.dat b/tests/test_filter_energyout/results_true.dat
index a0bef87798..fa0bfa6466 100644
--- a/tests/test_filter_energyout/results_true.dat
+++ b/tests/test_filter_energyout/results_true.dat
@@ -1,6 +1,6 @@
k-combined:
1.093844E+00 1.626801E-02
-tallies:
+tally 1:
2.740000E+01
1.516786E+02
4.163000E+01
diff --git a/tests/test_filter_energyout/test_filter_energyout.py b/tests/test_filter_energyout/test_filter_energyout.py
index 0130cd7a06..8f3b0785a8 100644
--- a/tests/test_filter_energyout/test_filter_energyout.py
+++ b/tests/test_filter_energyout/test_filter_energyout.py
@@ -1,65 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_output_exists():
- assert os.path.exists(os.path.join(cwd, 'tallies.out')), 'Tally output file does not exist.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- output.append(os.path.join(cwd, 'tallies.out'))
- 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_created_statepoint()
- test_output_exists()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*', True)
+ harness.execute_test()
diff --git a/tests/test_filter_group_transfer/results.py b/tests/test_filter_group_transfer/results.py
deleted file mode 100644
index 1574bbc25f..0000000000
--- a/tests/test_filter_group_transfer/results.py
+++ /dev/null
@@ -1,36 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-import numpy as np
-
-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.10.binary')
-sp.read_results()
-
-# extract tally results and convert to vector
-tally = sp._tallies[1]
-results = np.zeros((tally._sum.size + tally._sum.size, ))
-results[0::2] = tally._sum.ravel()
-results[1::2] = tally._sum_sq.ravel()
-
-# 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 tally results
-outstr += 'tallies:\n'
-for item in results:
- outstr += "{0:12.6E}\n".format(item)
-
-# write results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_filter_group_transfer/results_true.dat b/tests/test_filter_group_transfer/results_true.dat
index d91e385fd4..2222558273 100644
--- a/tests/test_filter_group_transfer/results_true.dat
+++ b/tests/test_filter_group_transfer/results_true.dat
@@ -1,6 +1,6 @@
k-combined:
1.093844E+00 1.626801E-02
-tallies:
+tally 1:
2.470000E+01
1.233286E+02
0.000000E+00
diff --git a/tests/test_filter_group_transfer/test_filter_group_transfer.py b/tests/test_filter_group_transfer/test_filter_group_transfer.py
index 0130cd7a06..8f3b0785a8 100644
--- a/tests/test_filter_group_transfer/test_filter_group_transfer.py
+++ b/tests/test_filter_group_transfer/test_filter_group_transfer.py
@@ -1,65 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_output_exists():
- assert os.path.exists(os.path.join(cwd, 'tallies.out')), 'Tally output file does not exist.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- output.append(os.path.join(cwd, 'tallies.out'))
- 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_created_statepoint()
- test_output_exists()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*', True)
+ harness.execute_test()
diff --git a/tests/test_filter_material/results.py b/tests/test_filter_material/results.py
deleted file mode 100644
index 3f215b2870..0000000000
--- a/tests/test_filter_material/results.py
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-import numpy as np
-
-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.10.binary')
-
-sp.read_results()
-
-# extract tally results and convert to vector
-tally = sp._tallies[1]
-results = np.zeros((tally._sum.size + tally._sum.size, ))
-results[0::2] = tally._sum.ravel()
-results[1::2] = tally._sum_sq.ravel()
-
-# 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 tally results
-outstr += 'tallies:\n'
-for item in results:
- outstr += "{0:12.6E}\n".format(item)
-
-# write results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_filter_material/results_true.dat b/tests/test_filter_material/results_true.dat
index d10924cc15..3d15ea4322 100644
--- a/tests/test_filter_material/results_true.dat
+++ b/tests/test_filter_material/results_true.dat
@@ -1,6 +1,6 @@
k-combined:
1.093844E+00 1.626801E-02
-tallies:
+tally 1:
2.819256E+01
1.591068E+02
6.599750E+00
diff --git a/tests/test_filter_material/test_filter_material.py b/tests/test_filter_material/test_filter_material.py
index 0130cd7a06..8f3b0785a8 100644
--- a/tests/test_filter_material/test_filter_material.py
+++ b/tests/test_filter_material/test_filter_material.py
@@ -1,65 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_output_exists():
- assert os.path.exists(os.path.join(cwd, 'tallies.out')), 'Tally output file does not exist.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- output.append(os.path.join(cwd, 'tallies.out'))
- 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_created_statepoint()
- test_output_exists()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*', True)
+ harness.execute_test()
diff --git a/tests/test_filter_mesh_2d/results.py b/tests/test_filter_mesh_2d/results.py
deleted file mode 100644
index 3f215b2870..0000000000
--- a/tests/test_filter_mesh_2d/results.py
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-import numpy as np
-
-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.10.binary')
-
-sp.read_results()
-
-# extract tally results and convert to vector
-tally = sp._tallies[1]
-results = np.zeros((tally._sum.size + tally._sum.size, ))
-results[0::2] = tally._sum.ravel()
-results[1::2] = tally._sum_sq.ravel()
-
-# 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 tally results
-outstr += 'tallies:\n'
-for item in results:
- outstr += "{0:12.6E}\n".format(item)
-
-# write results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_filter_mesh_2d/results_true.dat b/tests/test_filter_mesh_2d/results_true.dat
index 5e11bbaca7..126a6151fb 100644
--- a/tests/test_filter_mesh_2d/results_true.dat
+++ b/tests/test_filter_mesh_2d/results_true.dat
@@ -1,6 +1,6 @@
k-combined:
1.093844E+00 1.626801E-02
-tallies:
+tally 1:
0.000000E+00
0.000000E+00
0.000000E+00
diff --git a/tests/test_filter_mesh_2d/test_filter_mesh_2d.py b/tests/test_filter_mesh_2d/test_filter_mesh_2d.py
index 0130cd7a06..8f3b0785a8 100644
--- a/tests/test_filter_mesh_2d/test_filter_mesh_2d.py
+++ b/tests/test_filter_mesh_2d/test_filter_mesh_2d.py
@@ -1,65 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_output_exists():
- assert os.path.exists(os.path.join(cwd, 'tallies.out')), 'Tally output file does not exist.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- output.append(os.path.join(cwd, 'tallies.out'))
- 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_created_statepoint()
- test_output_exists()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*', True)
+ harness.execute_test()
diff --git a/tests/test_filter_mesh_3d/results.py b/tests/test_filter_mesh_3d/results.py
deleted file mode 100644
index 3f215b2870..0000000000
--- a/tests/test_filter_mesh_3d/results.py
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-import numpy as np
-
-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.10.binary')
-
-sp.read_results()
-
-# extract tally results and convert to vector
-tally = sp._tallies[1]
-results = np.zeros((tally._sum.size + tally._sum.size, ))
-results[0::2] = tally._sum.ravel()
-results[1::2] = tally._sum_sq.ravel()
-
-# 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 tally results
-outstr += 'tallies:\n'
-for item in results:
- outstr += "{0:12.6E}\n".format(item)
-
-# write results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_filter_mesh_3d/results_true.dat b/tests/test_filter_mesh_3d/results_true.dat
index cee9c2c496..e43a5c4d95 100644
--- a/tests/test_filter_mesh_3d/results_true.dat
+++ b/tests/test_filter_mesh_3d/results_true.dat
@@ -1,6 +1,6 @@
k-combined:
1.093844E+00 1.626801E-02
-tallies:
+tally 1:
0.000000E+00
0.000000E+00
0.000000E+00
diff --git a/tests/test_filter_mesh_3d/test_filter_mesh_3d.py b/tests/test_filter_mesh_3d/test_filter_mesh_3d.py
index 0130cd7a06..8f3b0785a8 100644
--- a/tests/test_filter_mesh_3d/test_filter_mesh_3d.py
+++ b/tests/test_filter_mesh_3d/test_filter_mesh_3d.py
@@ -1,65 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_output_exists():
- assert os.path.exists(os.path.join(cwd, 'tallies.out')), 'Tally output file does not exist.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- output.append(os.path.join(cwd, 'tallies.out'))
- 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_created_statepoint()
- test_output_exists()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*', True)
+ harness.execute_test()
diff --git a/tests/test_filter_universe/results.py b/tests/test_filter_universe/results.py
deleted file mode 100644
index 3f215b2870..0000000000
--- a/tests/test_filter_universe/results.py
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-import numpy as np
-
-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.10.binary')
-
-sp.read_results()
-
-# extract tally results and convert to vector
-tally = sp._tallies[1]
-results = np.zeros((tally._sum.size + tally._sum.size, ))
-results[0::2] = tally._sum.ravel()
-results[1::2] = tally._sum_sq.ravel()
-
-# 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 tally results
-outstr += 'tallies:\n'
-for item in results:
- outstr += "{0:12.6E}\n".format(item)
-
-# write results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_filter_universe/results_true.dat b/tests/test_filter_universe/results_true.dat
index e840d6aac0..1442d52b7f 100644
--- a/tests/test_filter_universe/results_true.dat
+++ b/tests/test_filter_universe/results_true.dat
@@ -1,6 +1,6 @@
k-combined:
1.093844E+00 1.626801E-02
-tallies:
+tally 1:
6.144371E+01
7.795909E+02
7.330533E+00
diff --git a/tests/test_filter_universe/test_filter_universe.py b/tests/test_filter_universe/test_filter_universe.py
index 0130cd7a06..8f3b0785a8 100644
--- a/tests/test_filter_universe/test_filter_universe.py
+++ b/tests/test_filter_universe/test_filter_universe.py
@@ -1,65 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_output_exists():
- assert os.path.exists(os.path.join(cwd, 'tallies.out')), 'Tally output file does not exist.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- output.append(os.path.join(cwd, 'tallies.out'))
- 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_created_statepoint()
- test_output_exists()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*', True)
+ harness.execute_test()
diff --git a/tests/test_fixed_source/results.py b/tests/test_fixed_source/results.py
deleted file mode 100644
index 80ae5515d8..0000000000
--- a/tests/test_fixed_source/results.py
+++ /dev/null
@@ -1,33 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-import numpy as np
-
-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.10.binary')
-
-sp.read_results()
-
-# extract tally results and convert to vector
-tally = sp._tallies[1]
-results = np.zeros((tally._sum.size + tally._sum.size, ))
-results[0::2] = tally._sum.ravel()
-results[1::2] = tally._sum_sq.ravel()
-
-# set up output string
-outstr = ''
-
-# write out tally results
-outstr += 'tallies:\n'
-for item in results:
- outstr += "{0:12.6E}\n".format(item)
-
-# write results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_fixed_source/results_true.dat b/tests/test_fixed_source/results_true.dat
index 270879bd16..2ec2d00b8e 100644
--- a/tests/test_fixed_source/results_true.dat
+++ b/tests/test_fixed_source/results_true.dat
@@ -1,3 +1,3 @@
-tallies:
+tally 1:
4.483337E+02
2.017057E+04
diff --git a/tests/test_fixed_source/test_fixed_source.py b/tests/test_fixed_source/test_fixed_source.py
index 0130cd7a06..06323f708f 100644
--- a/tests/test_fixed_source/test_fixed_source.py
+++ b/tests/test_fixed_source/test_fixed_source.py
@@ -1,65 +1,38 @@
#!/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 FixedSourceTestHarness(TestHarness):
+ 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()
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
+ # Write out tally data.
+ outstr = ''
+ if self._tallies:
+ tally_num = 1
+ for tally_ind in sp._tallies:
+ tally = sp._tallies[tally_ind]
+ results = np.zeros((tally._sum.size*2, ))
+ results[0::2] = tally._sum.ravel()
+ results[1::2] = tally._sum_sq.ravel()
+ results = ['{0:12.6E}'.format(x) for x in results]
-def test_output_exists():
- assert os.path.exists(os.path.join(cwd, 'tallies.out')), 'Tally output file does not exist.'
+ outstr += 'tally ' + str(tally_num) + ':\n'
+ outstr += '\n'.join(results) + '\n'
+ tally_num += 1
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
+ # 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.10.*'))
- output.append(os.path.join(cwd, 'tallies.out'))
- 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_created_statepoint()
- test_output_exists()
- test_results()
- finally:
- teardown()
+ harness = FixedSourceTestHarness('statepoint.10.*', True)
+ harness.execute_test()
diff --git a/tests/test_infinite_cell/results.py b/tests/test_infinite_cell/results.py
deleted file mode 100644
index c70b1a6de9..0000000000
--- a/tests/test_infinite_cell/results.py
+++ /dev/null
@@ -1,24 +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.10.binary')
-sp.read_results()
-
-# 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 results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_infinite_cell/test_infinite_cell.py b/tests/test_infinite_cell/test_infinite_cell.py
index ab227e2ba3..390e6d832e 100644
--- a/tests/test_infinite_cell/test_infinite_cell.py
+++ b/tests/test_infinite_cell/test_infinite_cell.py
@@ -1,60 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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_created_statepoint()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*')
+ harness.execute_test()
diff --git a/tests/test_lattice/results.py b/tests/test_lattice/results.py
deleted file mode 100644
index fc1b491c6c..0000000000
--- a/tests/test_lattice/results.py
+++ /dev/null
@@ -1,25 +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.10.binary')
-
-sp.read_results()
-
-# 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 results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_lattice/test_lattice.py b/tests/test_lattice/test_lattice.py
index ab227e2ba3..390e6d832e 100644
--- a/tests/test_lattice/test_lattice.py
+++ b/tests/test_lattice/test_lattice.py
@@ -1,60 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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_created_statepoint()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*')
+ harness.execute_test()
diff --git a/tests/test_lattice_hex/results.py b/tests/test_lattice_hex/results.py
deleted file mode 100644
index 021609f24d..0000000000
--- a/tests/test_lattice_hex/results.py
+++ /dev/null
@@ -1,26 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-import numpy as np
-
-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.10.binary')
-
-sp.read_results()
-
-# 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 results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_lattice_hex/test_lattice_hex.py b/tests/test_lattice_hex/test_lattice_hex.py
index ab227e2ba3..390e6d832e 100644
--- a/tests/test_lattice_hex/test_lattice_hex.py
+++ b/tests/test_lattice_hex/test_lattice_hex.py
@@ -1,60 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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_created_statepoint()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*')
+ harness.execute_test()
diff --git a/tests/test_lattice_mixed/results.py b/tests/test_lattice_mixed/results.py
deleted file mode 100644
index 953e810464..0000000000
--- a/tests/test_lattice_mixed/results.py
+++ /dev/null
@@ -1,26 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-import numpy as np
-
-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.10.binary')
-
-sp.read_results()
-
-# 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 results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_lattice_mixed/test_lattice_mixed.py b/tests/test_lattice_mixed/test_lattice_mixed.py
index ab227e2ba3..390e6d832e 100644
--- a/tests/test_lattice_mixed/test_lattice_mixed.py
+++ b/tests/test_lattice_mixed/test_lattice_mixed.py
@@ -1,60 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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_created_statepoint()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*')
+ harness.execute_test()
diff --git a/tests/test_lattice_multiple/results.py b/tests/test_lattice_multiple/results.py
deleted file mode 100644
index fc1b491c6c..0000000000
--- a/tests/test_lattice_multiple/results.py
+++ /dev/null
@@ -1,25 +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.10.binary')
-
-sp.read_results()
-
-# 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 results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_lattice_multiple/test_lattice_multiple.py b/tests/test_lattice_multiple/test_lattice_multiple.py
index ab227e2ba3..390e6d832e 100644
--- a/tests/test_lattice_multiple/test_lattice_multiple.py
+++ b/tests/test_lattice_multiple/test_lattice_multiple.py
@@ -1,60 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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_created_statepoint()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*')
+ harness.execute_test()
diff --git a/tests/test_many_scores/results.py b/tests/test_many_scores/results.py
deleted file mode 100644
index 8214d394c6..0000000000
--- a/tests/test_many_scores/results.py
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-import numpy as np
-
-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.5.binary')
-
-sp.read_results()
-
-# extract tally results and convert to vector
-tally1 = sp._tallies[1]
-results1 = np.zeros((tally1._sum.size + tally1._sum.size, ))
-results1[0::2] = tally1._sum.ravel()
-results1[1::2] = tally1._sum_sq.ravel()
-
-# 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 tally results
-outstr += 'tally 1:\n'
-for item in results1:
- outstr += "{0:12.6E}\n".format(item)
-
-# write results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_many_scores/test_many_scores.py b/tests/test_many_scores/test_many_scores.py
index 6b3ddeccae..c1a8684102 100644
--- a/tests/test_many_scores/test_many_scores.py
+++ b/tests/test_many_scores/test_many_scores.py
@@ -1,65 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.5.*'))
- 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.'
-
-def test_output_exists():
- assert os.path.exists(os.path.join(cwd, 'tallies.out')), 'Tally output file does not exist.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.5.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.5.*'))
- output.append(os.path.join(cwd, 'tallies.out'))
- 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_created_statepoint()
- test_output_exists()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.5.*', True)
+ harness.execute_test()
diff --git a/tests/test_natural_element/results.py b/tests/test_natural_element/results.py
deleted file mode 100644
index fc1b491c6c..0000000000
--- a/tests/test_natural_element/results.py
+++ /dev/null
@@ -1,25 +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.10.binary')
-
-sp.read_results()
-
-# 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 results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_natural_element/test_natural_element.py b/tests/test_natural_element/test_natural_element.py
index ab227e2ba3..390e6d832e 100644
--- a/tests/test_natural_element/test_natural_element.py
+++ b/tests/test_natural_element/test_natural_element.py
@@ -1,60 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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_created_statepoint()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*')
+ harness.execute_test()
diff --git a/tests/test_output/results.py b/tests/test_output/results.py
deleted file mode 100644
index fc1b491c6c..0000000000
--- a/tests/test_output/results.py
+++ /dev/null
@@ -1,25 +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.10.binary')
-
-sp.read_results()
-
-# 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 results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_output/test_output.py b/tests/test_output/test_output.py
index 03adf538e8..b890cb7b66 100644
--- a/tests/test_output/test_output.py
+++ b/tests/test_output/test_output.py
@@ -1,74 +1,35 @@
#!/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 OutputTestHarness(TestHarness):
+ def _test_output_created(self):
+ """Make sure output files have been created."""
+ # Check for the statepoint.
+ TestHarness._test_output_created(self)
-def test_summary_exists():
- summary = glob.glob(os.path.join(cwd, 'summary.*'))
- assert len(summary) == 1, 'Either multiple or no summary file exists.'
- assert summary[0].endswith('out') or summary[0].endswith('h5'),\
- 'Summary file is not a binary or hdf5 file.'
+ # Check for the summary.
+ summary = glob.glob(os.path.join(os.getcwd(), 'summary.*'))
+ assert len(summary) == 1, 'Either multiple or no summary file exists.'
+ assert summary[0].endswith('out') or summary[0].endswith('h5'),\
+ 'Summary file is not a binary or hdf5 file.'
-def test_cross_sections_exists():
- assert os.path.exists(os.path.join(cwd, 'cross_sections.out')),\
- 'Cross section output file does not exist.'
+ # Check for the cross sections.
+ assert os.path.exists(os.path.join(os.getcwd(), 'cross_sections.out')),\
+ 'Cross section output file does not exist.'
-def test_statepoint_exists():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
+ def _cleanup(self):
+ TestHarness._cleanup(self)
+ output = glob.glob(os.path.join(os.getcwd(), 'summary.*'))
+ output.append(os.path.join(os.getcwd(), 'cross_sections.out'))
+ for f in output:
+ if os.path.exists(f):
+ os.remove(f)
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*')) + glob.glob(os.path.join(cwd, 'summary.*'))
- output.append(os.path.join(cwd, 'summary.out'))
- output.append(os.path.join(cwd, 'cross_sections.out'))
- 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_summary_exists()
- test_cross_sections_exists()
- test_statepoint_exists()
- test_results()
- finally:
- teardown()
+ harness = OutputTestHarness('statepoint.10.*')
+ harness.execute_test()
diff --git a/tests/test_particle_restart_eigval/results.py b/tests/test_particle_restart_eigval/results.py
deleted file mode 100644
index adb0b3d7c0..0000000000
--- a/tests/test_particle_restart_eigval/results.py
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-
-sys.path.insert(0, '../..')
-import openmc.particle_restart as pr
-
-# read in particle restart file
-if len(sys.argv) > 1:
- p = pr.Particle(sys.argv[1])
-else:
- p = pr.Particle('particle_12_616.binary')
-
-# set up output string
-outstr = ''
-
-# write out properties
-outstr += 'current batch:\n'
-outstr += "{0:12.6E}\n".format(p.current_batch)
-outstr += 'current gen:\n'
-outstr += "{0:12.6E}\n".format(p.current_gen)
-outstr += 'particle id:\n'
-outstr += "{0:12.6E}\n".format(p.id)
-outstr += 'run mode:\n'
-outstr += "{0:12.6E}\n".format(p.run_mode)
-outstr += 'particle weight:\n'
-outstr += "{0:12.6E}\n".format(p.weight)
-outstr += 'particle energy:\n'
-outstr += "{0:12.6E}\n".format(p.energy)
-outstr += 'particle xyz:\n'
-outstr += "{0:12.6E} {1:12.6E} {2:12.6E}\n".format(p.xyz[0],p.xyz[1],p.xyz[2])
-outstr += 'particle uvw:\n'
-outstr += "{0:12.6E} {1:12.6E} {2:12.6E}\n".format(p.uvw[0],p.uvw[1],p.uvw[2])
-
-# write results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_particle_restart_eigval/test_particle_restart_eigval.py b/tests/test_particle_restart_eigval/test_particle_restart_eigval.py
index 6c8016dd27..0bacadc5c7 100644
--- a/tests/test_particle_restart_eigval/test_particle_restart_eigval.py
+++ b/tests/test_particle_restart_eigval/test_particle_restart_eigval.py
@@ -1,69 +1,55 @@
#!/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()
+import openmc.particle_restart as pr
-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.'
-def test_created_restart():
- particle = glob.glob(os.path.join(cwd, 'particle_12_616.*'))
- assert len(particle) == 1, 'Either multiple or no particle restart files exist.'
- assert particle[0].endswith('binary') or \
- particle[0].endswith('h5'), 'Particle restart file not a binary or hdf5 file.'
+class ParticleRestartTestHarness(TestHarness):
+ def _test_output_created(self):
+ """Make sure the restart file has been created."""
+ particle = glob.glob(os.path.join(os.getcwd(), self._sp_name))
+ assert len(particle) == 1, 'Either multiple or no particle restart ' \
+ 'files exist.'
+ assert particle[0].endswith('binary') \
+ or particle[0].endswith('h5'), \
+ 'Particle restart file is not a binary or hdf5 file.'
-def test_results():
- particle = glob.glob(os.path.join(cwd, 'particle_12_616.*'))
- call([sys.executable, 'results.py', particle[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 not agree.'
-def test_run_restart():
- particle = glob.glob(os.path.join(cwd, 'particle_12_616.*'))
- proc = Popen([opts.exe, '-r', particle[0], cwd], stderr=STDOUT, stdout=PIPE)
- print(proc.communicate()[0])
- returncode = proc.returncode
- assert returncode == 0, 'Particle restart not successful.'
+ def _get_results(self):
+ """Digest info in the restart file and create a simpler ASCII file."""
+ # Read the particle restart file.
+ particle = glob.glob(os.path.join(os.getcwd(), self._sp_name))[0]
+ p = pr.Particle(particle)
+
+ # Write out the properties.
+ outstr = ''
+ outstr += 'current batch:\n'
+ outstr += "{0:12.6E}\n".format(p.current_batch)
+ outstr += 'current gen:\n'
+ outstr += "{0:12.6E}\n".format(p.current_gen)
+ outstr += 'particle id:\n'
+ outstr += "{0:12.6E}\n".format(p.id)
+ outstr += 'run mode:\n'
+ outstr += "{0:12.6E}\n".format(p.run_mode)
+ outstr += 'particle weight:\n'
+ outstr += "{0:12.6E}\n".format(p.weight)
+ outstr += 'particle energy:\n'
+ outstr += "{0:12.6E}\n".format(p.energy)
+ outstr += 'particle xyz:\n'
+ outstr += "{0:12.6E} {1:12.6E} {2:12.6E}\n".format(p.xyz[0],p.xyz[1],
+ p.xyz[2])
+ outstr += 'particle uvw:\n'
+ outstr += "{0:12.6E} {1:12.6E} {2:12.6E}\n".format(p.uvw[0],p.uvw[1],
+ p.uvw[2])
+
+ # 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.*')) + \
- glob.glob(os.path.join(cwd, 'particle_*')) + \
- [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_created_restart()
- test_results()
- test_run_restart()
- finally:
- teardown()
+ harness = ParticleRestartTestHarness('particle_12_616.*')
+ harness.execute_test()
diff --git a/tests/test_particle_restart_fixed/results.py b/tests/test_particle_restart_fixed/results.py
deleted file mode 100644
index 1c01db35c1..0000000000
--- a/tests/test_particle_restart_fixed/results.py
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-
-sys.path.insert(0, '../..')
-import openmc.particle_restart as pr
-
-# read in particle restart file
-if len(sys.argv) > 1:
- p = pr.Particle(sys.argv[1])
-else:
- p = pr.Particle('particle_7_6144.binary')
-
-# set up output string
-outstr = ''
-
-# write out properties
-outstr += 'current batch:\n'
-outstr += "{0:12.6E}\n".format(p.current_batch)
-outstr += 'current gen:\n'
-outstr += "{0:12.6E}\n".format(p.current_gen)
-outstr += 'particle id:\n'
-outstr += "{0:12.6E}\n".format(p.id)
-outstr += 'run mode:\n'
-outstr += "{0:12.6E}\n".format(p.run_mode)
-outstr += 'particle weight:\n'
-outstr += "{0:12.6E}\n".format(p.weight)
-outstr += 'particle energy:\n'
-outstr += "{0:12.6E}\n".format(p.energy)
-outstr += 'particle xyz:\n'
-outstr += "{0:12.6E} {1:12.6E} {2:12.6E}\n".format(p.xyz[0],p.xyz[1],p.xyz[2])
-outstr += 'particle uvw:\n'
-outstr += "{0:12.6E} {1:12.6E} {2:12.6E}\n".format(p.uvw[0],p.uvw[1],p.uvw[2])
-
-# write results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_particle_restart_fixed/test_particle_restart_fixed.py b/tests/test_particle_restart_fixed/test_particle_restart_fixed.py
index ee6cfad532..397fec2ae3 100644
--- a/tests/test_particle_restart_fixed/test_particle_restart_fixed.py
+++ b/tests/test_particle_restart_fixed/test_particle_restart_fixed.py
@@ -1,69 +1,55 @@
#!/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()
+import openmc.particle_restart as pr
-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.'
-def test_created_restart():
- particle = glob.glob(os.path.join(cwd, 'particle_7_6144.*'))
- assert len(particle) == 1, 'Either multiple or no particle restart files exist.'
- assert particle[0].endswith('binary') or \
- particle[0].endswith('h5'), 'Particle restart file not a binary or hdf5 file.'
+class ParticleRestartTestHarness(TestHarness):
+ def _test_output_created(self):
+ """Make sure the restart file has been created."""
+ particle = glob.glob(os.path.join(os.getcwd(), self._sp_name))
+ assert len(particle) == 1, 'Either multiple or no particle restart ' \
+ 'files exist.'
+ assert particle[0].endswith('binary') \
+ or particle[0].endswith('h5'), \
+ 'Particle restart file is not a binary or hdf5 file.'
-def test_results():
- particle = glob.glob(os.path.join(cwd, 'particle_7_6144.*'))
- call([sys.executable, 'results.py', particle[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 not agree.'
-def test_run_restart():
- particle = glob.glob(os.path.join(cwd, 'particle_7_6144.*'))
- proc = Popen([opts.exe, '-r', particle[0], cwd], stderr=STDOUT, stdout=PIPE)
- print(proc.communicate()[0])
- returncode = proc.returncode
- assert returncode == 0, 'Particle restart not successful.'
+ def _get_results(self):
+ """Digest info in the restart file and create a simpler ASCII file."""
+ # Read the particle restart file.
+ particle = glob.glob(os.path.join(os.getcwd(), self._sp_name))[0]
+ p = pr.Particle(particle)
+
+ # Write out the properties.
+ outstr = ''
+ outstr += 'current batch:\n'
+ outstr += "{0:12.6E}\n".format(p.current_batch)
+ outstr += 'current gen:\n'
+ outstr += "{0:12.6E}\n".format(p.current_gen)
+ outstr += 'particle id:\n'
+ outstr += "{0:12.6E}\n".format(p.id)
+ outstr += 'run mode:\n'
+ outstr += "{0:12.6E}\n".format(p.run_mode)
+ outstr += 'particle weight:\n'
+ outstr += "{0:12.6E}\n".format(p.weight)
+ outstr += 'particle energy:\n'
+ outstr += "{0:12.6E}\n".format(p.energy)
+ outstr += 'particle xyz:\n'
+ outstr += "{0:12.6E} {1:12.6E} {2:12.6E}\n".format(p.xyz[0],p.xyz[1],
+ p.xyz[2])
+ outstr += 'particle uvw:\n'
+ outstr += "{0:12.6E} {1:12.6E} {2:12.6E}\n".format(p.uvw[0],p.uvw[1],
+ p.uvw[2])
+
+ # 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.*')) + \
- glob.glob(os.path.join(cwd, 'particle_*')) + \
- [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_created_restart()
- test_results()
- test_run_restart()
- finally:
- teardown()
+ harness = ParticleRestartTestHarness('particle_7_6144.*')
+ harness.execute_test()
diff --git a/tests/test_plot_background/test_plot_background.py b/tests/test_plot_background/test_plot_background.py
index 2330724005..45728e1ff5 100644
--- a/tests/test_plot_background/test_plot_background.py
+++ b/tests/test_plot_background/test_plot_background.py
@@ -1,45 +1,47 @@
#!/usr/bin/env python
-import os
import sys
-from subprocess import Popen, STDOUT, PIPE
-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, '-p', cwd],
- stderr=STDOUT, stdout=PIPE)
- else:
- proc = Popen([opts.exe, '-p', cwd], stderr=STDOUT, stdout=PIPE)
- print(proc.communicate()[0])
- returncode = proc.returncode
- assert returncode == 0, 'OpenMC did not exit successfully.'
+class PlotTestHarness(TestHarness):
+ def execute_test(self):
+ self._parse_args()
+ try:
+ self._run_openmc()
+ self._test_output_created()
+ finally:
+ self._cleanup()
-def test_plot_exists():
- assert os.path.exists(os.path.join(cwd ,'1_plot.ppm')), 'Plot ppm file does not exist.'
-def teardown():
- output = [os.path.join(cwd ,'1_plot.ppm')]
- for f in output:
- if os.path.exists(f):
- os.remove(f)
+ def _run_openmc(self):
+ if self._opts.mpi_exec != '':
+ proc = Popen([self._opts.mpi_exec, '-np', self._opts.mpi_np,
+ self._opts.exe, '-p', os.getcwd()],
+ stderr=STDOUT, stdout=PIPE)
+ else:
+ proc = Popen([self._opts.exe, '-p', os.getcwd()],
+ stderr=STDOUT, stdout=PIPE)
+ print(proc.communicate()[0])
+ returncode = proc.returncode
+ assert returncode == 0, 'OpenMC did not exit successfully.'
+
+
+ def _test_output_created(self):
+ """Make sure *.ppm has been created."""
+ assert os.path.exists(os.path.join(os.getcwd(), '1_plot.ppm')), \
+ 'Plot output file does not exist.'
+
+
+ def _cleanup(self):
+ TestHarness._cleanup(self)
+ output = glob.glob(os.path.join(os.getcwd(), '*.ppm'))
+ 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_plot_exists()
- finally:
- teardown()
+ harness = PlotTestHarness('statepoint.10.*', True)
+ harness.execute_test()
diff --git a/tests/test_plot_basis/test_plot_basis.py b/tests/test_plot_basis/test_plot_basis.py
index 680473b512..45728e1ff5 100644
--- a/tests/test_plot_basis/test_plot_basis.py
+++ b/tests/test_plot_basis/test_plot_basis.py
@@ -1,47 +1,47 @@
#!/usr/bin/env python
-import os
import sys
-from subprocess import Popen, STDOUT, PIPE
-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, '-p', cwd],
- stderr=STDOUT, stdout=PIPE)
- else:
- proc = Popen([opts.exe, '-p', cwd], stderr=STDOUT, stdout=PIPE)
- print(proc.communicate()[0])
- returncode = proc.returncode
- assert returncode == 0, 'OpenMC did not exit successfully.'
+class PlotTestHarness(TestHarness):
+ def execute_test(self):
+ self._parse_args()
+ try:
+ self._run_openmc()
+ self._test_output_created()
+ finally:
+ self._cleanup()
-def test_plots_exists():
- assert os.path.exists(os.path.join(cwd ,'1_plot.ppm')), 'Plot 1 result does not exist.'
- assert os.path.exists(os.path.join(cwd ,'2_plot.ppm')), 'Plot 2 result does not exist.'
- assert os.path.exists(os.path.join(cwd ,'3_plot.ppm')), 'Plot 3 result does not exist.'
-def teardown():
- output = [os.path.join(cwd ,'1_plot.ppm'), os.path.join(cwd ,'2_plot.ppm'), os.path.join(cwd ,'3_plot.ppm')]
- for f in output:
- if os.path.exists(f):
- os.remove(f)
+ def _run_openmc(self):
+ if self._opts.mpi_exec != '':
+ proc = Popen([self._opts.mpi_exec, '-np', self._opts.mpi_np,
+ self._opts.exe, '-p', os.getcwd()],
+ stderr=STDOUT, stdout=PIPE)
+ else:
+ proc = Popen([self._opts.exe, '-p', os.getcwd()],
+ stderr=STDOUT, stdout=PIPE)
+ print(proc.communicate()[0])
+ returncode = proc.returncode
+ assert returncode == 0, 'OpenMC did not exit successfully.'
+
+
+ def _test_output_created(self):
+ """Make sure *.ppm has been created."""
+ assert os.path.exists(os.path.join(os.getcwd(), '1_plot.ppm')), \
+ 'Plot output file does not exist.'
+
+
+ def _cleanup(self):
+ TestHarness._cleanup(self)
+ output = glob.glob(os.path.join(os.getcwd(), '*.ppm'))
+ 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_plots_exists()
- finally:
- teardown()
+ harness = PlotTestHarness('statepoint.10.*', True)
+ harness.execute_test()
diff --git a/tests/test_plot_colspec/test_plot_colspec.py b/tests/test_plot_colspec/test_plot_colspec.py
index 2330724005..45728e1ff5 100644
--- a/tests/test_plot_colspec/test_plot_colspec.py
+++ b/tests/test_plot_colspec/test_plot_colspec.py
@@ -1,45 +1,47 @@
#!/usr/bin/env python
-import os
import sys
-from subprocess import Popen, STDOUT, PIPE
-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, '-p', cwd],
- stderr=STDOUT, stdout=PIPE)
- else:
- proc = Popen([opts.exe, '-p', cwd], stderr=STDOUT, stdout=PIPE)
- print(proc.communicate()[0])
- returncode = proc.returncode
- assert returncode == 0, 'OpenMC did not exit successfully.'
+class PlotTestHarness(TestHarness):
+ def execute_test(self):
+ self._parse_args()
+ try:
+ self._run_openmc()
+ self._test_output_created()
+ finally:
+ self._cleanup()
-def test_plot_exists():
- assert os.path.exists(os.path.join(cwd ,'1_plot.ppm')), 'Plot ppm file does not exist.'
-def teardown():
- output = [os.path.join(cwd ,'1_plot.ppm')]
- for f in output:
- if os.path.exists(f):
- os.remove(f)
+ def _run_openmc(self):
+ if self._opts.mpi_exec != '':
+ proc = Popen([self._opts.mpi_exec, '-np', self._opts.mpi_np,
+ self._opts.exe, '-p', os.getcwd()],
+ stderr=STDOUT, stdout=PIPE)
+ else:
+ proc = Popen([self._opts.exe, '-p', os.getcwd()],
+ stderr=STDOUT, stdout=PIPE)
+ print(proc.communicate()[0])
+ returncode = proc.returncode
+ assert returncode == 0, 'OpenMC did not exit successfully.'
+
+
+ def _test_output_created(self):
+ """Make sure *.ppm has been created."""
+ assert os.path.exists(os.path.join(os.getcwd(), '1_plot.ppm')), \
+ 'Plot output file does not exist.'
+
+
+ def _cleanup(self):
+ TestHarness._cleanup(self)
+ output = glob.glob(os.path.join(os.getcwd(), '*.ppm'))
+ 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_plot_exists()
- finally:
- teardown()
+ harness = PlotTestHarness('statepoint.10.*', True)
+ harness.execute_test()
diff --git a/tests/test_plot_mask/test_plot_mask.py b/tests/test_plot_mask/test_plot_mask.py
index 680473b512..45728e1ff5 100644
--- a/tests/test_plot_mask/test_plot_mask.py
+++ b/tests/test_plot_mask/test_plot_mask.py
@@ -1,47 +1,47 @@
#!/usr/bin/env python
-import os
import sys
-from subprocess import Popen, STDOUT, PIPE
-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, '-p', cwd],
- stderr=STDOUT, stdout=PIPE)
- else:
- proc = Popen([opts.exe, '-p', cwd], stderr=STDOUT, stdout=PIPE)
- print(proc.communicate()[0])
- returncode = proc.returncode
- assert returncode == 0, 'OpenMC did not exit successfully.'
+class PlotTestHarness(TestHarness):
+ def execute_test(self):
+ self._parse_args()
+ try:
+ self._run_openmc()
+ self._test_output_created()
+ finally:
+ self._cleanup()
-def test_plots_exists():
- assert os.path.exists(os.path.join(cwd ,'1_plot.ppm')), 'Plot 1 result does not exist.'
- assert os.path.exists(os.path.join(cwd ,'2_plot.ppm')), 'Plot 2 result does not exist.'
- assert os.path.exists(os.path.join(cwd ,'3_plot.ppm')), 'Plot 3 result does not exist.'
-def teardown():
- output = [os.path.join(cwd ,'1_plot.ppm'), os.path.join(cwd ,'2_plot.ppm'), os.path.join(cwd ,'3_plot.ppm')]
- for f in output:
- if os.path.exists(f):
- os.remove(f)
+ def _run_openmc(self):
+ if self._opts.mpi_exec != '':
+ proc = Popen([self._opts.mpi_exec, '-np', self._opts.mpi_np,
+ self._opts.exe, '-p', os.getcwd()],
+ stderr=STDOUT, stdout=PIPE)
+ else:
+ proc = Popen([self._opts.exe, '-p', os.getcwd()],
+ stderr=STDOUT, stdout=PIPE)
+ print(proc.communicate()[0])
+ returncode = proc.returncode
+ assert returncode == 0, 'OpenMC did not exit successfully.'
+
+
+ def _test_output_created(self):
+ """Make sure *.ppm has been created."""
+ assert os.path.exists(os.path.join(os.getcwd(), '1_plot.ppm')), \
+ 'Plot output file does not exist.'
+
+
+ def _cleanup(self):
+ TestHarness._cleanup(self)
+ output = glob.glob(os.path.join(os.getcwd(), '*.ppm'))
+ 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_plots_exists()
- finally:
- teardown()
+ harness = PlotTestHarness('statepoint.10.*', True)
+ harness.execute_test()
diff --git a/tests/test_ptables_off/results.py b/tests/test_ptables_off/results.py
deleted file mode 100644
index fc1b491c6c..0000000000
--- a/tests/test_ptables_off/results.py
+++ /dev/null
@@ -1,25 +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.10.binary')
-
-sp.read_results()
-
-# 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 results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_ptables_off/test_ptables_off.py b/tests/test_ptables_off/test_ptables_off.py
index ab227e2ba3..390e6d832e 100644
--- a/tests/test_ptables_off/test_ptables_off.py
+++ b/tests/test_ptables_off/test_ptables_off.py
@@ -1,60 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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_created_statepoint()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*')
+ harness.execute_test()
diff --git a/tests/test_reflective_cone/results.py b/tests/test_reflective_cone/results.py
deleted file mode 100644
index fc1b491c6c..0000000000
--- a/tests/test_reflective_cone/results.py
+++ /dev/null
@@ -1,25 +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.10.binary')
-
-sp.read_results()
-
-# 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 results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_reflective_cone/test_reflective_cone.py b/tests/test_reflective_cone/test_reflective_cone.py
index ab227e2ba3..390e6d832e 100644
--- a/tests/test_reflective_cone/test_reflective_cone.py
+++ b/tests/test_reflective_cone/test_reflective_cone.py
@@ -1,60 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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_created_statepoint()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*')
+ harness.execute_test()
diff --git a/tests/test_reflective_cylinder/results.py b/tests/test_reflective_cylinder/results.py
deleted file mode 100644
index b194e843ed..0000000000
--- a/tests/test_reflective_cylinder/results.py
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-
-sys.path.insert(0, '../..')
-import openmc.statepoint as statepoint
-
-# read in statepoint file
-if len(sys.argv) > 1:
- sp = statepoint.StatePoint(sys.argv[1])
-else:
- sp = statepoint.StatePoint('statepoint.10.binary')
-sp.read_results()
-
-# 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 results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_reflective_cylinder/test_reflective_cylinder.py b/tests/test_reflective_cylinder/test_reflective_cylinder.py
index ab227e2ba3..390e6d832e 100644
--- a/tests/test_reflective_cylinder/test_reflective_cylinder.py
+++ b/tests/test_reflective_cylinder/test_reflective_cylinder.py
@@ -1,60 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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_created_statepoint()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*')
+ harness.execute_test()
diff --git a/tests/test_reflective_plane/results.py b/tests/test_reflective_plane/results.py
deleted file mode 100644
index b194e843ed..0000000000
--- a/tests/test_reflective_plane/results.py
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-
-sys.path.insert(0, '../..')
-import openmc.statepoint as statepoint
-
-# read in statepoint file
-if len(sys.argv) > 1:
- sp = statepoint.StatePoint(sys.argv[1])
-else:
- sp = statepoint.StatePoint('statepoint.10.binary')
-sp.read_results()
-
-# 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 results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_reflective_plane/test_reflective_plane.py b/tests/test_reflective_plane/test_reflective_plane.py
index ab227e2ba3..390e6d832e 100644
--- a/tests/test_reflective_plane/test_reflective_plane.py
+++ b/tests/test_reflective_plane/test_reflective_plane.py
@@ -1,60 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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_created_statepoint()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*')
+ harness.execute_test()
diff --git a/tests/test_reflective_sphere/results.py b/tests/test_reflective_sphere/results.py
deleted file mode 100644
index b194e843ed..0000000000
--- a/tests/test_reflective_sphere/results.py
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-
-sys.path.insert(0, '../..')
-import openmc.statepoint as statepoint
-
-# read in statepoint file
-if len(sys.argv) > 1:
- sp = statepoint.StatePoint(sys.argv[1])
-else:
- sp = statepoint.StatePoint('statepoint.10.binary')
-sp.read_results()
-
-# 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 results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_reflective_sphere/test_reflective_sphere.py b/tests/test_reflective_sphere/test_reflective_sphere.py
index ab227e2ba3..390e6d832e 100644
--- a/tests/test_reflective_sphere/test_reflective_sphere.py
+++ b/tests/test_reflective_sphere/test_reflective_sphere.py
@@ -1,60 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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_created_statepoint()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*')
+ harness.execute_test()
diff --git a/tests/test_resonance_scattering/results.py b/tests/test_resonance_scattering/results.py
deleted file mode 100644
index 084bcc683b..0000000000
--- a/tests/test_resonance_scattering/results.py
+++ /dev/null
@@ -1,24 +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.10.binary')
-sp.read_results()
-
-# 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 results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_resonance_scattering/test_resonance_scattering.py b/tests/test_resonance_scattering/test_resonance_scattering.py
index ab227e2ba3..390e6d832e 100644
--- a/tests/test_resonance_scattering/test_resonance_scattering.py
+++ b/tests/test_resonance_scattering/test_resonance_scattering.py
@@ -1,60 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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_created_statepoint()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*')
+ harness.execute_test()
diff --git a/tests/test_rotation/results.py b/tests/test_rotation/results.py
deleted file mode 100644
index b194e843ed..0000000000
--- a/tests/test_rotation/results.py
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-
-sys.path.insert(0, '../..')
-import openmc.statepoint as statepoint
-
-# read in statepoint file
-if len(sys.argv) > 1:
- sp = statepoint.StatePoint(sys.argv[1])
-else:
- sp = statepoint.StatePoint('statepoint.10.binary')
-sp.read_results()
-
-# 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 results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_rotation/test_rotation.py b/tests/test_rotation/test_rotation.py
index ab227e2ba3..390e6d832e 100644
--- a/tests/test_rotation/test_rotation.py
+++ b/tests/test_rotation/test_rotation.py
@@ -1,60 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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_created_statepoint()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*')
+ harness.execute_test()
diff --git a/tests/test_salphabeta/results.py b/tests/test_salphabeta/results.py
deleted file mode 100644
index b194e843ed..0000000000
--- a/tests/test_salphabeta/results.py
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-
-sys.path.insert(0, '../..')
-import openmc.statepoint as statepoint
-
-# read in statepoint file
-if len(sys.argv) > 1:
- sp = statepoint.StatePoint(sys.argv[1])
-else:
- sp = statepoint.StatePoint('statepoint.10.binary')
-sp.read_results()
-
-# 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 results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_salphabeta/test_salphabeta.py b/tests/test_salphabeta/test_salphabeta.py
index ab227e2ba3..390e6d832e 100644
--- a/tests/test_salphabeta/test_salphabeta.py
+++ b/tests/test_salphabeta/test_salphabeta.py
@@ -1,60 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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_created_statepoint()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*')
+ harness.execute_test()
diff --git a/tests/test_salphabeta_multiple/results.py b/tests/test_salphabeta_multiple/results.py
deleted file mode 100644
index fc1b491c6c..0000000000
--- a/tests/test_salphabeta_multiple/results.py
+++ /dev/null
@@ -1,25 +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.10.binary')
-
-sp.read_results()
-
-# 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 results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_salphabeta_multiple/test_salphabeta_multiple.py b/tests/test_salphabeta_multiple/test_salphabeta_multiple.py
index ab227e2ba3..390e6d832e 100644
--- a/tests/test_salphabeta_multiple/test_salphabeta_multiple.py
+++ b/tests/test_salphabeta_multiple/test_salphabeta_multiple.py
@@ -1,60 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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_created_statepoint()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*')
+ harness.execute_test()
diff --git a/tests/test_score_MT/results.py b/tests/test_score_MT/results.py
deleted file mode 100644
index 3f215b2870..0000000000
--- a/tests/test_score_MT/results.py
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-import numpy as np
-
-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.10.binary')
-
-sp.read_results()
-
-# extract tally results and convert to vector
-tally = sp._tallies[1]
-results = np.zeros((tally._sum.size + tally._sum.size, ))
-results[0::2] = tally._sum.ravel()
-results[1::2] = tally._sum_sq.ravel()
-
-# 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 tally results
-outstr += 'tallies:\n'
-for item in results:
- outstr += "{0:12.6E}\n".format(item)
-
-# write results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_score_MT/results_true.dat b/tests/test_score_MT/results_true.dat
index 91ae452f95..03b91f89fa 100644
--- a/tests/test_score_MT/results_true.dat
+++ b/tests/test_score_MT/results_true.dat
@@ -1,6 +1,6 @@
k-combined:
1.093844E+00 1.626801E-02
-tallies:
+tally 1:
0.000000E+00
0.000000E+00
0.000000E+00
diff --git a/tests/test_score_MT/test_score_MT.py b/tests/test_score_MT/test_score_MT.py
index 0130cd7a06..8f3b0785a8 100644
--- a/tests/test_score_MT/test_score_MT.py
+++ b/tests/test_score_MT/test_score_MT.py
@@ -1,65 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_output_exists():
- assert os.path.exists(os.path.join(cwd, 'tallies.out')), 'Tally output file does not exist.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- output.append(os.path.join(cwd, 'tallies.out'))
- 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_created_statepoint()
- test_output_exists()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*', True)
+ harness.execute_test()
diff --git a/tests/test_score_absorption/results.py b/tests/test_score_absorption/results.py
deleted file mode 100644
index ac9a0e91be..0000000000
--- a/tests/test_score_absorption/results.py
+++ /dev/null
@@ -1,46 +0,0 @@
-
-#!/usr/bin/env python
-
-import sys
-import numpy as np
-
-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.10.binary')
-
-sp.read_results()
-
-# extract tally results and convert to vector
-tally1 = sp._tallies[1]
-results1 = np.zeros((tally1._sum.size + tally1._sum.size, ))
-results1[0::2] = tally1._sum.ravel()
-results1[1::2] = tally1._sum_sq.ravel()
-
-tally2 = sp._tallies[2]
-results2 = np.zeros((tally2._sum.size + tally2._sum.size, ))
-results2[0::2] = tally2._sum.ravel()
-results2[1::2] = tally2._sum_sq.ravel()
-
-# 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 tally results
-outstr += 'tally 1:\n'
-for item in results1:
- outstr += "{0:12.6E}\n".format(item)
-outstr += 'tally 2:\n'
-for item in results2:
- outstr += "{0:12.6E}\n".format(item)
-
-# write results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_score_absorption/test_score_absorption.py b/tests/test_score_absorption/test_score_absorption.py
index 0130cd7a06..8f3b0785a8 100644
--- a/tests/test_score_absorption/test_score_absorption.py
+++ b/tests/test_score_absorption/test_score_absorption.py
@@ -1,65 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_output_exists():
- assert os.path.exists(os.path.join(cwd, 'tallies.out')), 'Tally output file does not exist.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- output.append(os.path.join(cwd, 'tallies.out'))
- 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_created_statepoint()
- test_output_exists()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*', True)
+ harness.execute_test()
diff --git a/tests/test_score_current/results.py b/tests/test_score_current/results.py
deleted file mode 100644
index d2cb9adc0a..0000000000
--- a/tests/test_score_current/results.py
+++ /dev/null
@@ -1,45 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-import numpy as np
-
-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.10.binary')
-
-sp.read_results()
-
-# extract tally results and convert to vector
-tally1 = sp._tallies[1]
-results1 = np.zeros((tally1._sum.size + tally1._sum.size, ))
-results1[0::2] = tally1._sum.ravel()
-results1[1::2] = tally1._sum_sq.ravel()
-
-tally2 = sp._tallies[2]
-results2 = np.zeros((tally2._sum.size + tally2._sum.size, ))
-results2[0::2] = tally2._sum.ravel()
-results2[1::2] = tally2._sum_sq.ravel()
-
-# 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 tally results
-outstr += 'tally 1:\n'
-for item in results1:
- outstr += "{0:12.6E}\n".format(item)
-outstr += 'tally 2:\n'
-for item in results2:
- outstr += "{0:12.6E}\n".format(item)
-
-# write results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_score_current/test_score_current.py b/tests/test_score_current/test_score_current.py
index 0130cd7a06..8f3b0785a8 100644
--- a/tests/test_score_current/test_score_current.py
+++ b/tests/test_score_current/test_score_current.py
@@ -1,65 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_output_exists():
- assert os.path.exists(os.path.join(cwd, 'tallies.out')), 'Tally output file does not exist.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- output.append(os.path.join(cwd, 'tallies.out'))
- 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_created_statepoint()
- test_output_exists()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*', True)
+ harness.execute_test()
diff --git a/tests/test_score_events/results.py b/tests/test_score_events/results.py
deleted file mode 100644
index d2cb9adc0a..0000000000
--- a/tests/test_score_events/results.py
+++ /dev/null
@@ -1,45 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-import numpy as np
-
-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.10.binary')
-
-sp.read_results()
-
-# extract tally results and convert to vector
-tally1 = sp._tallies[1]
-results1 = np.zeros((tally1._sum.size + tally1._sum.size, ))
-results1[0::2] = tally1._sum.ravel()
-results1[1::2] = tally1._sum_sq.ravel()
-
-tally2 = sp._tallies[2]
-results2 = np.zeros((tally2._sum.size + tally2._sum.size, ))
-results2[0::2] = tally2._sum.ravel()
-results2[1::2] = tally2._sum_sq.ravel()
-
-# 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 tally results
-outstr += 'tally 1:\n'
-for item in results1:
- outstr += "{0:12.6E}\n".format(item)
-outstr += 'tally 2:\n'
-for item in results2:
- outstr += "{0:12.6E}\n".format(item)
-
-# write results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_score_events/test_score_events.py b/tests/test_score_events/test_score_events.py
index 0130cd7a06..8f3b0785a8 100644
--- a/tests/test_score_events/test_score_events.py
+++ b/tests/test_score_events/test_score_events.py
@@ -1,65 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_output_exists():
- assert os.path.exists(os.path.join(cwd, 'tallies.out')), 'Tally output file does not exist.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- output.append(os.path.join(cwd, 'tallies.out'))
- 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_created_statepoint()
- test_output_exists()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*', True)
+ harness.execute_test()
diff --git a/tests/test_score_fission/results.py b/tests/test_score_fission/results.py
deleted file mode 100644
index d2cb9adc0a..0000000000
--- a/tests/test_score_fission/results.py
+++ /dev/null
@@ -1,45 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-import numpy as np
-
-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.10.binary')
-
-sp.read_results()
-
-# extract tally results and convert to vector
-tally1 = sp._tallies[1]
-results1 = np.zeros((tally1._sum.size + tally1._sum.size, ))
-results1[0::2] = tally1._sum.ravel()
-results1[1::2] = tally1._sum_sq.ravel()
-
-tally2 = sp._tallies[2]
-results2 = np.zeros((tally2._sum.size + tally2._sum.size, ))
-results2[0::2] = tally2._sum.ravel()
-results2[1::2] = tally2._sum_sq.ravel()
-
-# 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 tally results
-outstr += 'tally 1:\n'
-for item in results1:
- outstr += "{0:12.6E}\n".format(item)
-outstr += 'tally 2:\n'
-for item in results2:
- outstr += "{0:12.6E}\n".format(item)
-
-# write results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_score_fission/test_score_fission.py b/tests/test_score_fission/test_score_fission.py
index 0130cd7a06..8f3b0785a8 100644
--- a/tests/test_score_fission/test_score_fission.py
+++ b/tests/test_score_fission/test_score_fission.py
@@ -1,65 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_output_exists():
- assert os.path.exists(os.path.join(cwd, 'tallies.out')), 'Tally output file does not exist.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- output.append(os.path.join(cwd, 'tallies.out'))
- 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_created_statepoint()
- test_output_exists()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*', True)
+ harness.execute_test()
diff --git a/tests/test_score_flux/results.py b/tests/test_score_flux/results.py
deleted file mode 100644
index 3f215b2870..0000000000
--- a/tests/test_score_flux/results.py
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-import numpy as np
-
-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.10.binary')
-
-sp.read_results()
-
-# extract tally results and convert to vector
-tally = sp._tallies[1]
-results = np.zeros((tally._sum.size + tally._sum.size, ))
-results[0::2] = tally._sum.ravel()
-results[1::2] = tally._sum_sq.ravel()
-
-# 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 tally results
-outstr += 'tallies:\n'
-for item in results:
- outstr += "{0:12.6E}\n".format(item)
-
-# write results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_score_flux/results_true.dat b/tests/test_score_flux/results_true.dat
index ecab5d7fb1..9c21a0f3d8 100644
--- a/tests/test_score_flux/results_true.dat
+++ b/tests/test_score_flux/results_true.dat
@@ -1,6 +1,6 @@
k-combined:
1.093844E+00 1.626801E-02
-tallies:
+tally 1:
3.403102E+01
2.393236E+02
1.143060E+01
diff --git a/tests/test_score_flux/test_score_flux.py b/tests/test_score_flux/test_score_flux.py
index 0130cd7a06..8f3b0785a8 100644
--- a/tests/test_score_flux/test_score_flux.py
+++ b/tests/test_score_flux/test_score_flux.py
@@ -1,65 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_output_exists():
- assert os.path.exists(os.path.join(cwd, 'tallies.out')), 'Tally output file does not exist.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- output.append(os.path.join(cwd, 'tallies.out'))
- 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_created_statepoint()
- test_output_exists()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*', True)
+ harness.execute_test()
diff --git a/tests/test_score_flux_yn/results.py b/tests/test_score_flux_yn/results.py
deleted file mode 100644
index d2cb9adc0a..0000000000
--- a/tests/test_score_flux_yn/results.py
+++ /dev/null
@@ -1,45 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-import numpy as np
-
-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.10.binary')
-
-sp.read_results()
-
-# extract tally results and convert to vector
-tally1 = sp._tallies[1]
-results1 = np.zeros((tally1._sum.size + tally1._sum.size, ))
-results1[0::2] = tally1._sum.ravel()
-results1[1::2] = tally1._sum_sq.ravel()
-
-tally2 = sp._tallies[2]
-results2 = np.zeros((tally2._sum.size + tally2._sum.size, ))
-results2[0::2] = tally2._sum.ravel()
-results2[1::2] = tally2._sum_sq.ravel()
-
-# 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 tally results
-outstr += 'tally 1:\n'
-for item in results1:
- outstr += "{0:12.6E}\n".format(item)
-outstr += 'tally 2:\n'
-for item in results2:
- outstr += "{0:12.6E}\n".format(item)
-
-# write results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_score_flux_yn/test_score_flux_yn.py b/tests/test_score_flux_yn/test_score_flux_yn.py
old mode 100644
new mode 100755
index fd3b3ed5b2..8f3b0785a8
--- a/tests/test_score_flux_yn/test_score_flux_yn.py
+++ b/tests/test_score_flux_yn/test_score_flux_yn.py
@@ -1,63 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_output_exists():
- assert os.path.exists(os.path.join(cwd, 'tallies.out')), 'Tally output file does not exist.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- output.append(os.path.join(cwd, 'tallies.out'))
- 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
- test_run()
- test_created_statepoint()
- test_output_exists()
- test_results()
- teardown()
+ harness = TestHarness('statepoint.10.*', True)
+ harness.execute_test()
diff --git a/tests/test_score_kappafission/results.py b/tests/test_score_kappafission/results.py
deleted file mode 100644
index 3f215b2870..0000000000
--- a/tests/test_score_kappafission/results.py
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-import numpy as np
-
-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.10.binary')
-
-sp.read_results()
-
-# extract tally results and convert to vector
-tally = sp._tallies[1]
-results = np.zeros((tally._sum.size + tally._sum.size, ))
-results[0::2] = tally._sum.ravel()
-results[1::2] = tally._sum_sq.ravel()
-
-# 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 tally results
-outstr += 'tallies:\n'
-for item in results:
- outstr += "{0:12.6E}\n".format(item)
-
-# write results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_score_kappafission/results_true.dat b/tests/test_score_kappafission/results_true.dat
index d0a8d85021..f9f4c44b9a 100644
--- a/tests/test_score_kappafission/results_true.dat
+++ b/tests/test_score_kappafission/results_true.dat
@@ -1,6 +1,6 @@
k-combined:
1.093844E+00 1.626801E-02
-tallies:
+tally 1:
2.135627E+02
9.364189E+03
0.000000E+00
diff --git a/tests/test_score_kappafission/test_score_kappafission.py b/tests/test_score_kappafission/test_score_kappafission.py
index 0130cd7a06..8f3b0785a8 100644
--- a/tests/test_score_kappafission/test_score_kappafission.py
+++ b/tests/test_score_kappafission/test_score_kappafission.py
@@ -1,65 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_output_exists():
- assert os.path.exists(os.path.join(cwd, 'tallies.out')), 'Tally output file does not exist.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- output.append(os.path.join(cwd, 'tallies.out'))
- 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_created_statepoint()
- test_output_exists()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*', True)
+ harness.execute_test()
diff --git a/tests/test_score_nufission/results.py b/tests/test_score_nufission/results.py
deleted file mode 100644
index 3f215b2870..0000000000
--- a/tests/test_score_nufission/results.py
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-import numpy as np
-
-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.10.binary')
-
-sp.read_results()
-
-# extract tally results and convert to vector
-tally = sp._tallies[1]
-results = np.zeros((tally._sum.size + tally._sum.size, ))
-results[0::2] = tally._sum.ravel()
-results[1::2] = tally._sum_sq.ravel()
-
-# 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 tally results
-outstr += 'tallies:\n'
-for item in results:
- outstr += "{0:12.6E}\n".format(item)
-
-# write results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_score_nufission/results_true.dat b/tests/test_score_nufission/results_true.dat
index 72ca819eae..21d6586b68 100644
--- a/tests/test_score_nufission/results_true.dat
+++ b/tests/test_score_nufission/results_true.dat
@@ -1,6 +1,6 @@
k-combined:
1.093844E+00 1.626801E-02
-tallies:
+tally 1:
2.879098E+00
1.700626E+00
0.000000E+00
diff --git a/tests/test_score_nufission/test_score_nufission.py b/tests/test_score_nufission/test_score_nufission.py
index 0130cd7a06..8f3b0785a8 100644
--- a/tests/test_score_nufission/test_score_nufission.py
+++ b/tests/test_score_nufission/test_score_nufission.py
@@ -1,65 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_output_exists():
- assert os.path.exists(os.path.join(cwd, 'tallies.out')), 'Tally output file does not exist.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- output.append(os.path.join(cwd, 'tallies.out'))
- 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_created_statepoint()
- test_output_exists()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*', True)
+ harness.execute_test()
diff --git a/tests/test_score_nuscatter/results.py b/tests/test_score_nuscatter/results.py
deleted file mode 100644
index 3f215b2870..0000000000
--- a/tests/test_score_nuscatter/results.py
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-import numpy as np
-
-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.10.binary')
-
-sp.read_results()
-
-# extract tally results and convert to vector
-tally = sp._tallies[1]
-results = np.zeros((tally._sum.size + tally._sum.size, ))
-results[0::2] = tally._sum.ravel()
-results[1::2] = tally._sum_sq.ravel()
-
-# 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 tally results
-outstr += 'tallies:\n'
-for item in results:
- outstr += "{0:12.6E}\n".format(item)
-
-# write results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_score_nuscatter/results_true.dat b/tests/test_score_nuscatter/results_true.dat
index 6dab56d44d..e2be939c75 100644
--- a/tests/test_score_nuscatter/results_true.dat
+++ b/tests/test_score_nuscatter/results_true.dat
@@ -1,6 +1,6 @@
k-combined:
1.093844E+00 1.626801E-02
-tallies:
+tally 1:
0.000000E+00
0.000000E+00
1.239000E+01
diff --git a/tests/test_score_nuscatter/test_score_nuscatter.py b/tests/test_score_nuscatter/test_score_nuscatter.py
index 0130cd7a06..8f3b0785a8 100644
--- a/tests/test_score_nuscatter/test_score_nuscatter.py
+++ b/tests/test_score_nuscatter/test_score_nuscatter.py
@@ -1,65 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_output_exists():
- assert os.path.exists(os.path.join(cwd, 'tallies.out')), 'Tally output file does not exist.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- output.append(os.path.join(cwd, 'tallies.out'))
- 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_created_statepoint()
- test_output_exists()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*', True)
+ harness.execute_test()
diff --git a/tests/test_score_nuscatter_n/results.py b/tests/test_score_nuscatter_n/results.py
deleted file mode 100644
index 3f215b2870..0000000000
--- a/tests/test_score_nuscatter_n/results.py
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-import numpy as np
-
-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.10.binary')
-
-sp.read_results()
-
-# extract tally results and convert to vector
-tally = sp._tallies[1]
-results = np.zeros((tally._sum.size + tally._sum.size, ))
-results[0::2] = tally._sum.ravel()
-results[1::2] = tally._sum_sq.ravel()
-
-# 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 tally results
-outstr += 'tallies:\n'
-for item in results:
- outstr += "{0:12.6E}\n".format(item)
-
-# write results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_score_nuscatter_n/results_true.dat b/tests/test_score_nuscatter_n/results_true.dat
index 638fa5e900..9b84b70786 100644
--- a/tests/test_score_nuscatter_n/results_true.dat
+++ b/tests/test_score_nuscatter_n/results_true.dat
@@ -1,6 +1,6 @@
k-combined:
1.093844E+00 1.626801E-02
-tallies:
+tally 1:
1.239000E+01
3.172630E+01
1.431689E+00
diff --git a/tests/test_score_nuscatter_n/test_score_nuscatter_n.py b/tests/test_score_nuscatter_n/test_score_nuscatter_n.py
index fd3b3ed5b2..8f3b0785a8 100644
--- a/tests/test_score_nuscatter_n/test_score_nuscatter_n.py
+++ b/tests/test_score_nuscatter_n/test_score_nuscatter_n.py
@@ -1,63 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_output_exists():
- assert os.path.exists(os.path.join(cwd, 'tallies.out')), 'Tally output file does not exist.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- output.append(os.path.join(cwd, 'tallies.out'))
- 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
- test_run()
- test_created_statepoint()
- test_output_exists()
- test_results()
- teardown()
+ harness = TestHarness('statepoint.10.*', True)
+ harness.execute_test()
diff --git a/tests/test_score_nuscatter_pn/results.py b/tests/test_score_nuscatter_pn/results.py
deleted file mode 100644
index d2cb9adc0a..0000000000
--- a/tests/test_score_nuscatter_pn/results.py
+++ /dev/null
@@ -1,45 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-import numpy as np
-
-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.10.binary')
-
-sp.read_results()
-
-# extract tally results and convert to vector
-tally1 = sp._tallies[1]
-results1 = np.zeros((tally1._sum.size + tally1._sum.size, ))
-results1[0::2] = tally1._sum.ravel()
-results1[1::2] = tally1._sum_sq.ravel()
-
-tally2 = sp._tallies[2]
-results2 = np.zeros((tally2._sum.size + tally2._sum.size, ))
-results2[0::2] = tally2._sum.ravel()
-results2[1::2] = tally2._sum_sq.ravel()
-
-# 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 tally results
-outstr += 'tally 1:\n'
-for item in results1:
- outstr += "{0:12.6E}\n".format(item)
-outstr += 'tally 2:\n'
-for item in results2:
- outstr += "{0:12.6E}\n".format(item)
-
-# write results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_score_nuscatter_pn/test_score_nuscatter_pn.py b/tests/test_score_nuscatter_pn/test_score_nuscatter_pn.py
index fd3b3ed5b2..8f3b0785a8 100644
--- a/tests/test_score_nuscatter_pn/test_score_nuscatter_pn.py
+++ b/tests/test_score_nuscatter_pn/test_score_nuscatter_pn.py
@@ -1,63 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_output_exists():
- assert os.path.exists(os.path.join(cwd, 'tallies.out')), 'Tally output file does not exist.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- output.append(os.path.join(cwd, 'tallies.out'))
- 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
- test_run()
- test_created_statepoint()
- test_output_exists()
- test_results()
- teardown()
+ harness = TestHarness('statepoint.10.*', True)
+ harness.execute_test()
diff --git a/tests/test_score_nuscatter_yn/results.py b/tests/test_score_nuscatter_yn/results.py
deleted file mode 100644
index d2cb9adc0a..0000000000
--- a/tests/test_score_nuscatter_yn/results.py
+++ /dev/null
@@ -1,45 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-import numpy as np
-
-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.10.binary')
-
-sp.read_results()
-
-# extract tally results and convert to vector
-tally1 = sp._tallies[1]
-results1 = np.zeros((tally1._sum.size + tally1._sum.size, ))
-results1[0::2] = tally1._sum.ravel()
-results1[1::2] = tally1._sum_sq.ravel()
-
-tally2 = sp._tallies[2]
-results2 = np.zeros((tally2._sum.size + tally2._sum.size, ))
-results2[0::2] = tally2._sum.ravel()
-results2[1::2] = tally2._sum_sq.ravel()
-
-# 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 tally results
-outstr += 'tally 1:\n'
-for item in results1:
- outstr += "{0:12.6E}\n".format(item)
-outstr += 'tally 2:\n'
-for item in results2:
- outstr += "{0:12.6E}\n".format(item)
-
-# write results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_score_nuscatter_yn/test_score_nuscatter_yn.py b/tests/test_score_nuscatter_yn/test_score_nuscatter_yn.py
index fd3b3ed5b2..8f3b0785a8 100644
--- a/tests/test_score_nuscatter_yn/test_score_nuscatter_yn.py
+++ b/tests/test_score_nuscatter_yn/test_score_nuscatter_yn.py
@@ -1,63 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_output_exists():
- assert os.path.exists(os.path.join(cwd, 'tallies.out')), 'Tally output file does not exist.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- output.append(os.path.join(cwd, 'tallies.out'))
- 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
- test_run()
- test_created_statepoint()
- test_output_exists()
- test_results()
- teardown()
+ harness = TestHarness('statepoint.10.*', True)
+ harness.execute_test()
diff --git a/tests/test_score_scatter/results.py b/tests/test_score_scatter/results.py
deleted file mode 100644
index 3f215b2870..0000000000
--- a/tests/test_score_scatter/results.py
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-import numpy as np
-
-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.10.binary')
-
-sp.read_results()
-
-# extract tally results and convert to vector
-tally = sp._tallies[1]
-results = np.zeros((tally._sum.size + tally._sum.size, ))
-results[0::2] = tally._sum.ravel()
-results[1::2] = tally._sum_sq.ravel()
-
-# 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 tally results
-outstr += 'tallies:\n'
-for item in results:
- outstr += "{0:12.6E}\n".format(item)
-
-# write results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_score_scatter/results_true.dat b/tests/test_score_scatter/results_true.dat
index bc73884816..9619e0f49d 100644
--- a/tests/test_score_scatter/results_true.dat
+++ b/tests/test_score_scatter/results_true.dat
@@ -1,6 +1,6 @@
k-combined:
1.093844E+00 1.626801E-02
-tallies:
+tally 1:
0.000000E+00
0.000000E+00
1.290818E+01
diff --git a/tests/test_score_scatter/test_score_scatter.py b/tests/test_score_scatter/test_score_scatter.py
index 0130cd7a06..8f3b0785a8 100644
--- a/tests/test_score_scatter/test_score_scatter.py
+++ b/tests/test_score_scatter/test_score_scatter.py
@@ -1,65 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_output_exists():
- assert os.path.exists(os.path.join(cwd, 'tallies.out')), 'Tally output file does not exist.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- output.append(os.path.join(cwd, 'tallies.out'))
- 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_created_statepoint()
- test_output_exists()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*', True)
+ harness.execute_test()
diff --git a/tests/test_score_scatter_n/results.py b/tests/test_score_scatter_n/results.py
deleted file mode 100644
index 3f215b2870..0000000000
--- a/tests/test_score_scatter_n/results.py
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-import numpy as np
-
-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.10.binary')
-
-sp.read_results()
-
-# extract tally results and convert to vector
-tally = sp._tallies[1]
-results = np.zeros((tally._sum.size + tally._sum.size, ))
-results[0::2] = tally._sum.ravel()
-results[1::2] = tally._sum_sq.ravel()
-
-# 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 tally results
-outstr += 'tallies:\n'
-for item in results:
- outstr += "{0:12.6E}\n".format(item)
-
-# write results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_score_scatter_n/results_true.dat b/tests/test_score_scatter_n/results_true.dat
index d7a49c1f34..418eabad78 100644
--- a/tests/test_score_scatter_n/results_true.dat
+++ b/tests/test_score_scatter_n/results_true.dat
@@ -1,6 +1,6 @@
k-combined:
1.093844E+00 1.626801E-02
-tallies:
+tally 1:
1.238000E+01
3.168320E+01
1.437080E+00
diff --git a/tests/test_score_scatter_n/test_score_scatter_n.py b/tests/test_score_scatter_n/test_score_scatter_n.py
index 0130cd7a06..8f3b0785a8 100644
--- a/tests/test_score_scatter_n/test_score_scatter_n.py
+++ b/tests/test_score_scatter_n/test_score_scatter_n.py
@@ -1,65 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_output_exists():
- assert os.path.exists(os.path.join(cwd, 'tallies.out')), 'Tally output file does not exist.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- output.append(os.path.join(cwd, 'tallies.out'))
- 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_created_statepoint()
- test_output_exists()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*', True)
+ harness.execute_test()
diff --git a/tests/test_score_scatter_pn/results.py b/tests/test_score_scatter_pn/results.py
deleted file mode 100644
index d2cb9adc0a..0000000000
--- a/tests/test_score_scatter_pn/results.py
+++ /dev/null
@@ -1,45 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-import numpy as np
-
-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.10.binary')
-
-sp.read_results()
-
-# extract tally results and convert to vector
-tally1 = sp._tallies[1]
-results1 = np.zeros((tally1._sum.size + tally1._sum.size, ))
-results1[0::2] = tally1._sum.ravel()
-results1[1::2] = tally1._sum_sq.ravel()
-
-tally2 = sp._tallies[2]
-results2 = np.zeros((tally2._sum.size + tally2._sum.size, ))
-results2[0::2] = tally2._sum.ravel()
-results2[1::2] = tally2._sum_sq.ravel()
-
-# 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 tally results
-outstr += 'tally 1:\n'
-for item in results1:
- outstr += "{0:12.6E}\n".format(item)
-outstr += 'tally 2:\n'
-for item in results2:
- outstr += "{0:12.6E}\n".format(item)
-
-# write results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_score_scatter_pn/test_score_scatter_pn.py b/tests/test_score_scatter_pn/test_score_scatter_pn.py
index 0130cd7a06..8f3b0785a8 100644
--- a/tests/test_score_scatter_pn/test_score_scatter_pn.py
+++ b/tests/test_score_scatter_pn/test_score_scatter_pn.py
@@ -1,65 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_output_exists():
- assert os.path.exists(os.path.join(cwd, 'tallies.out')), 'Tally output file does not exist.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- output.append(os.path.join(cwd, 'tallies.out'))
- 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_created_statepoint()
- test_output_exists()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*', True)
+ harness.execute_test()
diff --git a/tests/test_score_scatter_yn/results.py b/tests/test_score_scatter_yn/results.py
deleted file mode 100644
index d2cb9adc0a..0000000000
--- a/tests/test_score_scatter_yn/results.py
+++ /dev/null
@@ -1,45 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-import numpy as np
-
-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.10.binary')
-
-sp.read_results()
-
-# extract tally results and convert to vector
-tally1 = sp._tallies[1]
-results1 = np.zeros((tally1._sum.size + tally1._sum.size, ))
-results1[0::2] = tally1._sum.ravel()
-results1[1::2] = tally1._sum_sq.ravel()
-
-tally2 = sp._tallies[2]
-results2 = np.zeros((tally2._sum.size + tally2._sum.size, ))
-results2[0::2] = tally2._sum.ravel()
-results2[1::2] = tally2._sum_sq.ravel()
-
-# 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 tally results
-outstr += 'tally 1:\n'
-for item in results1:
- outstr += "{0:12.6E}\n".format(item)
-outstr += 'tally 2:\n'
-for item in results2:
- outstr += "{0:12.6E}\n".format(item)
-
-# write results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_score_scatter_yn/test_score_scatter_yn.py b/tests/test_score_scatter_yn/test_score_scatter_yn.py
index fd3b3ed5b2..8f3b0785a8 100644
--- a/tests/test_score_scatter_yn/test_score_scatter_yn.py
+++ b/tests/test_score_scatter_yn/test_score_scatter_yn.py
@@ -1,63 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_output_exists():
- assert os.path.exists(os.path.join(cwd, 'tallies.out')), 'Tally output file does not exist.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- output.append(os.path.join(cwd, 'tallies.out'))
- 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
- test_run()
- test_created_statepoint()
- test_output_exists()
- test_results()
- teardown()
+ harness = TestHarness('statepoint.10.*', True)
+ harness.execute_test()
diff --git a/tests/test_score_total/results.py b/tests/test_score_total/results.py
deleted file mode 100644
index 3022c32723..0000000000
--- a/tests/test_score_total/results.py
+++ /dev/null
@@ -1,36 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-import numpy as np
-
-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.10.binary')
-sp.read_results()
-
-# extract tally results and convert to vector
-tally = sp._tallies[1]
-results = np.empty((tally._sum.size + tally._sum.size, ), dtype=np.float64)
-results[0::2] = tally._sum.ravel()
-results[1::2] = tally._sum_sq.ravel()
-
-# 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 tally results
-outstr += 'tallies:\n'
-for item in results:
- outstr += "{0:12.6E}\n".format(item)
-
-# write results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_score_total/results_true.dat b/tests/test_score_total/results_true.dat
index 0a1924c5d7..0838e7baed 100644
--- a/tests/test_score_total/results_true.dat
+++ b/tests/test_score_total/results_true.dat
@@ -1,6 +1,6 @@
k-combined:
1.093844E+00 1.626801E-02
-tallies:
+tally 1:
0.000000E+00
0.000000E+00
1.517577E+01
diff --git a/tests/test_score_total/test_score_total.py b/tests/test_score_total/test_score_total.py
index 0130cd7a06..8f3b0785a8 100644
--- a/tests/test_score_total/test_score_total.py
+++ b/tests/test_score_total/test_score_total.py
@@ -1,65 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_output_exists():
- assert os.path.exists(os.path.join(cwd, 'tallies.out')), 'Tally output file does not exist.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- output.append(os.path.join(cwd, 'tallies.out'))
- 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_created_statepoint()
- test_output_exists()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*', True)
+ harness.execute_test()
diff --git a/tests/test_score_total_yn/results.py b/tests/test_score_total_yn/results.py
deleted file mode 100644
index c858d6baa6..0000000000
--- a/tests/test_score_total_yn/results.py
+++ /dev/null
@@ -1,44 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-import numpy as np
-
-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.10.binary')
-sp.read_results()
-
-# extract tally results and convert to vector
-tally1 = sp._tallies[1]
-results1 = np.empty((tally1._sum.size + tally1._sum.size, ), dtype=np.float64)
-results1[0::2] = tally1._sum.ravel()
-results1[1::2] = tally1._sum_sq.ravel()
-
-tally2 = sp._tallies[2]
-results2 = np.empty((tally2._sum.size + tally2._sum.size, ), dtype=np.float64)
-results2[0::2] = tally2._sum.ravel()
-results2[1::2] = tally2._sum_sq.ravel()
-
-# 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 tally results
-outstr += 'tally 1:\n'
-for item in results1:
- outstr += "{0:12.6E}\n".format(item)
-outstr += 'tally 2:\n'
-for item in results2:
- outstr += "{0:12.6E}\n".format(item)
-
-# write results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_score_total_yn/test_score_total_yn.py b/tests/test_score_total_yn/test_score_total_yn.py
index fd3b3ed5b2..8f3b0785a8 100644
--- a/tests/test_score_total_yn/test_score_total_yn.py
+++ b/tests/test_score_total_yn/test_score_total_yn.py
@@ -1,63 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_output_exists():
- assert os.path.exists(os.path.join(cwd, 'tallies.out')), 'Tally output file does not exist.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- output.append(os.path.join(cwd, 'tallies.out'))
- 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
- test_run()
- test_created_statepoint()
- test_output_exists()
- test_results()
- teardown()
+ harness = TestHarness('statepoint.10.*', True)
+ harness.execute_test()
diff --git a/tests/test_seed/results.py b/tests/test_seed/results.py
deleted file mode 100644
index fc1b491c6c..0000000000
--- a/tests/test_seed/results.py
+++ /dev/null
@@ -1,25 +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.10.binary')
-
-sp.read_results()
-
-# 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 results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_seed/test_seed.py b/tests/test_seed/test_seed.py
index ab227e2ba3..390e6d832e 100644
--- a/tests/test_seed/test_seed.py
+++ b/tests/test_seed/test_seed.py
@@ -1,60 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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_created_statepoint()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*')
+ harness.execute_test()
diff --git a/tests/test_source_angle_mono/results.py b/tests/test_source_angle_mono/results.py
deleted file mode 100644
index fc1b491c6c..0000000000
--- a/tests/test_source_angle_mono/results.py
+++ /dev/null
@@ -1,25 +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.10.binary')
-
-sp.read_results()
-
-# 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 results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_source_angle_mono/test_source_angle_mono.py b/tests/test_source_angle_mono/test_source_angle_mono.py
index ab227e2ba3..390e6d832e 100644
--- a/tests/test_source_angle_mono/test_source_angle_mono.py
+++ b/tests/test_source_angle_mono/test_source_angle_mono.py
@@ -1,60 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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_created_statepoint()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*')
+ harness.execute_test()
diff --git a/tests/test_source_energy_maxwell/results.py b/tests/test_source_energy_maxwell/results.py
deleted file mode 100644
index fc1b491c6c..0000000000
--- a/tests/test_source_energy_maxwell/results.py
+++ /dev/null
@@ -1,25 +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.10.binary')
-
-sp.read_results()
-
-# 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 results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_source_energy_maxwell/test_source_energy_maxwell.py b/tests/test_source_energy_maxwell/test_source_energy_maxwell.py
index ab227e2ba3..390e6d832e 100644
--- a/tests/test_source_energy_maxwell/test_source_energy_maxwell.py
+++ b/tests/test_source_energy_maxwell/test_source_energy_maxwell.py
@@ -1,60 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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_created_statepoint()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*')
+ harness.execute_test()
diff --git a/tests/test_source_energy_mono/results.py b/tests/test_source_energy_mono/results.py
deleted file mode 100644
index fc1b491c6c..0000000000
--- a/tests/test_source_energy_mono/results.py
+++ /dev/null
@@ -1,25 +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.10.binary')
-
-sp.read_results()
-
-# 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 results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_source_energy_mono/test_source_energy_mono.py b/tests/test_source_energy_mono/test_source_energy_mono.py
index ab227e2ba3..390e6d832e 100644
--- a/tests/test_source_energy_mono/test_source_energy_mono.py
+++ b/tests/test_source_energy_mono/test_source_energy_mono.py
@@ -1,60 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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_created_statepoint()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*')
+ harness.execute_test()
diff --git a/tests/test_source_file/results.py b/tests/test_source_file/results.py
deleted file mode 100644
index fc1b491c6c..0000000000
--- a/tests/test_source_file/results.py
+++ /dev/null
@@ -1,25 +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.10.binary')
-
-sp.read_results()
-
-# 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 results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_source_file/settings.xml b/tests/test_source_file/settings.xml
index 17d4ee2e2e..4464d43696 100644
--- a/tests/test_source_file/settings.xml
+++ b/tests/test_source_file/settings.xml
@@ -1,19 +1,15 @@
-
-
10
5
1000
-
-4 -4 -4 4 4 4
-
diff --git a/tests/test_source_file/test_source_file.py b/tests/test_source_file/test_source_file.py
index b85f70d537..8260fee1d1 100644
--- a/tests/test_source_file/test_source_file.py
+++ b/tests/test_source_file/test_source_file.py
@@ -1,119 +1,97 @@
#!/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()
settings1="""
-
-
10
5
1000
-
-4 -4 -4 4 4 4
-
"""
settings2 = """
-
10
5
1000
-
source.10.{0}
-
"""
-def test_run1():
- 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.'
-def test_statepoint_exists():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
- source = glob.glob(os.path.join(cwd, 'source.10.*'))
- assert len(statepoint) == 1, 'Either multple or no source files exist.'
- assert source[0].endswith('binary') or source[0].endswith('h5'),\
- 'Source file is not a binary or hdf5 file.'
+class SourceFileTestHarness(TestHarness):
+ def execute_test(self):
+ self._parse_args()
+ try:
+ self._run_openmc()
+ self._test_output_created()
+ self._run_openmc_restart()
+ self._get_results()
+ self._compare_results()
+ finally:
+ self._cleanup()
-def test_run2():
- openmc_path = os.path.join(cwd, '../../src/openmc')
- source = glob.glob(os.path.join(cwd, 'source.10.*'))
- with open('settings.xml','w') as fh:
- fh.write(settings2.format(source[0].split('.')[-1]))
- 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.'
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
+ def _test_output_created(self):
+ """Make sure statepoint and source files have been created."""
+ statepoint = glob.glob(os.path.join(os.getcwd(), self._sp_name))
+ 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.'
+
+ source = glob.glob(os.path.join(os.getcwd(), 'source.10.*'))
+ assert len(source) == 1, 'Either multiple or no source files exist.'
+ assert source[0].endswith('binary') \
+ or source[0].endswith('h5'), \
+ 'Source file is not a binary or hdf5 file.'
+
+
+ def _run_openmc_restart(self):
+ source = glob.glob(os.path.join(os.getcwd(), 'source.10.*'))
+ with open('settings.xml','w') as fh:
+ fh.write(settings2.format(source[0].split('.')[-1]))
+
+ if self._opts.mpi_exec != '':
+ proc = Popen([self._opts.mpi_exec, '-np', self._opts.mpi_np,
+ self._opts.exe, os.getcwd()],
+ stderr=STDOUT, stdout=PIPE)
+ else:
+ proc = Popen([self._opts.exe, os.getcwd()],
+ stderr=STDOUT, stdout=PIPE)
+ print(proc.communicate()[0])
+ returncode = proc.returncode
+ assert returncode == 0, 'OpenMC did not exit successfully.'
+
+
+ def _cleanup(self):
+ TestHarness._cleanup(self)
+ output = glob.glob(os.path.join(os.getcwd(), 'source.*'))
+ for f in output:
+ if os.path.exists(f):
+ os.remove(f)
+ with open('settings.xml','w') as fh:
+ fh.write(settings1)
-def teardown():
- with open('settings.xml','w') as fh:
- fh.write(settings1)
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- output += glob.glob(os.path.join(cwd, 'source.10.*'))
- 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_run1()
- test_statepoint_exists()
- test_run2()
- test_results()
- finally:
- teardown()
+ harness = SourceFileTestHarness('statepoint.10.*')
+ harness.execute_test()
diff --git a/tests/test_source_point/results.py b/tests/test_source_point/results.py
deleted file mode 100644
index fc1b491c6c..0000000000
--- a/tests/test_source_point/results.py
+++ /dev/null
@@ -1,25 +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.10.binary')
-
-sp.read_results()
-
-# 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 results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_source_point/test_source_point.py b/tests/test_source_point/test_source_point.py
index ab227e2ba3..390e6d832e 100644
--- a/tests/test_source_point/test_source_point.py
+++ b/tests/test_source_point/test_source_point.py
@@ -1,60 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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_created_statepoint()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*')
+ harness.execute_test()
diff --git a/tests/test_sourcepoint_batch/results.py b/tests/test_sourcepoint_batch/results.py
deleted file mode 100644
index 47e9dcdc9d..0000000000
--- a/tests/test_sourcepoint_batch/results.py
+++ /dev/null
@@ -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)
diff --git a/tests/test_sourcepoint_batch/results_true.dat b/tests/test_sourcepoint_batch/results_true.dat
index e7232e5f8b..6dd7a8a220 100644
--- a/tests/test_sourcepoint_batch/results_true.dat
+++ b/tests/test_sourcepoint_batch/results_true.dat
@@ -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
diff --git a/tests/test_sourcepoint_batch/test_sourcepoint_batch.py b/tests/test_sourcepoint_batch/test_sourcepoint_batch.py
index 7f225540f9..ced07de89a 100644
--- a/tests/test_sourcepoint_batch/test_sourcepoint_batch.py
+++ b/tests/test_sourcepoint_batch/test_sourcepoint_batch.py
@@ -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()
diff --git a/tests/test_sourcepoint_interval/results.py b/tests/test_sourcepoint_interval/results.py
deleted file mode 100644
index 47e9dcdc9d..0000000000
--- a/tests/test_sourcepoint_interval/results.py
+++ /dev/null
@@ -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)
diff --git a/tests/test_sourcepoint_interval/results_true.dat b/tests/test_sourcepoint_interval/results_true.dat
index e7232e5f8b..6dd7a8a220 100644
--- a/tests/test_sourcepoint_interval/results_true.dat
+++ b/tests/test_sourcepoint_interval/results_true.dat
@@ -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
diff --git a/tests/test_sourcepoint_interval/test_sourcepoint_interval.py b/tests/test_sourcepoint_interval/test_sourcepoint_interval.py
index 4b75ed68e1..ced07de89a 100644
--- a/tests/test_sourcepoint_interval/test_sourcepoint_interval.py
+++ b/tests/test_sourcepoint_interval/test_sourcepoint_interval.py
@@ -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 not 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()
diff --git a/tests/test_sourcepoint_latest/results.py b/tests/test_sourcepoint_latest/results.py
deleted file mode 100644
index fc1b491c6c..0000000000
--- a/tests/test_sourcepoint_latest/results.py
+++ /dev/null
@@ -1,25 +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.10.binary')
-
-sp.read_results()
-
-# 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 results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_sourcepoint_latest/test_sourcepoint_latest.py b/tests/test_sourcepoint_latest/test_sourcepoint_latest.py
index 44f1fd300b..5929865ded 100644
--- a/tests/test_sourcepoint_latest/test_sourcepoint_latest.py
+++ b/tests/test_sourcepoint_latest/test_sourcepoint_latest.py
@@ -1,65 +1,22 @@
#!/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.* and source* have been created."""
+ TestHarness._test_output_created(self)
+ source = glob.glob(os.path.join(os.getcwd(), 'source.*'))
+ assert len(source) == 1, 'Either multiple or no source files ' \
+ 'exist.'
+ assert source[0].endswith('binary') \
+ or source[0].endswith('h5'), \
+ 'Source file is not a binary or hdf5 file.'
-def test_statepoint_exists():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- assert len(statepoint) == 1, 'Either multiple or no statepoint file exists.'
- assert statepoint[0].endswith('binary') or statepoint[0].endswith('h5'),\
- 'Statepoint file is not a binary or hdf5 file.'
- source = glob.glob(os.path.join(cwd, 'source.*'))
- assert len(source) == 1, 'Either multple or no source file exists.'
- assert source[0].endswith('binary') or source[0].endswith('h5'),\
- 'Source file is not a binary or hdf5 file.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- output += glob.glob(os.path.join(cwd, 'source.*'))
- 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 = TestHarness('statepoint.10.*')
+ harness.execute_test()
diff --git a/tests/test_sourcepoint_restart/results.py b/tests/test_sourcepoint_restart/results.py
deleted file mode 100644
index 88789385b2..0000000000
--- a/tests/test_sourcepoint_restart/results.py
+++ /dev/null
@@ -1,45 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-import numpy as np
-
-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.10.binary')
-
-sp.read_results()
-
-# extract tally results and convert to vector
-tally10 = sp._tallies[10]
-results10 = np.zeros((tally10._sum.size + tally10._sum.size, ))
-results10[0::2] = tally10._sum.ravel()
-results10[1::2] = tally10._sum_sq.ravel()
-
-tally5 = sp._tallies[5]
-results5 = np.zeros((tally5._sum.size + tally5._sum.size, ))
-results5[0::2] = tally5._sum.ravel()
-results5[1::2] = tally5._sum_sq.ravel()
-
-# 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 tally results
-outstr += 'tally 1:\n'
-for item in results10:
- outstr += "{0:12.6E}\n".format(item)
-outstr += 'tally 2:\n'
-for item in results5:
- outstr += "{0:12.6E}\n".format(item)
-
-# write results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_sourcepoint_restart/test_sourcepoint_restart.py b/tests/test_sourcepoint_restart/test_sourcepoint_restart.py
index 706f24e969..8f3b0785a8 100644
--- a/tests/test_sourcepoint_restart/test_sourcepoint_restart.py
+++ b/tests/test_sourcepoint_restart/test_sourcepoint_restart.py
@@ -1,151 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.*'))
- assert len(statepoint) == 2, '2 statepoint files must exist.'
- assert statepoint[0].endswith('binary') or statepoint[0].endswith('h5'),\
- 'Statepoint file must either be binary or hdf5.'
- sourcepoint = glob.glob(os.path.join(cwd, 'source.07.*'))
- assert len(sourcepoint) == 1, 'Either multiple or no source files found.'
- assert sourcepoint[0].endswith('binary') or sourcepoint[0].endswith('h5'),\
- 'Source file must either be binary or hdf5.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
- os.remove(statepoint[0])
-
-def test_restart_form1():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.07.*'))
- sourcepoint = glob.glob(os.path.join(cwd, 'source.07.*'))
- if opts.mpi_exec != '':
- proc = Popen([opts.mpi_exec, '-np', opts.mpi_np, opts.exe,
- '-r', statepoint[0], sourcepoint[0], cwd], stderr=STDOUT, stdout=PIPE)
- else:
- proc = Popen([opts.exe, '-r', statepoint[0], sourcepoint[0], cwd], stderr=STDOUT, stdout=PIPE)
- print(proc.communicate()[0])
- returncode = proc.returncode
- assert returncode == 0, 'OpenMC restart 1 did not exit successfully.'
-
-def test_created_statepoint_form1():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- assert len(statepoint) == 1, 'Batch 10 statepoint file does not exist.'
- assert statepoint[0].endswith('binary') or statepoint[0].endswith('h5'),\
- 'Statepoint file must be a binary or hdf5 file.'
-
-def test_results_form1():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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, 'Restart 1 results do not agree.'
- os.remove(statepoint[0])
-
-def test_restart_form2():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.07.*'))
- sourcepoint = glob.glob(os.path.join(cwd, 'source.07.*'))
- if opts.mpi_exec != '':
- proc = Popen([opts.mpi_exec, '-np', opts.mpi_np, opts.exe,
- '--restart', statepoint[0], sourcepoint[0], cwd], stderr=STDOUT, stdout=PIPE)
- else:
- proc = Popen([opts.exe, '--restart', statepoint[0], sourcepoint[0], cwd], stderr=STDOUT, stdout=PIPE)
- print(proc.communicate()[0])
- returncode = proc.returncode
- assert returncode == 0, 'OpenMC restart 2 did not exit successfully.'
-
-def test_created_statepoint_form2():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- assert len(statepoint) == 1, 'Batch 10 statepoint file does not exist.'
- assert statepoint[0].endswith('binary') or statepoint[0].endswith('h5'),\
- 'Statepoint file not a binary or hdf5 file.'
-
-def test_results_form2():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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, 'Restart 2 results do not agree.'
- os.remove(statepoint[0])
-
-def test_restart_serial():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.07.*'))
- sourcepoint = glob.glob(os.path.join(cwd, 'source.07.*'))
- proc = Popen([opts.exe, '--restart', statepoint[0], sourcepoint[0], cwd], stderr=STDOUT, stdout=PIPE)
- print(proc.communicate()[0])
- returncode = proc.returncode
- assert returncode == 0, 'OpenMC restart serial did not exit successfully.'
-
-def test_created_statepoint_serial():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- assert len(statepoint) == 1, 'Batch 10 statepoint file does not exist.'
- assert statepoint[0].endswith('binary') or statepoint[0].endswith('h5'),\
- 'Statepoint file is not a binary or hdf5 file.'
-
-def test_results_serial():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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, 'Serial results do not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.*'))
- output += glob.glob(os.path.join(cwd, 'source.*'))
- 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_created_statepoint()
- test_results()
- test_restart_form1()
- test_created_statepoint_form1()
- test_results_form1()
- test_restart_form2()
- test_created_statepoint_form2()
- test_results_form2()
- test_restart_serial()
- test_created_statepoint_serial()
- test_results_serial()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*', True)
+ harness.execute_test()
diff --git a/tests/test_statepoint_batch/results.py b/tests/test_statepoint_batch/results.py
deleted file mode 100644
index e9237ee874..0000000000
--- a/tests/test_statepoint_batch/results.py
+++ /dev/null
@@ -1,25 +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.09.binary')
-
-sp.read_results()
-
-# 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 results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_statepoint_batch/test_statepoint_batch.py b/tests/test_statepoint_batch/test_statepoint_batch.py
index 4298536c52..248d8874c3 100644
--- a/tests/test_statepoint_batch/test_statepoint_batch.py
+++ b/tests/test_statepoint_batch/test_statepoint_batch.py
@@ -1,68 +1,26 @@
#!/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 StatepointTestHarness(TestHarness):
+ def __init__(self):
+ self._sp_name = None
+ self._tallies = False
+ self._opts = None
+ self._args = None
-def test_statepoints_exist():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.03.*'))
- assert len(statepoint) == 1, 'Either multiple or no statepoint.03 files exist.'
- assert statepoint[0].endswith('binary') or statepoint[0].endswith('h5'),\
- 'Statepoint.3 file is not a binary or hdf5 file.'
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.06.*'))
- assert len(statepoint) == 1, 'Either multiple or no statepoint.06 files exist.'
- assert statepoint[0].endswith('binary') or statepoint[0].endswith('h5'),\
- 'Statepoint.6 file is not a binary or hdf5 file.'
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.09.*'))
- assert len(statepoint) == 1, 'Either multiple or no statepoint.09 files exist.'
- assert statepoint[0].endswith('binary') or statepoint[0].endswith('h5'),\
- 'Statepoint.9 file is not a binary or hdf5 file.'
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.09.*'))
- 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 not agree.'
+ def _test_output_created(self):
+ """Make sure statepoint files have been created."""
+ sps = ('statepoint.03.*', 'statepoint.06.*', 'statepoint.09.*')
+ for sp in sps:
+ self._sp_name = sp
+ TestHarness._test_output_created(self)
-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_statepoints_exist()
- test_results()
- finally:
- teardown()
+ harness = StatepointTestHarness()
+ harness.execute_test()
diff --git a/tests/test_statepoint_interval/results.py b/tests/test_statepoint_interval/results.py
deleted file mode 100644
index fc1b491c6c..0000000000
--- a/tests/test_statepoint_interval/results.py
+++ /dev/null
@@ -1,25 +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.10.binary')
-
-sp.read_results()
-
-# 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 results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_statepoint_interval/test_statepoint_interval.py b/tests/test_statepoint_interval/test_statepoint_interval.py
index c70d547d8c..ff686645e1 100644
--- a/tests/test_statepoint_interval/test_statepoint_interval.py
+++ b/tests/test_statepoint_interval/test_statepoint_interval.py
@@ -1,77 +1,27 @@
#!/usr/bin/env python
-import os
import sys
-import glob
-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 StatepointTestHarness(TestHarness):
+ def __init__(self):
+ self._sp_name = None
+ self._tallies = False
+ self._opts = None
+ self._args = None
-def test_statepoints_exist():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.02.*'))
- assert len(statepoint) == 1, 'Either multiple or no statepoint.02 files exist.'
- assert statepoint[0].endswith('binary') or statepoint[0].endswith('h5'),\
- 'Statepoint.2 file is not a binary or hdf5 file.'
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.04.*'))
- assert len(statepoint) == 1, 'Either multiple or no statepoint.04 files exist.'
- assert statepoint[0].endswith('binary') or statepoint[0].endswith('h5'),\
- 'Statepoint.4 file is not a binary or hdf5 file.'
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.06.*'))
- assert len(statepoint) == 1, 'Either multiple or no statepoint.06 files exist.'
- assert statepoint[0].endswith('binary') or statepoint[0].endswith('h5'),\
- 'Statepoint.6 file is not a binary or hdf5 file.'
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.08.*'))
- assert len(statepoint) == 1, 'Either multiple or no statepoint.08 files exist.'
- assert statepoint[0].endswith('binary') or statepoint[0].endswith('h5'),\
- 'Statepoint.8 file is not a binary or hdf5 file.'
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- assert len(statepoint) == 1, 'Either multiple or no statepoint.10 files exist.'
- assert statepoint[0].endswith('binary') or statepoint[0].endswith('h5'),\
- 'Statepoint.10 file is not a binary or hdf5 file.'
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
+ def _test_output_created(self):
+ """Make sure statepoint files have been created."""
+ sps = ('statepoint.02.*', 'statepoint.04.*', 'statepoint.06.*',
+ 'statepoint.08.*', 'statepoint.10.*')
+ for sp in sps:
+ self._sp_name = sp
+ TestHarness._test_output_created(self)
-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_statepoints_exist()
- test_results()
- finally:
- teardown()
+ harness = StatepointTestHarness()
+ harness.execute_test()
diff --git a/tests/test_statepoint_restart/results.py b/tests/test_statepoint_restart/results.py
deleted file mode 100644
index 1341d67544..0000000000
--- a/tests/test_statepoint_restart/results.py
+++ /dev/null
@@ -1,45 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-import numpy as np
-
-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.07.binary')
-
-sp.read_results()
-
-# extract tally results and convert to vector
-tally5 = sp._tallies[5]
-results5 = np.zeros((tally5._sum.size + tally5._sum.size, ))
-results5[0::2] = tally5._sum.ravel()
-results5[1::2] = tally5._sum_sq.ravel()
-
-tally10 = sp._tallies[10]
-results10 = np.zeros((tally10._sum.size + tally10._sum.size, ))
-results10[0::2] = tally10._sum.ravel()
-results10[1::2] = tally10._sum_sq.ravel()
-
-# 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 tally results
-outstr += 'tally 1:\n'
-for item in results10:
- outstr += "{0:12.6E}\n".format(item)
-outstr += 'tally 2:\n'
-for item in results5:
- outstr += "{0:12.6E}\n".format(item)
-
-# write results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_statepoint_restart/test_statepoint_restart.py b/tests/test_statepoint_restart/test_statepoint_restart.py
index 294e8b812b..90dfb94833 100644
--- a/tests/test_statepoint_restart/test_statepoint_restart.py
+++ b/tests/test_statepoint_restart/test_statepoint_restart.py
@@ -1,140 +1,62 @@
#!/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 StatepointRestartTestHarness(TestHarness):
+ def execute_test(self):
+ self._parse_args()
+ try:
+ self._run_openmc()
+ self._test_output_created()
+ self._get_results()
+ self._compare_results()
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.07.*'))
- 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.'
+ self._run_openmc_restart1()
+ self._test_output_created()
+ self._get_results()
+ self._compare_results()
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.07.*'))
- 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, 'Initial test results do not agree.'
+ self._run_openmc_restart2()
+ self._test_output_created()
+ self._get_results()
+ self._compare_results()
+ finally:
+ self._cleanup()
-def test_restart_form1():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.07.*'))
- if opts.mpi_exec != '':
- proc = Popen([opts.mpi_exec, '-np', opts.mpi_np, opts.exe,
- '-r', statepoint[0], cwd], stderr=STDOUT, stdout=PIPE)
- else:
- proc = Popen([opts.exe, '-r', statepoint[0], cwd], stderr=STDOUT, stdout=PIPE)
- print(proc.communicate()[0])
- returncode = proc.returncode
- assert returncode == 0, 'OpenMC restart 1 did not exit successfully.'
-def test_created_statepoint_form1():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.07.*'))
- 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.'
+ def _run_openmc_restart1(self):
+ statepoint = glob.glob(os.path.join(os.getcwd(), self._sp_name))
-def test_results_form1():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.07.*'))
- 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, 'Restart 1 test results do not agree.'
+ if self._opts.mpi_exec != '':
+ proc = Popen([self._opts.mpi_exec, '-np', self._opts.mpi_np,
+ self._opts.exe, '-r', statepoint[0], os.getcwd()],
+ stderr=STDOUT, stdout=PIPE)
+ else:
+ proc = Popen([self._opts.exe, '-r', statepoint[0], os.getcwd()],
+ stderr=STDOUT, stdout=PIPE)
+ print(proc.communicate()[0])
+ returncode = proc.returncode
+ assert returncode == 0, 'OpenMC did not exit successfully.'
-def test_restart_form2():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.07.*'))
- if opts.mpi_exec != '':
- proc = Popen([opts.mpi_exec, '-np', opts.mpi_np, opts.exe,
- '--restart', statepoint[0], cwd], stderr=STDOUT, stdout=PIPE)
- else:
- proc = Popen([opts.exe, '--restart', statepoint[0], cwd], stderr=STDOUT, stdout=PIPE)
- print(proc.communicate()[0])
- returncode = proc.returncode
- assert returncode == 0, 'OpenMC restart 2 did not exit successfully.'
-def test_created_statepoint_form2():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.07.*'))
- 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.'
+ def _run_openmc_restart2(self):
+ statepoint = glob.glob(os.path.join(os.getcwd(), self._sp_name))
-def test_results_form2():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.07.*'))
- 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, 'Restart 2 test results do not agree.'
+ if self._opts.mpi_exec != '':
+ proc = Popen([self._opts.mpi_exec, '-np', self._opts.mpi_np,
+ self._opts.exe, '--restart', statepoint[0],
+ os.getcwd()], stderr=STDOUT, stdout=PIPE)
+ else:
+ proc = Popen([self._opts.exe, '--restart', statepoint[0],
+ os.getcwd()], stderr=STDOUT, stdout=PIPE)
+ print(proc.communicate()[0])
+ returncode = proc.returncode
+ assert returncode == 0, 'OpenMC did not exit successfully.'
-def test_restart_serial():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.07.*'))
- proc = Popen([opts.exe, '--restart', statepoint[0], cwd], stderr=STDOUT, stdout=PIPE)
- print(proc.communicate()[0])
- returncode = proc.returncode
- assert returncode == 0, 'OpenMC restart serial did not exit successfully.'
-
-def test_created_statepoint_serial():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.07.*'))
- 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.'
-
-def test_results_serial():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.07.*'))
- 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, 'Restart serial test results do not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.07.*'))
- 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_created_statepoint()
- test_results()
- test_restart_form1()
- test_created_statepoint_form1()
- test_results_form1()
- test_restart_form2()
- test_created_statepoint_form2()
- test_results_form2()
- test_restart_serial()
- test_created_statepoint_serial()
- test_results_serial()
- finally:
- teardown()
+ harness = StatepointRestartTestHarness('statepoint.07.*', True)
+ harness.execute_test()
diff --git a/tests/test_statepoint_sourcesep/results.py b/tests/test_statepoint_sourcesep/results.py
deleted file mode 100644
index fc1b491c6c..0000000000
--- a/tests/test_statepoint_sourcesep/results.py
+++ /dev/null
@@ -1,25 +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.10.binary')
-
-sp.read_results()
-
-# 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 results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_statepoint_sourcesep/test_statepoint_sourcesep.py b/tests/test_statepoint_sourcesep/test_statepoint_sourcesep.py
index b79743ae98..5929865ded 100644
--- a/tests/test_statepoint_sourcesep/test_statepoint_sourcesep.py
+++ b/tests/test_statepoint_sourcesep/test_statepoint_sourcesep.py
@@ -1,65 +1,22 @@
#!/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.* and source* have been created."""
+ TestHarness._test_output_created(self)
+ source = glob.glob(os.path.join(os.getcwd(), 'source.*'))
+ assert len(source) == 1, 'Either multiple or no source files ' \
+ 'exist.'
+ assert source[0].endswith('binary') \
+ or source[0].endswith('h5'), \
+ 'Source file is not a binary or hdf5 file.'
-def test_statepoint_exists():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
- source = glob.glob(os.path.join(cwd, 'source.10.*'))
- assert len(source) == 1, 'Either multiple or no source files exist.'
- assert source[0].endswith('binary') or source[0].endswith('h5'),\
- 'Source file is not a binary or hdf5 file.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- output += glob.glob(os.path.join(cwd, 'source.10.*'))
- 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 = TestHarness('statepoint.10.*')
+ harness.execute_test()
diff --git a/tests/test_survival_biasing/results.py b/tests/test_survival_biasing/results.py
deleted file mode 100644
index fc1b491c6c..0000000000
--- a/tests/test_survival_biasing/results.py
+++ /dev/null
@@ -1,25 +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.10.binary')
-
-sp.read_results()
-
-# 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 results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_survival_biasing/test_survival_biasing.py b/tests/test_survival_biasing/test_survival_biasing.py
index ab227e2ba3..390e6d832e 100644
--- a/tests/test_survival_biasing/test_survival_biasing.py
+++ b/tests/test_survival_biasing/test_survival_biasing.py
@@ -1,60 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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_created_statepoint()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*')
+ harness.execute_test()
diff --git a/tests/test_tally_assumesep/results.py b/tests/test_tally_assumesep/results.py
deleted file mode 100644
index f04df3a018..0000000000
--- a/tests/test_tally_assumesep/results.py
+++ /dev/null
@@ -1,53 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-import numpy as np
-
-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.10.binary')
-
-sp.read_results()
-
-# extract tally results and convert to vector
-tally1 = sp._tallies[1]
-results1 = np.zeros((tally1._sum.size + tally1._sum.size, ))
-results1[0::2] = tally1._sum.ravel()
-results1[1::2] = tally1._sum_sq.ravel()
-
-tally2 = sp._tallies[2]
-results2 = np.zeros((tally2._sum.size + tally2._sum.size, ))
-results2[0::2] = tally2._sum.ravel()
-results2[1::2] = tally2._sum_sq.ravel()
-
-tally3 = sp._tallies[3]
-results3 = np.zeros((tally3._sum.size + tally3._sum.size, ))
-results3[0::2] = tally3._sum.ravel()
-results3[1::2] = tally3._sum_sq.ravel()
-
-# 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 tally results
-outstr += 'tally 1:\n'
-for item in results1:
- outstr += "{0:12.6E}\n".format(item)
-outstr += 'tally 2:\n'
-for item in results2:
- outstr += "{0:12.6E}\n".format(item)
-outstr += 'tally 3:\n'
-for item in results3:
- outstr += "{0:12.6E}\n".format(item)
-
-# write results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_tally_assumesep/test_tally_assumesep.py b/tests/test_tally_assumesep/test_tally_assumesep.py
index 0130cd7a06..8f3b0785a8 100644
--- a/tests/test_tally_assumesep/test_tally_assumesep.py
+++ b/tests/test_tally_assumesep/test_tally_assumesep.py
@@ -1,65 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_output_exists():
- assert os.path.exists(os.path.join(cwd, 'tallies.out')), 'Tally output file does not exist.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- output.append(os.path.join(cwd, 'tallies.out'))
- 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_created_statepoint()
- test_output_exists()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*', True)
+ harness.execute_test()
diff --git a/tests/test_tally_nuclides/results.py b/tests/test_tally_nuclides/results.py
deleted file mode 100644
index edbebc1266..0000000000
--- a/tests/test_tally_nuclides/results.py
+++ /dev/null
@@ -1,44 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-import numpy as np
-
-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.10.binary')
-
-sp.read_results()
-
-# extract tally results and convert to vector
-tally1 = sp._tallies[1]
-results1 = np.zeros((tally1._sum.size + tally1._sum.size, ))
-results1[0::2] = tally1._sum.ravel()
-results1[1::2] = tally1._sum_sq.ravel()
-
-tally2 = sp._tallies[2]
-results2 = np.zeros((tally2._sum.size + tally2._sum.size, ))
-results2[0::2] = tally2._sum.ravel()
-results2[1::2] = tally2._sum_sq.ravel()
-
-results = np.concatenate((results1.flatten(), results2.flatten()))
-
-# 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 tally results
-outstr += 'tallies:\n'
-for item in results:
- outstr += "{0:12.6E}\n".format(item)
-
-# write results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_tally_nuclides/results_true.dat b/tests/test_tally_nuclides/results_true.dat
index cfcee45ecc..b8e903049b 100644
--- a/tests/test_tally_nuclides/results_true.dat
+++ b/tests/test_tally_nuclides/results_true.dat
@@ -1,6 +1,6 @@
k-combined:
9.851180E-01 1.587642E-02
-tallies:
+tally 1:
7.516940E+00
1.149356E+01
1.700884E+00
@@ -17,6 +17,7 @@ tallies:
5.385674E-01
5.816056E+00
6.901370E+00
+tally 2:
7.516940E+00
1.149356E+01
1.700884E+00
diff --git a/tests/test_tally_nuclides/test_tally_nuclides.py b/tests/test_tally_nuclides/test_tally_nuclides.py
index ab227e2ba3..8f3b0785a8 100644
--- a/tests/test_tally_nuclides/test_tally_nuclides.py
+++ b/tests/test_tally_nuclides/test_tally_nuclides.py
@@ -1,60 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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_created_statepoint()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*', True)
+ harness.execute_test()
diff --git a/tests/test_trace/results.py b/tests/test_trace/results.py
deleted file mode 100644
index fc1b491c6c..0000000000
--- a/tests/test_trace/results.py
+++ /dev/null
@@ -1,25 +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.10.binary')
-
-sp.read_results()
-
-# 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 results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_trace/test_trace.py b/tests/test_trace/test_trace.py
index bfa5163b89..390e6d832e 100644
--- a/tests/test_trace/test_trace.py
+++ b/tests/test_trace/test_trace.py
@@ -1,62 +1,10 @@
#!/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 TestHarness
-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)
- stdout = proc.communicate()[0]
- print(stdout)
- returncode = proc.returncode
- assert returncode == 0, 'OpenMC did not exit successfully.'
- assert stdout.find(b'Simulating Particle 453') != -1
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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_created_statepoint()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*')
+ harness.execute_test()
diff --git a/tests/test_track_output/geometry.xml b/tests/test_track_output/geometry.xml
index dc20bd1b88..3b5a493115 100644
--- a/tests/test_track_output/geometry.xml
+++ b/tests/test_track_output/geometry.xml
@@ -35,7 +35,7 @@
-
+
-12.2682 -12.2682
1.63576 1.63576
@@ -59,7 +59,7 @@
|
-
+
-12.2682 -12.2682
1.63576 1.63576
@@ -86,7 +86,7 @@
|
-
+
-12.2682 -12.2682
1.63576 1.63576
@@ -115,7 +115,7 @@
-
+
-12.2682 -12.2682
1.63576 1.63576
@@ -139,7 +139,7 @@
|
-
+
-12.2682 -12.2682
1.63576 1.63576
@@ -166,7 +166,7 @@
|
-
+
-12.2682 -12.2682
1.63576 1.63576
@@ -193,7 +193,7 @@
|
-
+
-12.2682 -12.2682
1.63576 1.63576
@@ -221,7 +221,7 @@
-
+
-12.2682 -12.2682
1.63576 1.63576
@@ -248,7 +248,7 @@
|
-
+
-12.2682 -12.2682
1.63576 1.63576
@@ -284,7 +284,7 @@
-
+
-85.8774 -85.8774
24.5364 24.5364
diff --git a/tests/test_track_output/results.py b/tests/test_track_output/results.py
deleted file mode 100644
index dedc07873f..0000000000
--- a/tests/test_track_output/results.py
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/usr/bin/env python
-
-import os
-import sys
-import glob
-import shutil
-from subprocess import call
-
-# If vtk python module is not available, we can't run track.py so skip this
-# test
-cwd = os.getcwd()
-try:
- import vtk
-except ImportError:
- print('----------------Skipping test-------------')
- shutil.copy('results_true.dat', 'results_test.dat')
- exit()
-
-# Run track processing script
-call(['../../scripts/openmc-track-to-vtk', '-o', 'poly'] +
- glob.glob(''.join((cwd, '/track*'))))
-poly = ''.join((cwd, '/poly.pvtp'))
-assert os.path.isfile(poly), 'poly.pvtp file not found.'
-shutil.copy('poly.pvtp', 'results_test.dat')
diff --git a/tests/test_track_output/test_track_output.py b/tests/test_track_output/test_track_output.py
index 089efbfb22..e134ae6cf7 100644
--- a/tests/test_track_output/test_track_output.py
+++ b/tests/test_track_output/test_track_output.py
@@ -1,64 +1,54 @@
#!/usr/bin/env python
-import os
+import shutil
import sys
-from subprocess import Popen, STDOUT, PIPE, call
-import filecmp
-import glob
-from optparse import OptionParser
-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()
+sys.path.insert(0, '..')
+from testing_harness import *
-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.'
-def test_created_outputs():
- outputs = [glob.glob(''.join((cwd, '/track_1_1_1.*')))]
- outputs.append(glob.glob(''.join((cwd, '/track_1_1_2.*'))))
- for files in outputs:
- assert len(files) == 1, 'Multiple or no track files detected.'
- assert files[0].endswith('binary') or files[0].endswith('h5'),\
- 'Track files not a binary or hdf5 file'
+class TrackTestHarness(TestHarness):
+ def _test_output_created(self):
+ """Make sure statepoint.* and track* have been created."""
+ TestHarness._test_output_created(self)
-def test_outputs():
- call([sys.executable, 'results.py'])
- compare = filecmp.cmp('results_test.dat', 'results_true.dat')
- if not compare:
- os.rename('results_test.dat', 'results_error.dat')
- assert compare, 'Results to not agree'
+ outputs = [glob.glob(''.join((os.getcwd(), '/track_1_1_1.*')))]
+ outputs.append(glob.glob(''.join((os.getcwd(), '/track_1_1_2.*'))))
+ for files in outputs:
+ assert len(files) == 1, 'Multiple or no track files detected.'
+ assert files[0].endswith('binary') or files[0].endswith('h5'),\
+ 'Track files are not binary or hdf5 files'
+
+
+ def _get_results(self):
+ """Digest info and create a simpler ASCII file."""
+ # Run the track-to-vtk conversion script.
+ call(['../../scripts/openmc-track-to-vtk', '-o', 'poly'] +
+ glob.glob(''.join((os.getcwd(), '/track*'))))
+
+ # Make sure the vtk file was created then copy it to results.
+ poly = ''.join((os.getcwd(), '/poly.pvtp'))
+ assert os.path.isfile(poly), 'poly.pvtp file not found.'
+ shutil.copy('poly.pvtp', 'results_test.dat')
+
+
+ def _cleanup(self):
+ TestHarness._cleanup(self)
+ output = glob.glob(os.path.join(os.getcwd(), 'track*'))
+ output += glob.glob(os.path.join(os.getcwd(), 'poly*'))
+ for f in output:
+ if os.path.exists(f):
+ os.remove(f)
-def teardown():
- temp_files = glob.glob('statepoint*')
- temp_files += glob.glob('track*')
- temp_files += glob.glob('*.vtp')
- temp_files += glob.glob('*.pvtp')
- temp_files = temp_files + ['results_test.dat']
- for f in temp_files:
- 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
+ # If vtk python module is not available, we can't run track.py so skip this
+ # test.
try:
- test_run()
- test_created_outputs()
- test_outputs()
- finally:
- teardown()
+ import vtk
+ except ImportError:
+ print('----------------Skipping test-------------')
+ shutil.copy('results_true.dat', 'results_test.dat')
+ exit()
+ harness = TrackTestHarness('statepoint.2.*')
+ harness.execute_test()
diff --git a/tests/test_translation/results.py b/tests/test_translation/results.py
deleted file mode 100644
index fc1b491c6c..0000000000
--- a/tests/test_translation/results.py
+++ /dev/null
@@ -1,25 +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.10.binary')
-
-sp.read_results()
-
-# 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 results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_translation/test_translation.py b/tests/test_translation/test_translation.py
index ab227e2ba3..390e6d832e 100644
--- a/tests/test_translation/test_translation.py
+++ b/tests/test_translation/test_translation.py
@@ -1,60 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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_created_statepoint()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*')
+ harness.execute_test()
diff --git a/tests/test_trigger_batch_interval/results.py b/tests/test_trigger_batch_interval/results.py
deleted file mode 100644
index 8710a976c3..0000000000
--- a/tests/test_trigger_batch_interval/results.py
+++ /dev/null
@@ -1,42 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-import numpy as np
-
-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.19.binary')
-
-sp.read_results()
-
-# extract tally results and convert to vector
-sum1 = sp._tallies[1]._sum
-sum_sq1 = sp._tallies[1]._sum_sq
-results1 = np.concatenate([sum1, sum_sq1])
-
-sum2 = sp._tallies[2]._sum
-sum_sq2 = sp._tallies[2]._sum_sq
-results2 = np.concatenate([sum2, sum_sq2])
-
-results = np.concatenate([results1.flatten(), results2.flatten()])
-
-# 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 tally results
-outstr += 'tallies:\n'
-for item in results:
- outstr += "{0:12.6E}\n".format(item)
-
-# write results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_trigger_batch_interval/results_true.dat b/tests/test_trigger_batch_interval/results_true.dat
index 95bbef6f64..46e3d115ae 100644
--- a/tests/test_trigger_batch_interval/results_true.dat
+++ b/tests/test_trigger_batch_interval/results_true.dat
@@ -1,27 +1,28 @@
k-combined:
9.851940E-01 4.283951E-03
-tallies:
+tally 1:
1.972289E+01
-4.489781E+00
-4.356175E+00
-1.523311E+01
-1.972289E+01
-4.489781E+00
-4.356175E+00
-1.523311E+01
-2.779778E+01
-1.440247E+00
-1.355797E+00
-1.658397E+01
2.779778E+01
+4.489781E+00
1.440247E+00
+4.356175E+00
1.355797E+00
+1.523311E+01
1.658397E+01
1.972289E+01
-4.489781E+00
-4.356175E+00
-1.523311E+01
2.779778E+01
+4.489781E+00
1.440247E+00
+4.356175E+00
1.355797E+00
+1.523311E+01
+1.658397E+01
+tally 2:
+1.972289E+01
+2.779778E+01
+4.489781E+00
+1.440247E+00
+4.356175E+00
+1.355797E+00
+1.523311E+01
1.658397E+01
diff --git a/tests/test_trigger_batch_interval/test_trigger_batch_interval.py b/tests/test_trigger_batch_interval/test_trigger_batch_interval.py
index c82edb5b5a..219089d131 100644
--- a/tests/test_trigger_batch_interval/test_trigger_batch_interval.py
+++ b/tests/test_trigger_batch_interval/test_trigger_batch_interval.py
@@ -1,60 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.19.*'))
- 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.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.19.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.19.*'))
- 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_created_statepoint()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.19.*', True)
+ harness.execute_test()
diff --git a/tests/test_trigger_no_batch_interval/results.py b/tests/test_trigger_no_batch_interval/results.py
deleted file mode 100644
index 993296a576..0000000000
--- a/tests/test_trigger_no_batch_interval/results.py
+++ /dev/null
@@ -1,41 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-import numpy as np
-
-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.19.binary')
-sp.read_results()
-
-# extract tally results and convert to vector
-sum1 = sp._tallies[1]._sum
-sum_sq1 = sp._tallies[1]._sum_sq
-results1 = np.concatenate([sum1, sum_sq1])
-
-sum2 = sp._tallies[2]._sum
-sum_sq2 = sp._tallies[2]._sum_sq
-results2 = np.concatenate([sum2, sum_sq2])
-
-results = np.concatenate([results1.flatten(), results2.flatten()])
-
-# 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 tally results
-outstr += 'tallies:\n'
-for item in results:
- outstr += "{0:12.6E}\n".format(item)
-
-# write results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_trigger_no_batch_interval/results_true.dat b/tests/test_trigger_no_batch_interval/results_true.dat
index 95bbef6f64..46e3d115ae 100644
--- a/tests/test_trigger_no_batch_interval/results_true.dat
+++ b/tests/test_trigger_no_batch_interval/results_true.dat
@@ -1,27 +1,28 @@
k-combined:
9.851940E-01 4.283951E-03
-tallies:
+tally 1:
1.972289E+01
-4.489781E+00
-4.356175E+00
-1.523311E+01
-1.972289E+01
-4.489781E+00
-4.356175E+00
-1.523311E+01
-2.779778E+01
-1.440247E+00
-1.355797E+00
-1.658397E+01
2.779778E+01
+4.489781E+00
1.440247E+00
+4.356175E+00
1.355797E+00
+1.523311E+01
1.658397E+01
1.972289E+01
-4.489781E+00
-4.356175E+00
-1.523311E+01
2.779778E+01
+4.489781E+00
1.440247E+00
+4.356175E+00
1.355797E+00
+1.523311E+01
+1.658397E+01
+tally 2:
+1.972289E+01
+2.779778E+01
+4.489781E+00
+1.440247E+00
+4.356175E+00
+1.355797E+00
+1.523311E+01
1.658397E+01
diff --git a/tests/test_trigger_no_batch_interval/test_trigger_no_batch_interval.py b/tests/test_trigger_no_batch_interval/test_trigger_no_batch_interval.py
index c82edb5b5a..219089d131 100644
--- a/tests/test_trigger_no_batch_interval/test_trigger_no_batch_interval.py
+++ b/tests/test_trigger_no_batch_interval/test_trigger_no_batch_interval.py
@@ -1,60 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.19.*'))
- 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.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.19.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.19.*'))
- 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_created_statepoint()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.19.*', True)
+ harness.execute_test()
diff --git a/tests/test_trigger_no_status/results.py b/tests/test_trigger_no_status/results.py
deleted file mode 100644
index c371ffb97e..0000000000
--- a/tests/test_trigger_no_status/results.py
+++ /dev/null
@@ -1,41 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-import numpy as np
-
-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.10.binary')
-sp.read_results()
-
-# extract tally results and convert to vector
-sum1 = sp._tallies[1]._sum
-sum_sq1 = sp._tallies[1]._sum_sq
-results1 = np.concatenate([sum1, sum_sq1])
-
-sum2 = sp._tallies[2]._sum
-sum_sq2 = sp._tallies[2]._sum_sq
-results2 = np.concatenate([sum2, sum_sq2])
-
-results = np.concatenate([results1.flatten(), results2.flatten()])
-
-# 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 tally results
-outstr += 'tallies:\n'
-for item in results:
- outstr += "{0:12.6E}\n".format(item)
-
-# write results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_trigger_no_status/results_true.dat b/tests/test_trigger_no_status/results_true.dat
index 4ab52de535..b9dc78dd03 100644
--- a/tests/test_trigger_no_status/results_true.dat
+++ b/tests/test_trigger_no_status/results_true.dat
@@ -1,27 +1,28 @@
k-combined:
9.809303E-01 7.264435E-03
-tallies:
+tally 1:
7.031241E+00
-1.599216E+00
-1.550710E+00
-5.432025E+00
-7.031241E+00
-1.599216E+00
-1.550710E+00
-5.432025E+00
-9.892232E+00
-5.115987E-01
-4.810241E-01
-5.904811E+00
9.892232E+00
+1.599216E+00
5.115987E-01
+1.550710E+00
4.810241E-01
+5.432025E+00
5.904811E+00
7.031241E+00
-1.599216E+00
-1.550710E+00
-5.432025E+00
9.892232E+00
+1.599216E+00
5.115987E-01
+1.550710E+00
4.810241E-01
+5.432025E+00
+5.904811E+00
+tally 2:
+7.031241E+00
+9.892232E+00
+1.599216E+00
+5.115987E-01
+1.550710E+00
+4.810241E-01
+5.432025E+00
5.904811E+00
diff --git a/tests/test_trigger_no_status/test_trigger_no_status.py b/tests/test_trigger_no_status/test_trigger_no_status.py
index ab227e2ba3..8f3b0785a8 100644
--- a/tests/test_trigger_no_status/test_trigger_no_status.py
+++ b/tests/test_trigger_no_status/test_trigger_no_status.py
@@ -1,60 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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_created_statepoint()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*', True)
+ harness.execute_test()
diff --git a/tests/test_trigger_tallies/results.py b/tests/test_trigger_tallies/results.py
deleted file mode 100644
index 1dc1940795..0000000000
--- a/tests/test_trigger_tallies/results.py
+++ /dev/null
@@ -1,42 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-import numpy as np
-
-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.15.binary')
-sp.read_results()
-
-# extract tally results and convert to vector
-sum1 = sp._tallies[1]._sum
-sum_sq1 = sp._tallies[1]._sum_sq
-results1 = np.concatenate([sum1, sum_sq1])
-
-sum2 = sp._tallies[2]._sum
-sum_sq2 = sp._tallies[2]._sum_sq
-results2 = np.concatenate([sum2, sum_sq2])
-
-results = np.concatenate([results1.flatten(), results2.flatten()])
-
-# 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 tally results
-outstr += 'tallies:\n'
-for item in results:
- outstr += "{0:12.6E}\n".format(item)
-
-# write results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
-
diff --git a/tests/test_trigger_tallies/results_true.dat b/tests/test_trigger_tallies/results_true.dat
index 86c3cfa035..418856e065 100644
--- a/tests/test_trigger_tallies/results_true.dat
+++ b/tests/test_trigger_tallies/results_true.dat
@@ -1,27 +1,28 @@
k-combined:
9.824135E-01 6.844128E-03
-tallies:
+tally 1:
1.408810E+01
-3.199600E+00
-3.102648E+00
-1.088850E+01
-1.408810E+01
-3.199600E+00
-3.102648E+00
-1.088850E+01
-1.985836E+01
-1.024050E+00
-9.629173E-01
-1.186391E+01
1.985836E+01
+3.199600E+00
1.024050E+00
+3.102648E+00
9.629173E-01
+1.088850E+01
1.186391E+01
1.408810E+01
-3.199600E+00
-3.102648E+00
-1.088850E+01
1.985836E+01
+3.199600E+00
1.024050E+00
+3.102648E+00
9.629173E-01
+1.088850E+01
+1.186391E+01
+tally 2:
+1.408810E+01
+1.985836E+01
+3.199600E+00
+1.024050E+00
+3.102648E+00
+9.629173E-01
+1.088850E+01
1.186391E+01
diff --git a/tests/test_trigger_tallies/test_trigger_tallies.py b/tests/test_trigger_tallies/test_trigger_tallies.py
index 940d5dc176..a77e996e50 100644
--- a/tests/test_trigger_tallies/test_trigger_tallies.py
+++ b/tests/test_trigger_tallies/test_trigger_tallies.py
@@ -1,60 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.15.*'))
- 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.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.15.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.15.*'))
- 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_created_statepoint()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.15.*', True)
+ harness.execute_test()
diff --git a/tests/test_uniform_fs/results.py b/tests/test_uniform_fs/results.py
deleted file mode 100644
index fc1b491c6c..0000000000
--- a/tests/test_uniform_fs/results.py
+++ /dev/null
@@ -1,25 +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.10.binary')
-
-sp.read_results()
-
-# 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 results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_uniform_fs/test_uniform_fs.py b/tests/test_uniform_fs/test_uniform_fs.py
index ab227e2ba3..390e6d832e 100644
--- a/tests/test_uniform_fs/test_uniform_fs.py
+++ b/tests/test_uniform_fs/test_uniform_fs.py
@@ -1,60 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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_created_statepoint()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*')
+ harness.execute_test()
diff --git a/tests/test_union_energy_grids/results.py b/tests/test_union_energy_grids/results.py
deleted file mode 100644
index 234e69f333..0000000000
--- a/tests/test_union_energy_grids/results.py
+++ /dev/null
@@ -1,25 +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:
- print(sys.argv)
- sp = StatePoint(sys.argv[1])
-else:
- sp = StatePoint('statepoint.10.binary')
-sp.read_results()
-
-# 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 results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_union_energy_grids/test_union_energy_grids.py b/tests/test_union_energy_grids/test_union_energy_grids.py
index ab227e2ba3..390e6d832e 100644
--- a/tests/test_union_energy_grids/test_union_energy_grids.py
+++ b/tests/test_union_energy_grids/test_union_energy_grids.py
@@ -1,60 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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_created_statepoint()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*')
+ harness.execute_test()
diff --git a/tests/test_universe/results.py b/tests/test_universe/results.py
deleted file mode 100644
index fc1b491c6c..0000000000
--- a/tests/test_universe/results.py
+++ /dev/null
@@ -1,25 +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.10.binary')
-
-sp.read_results()
-
-# 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 results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_universe/test_universe.py b/tests/test_universe/test_universe.py
index ab227e2ba3..390e6d832e 100644
--- a/tests/test_universe/test_universe.py
+++ b/tests/test_universe/test_universe.py
@@ -1,60 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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_created_statepoint()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*')
+ harness.execute_test()
diff --git a/tests/test_void/results.py b/tests/test_void/results.py
deleted file mode 100644
index fc1b491c6c..0000000000
--- a/tests/test_void/results.py
+++ /dev/null
@@ -1,25 +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.10.binary')
-
-sp.read_results()
-
-# 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 results to file
-with open('results_test.dat','w') as fh:
- fh.write(outstr)
diff --git a/tests/test_void/test_void.py b/tests/test_void/test_void.py
index ab227e2ba3..390e6d832e 100644
--- a/tests/test_void/test_void.py
+++ b/tests/test_void/test_void.py
@@ -1,60 +1,10 @@
#!/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 TestHarness
-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.'
-
-def test_created_statepoint():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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.'
-
-def test_results():
- statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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 not agree.'
-
-def teardown():
- output = glob.glob(os.path.join(cwd, 'statepoint.10.*'))
- 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_created_statepoint()
- test_results()
- finally:
- teardown()
+ harness = TestHarness('statepoint.10.*')
+ harness.execute_test()
diff --git a/tests/test_harness.py b/tests/testing_harness.py
similarity index 100%
rename from tests/test_harness.py
rename to tests/testing_harness.py