From 05a8d948cf124f0c13cbf1e25a014f4fed89f9a3 Mon Sep 17 00:00:00 2001 From: Bryan Herman Date: Tue, 25 Feb 2014 11:39:48 -0500 Subject: [PATCH] converted plot and ptables tests --- .../test_plot_background.py | 37 +++++++++----- tests/test_plot_basis/test_plot_basis.py | 41 ++++++++++------ tests/test_plot_colspec/test_plot_colspec.py | 37 +++++++++----- tests/test_plot_mask/test_plot_mask.py | 41 ++++++++++------ tests/test_ptables_off/test_ptables_off.py | 49 ++++++++++++------- 5 files changed, 131 insertions(+), 74 deletions(-) diff --git a/tests/test_plot_background/test_plot_background.py b/tests/test_plot_background/test_plot_background.py index d8fc18f75..fdf786314 100644 --- a/tests/test_plot_background/test_plot_background.py +++ b/tests/test_plot_background/test_plot_background.py @@ -2,30 +2,41 @@ import os from subprocess import Popen, STDOUT, PIPE -from nose_mpi import NoseMPI +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, '-p'], + if opts.mpi_exec != '': + proc = Popen([opts.mpi_exec, '-np', opts.mpi_np, opts.exe, '-p', cwd], stderr=STDOUT, stdout=PIPE) else: - proc = Popen([openmc_path, '-p'], stderr=STDOUT, stdout=PIPE) + proc = Popen([opts.exe, '-p', 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_plot_exists(): - assert os.path.exists(pwd + '/1_plot.ppm') + assert os.path.exists(cwd + '/1_plot.ppm'), 'Plot ppm file does not exist.' def teardown(): - output = [pwd + '/1_plot.ppm'] + output = [cwd + '/1_plot.ppm'] 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_plot_exists() + teardown() diff --git a/tests/test_plot_basis/test_plot_basis.py b/tests/test_plot_basis/test_plot_basis.py index 86a415920..2c650d876 100644 --- a/tests/test_plot_basis/test_plot_basis.py +++ b/tests/test_plot_basis/test_plot_basis.py @@ -2,32 +2,43 @@ import os from subprocess import Popen, STDOUT, PIPE -from nose_mpi import NoseMPI +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, '-p'], + if opts.mpi_exec != '': + proc = Popen([opts.mpi_exec, '-np', opts.mpi_np, opts.exe, '-p', cwd], stderr=STDOUT, stdout=PIPE) else: - proc = Popen([openmc_path, '-p'], stderr=STDOUT, stdout=PIPE) + proc = Popen([opts.exe, '-p', 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_plots_exists(): - assert os.path.exists(pwd + '/1_plot.ppm') - assert os.path.exists(pwd + '/2_plot.ppm') - assert os.path.exists(pwd + '/3_plot.ppm') + assert os.path.exists(cwd + '/1_plot.ppm'), 'Plot 1 result does not exist.' + assert os.path.exists(cwd + '/2_plot.ppm'), 'Plot 2 result does not exist.' + assert os.path.exists(cwd + '/3_plot.ppm'), 'Plot 3 result does not exist.' def teardown(): - output = [pwd + '/1_plot.ppm', pwd + '/2_plot.ppm', pwd + '/3_plot.ppm'] + output = [cwd + '/1_plot.ppm', cwd + '/2_plot.ppm', cwd + '/3_plot.ppm'] 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_plots_exists() + teardown() diff --git a/tests/test_plot_colspec/test_plot_colspec.py b/tests/test_plot_colspec/test_plot_colspec.py index d8fc18f75..fdf786314 100644 --- a/tests/test_plot_colspec/test_plot_colspec.py +++ b/tests/test_plot_colspec/test_plot_colspec.py @@ -2,30 +2,41 @@ import os from subprocess import Popen, STDOUT, PIPE -from nose_mpi import NoseMPI +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, '-p'], + if opts.mpi_exec != '': + proc = Popen([opts.mpi_exec, '-np', opts.mpi_np, opts.exe, '-p', cwd], stderr=STDOUT, stdout=PIPE) else: - proc = Popen([openmc_path, '-p'], stderr=STDOUT, stdout=PIPE) + proc = Popen([opts.exe, '-p', 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_plot_exists(): - assert os.path.exists(pwd + '/1_plot.ppm') + assert os.path.exists(cwd + '/1_plot.ppm'), 'Plot ppm file does not exist.' def teardown(): - output = [pwd + '/1_plot.ppm'] + output = [cwd + '/1_plot.ppm'] 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_plot_exists() + teardown() diff --git a/tests/test_plot_mask/test_plot_mask.py b/tests/test_plot_mask/test_plot_mask.py index 86a415920..2c650d876 100644 --- a/tests/test_plot_mask/test_plot_mask.py +++ b/tests/test_plot_mask/test_plot_mask.py @@ -2,32 +2,43 @@ import os from subprocess import Popen, STDOUT, PIPE -from nose_mpi import NoseMPI +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, '-p'], + if opts.mpi_exec != '': + proc = Popen([opts.mpi_exec, '-np', opts.mpi_np, opts.exe, '-p', cwd], stderr=STDOUT, stdout=PIPE) else: - proc = Popen([openmc_path, '-p'], stderr=STDOUT, stdout=PIPE) + proc = Popen([opts.exe, '-p', 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_plots_exists(): - assert os.path.exists(pwd + '/1_plot.ppm') - assert os.path.exists(pwd + '/2_plot.ppm') - assert os.path.exists(pwd + '/3_plot.ppm') + assert os.path.exists(cwd + '/1_plot.ppm'), 'Plot 1 result does not exist.' + assert os.path.exists(cwd + '/2_plot.ppm'), 'Plot 2 result does not exist.' + assert os.path.exists(cwd + '/3_plot.ppm'), 'Plot 3 result does not exist.' def teardown(): - output = [pwd + '/1_plot.ppm', pwd + '/2_plot.ppm', pwd + '/3_plot.ppm'] + output = [cwd + '/1_plot.ppm', cwd + '/2_plot.ppm', cwd + '/3_plot.ppm'] 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_plots_exists() + teardown() diff --git a/tests/test_ptables_off/test_ptables_off.py b/tests/test_ptables_off/test_ptables_off.py index 64d20b611..54733fb13 100644 --- a/tests/test_ptables_off/test_ptables_off.py +++ b/tests/test_ptables_off/test_ptables_off.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()