From 0b6d664bc9ed93d8bb014a4af93cf83c384d22b3 Mon Sep 17 00:00:00 2001 From: Bryan Herman Date: Tue, 25 Feb 2014 11:18:51 -0500 Subject: [PATCH] converted fixed source, lattice, element, output and particle restart tests --- tests/test_fixed_source/test_fixed_source.py | 54 +++++++++------ tests/test_lattice/test_lattice.py | 49 +++++++++----- .../test_lattice_multiple.py | 49 +++++++++----- .../test_natural_element.py | 49 +++++++++----- tests/test_output/test_output.py | 65 ++++++++++++------- .../test_particle_restart.py | 63 +++++++++++------- 6 files changed, 206 insertions(+), 123 deletions(-) diff --git a/tests/test_fixed_source/test_fixed_source.py b/tests/test_fixed_source/test_fixed_source.py index 151df366b..435cb80eb 100644 --- a/tests/test_fixed_source/test_fixed_source.py +++ b/tests/test_fixed_source/test_fixed_source.py @@ -3,46 +3,60 @@ import os from subprocess import Popen, STDOUT, PIPE, call import filecmp -from nose_mpi import NoseMPI import glob +from optparse import OptionParser -pwd = os.path.dirname(__file__) - -def setup(): - os.putenv('PWD', pwd) - os.chdir(pwd) +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], + 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) + proc = Popen([opts.exe, cwd], stderr=STDOUT, stdout=PIPE) print(proc.communicate()[0]) returncode = proc.returncode - assert returncode == 0 + assert returncode == 0, 'OpenMC did not exit successfully.' def test_created_statepoint(): - statepoint = glob.glob(pwd + '/statepoint.10.*') - assert len(statepoint) == 1 - assert statepoint[0].endswith('binary') or statepoint[0].endswith('h5') + statepoint = glob.glob(cwd + '/statepoint.10.*') + 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(): - assert os.path.exists(pwd + '/tallies.out') + assert os.path.exists(cwd + '/tallies.out'), 'Tally output file does not exist.' def test_results(): - statepoint = glob.glob(pwd + '/statepoint.10.*') + statepoint = glob.glob(cwd + '/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 + assert compare, 'Results do not agree.' def teardown(): - output = glob.glob(pwd + '/statepoint.10.*') - output.append(pwd + '/tallies.out') - output.append(pwd + '/results_test.dat') + output = glob.glob(cwd + '/statepoint.10.*') + 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() diff --git a/tests/test_lattice/test_lattice.py b/tests/test_lattice/test_lattice.py index 64d20b611..54733fb13 100644 --- a/tests/test_lattice/test_lattice.py +++ b/tests/test_lattice/test_lattice.py @@ -3,42 +3,55 @@ import os from subprocess import Popen, STDOUT, PIPE, call import filecmp -from nose_mpi import NoseMPI import glob +from optparse import OptionParser -pwd = os.path.dirname(__file__) - -def setup(): - os.putenv('PWD', pwd) - os.chdir(pwd) +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], + 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) + proc = Popen([opts.exe, cwd], stderr=STDOUT, stdout=PIPE) print(proc.communicate()[0]) returncode = proc.returncode - assert returncode == 0 + assert returncode == 0, 'OpenMC did not exit successfully.' def test_created_statepoint(): - statepoint = glob.glob(pwd + '/statepoint.10.*') - assert len(statepoint) == 1 - assert statepoint[0].endswith('binary') or statepoint[0].endswith('h5') + statepoint = glob.glob(cwd + '/statepoint.10.*') + 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_results(): - statepoint = glob.glob(pwd + '/statepoint.10.*') + statepoint = glob.glob(cwd + '/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 + assert compare, 'Results do not agree.' def teardown(): - output = glob.glob(pwd + '/statepoint.10.*') - output.append(pwd + '/results_test.dat') + output = glob.glob(cwd + '/statepoint.10.*') + 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_results() + teardown() diff --git a/tests/test_lattice_multiple/test_lattice_multiple.py b/tests/test_lattice_multiple/test_lattice_multiple.py index 64d20b611..54733fb13 100644 --- a/tests/test_lattice_multiple/test_lattice_multiple.py +++ b/tests/test_lattice_multiple/test_lattice_multiple.py @@ -3,42 +3,55 @@ import os from subprocess import Popen, STDOUT, PIPE, call import filecmp -from nose_mpi import NoseMPI import glob +from optparse import OptionParser -pwd = os.path.dirname(__file__) - -def setup(): - os.putenv('PWD', pwd) - os.chdir(pwd) +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], + 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) + proc = Popen([opts.exe, cwd], stderr=STDOUT, stdout=PIPE) print(proc.communicate()[0]) returncode = proc.returncode - assert returncode == 0 + assert returncode == 0, 'OpenMC did not exit successfully.' def test_created_statepoint(): - statepoint = glob.glob(pwd + '/statepoint.10.*') - assert len(statepoint) == 1 - assert statepoint[0].endswith('binary') or statepoint[0].endswith('h5') + statepoint = glob.glob(cwd + '/statepoint.10.*') + 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_results(): - statepoint = glob.glob(pwd + '/statepoint.10.*') + statepoint = glob.glob(cwd + '/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 + assert compare, 'Results do not agree.' def teardown(): - output = glob.glob(pwd + '/statepoint.10.*') - output.append(pwd + '/results_test.dat') + output = glob.glob(cwd + '/statepoint.10.*') + 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_results() + teardown() diff --git a/tests/test_natural_element/test_natural_element.py b/tests/test_natural_element/test_natural_element.py index 64d20b611..54733fb13 100644 --- a/tests/test_natural_element/test_natural_element.py +++ b/tests/test_natural_element/test_natural_element.py @@ -3,42 +3,55 @@ import os from subprocess import Popen, STDOUT, PIPE, call import filecmp -from nose_mpi import NoseMPI import glob +from optparse import OptionParser -pwd = os.path.dirname(__file__) - -def setup(): - os.putenv('PWD', pwd) - os.chdir(pwd) +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], + 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) + proc = Popen([opts.exe, cwd], stderr=STDOUT, stdout=PIPE) print(proc.communicate()[0]) returncode = proc.returncode - assert returncode == 0 + assert returncode == 0, 'OpenMC did not exit successfully.' def test_created_statepoint(): - statepoint = glob.glob(pwd + '/statepoint.10.*') - assert len(statepoint) == 1 - assert statepoint[0].endswith('binary') or statepoint[0].endswith('h5') + statepoint = glob.glob(cwd + '/statepoint.10.*') + 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_results(): - statepoint = glob.glob(pwd + '/statepoint.10.*') + statepoint = glob.glob(cwd + '/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 + assert compare, 'Results do not agree.' def teardown(): - output = glob.glob(pwd + '/statepoint.10.*') - output.append(pwd + '/results_test.dat') + output = glob.glob(cwd + '/statepoint.10.*') + 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_results() + teardown() diff --git a/tests/test_output/test_output.py b/tests/test_output/test_output.py index dc48dc37b..4ed425539 100644 --- a/tests/test_output/test_output.py +++ b/tests/test_output/test_output.py @@ -3,52 +3,69 @@ import os from subprocess import Popen, STDOUT, PIPE, call import filecmp -from nose_mpi import NoseMPI import glob +from optparse import OptionParser -pwd = os.path.dirname(__file__) - -def setup(): - os.putenv('PWD', pwd) - os.chdir(pwd) +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], + 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) + proc = Popen([opts.exe, cwd], stderr=STDOUT, stdout=PIPE) print(proc.communicate()[0]) returncode = proc.returncode - assert returncode == 0 + assert returncode == 0, 'OpenMC did not exit successfully.' def test_summary_exists(): - summary = glob.glob(pwd + '/summary.*') - assert len(summary) == 1 - assert summary[0].endswith('out') or summary[0].endswith('h5') + summary = glob.glob(cwd + '/summary.*') + assert len(summary) == 1, 'Either multiple or no summary file exists.' + assert summary[0].endswith('out') or summary[0].endswith('h5'),\ + 'Summary file is not a binary or hdf5 file.' def test_cross_sections_exists(): - assert os.path.exists(pwd + '/cross_sections.out') + assert os.path.exists(cwd + '/cross_sections.out'),\ + 'Cross section output file does not exist.' def test_statepoint_exists(): - statepoint = glob.glob(pwd + '/statepoint.10.*') - assert len(statepoint) == 1 - assert statepoint[0].endswith('binary') or statepoint[0].endswith('h5') + statepoint = glob.glob(cwd + '/statepoint.10.*') + 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_results(): - statepoint = glob.glob(pwd + '/statepoint.10.*') + statepoint = glob.glob(cwd + '/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 + assert compare, 'Results do not agree.' def teardown(): - output = glob.glob(pwd + '/statepoint.10.*') + glob.glob(pwd + '/summary.*') - output.append(pwd + '/summary.out') - output.append(pwd + '/cross_sections.out') - output.append(pwd + '/results_test.dat') + output = glob.glob(cwd + '/statepoint.10.*') + glob.glob(cwd + '/summary.*') + output.append(cwd + '/summary.out') + output.append(cwd + '/cross_sections.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_summary_exists() + test_cross_sections_exists() + test_statepoint_exists() + test_results() + teardown() diff --git a/tests/test_particle_restart/test_particle_restart.py b/tests/test_particle_restart/test_particle_restart.py index 1cc576fa7..4c63efe37 100644 --- a/tests/test_particle_restart/test_particle_restart.py +++ b/tests/test_particle_restart/test_particle_restart.py @@ -3,50 +3,63 @@ import os from subprocess import Popen, STDOUT, PIPE, call import filecmp -from nose_mpi import NoseMPI import glob +from optparse import OptionParser -pwd = os.path.dirname(__file__) - -def setup(): - os.putenv('PWD', pwd) - os.chdir(pwd) +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=PIPE, 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=PIPE, stdout=PIPE) - stdout, stderr = proc.communicate() - assert stderr != '' + proc = Popen([opts.exe, cwd], stderr=STDOUT, stdout=PIPE) + print(proc.communicate()[0]) + returncode = proc.returncode + assert returncode == 0, 'OpenMC did not exit successfully.' def test_created_restart(): - particle = glob.glob(pwd + '/particle_10_394.*') - assert len(particle) == 1 + particle = glob.glob(cwd + '/particle_10_394.*') + assert len(particle) == 1, 'Either multiple or no particle restart files exist.' assert particle[0].endswith('binary') or \ - particle[0].endswith('h5') + particle[0].endswith('h5'), 'Particle restart file not a binary or hdf5 file.' def test_results(): - particle = glob.glob(pwd + '/particle_10_394.*') + particle = glob.glob(cwd + '/particle_10_394.*') call(['python', 'results.py', particle[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 test_run_restart(): - particle = glob.glob(pwd + '/particle_10_394.*') - proc = Popen([pwd + '/../../src/openmc -r ' + particle[0]], - stderr=PIPE, stdout=PIPE, shell=True) + particle = glob.glob(cwd + '/particle_10_394.*') + proc = Popen([opts.exe, '-r', particle[0], cwd], stderr=PIPE, stdout=PIPE) stdout, stderr = proc.communicate() - assert stderr == '' + assert stderr == '', 'Particle restart not successful.' def teardown(): - output = glob.glob(pwd + '/statepoint.*') + \ - glob.glob(pwd + '/particle_*') + \ - [pwd + '/results_test.dat'] + output = glob.glob(cwd + '/statepoint.*') + \ + glob.glob(cwd + '/particle_*') + \ + [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_restart() + test_results() + test_run_restart() + teardown()