Improve _cleanup method for testing harness

This commit is contained in:
Paul Romano 2016-12-08 08:05:36 -06:00
parent 7e2eb1746e
commit 4cc44f9a50
18 changed files with 27 additions and 116 deletions

View file

@ -1 +1 @@
6bcc9cca24d42995bdff9bf9aca5e852c2dbca5cfb42a12ac637def9cf5cac227654182fc9cf9e17d07cf2e9af11fea832e3ae0eb7001cc09856f73d219664f9
25bfa163360c4c48a9f51c4cde33c4fb9080e472e11b11ad6d01452d90bcb57d123b95bb4ba6b92178e0c678a38e7d8fc136430e9c105b2be8d7243b5561c641

View file

@ -69,7 +69,6 @@ class AsymmetricLatticeTestHarness(PyAPITestHarness):
source = openmc.Source(space=openmc.stats.Box([-32, -32, 0], [32, 32, 32]))
source.space.only_fissionable = True
self._input_set.settings.source = source
self._input_set.settings.output = {'summary': True}
# Write input XML files
self._input_set.export()
@ -107,11 +106,6 @@ class AsymmetricLatticeTestHarness(PyAPITestHarness):
return outstr
def _cleanup(self):
super(AsymmetricLatticeTestHarness, self)._cleanup()
f = os.path.join(os.getcwd(), 'tallies.xml')
if os.path.exists(f): os.remove(f)
if __name__ == '__main__':
harness = AsymmetricLatticeTestHarness('statepoint.10.h5', True)

View file

@ -62,18 +62,12 @@ class CreateFissionNeutronsTestHarness(PyAPITestHarness):
# Write out tally data.
outstr = ''
t = sp.get_tally()
outstr += 'tally {0}:\n'.format(t.id)
outstr += 'sum = {0:12.6E}\n'.format(t.sum[0, 0, 0])
outstr += 'sum_sq = {0:12.6E}\n'.format(t.sum_sq[0, 0, 0])
outstr += 'tally {}:\n'.format(t.id)
outstr += 'sum = {:12.6E}\n'.format(t.sum[0, 0, 0])
outstr += 'sum_sq = {:12.6E}\n'.format(t.sum_sq[0, 0, 0])
return outstr
def _cleanup(self):
super(CreateFissionNeutronsTestHarness, self)._cleanup()
f = os.path.join(os.getcwd(), 'tallies.xml')
if os.path.exists(f):
os.remove(f)
if __name__ == '__main__':
harness = CreateFissionNeutronsTestHarness('statepoint.10.h5', True)

View file

@ -129,11 +129,6 @@ class DiffTallyTestHarness(PyAPITestHarness):
'std. dev.')
return df.to_csv(None, columns=cols, index=False, float_format='%.7e')
def _cleanup(self):
super(DiffTallyTestHarness, self)._cleanup()
f = os.path.join(os.getcwd(), 'tallies.xml')
if os.path.exists(f): os.remove(f)
if __name__ == '__main__':
harness = DiffTallyTestHarness('statepoint.3.h5', True)

View file

@ -66,18 +66,12 @@ class EnergyCutoffTestHarness(PyAPITestHarness):
# Write out tally data.
outstr = ''
t = sp.get_tally()
outstr += 'tally {0}:\n'.format(t.id)
outstr += 'sum = {0:12.6E}\n'.format(t.sum[0, 0, 0])
outstr += 'sum_sq = {0:12.6E}\n'.format(t.sum_sq[0, 0, 0])
outstr += 'tally {}:\n'.format(t.id)
outstr += 'sum = {:12.6E}\n'.format(t.sum[0, 0, 0])
outstr += 'sum_sq = {:12.6E}\n'.format(t.sum_sq[0, 0, 0])
return outstr
def _cleanup(self):
super(EnergyCutoffTestHarness, self)._cleanup()
f = os.path.join(os.getcwd(), 'tallies.xml')
if os.path.exists(f):
os.remove(f)
if __name__ == '__main__':
harness = EnergyCutoffTestHarness('statepoint.10.h5', True)

View file

@ -53,11 +53,6 @@ class FilterEnergyFunHarness(PyAPITestHarness):
# Output the tally in a Pandas DataFrame.
return br_tally.get_pandas_dataframe().to_string() + '\n'
def _cleanup(self):
super(FilterEnergyFunHarness, self)._cleanup()
f = os.path.join(os.getcwd(), 'tallies.xml')
if os.path.exists(f): os.remove(f)
if __name__ == '__main__':
harness = FilterEnergyFunHarness('statepoint.10.h5', True)

View file

