converted CMFD tests

This commit is contained in:
Bryan Herman 2014-02-25 08:24:20 -05:00
parent 6124f2d12f
commit 6f0ce383be
3 changed files with 108 additions and 129 deletions

View file

@ -4,70 +4,62 @@ import os
from subprocess import Popen, STDOUT, PIPE, call
import filecmp
import glob
from optparse import OptionParser
from nose.plugins.skip import SkipTest
from nose_mpi import NoseMPI
pwd = os.path.dirname(__file__)
skipAll = False
def setup():
os.putenv('PWD', pwd)
os.chdir(pwd)
global skipAll
skipAll = False
parser = OptionParser()
parser.add_option('--mpi_exec', dest='mpi_exec', default='')
parser.add_option('--mpi_np', dest='mpi_np', default='3')
parser.add_option('--exe', dest='exe')
(opts, args) = parser.parse_args()
cwd = os.getcwd()
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)
if opts.mpi_exec != '':
proc = Popen([opts.mpi_exec, '-np', opts.mpi_np, opts.exe, cwd],
stderr=STDOUT, stdout=PIPE)
else:
proc = Popen([openmc_path], stderr=STDOUT, stdout=PIPE)
output = proc.communicate()[0]
print(output)
proc = Popen([opts.exe, cwd], stderr=STDOUT, stdout=PIPE)
print(proc.communicate()[0])
returncode = proc.returncode
if 'CMFD is not available' in output:
global skipAll
skipAll = True
raise SkipTest
assert returncode == 0
assert returncode == 0, 'OpenMC did not exit successfully.'
def test_created_statepoint():
if skipAll:
raise SkipTest
statepoint = glob.glob(pwd + '/statepoint.20.*')
assert len(statepoint) == 1
assert statepoint[0].endswith('binary') or statepoint[0].endswith('h5')
statepoint = glob.glob(cwd + '/statepoint.20.*')
assert len(statepoint) == 1, 'Either multiple or no statepoint files exist.'
assert statepoint[0].endswith('binary') or statepoint[0].endswith('h5'),\
'Statepoint file is not a binary or hdf5 file.'
def test_output_exists():
if skipAll:
raise SkipTest
assert os.path.exists(pwd + '/tallies.out')
assert os.path.exists(cwd + '/tallies.out'), 'Tally output file does not exist.'
def test_results():
if skipAll:
raise SkipTest
statepoint = glob.glob(pwd + '/statepoint.20.*')
statepoint = glob.glob(cwd + '/statepoint.20.*')
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
assert compare, 'Results do not agree.'
def teardown():
output = glob.glob(pwd + '/statepoint.20.*')
output.append(pwd + '/tallies.out')
output.append(pwd + '/results_test.dat')
output = glob.glob(cwd + '/statepoint.20.*')
output.append(cwd + '/tallies.out')
output.append(cwd + '/results_test.dat')
for f in output:
if os.path.exists(f):
os.remove(f)
if __name__ == '__main__':
# test for openmc executable
if opts.exe == None:
raise Exception('Must specify OpenMC executable from command line with --exe.')
# run tests
test_run()
test_created_statepoint()
test_output_exists()
test_results()
teardown()

View file

