2013-02-01 15:22:32 -05:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
2016-01-19 12:32:22 -06:00
|
|
|
import glob
|
|
|
|
|
import hashlib
|
2015-10-02 23:19:00 -04:00
|
|
|
import os
|
2015-06-04 13:53:42 +07:00
|
|
|
import sys
|
2015-10-02 23:19:00 -04:00
|
|
|
sys.path.insert(0, os.pardir)
|
2016-01-19 12:32:22 -06:00
|
|
|
from testing_harness import TestHarness
|
|
|
|
|
|
|
|
|
|
import h5py
|
|
|
|
|
|
2016-04-25 09:04:52 -05:00
|
|
|
import openmc
|
2016-01-19 12:32:22 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class PlotTestHarness(TestHarness):
|
|
|
|
|
"""Specialized TestHarness for running OpenMC plotting tests."""
|
|
|
|
|
def __init__(self, plot_names):
|
2017-04-07 10:25:24 -05:00
|
|
|
super(PlotTestHarness, self).__init__(None)
|
2016-01-19 12:32:22 -06:00
|
|
|
self._plot_names = plot_names
|
|
|
|
|
|
|
|
|
|
def _run_openmc(self):
|
2016-04-25 10:37:06 -05:00
|
|
|
returncode = openmc.plot_geometry(openmc_exec=self._opts.exe)
|
2016-01-19 12:32:22 -06:00
|
|
|
assert returncode == 0, 'OpenMC did not exit successfully.'
|
|
|
|
|
|
|
|
|
|
def _test_output_created(self):
|
|
|
|
|
"""Make sure *.ppm has been created."""
|
|
|
|
|
for fname in self._plot_names:
|
|
|
|
|
assert os.path.exists(os.path.join(os.getcwd(), fname)), \
|
|
|
|
|
'Plot output file does not exist.'
|
|
|
|
|
|
|
|
|
|
def _cleanup(self):
|
|
|
|
|
super(PlotTestHarness, self)._cleanup()
|
|
|
|
|
for fname in self._plot_names:
|
|
|
|
|
path = os.path.join(os.getcwd(), fname)
|
|
|
|
|
if os.path.exists(path):
|
2017-02-20 12:12:18 -06:00
|
|
|
os.remove(path)
|
2016-01-19 12:32:22 -06:00
|
|
|
|
|
|
|
|
def _get_results(self):
|
|
|
|
|
"""Return a string hash of the plot files."""
|
|
|
|
|
outstr = bytes()
|
|
|
|
|
|
2017-02-20 12:12:18 -06:00
|
|
|
for fname in self._plot_names:
|
|
|
|
|
if fname.endswith('.ppm'):
|
|
|
|
|
# Add PPM output to results
|
|
|
|
|
with open(fname, 'rb') as fh:
|
|
|
|
|
outstr += fh.read()
|
|
|
|
|
elif fname.endswith('.h5'):
|
|
|
|
|
# Add voxel data to results
|
|
|
|
|
with h5py.File(fname, 'r') as fh:
|
|
|
|
|
outstr += fh.attrs['filetype']
|
|
|
|
|
outstr += fh.attrs['num_voxels'].tostring()
|
|
|
|
|
outstr += fh.attrs['lower_left'].tostring()
|
|
|
|
|
outstr += fh.attrs['voxel_width'].tostring()
|
|
|
|
|
outstr += fh['data'].value.tostring()
|
2016-01-19 12:32:22 -06:00
|
|
|
|
|
|
|
|
# Hash the information and return.
|
|
|
|
|
sha512 = hashlib.sha512()
|
|
|
|
|
sha512.update(outstr)
|
|
|
|
|
outstr = sha512.hexdigest()
|
|
|
|
|
|
|
|
|
|
return outstr
|
2015-06-25 00:10:07 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2017-02-20 12:12:18 -06:00
|
|
|
harness = PlotTestHarness(('plot_1.ppm', 'plot_2.ppm', 'plot_3.ppm',
|
|
|
|
|
'plot_4.h5'))
|
2015-06-29 18:50:53 -06:00
|
|
|
harness.main()
|