@ -77,12 +77,7 @@ class FilterMeshTestHarness(HashedPyAPITestHarness):
self._input_set.tallies = tallies_file
super(FilterMeshTestHarness, self)._build_inputs()
def _cleanup(self):
super(FilterMeshTestHarness, self)._cleanup()
f = os.path.join(os.getcwd(), 'tallies.xml')
if os.path.exists(f): os.remove(f)
if __name__ == '__main__':
harness = FilterMeshTestHarness('statepoint.10.*', True)
harness = FilterMeshTestHarness('statepoint.10.h5', True)
harness.main()

View file

@ -82,12 +82,7 @@ class MGTalliesTestHarness(HashedPyAPITestHarness):
self._input_set.export()
def _cleanup(self):
super(MGTalliesTestHarness, self)._cleanup()
f = os.path.join(os.getcwd(), 'tallies.xml')
if os.path.exists(f): os.remove(f)
if __name__ == '__main__':
harness = MGTalliesTestHarness('statepoint.10.*', True, mg=True)
harness = MGTalliesTestHarness('statepoint.10.h5', True, mg=True)
harness.main()

View file

@ -71,12 +71,6 @@ class MGXSTestHarness(PyAPITestHarness):
return outstr
def _cleanup(self):
super(MGXSTestHarness, self)._cleanup()
f = os.path.join(os.getcwd(), 'tallies.xml')
if os.path.exists(f): os.remove(f)
if __name__ == '__main__':
harness = MGXSTestHarness('statepoint.10.*', True)
harness.main()

View file

@ -72,12 +72,7 @@ class MGXSTestHarness(PyAPITestHarness):
return outstr
def _cleanup(self):
super(MGXSTestHarness, self)._cleanup()
f = os.path.join(os.getcwd(), 'tallies.xml')
if os.path.exists(f): os.remove(f)
if __name__ == '__main__':
harness = MGXSTestHarness('statepoint.10.*', True)
harness = MGXSTestHarness('statepoint.10.h5', True)
harness.main()

View file

@ -72,12 +72,7 @@ class MGXSTestHarness(PyAPITestHarness):
return outstr
def _cleanup(self):
super(MGXSTestHarness, self)._cleanup()
f = os.path.join(os.getcwd(), 'tallies.xml')
if os.path.exists(f): os.remove(f)
if __name__ == '__main__':
harness = MGXSTestHarness('statepoint.10.*', True)
harness = MGXSTestHarness('statepoint.10.h5', True)
harness.main()

View file

@ -67,12 +67,6 @@ class MGXSTestHarness(PyAPITestHarness):
return outstr
def _cleanup(self):
super(MGXSTestHarness, self)._cleanup()
f = os.path.join(os.getcwd(), 'tallies.xml')
if os.path.exists(f): os.remove(f)
if __name__ == '__main__':
harness = MGXSTestHarness('statepoint.10.*', True)
harness = MGXSTestHarness('statepoint.10.h5', True)
harness.main()

View file

@ -64,12 +64,6 @@ class MGXSTestHarness(PyAPITestHarness):
return outstr
def _cleanup(self):
super(MGXSTestHarness, self)._cleanup()
f = os.path.join(os.getcwd(), 'tallies.xml')
if os.path.exists(f): os.remove(f)
if __name__ == '__main__':
harness = MGXSTestHarness('statepoint.10.*', True)
harness = MGXSTestHarness('statepoint.10.h5', True)
harness.main()

View file

@ -177,12 +177,7 @@ class TalliesTestHarness(PyAPITestHarness):
def _get_results(self):
return super(TalliesTestHarness, self)._get_results(hash_output=True)
def _cleanup(self):
super(TalliesTestHarness, self)._cleanup()
f = os.path.join(os.getcwd(), 'tallies.xml')
if os.path.exists(f): os.remove(f)
if __name__ == '__main__':
harness = TalliesTestHarness('statepoint.5.*', True)
harness = TalliesTestHarness('statepoint.5.h5', True)
harness.main()

View file

@ -76,10 +76,6 @@ class TallyAggregationTestHarness(PyAPITestHarness):
return outstr
def _cleanup(self):
super(TallyAggregationTestHarness, self)._cleanup()
f = os.path.join(os.getcwd(), 'tallies.xml')
if os.path.exists(f): os.remove(f)
if __name__ == '__main__':
harness = TallyAggregationTestHarness('statepoint.10.h5', True)

View file

@ -93,10 +93,6 @@ class TallyArithmeticTestHarness(PyAPITestHarness):
return outstr
def _cleanup(self):
super(TallyArithmeticTestHarness, self)._cleanup()
f = os.path.join(os.getcwd(), 'tallies.xml')
if os.path.exists(f): os.remove(f)
if __name__ == '__main__':
harness = TallyArithmeticTestHarness('statepoint.10.h5', True)

