From 5d00dfa6382161bf9dd5cf0b866b4c476f6b3f7c Mon Sep 17 00:00:00 2001 From: Bryan Herman Date: Mon, 12 Aug 2013 13:17:03 -0400 Subject: [PATCH] added new results test for basic test --- tests/test_basic/results.py | 22 ++++++++++++++++++++++ tests/test_basic/results_true.dat | 2 ++ tests/test_basic/test_basic.py | 5 +++++ tests/update_results.py | 31 +++++++++++++++++++++++++++++++ 4 files changed, 60 insertions(+) create mode 100644 tests/test_basic/results.py create mode 100644 tests/test_basic/results_true.dat create mode 100644 tests/update_results.py diff --git a/tests/test_basic/results.py b/tests/test_basic/results.py new file mode 100644 index 0000000000..8d51105462 --- /dev/null +++ b/tests/test_basic/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_basic/results_true.dat b/tests/test_basic/results_true.dat new file mode 100644 index 0000000000..c4825f272a --- /dev/null +++ b/tests/test_basic/results_true.dat @@ -0,0 +1,2 @@ +k-combined: +0.30078030 0.00343315 \ No newline at end of file diff --git a/tests/test_basic/test_basic.py b/tests/test_basic/test_basic.py index 260af75774..5c5b236f32 100644 --- a/tests/test_basic/test_basic.py +++ b/tests/test_basic/test_basic.py @@ -2,6 +2,7 @@ import os from subprocess import Popen, STDOUT, PIPE +import filecmp pwd = os.path.dirname(__file__) @@ -18,6 +19,10 @@ def test_run(): def test_created_statepoint(): assert os.path.exists(pwd + '/statepoint.10.binary') +def test_results(): + os.system('python results.py') + assert filecmp.cmp('results_test.dat', 'results_true.dat') + def teardown(): output = [pwd + '/statepoint.10.binary'] for f in output: diff --git a/tests/update_results.py b/tests/update_results.py new file mode 100644 index 0000000000..d435701a70 --- /dev/null +++ b/tests/update_results.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python + +import os +import sys +from subprocess import Popen, STDOUT, PIPE + +# Loop around directories +for root, dirs, files in os.walk('.'): + + # Don't continue if not prefixed by test + if root[2:6] != 'test': + continue + + # Go into that directory + os.chdir(root) + pwd = os.path.abspath(os.path.dirname('settings.xml')) + os.putenv('PWD', pwd) + + # Run openmc + proc = Popen(['../../src/openmc']) + returncode = proc.wait() + + # Process results + os.system('python results.py') + os.system('mv results_test.dat results_true.dat') + os.system('rm *.binary') + + # Go back a directory + os.chdir('..') + + exit()