From bfc172f26485487bd780a37d233d0f4961df4bca Mon Sep 17 00:00:00 2001 From: Sterling Harper Date: Thu, 10 Oct 2013 00:02:26 -0400 Subject: [PATCH] Added track output test. Also fixed a typo in track.py --- src/utils/track.py | 2 +- tests/test_track_output/geometry.xml | 305 +++++++++++++++++++ tests/test_track_output/materials.xml | 95 ++++++ tests/test_track_output/settings.xml | 30 ++ tests/test_track_output/test_track_output.py | 80 +++++ tests/test_track_output/true_poly.pvtp | 9 + 6 files changed, 520 insertions(+), 1 deletion(-) create mode 100644 tests/test_track_output/geometry.xml create mode 100644 tests/test_track_output/materials.xml create mode 100644 tests/test_track_output/settings.xml create mode 100644 tests/test_track_output/test_track_output.py create mode 100644 tests/test_track_output/true_poly.pvtp diff --git a/src/utils/track.py b/src/utils/track.py index 5fe20ce53..a2dca34e1 100755 --- a/src/utils/track.py +++ b/src/utils/track.py @@ -42,7 +42,7 @@ def main(): # Check input file extensions. for fname in args.input: if not (fname.endswith('.h5') or fname.endswith('.binary')): - raise ValueError("Input file names must either end iwth '.h5' or" + raise ValueError("Input file names must either end with '.h5' or" "'.binary'.") # Make sure that the output filename ends with '.pvtp'. diff --git a/tests/test_track_output/geometry.xml b/tests/test_track_output/geometry.xml new file mode 100644 index 000000000..f3566ab17 --- /dev/null +++ b/tests/test_track_output/geometry.xml @@ -0,0 +1,305 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -12.2682 -12.2682 + 1.63576 1.63576 + + 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 + 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 + 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 + 2 2 2 3 2 2 2 2 2 2 2 3 2 2 2 + 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 + 2 2 1 2 2 1 2 2 2 1 2 2 1 2 2 + 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 + 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 + 2 2 2 2 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 2 2 2 1 1 + 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 + 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 + 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 + 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 + 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 + 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 + 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 + + + + + + + + + + + + + + + + + + + -85.8774 -85.8774 + 24.5364 24.5364 + + 999 999 130 140 150 999 999 + 999 220 230 240 250 260 999 + 130 320 777 222 333 360 150 + 410 240 444 111 666 240 470 + 510 520 888 555 998 560 570 + 999 620 630 240 650 660 999 + 999 999 510 740 570 999 999 + + + + + + + + diff --git a/tests/test_track_output/materials.xml b/tests/test_track_output/materials.xml new file mode 100644 index 000000000..7befbddf5 --- /dev/null +++ b/tests/test_track_output/materials.xml @@ -0,0 +1,95 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/test_track_output/settings.xml b/tests/test_track_output/settings.xml new file mode 100644 index 000000000..420bc5949 --- /dev/null +++ b/tests/test_track_output/settings.xml @@ -0,0 +1,30 @@ + + + + + + + + + + 8 + 1 + 1000 + + + + + + + + + -1 -1 -1 1 1 1 + + + + + 1 1 1 + 1 1 2 + + + diff --git a/tests/test_track_output/test_track_output.py b/tests/test_track_output/test_track_output.py new file mode 100644 index 000000000..d652d97e3 --- /dev/null +++ b/tests/test_track_output/test_track_output.py @@ -0,0 +1,80 @@ +#!/usr/bin/env python + +import os +from subprocess import Popen, STDOUT, PIPE, call +import filecmp +from nose_mpi import NoseMPI +import glob + +pwd = os.path.dirname(__file__) + +def setup(): + os.putenv('PWD', pwd) + os.chdir(pwd) + +def test_run(): + openmc_path = pwd + '/../../src/openmc' + if int(NoseMPI.mpi_np) > 0: + proc = Popen([NoseMPI.mpi_exec, '-np', NoseMPI.mpi_np, openmc_path], + stderr=STDOUT, stdout=PIPE) + else: + proc = Popen([openmc_path], stderr=STDOUT, stdout=PIPE) + returncode = proc.wait() + print(proc.communicate()[0]) + assert returncode == 0 + +def test_created_outputs(): + outputs = [glob.glob(''.join((pwd, '/track_1_1_1.*')))] + outputs.append(glob.glob(''.join((pwd, '/track_1_1_2.*')))) + for files in outputs: + assert len(files) == 1 + assert files[0].endswith('binary') or files[0].endswith('h5') + +##def test_outputs(): +## outputs = [glob.glob(''.join((pwd, '/track_1_1_1.*')))[0]] +## outputs.append(glob.glob(''.join((pwd, '/track_1_1_2.*')))[0]) +## if outputs[0].endswith('binary'): +## metrics = [''.join((pwd, '/track_1_1_1_true.binary')), +## ''.join((pwd, '/track_1_1_2_true.binary'))] +## else: +## metrics = [''.join((pwd, '/track_1_1_1_true.h5')), +## ''.join((pwd, '/track_1_1_2_true.h5'))] +## for i in range(2): +## output = outputs[i] +## metric = metrics[i] +## compare = filecmp.cmp(output, metric) +## if not compare: +## if outputs[0].endswith('binary'): +## extension = 'binary' +## else: +## extension = 'h5' +## os.rename(output, ''.join((pwd, '/track_1_1_{}_error.{}'.format( +## i+1, extension)))) +## assert compare + +def test_outputs(): + call(['../../src/utils/track.py', '-o', 'poly'] + + glob.glob(''.join((pwd, '/track*')))) + poly = ''.join((pwd, '/poly.pvtp')) + assert os.path.isfile(poly) + metric = ''.join((pwd, '/true_poly.pvtp')) + compare = filecmp.cmp(poly, metric) + if not compare: + os.rename('poly.pvtp', 'poly_error.pvtp') + assert compare + +##def test_results(): +## statepoint = glob.glob(pwd + '/statepoint.10.*') +## call(['python', 'results.py', statepoint[0]]) +## compare = filecmp.cmp('results_test.dat', 'results_true.dat') +## if not compare: +## os.rename('results_test.dat', 'results_error.dat') +## assert compare + +def teardown(): + temp_files = glob.glob(''.join((pwd, '/statepoint*'))) + temp_files = temp_files + glob.glob(''.join((pwd, '/track*'))) + temp_files = temp_files + glob.glob(''.join((pwd, '/poly*'))) + for f in temp_files: + if os.path.exists(f): + os.remove(f) diff --git a/tests/test_track_output/true_poly.pvtp b/tests/test_track_output/true_poly.pvtp new file mode 100644 index 000000000..6ded87a0e --- /dev/null +++ b/tests/test_track_output/true_poly.pvtp @@ -0,0 +1,9 @@ + + + + + + + + +