View file

@ -176,10 +176,6 @@ class TallySliceMergeTestHarness(PyAPITestHarness):
return outstr
def _cleanup(self):
super(TallySliceMergeTestHarness, self)._cleanup()
f = os.path.join(os.getcwd(), 'tallies.xml')
if os.path.exists(f): os.remove(f)
if __name__ == '__main__':
harness = TallySliceMergeTestHarness('statepoint.10.h5', True)

View file

@ -73,19 +73,19 @@ class TestHarness(object):
def _test_output_created(self):
"""Make sure statepoint.* and tallies.out have been created."""
statepoint = glob.glob(os.path.join(os.getcwd(), self._sp_name))
statepoint = glob.glob(self._sp_name)
assert len(statepoint) == 1, 'Either multiple or no statepoint files' \
' exist.'
assert statepoint[0].endswith('h5'), \
'Statepoint file is not a HDF5 file.'
if self._tallies:
assert os.path.exists(os.path.join(os.getcwd(), 'tallies.out')), \
assert os.path.exists('tallies.out'), \
'Tally output file does not exist.'
def _get_results(self, hash_output=False):
"""Digest info in the statepoint and return as a string."""
# Read the statepoint file.
statepoint = glob.glob(os.path.join(os.getcwd(), self._sp_name))[0]
statepoint = glob.glob(self._sp_name)[0]
sp = openmc.StatePoint(statepoint)
# Write out k-combined.
@ -133,11 +133,9 @@ class TestHarness(object):
def _cleanup(self):
"""Delete statepoints, tally, and test files."""
output = glob.glob(os.path.join(os.getcwd(), 'statepoint.*.h5'))
output.append(os.path.join(os.getcwd(), 'tallies.out'))
output.append(os.path.join(os.getcwd(), 'results_test.dat'))
output.append(os.path.join(os.getcwd(), 'summary.h5'))
output += glob.glob(os.path.join(os.getcwd(), 'volume_*.h5'))
output = glob.glob('statepoint.*.h5')
output += ['tallies.out', 'results_test.dat', 'summary.h5']
output += glob.glob('volume_*.h5')
for f in output:
if os.path.exists(f):
os.remove(f)
@ -157,7 +155,7 @@ class CMFDTestHarness(TestHarness):
def _get_results(self):
"""Digest info in the statepoint and return as a string."""
# Read the statepoint file.
statepoint = glob.glob(os.path.join(os.getcwd(), self._sp_name))[0]
statepoint = glob.glob(self._sp_name)[0]
sp = openmc.StatePoint(statepoint)
# Write out the eigenvalue and tallies.
@ -206,7 +204,7 @@ 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))
particle = glob.glob(self._sp_name)
assert len(particle) == 1, 'Either multiple or no particle restart ' \
'files exist.'
assert particle[0].endswith('h5'), \
@ -215,7 +213,7 @@ class ParticleRestartTestHarness(TestHarness):
def _get_results(self):
"""Digest info in the statepoint and return as a string."""
# Read the particle restart file.
particle = glob.glob(os.path.join(os.getcwd(), self._sp_name))[0]
particle = glob.glob(self._sp_name)[0]
p = openmc.Particle(particle)
# Write out the properties.
@ -301,9 +299,8 @@ class PyAPITestHarness(TestHarness):
def _get_inputs(self):
"""Return a hash digest of the input XML files."""
xmls = ('geometry.xml', 'tallies.xml', 'materials.xml', 'settings.xml',
'plots.xml')
xmls = [os.path.join(os.getcwd(), fname) for fname in xmls]
xmls = ['geometry.xml', 'tallies.xml', 'materials.xml', 'settings.xml',
'plots.xml']
outstr = '\n'.join([open(fname).read() for fname in xmls
if os.path.exists(fname)])
@ -336,11 +333,8 @@ class PyAPITestHarness(TestHarness):
def _cleanup(self):
"""Delete XMLs, statepoints, tally, and test files."""
super(PyAPITestHarness, self)._cleanup()
output = [os.path.join(os.getcwd(), 'materials.xml')]
output.append(os.path.join(os.getcwd(), 'geometry.xml'))
output.append(os.path.join(os.getcwd(), 'settings.xml'))
output.append(os.path.join(os.getcwd(), 'inputs_test.dat'))
output.append(os.path.join(os.getcwd(), 'summary.h5'))
output = ['materials.xml', 'geometry.xml', 'settings.xml',
'tallies.xml', 'inputs_test.dat']
for f in output:
if os.path.exists(f):
os.remove(f)