From a5f2d678921c39d640454b4f164d32522c7b6f22 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Tue, 19 Jan 2016 12:32:22 -0600 Subject: [PATCH] Add a voxel plot to test_plot --- tests/test_plot/plots.xml | 6 +++ tests/test_plot/results_true.dat | 2 +- tests/test_plot/test_plot.py | 64 +++++++++++++++++++++++++++++++- tests/testing_harness.py | 43 --------------------- 4 files changed, 69 insertions(+), 46 deletions(-) diff --git a/tests/test_plot/plots.xml b/tests/test_plot/plots.xml index e8848f6172..d5e03f598f 100644 --- a/tests/test_plot/plots.xml +++ b/tests/test_plot/plots.xml @@ -23,4 +23,10 @@ 0 0 0 + + 100 100 10 + 0. 0. 0. + 20 20 10 + + diff --git a/tests/test_plot/results_true.dat b/tests/test_plot/results_true.dat index 910e41a060..ba8a49226a 100644 --- a/tests/test_plot/results_true.dat +++ b/tests/test_plot/results_true.dat @@ -1 +1 @@ -f76183da6a581c17f9a1572e1f1573d784e3f2e3efa3e7a3bd8786991df7a086e0b5f7f1c6b00343fa61b601ec70ad619b5ff5d8120af32559b882ca57be6768 \ No newline at end of file +01ecda0f3820a49c8a41d8dc47d1e5c58767a04301621c2437231fcc04401ddea47b67d0529ca56a32d4d97b4f1416a2e0b6120d3bdc87d74a7e9889758a8808 \ No newline at end of file diff --git a/tests/test_plot/test_plot.py b/tests/test_plot/test_plot.py index d45479e256..62cea67df4 100644 --- a/tests/test_plot/test_plot.py +++ b/tests/test_plot/test_plot.py @@ -1,11 +1,71 @@ #!/usr/bin/env python +import glob +import hashlib import os import sys sys.path.insert(0, os.pardir) -from testing_harness import PlotTestHarness +from testing_harness import TestHarness + +import h5py + +from openmc import Executor + + +class PlotTestHarness(TestHarness): + """Specialized TestHarness for running OpenMC plotting tests.""" + def __init__(self, plot_names): + super(PlotTestHarness, self).__init__(None, False) + self._plot_names = plot_names + + def _run_openmc(self): + executor = Executor() + returncode = executor.plot_geometry(openmc_exec=self._opts.exe) + 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): + #os.remove(path) + pass + + def _get_results(self): + """Return a string hash of the plot files.""" + outstr = bytes() + + # Add PPM output to results + ppm_files = glob.glob(os.path.join(os.getcwd(), '*.ppm')) + for fname in sorted(ppm_files): + with open(fname, 'rb') as fh: + outstr += fh.read() + + # Add voxel data to results + voxel_files = glob.glob(os.path.join(os.getcwd(), '*.voxel')) + for fname in sorted(voxel_files): + with h5py.File(fname, 'r') as fh: + outstr += fh['filetype'].value + outstr += fh['num_voxels'].value.tobytes() + outstr += fh['lower_left'].value.tobytes() + outstr += fh['voxel_width'].value.tobytes() + outstr += fh['data'].value.tobytes() + + # Hash the information and return. + sha512 = hashlib.sha512() + sha512.update(outstr) + outstr = sha512.hexdigest() + + return outstr if __name__ == '__main__': - harness = PlotTestHarness(('1_plot.ppm', '2_plot.ppm', '3_plot.ppm')) + harness = PlotTestHarness(('1_plot.ppm', '2_plot.ppm', '3_plot.ppm', + '4_plot.voxel')) harness.main() diff --git a/tests/testing_harness.py b/tests/testing_harness.py index 190c702282..66cadfe633 100644 --- a/tests/testing_harness.py +++ b/tests/testing_harness.py @@ -152,49 +152,6 @@ class HashedTestHarness(TestHarness): return super(HashedTestHarness, self)._get_results(True) -class PlotTestHarness(TestHarness): - """Specialized TestHarness for running OpenMC plotting tests.""" - def __init__(self, plot_names): - super(PlotTestHarness, self).__init__(None, False) - self._plot_names = plot_names - - def _run_openmc(self): - executor = Executor() - returncode = executor.plot_geometry(openmc_exec=self._opts.exe) - 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() - output = glob.glob(os.path.join(os.getcwd(), '*.ppm')) - for f in output: - if os.path.exists(f): - os.remove(f) - - def _get_results(self): - """Return a string hash of the plot files.""" - # Find the plot files. - plot_files = glob.glob(os.path.join(os.getcwd(), '*.ppm')) - - # Read the plot files. - outstr = bytes() - for fname in sorted(plot_files): - with open(fname, 'rb') as fh: - outstr += fh.read() - - # Hash the information and return. - sha512 = hashlib.sha512() - sha512.update(outstr) - outstr = sha512.hexdigest() - - return outstr - - class CMFDTestHarness(TestHarness): """Specialized TestHarness for running OpenMC CMFD tests.""" def _get_results(self):