@ -4,70 +4,63 @@ import os
from subprocess import Popen, STDOUT, PIPE, call
import filecmp
import glob
from optparse import OptionParser
from nose.plugins.skip import SkipTest
from nose_mpi import NoseMPI
pwd = os.path.dirname(__file__)
skipAll = False
def setup():
os.putenv('PWD', pwd)
os.chdir(pwd)
global skipAll
skipAll = False
parser = OptionParser()
parser.add_option('--mpi_exec', dest='mpi_exec', default='')
parser.add_option('--mpi_np', dest='mpi_np', default='3')
parser.add_option('--exe', dest='exe')
(opts, args) = parser.parse_args()
cwd = os.getcwd()
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)
if opts.mpi_exec != '':
proc = Popen([opts.mpi_exec, '-np', opts.mpi_np, opts.exe, cwd],
stderr=STDOUT, stdout=PIPE)
else:
proc = Popen([openmc_path], stderr=STDOUT, stdout=PIPE)
output = proc.communicate()[0]
print(output)
proc = Popen([opts.exe, cwd], stderr=STDOUT, stdout=PIPE)
print(proc.communicate()[0])
returncode = proc.returncode
if 'CMFD is not available' in output:
global skipAll
skipAll = True
raise SkipTest
assert returncode == 0
assert returncode == 0, 'OpenMC did not exit successfully.'
def test_created_statepoint():
if skipAll:
raise SkipTest
statepoint = glob.glob(pwd + '/statepoint.20.*')
assert len(statepoint) == 1
assert statepoint[0].endswith('binary') or statepoint[0].endswith('h5')
statepoint = glob.glob(cwd + '/statepoint.20.*')
assert len(statepoint) == 1, 'Either multiple or no statepoint files exist.'
assert statepoint[0].endswith('binary') or statepoint[0].endswith('h5'),\
'Statepoint file is not a binary or hdf5 file.'
def test_output_exists():
if skipAll:
raise SkipTest
assert os.path.exists(pwd + '/tallies.out')
assert os.path.exists(cwd + '/tallies.out'), 'Tally output file does not exist.'
def test_results():
if skipAll:
raise SkipTest
statepoint = glob.glob(pwd + '/statepoint.20.*')
statepoint = glob.glob(cwd + '/statepoint.20.*')
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
assert compare, 'Results do not agree.'
def teardown():
output = glob.glob(pwd + '/statepoint.20.*')
output.append(pwd + '/tallies.out')
output.append(pwd + '/results_test.dat')
output = glob.glob(cwd + '/statepoint.20.*')
output.append(cwd + '/tallies.out')
output.append(cwd + '/results_test.dat')
for f in output:
if os.path.exists(f):
os.remove(f)
if __name__ == '__main__':
# test for openmc executable
if opts.exe == None:
raise Exception('Must specify OpenMC executable from command line with --exe.')
# run tests
test_run()
test_created_statepoint()
test_output_exists()
test_results()
teardown()

View file

@ -4,69 +4,63 @@ import os
from subprocess import Popen, STDOUT, PIPE, call
import filecmp
import glob
from optparse import OptionParser
from nose.plugins.skip import SkipTest
from nose_mpi import NoseMPI
pwd = os.path.dirname(__file__)
skipAll = False
def setup():
os.putenv('PWD', pwd)
os.chdir(pwd)
global skipAll
skipAll = False
parser = OptionParser()
parser.add_option('--mpi_exec', dest='mpi_exec', default='')
parser.add_option('--mpi_np', dest='mpi_np', default='3')
parser.add_option('--exe', dest='exe')
(opts, args) = parser.parse_args()
cwd = os.getcwd()
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)
if opts.mpi_exec != '':
proc = Popen([opts.mpi_exec, '-np', opts.mpi_np, opts.exe, cwd],
stderr=STDOUT, stdout=PIPE)
else:
proc = Popen([openmc_path], stderr=STDOUT, stdout=PIPE)
output = proc.communicate()[0]
print(output)
proc = Popen([opts.exe, cwd], stderr=STDOUT, stdout=PIPE)
print(proc.communicate()[0])
returncode = proc.returncode
if 'CMFD is not available' in output:
global skipAll
skipAll = True
raise SkipTest
assert returncode == 0
assert returncode == 0, 'OpenMC did not exit successfully.'
def test_created_statepoint():
if skipAll:
raise SkipTest
statepoint = glob.glob(pwd + '/statepoint.20.*')
assert len(statepoint) == 1
assert statepoint[0].endswith('binary') or statepoint[0].endswith('h5')
statepoint = glob.glob(cwd + '/statepoint.20.*')
assert len(statepoint) == 1, 'Either multiple or no statepoint files exist.'
assert statepoint[0].endswith('binary') or statepoint[0].endswith('h5'),\
'Statepoint file is not a binary or hdf5 file.'
def test_output_exists():
if skipAll:
raise SkipTest
assert os.path.exists(pwd + '/tallies.out')
assert os.path.exists(cwd + '/tallies.out'), 'Tally output file does not exist.'
def test_results():
if skipAll:
raise SkipTest
statepoint = glob.glob(pwd + '/statepoint.20.*')
statepoint = glob.glob(cwd + '/statepoint.20.*')
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
assert compare, 'Results do not agree.'
def teardown():
output = glob.glob(pwd + '/statepoint.20.*')
output.append(pwd + '/tallies.out')
output.append(pwd + '/results_test.dat')
output = glob.glob(cwd + '/statepoint.20.*')
output.append(cwd + '/tallies.out')
output.append(cwd + '/results_test.dat')
for f in output:
if os.path.exists(f):
os.remove(f)
if __name__ == '__main__':
# test for openmc executable
if opts.exe == None:
raise Exception('Must specify OpenMC executable from command line with --exe.')
# run tests
test_run()
test_created_statepoint()
test_output_exists()
test_results()
teardown()