From d932ed3b17bcb7a468b3abdccadf3cb0a9df1c2f Mon Sep 17 00:00:00 2001 From: Bryan Herman Date: Mon, 12 Aug 2013 17:59:58 -0400 Subject: [PATCH] updated trace test and now it checks stdout for trace data --- tests/test_trace/results.py | 22 ++++++++++++++++++++++ tests/test_trace/results_true.dat | 2 ++ tests/test_trace/test_trace.py | 17 +++++++++++++++-- 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 tests/test_trace/results.py create mode 100644 tests/test_trace/results_true.dat diff --git a/tests/test_trace/results.py b/tests/test_trace/results.py new file mode 100644 index 0000000000..8d51105462 --- /dev/null +++ b/tests/test_trace/results.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python + +import sys + +# import statepoint +sys.path.append('../../src/utils') +import statepoint + +# read in statepoint file +sp = statepoint.StatePoint('statepoint.10.binary') +sp.read_results() + +# set up output string +outstr = '' + +# write out k-combined +outstr += 'k-combined:\n' +outstr += "{0:10.8f} {1:10.8f}".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/results_true.dat b/tests/test_trace/results_true.dat new file mode 100644 index 0000000000..c4825f272a --- /dev/null +++ b/tests/test_trace/results_true.dat @@ -0,0 +1,2 @@ +k-combined: +0.30078030 0.00343315 \ No newline at end of file diff --git a/tests/test_trace/test_trace.py b/tests/test_trace/test_trace.py index c2b419f647..38b2abff02 100644 --- a/tests/test_trace/test_trace.py +++ b/tests/test_trace/test_trace.py @@ -2,6 +2,7 @@ import os from subprocess import Popen, STDOUT, PIPE +import filecmp pwd = os.path.dirname(__file__) @@ -12,11 +13,23 @@ def setup(): def test_run(): proc = Popen([pwd + '/../../src/openmc'], stderr=STDOUT, stdout=PIPE) returncode = proc.wait() - print(proc.communicate()[0]) + stdout = proc.communicate()[0] + print(stdout) assert returncode == 0 + assert stdout.find('Simulating Particle 453') != -1 + +def test_created_statepoint(): + assert os.path.exists(pwd + '/statepoint.10.binary') + +def test_results(): + os.system('python results.py') + compare = filecmp.cmp('results_test.dat', 'results_true.dat') + if not compare: + os.system('cp results_test.dat results_error.dat') + assert compare def teardown(): - output = [pwd + '/statepoint.10.binary'] + output = [pwd + '/statepoint.10.binary', pwd + '/results_test.dat'] for f in output: if os.path.exists(f): os.remove(f)