Skip to content

Commit

Permalink
Updated plasma_test_data.h5 and test_data.h5
Browse files Browse the repository at this point in the history
The old files contained wrong values (see issue tardis-sn#455)
With this change the following tests will run again:

* test_packet_output
* test_plasma_estimates
* TestPlasma.test_lte_plasma

One should consider updating tardis/simulation/tests/test_simulation.py
since it creates a new model which essentially tests the whole codebase.
These tests will always fail if something in the codebase changes ( see comment
in the file ).
  • Loading branch information
yeganer committed Feb 2, 2016
1 parent 8ad2d87 commit 2ee14d5
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 15 deletions.
9 changes: 3 additions & 6 deletions tardis/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def pytest_report_header(config):
s = "\n"
if six.PY2:
args = [x.decode('utf-8') for x in config.args]
elif six.PY3:
else:
args = config.args
s += "Running tests in {0}.\n\n".format(" ".join(args))

Expand Down Expand Up @@ -133,10 +133,10 @@ def pytest_report_header(config):
if opts:
s += "Using Astropy options: {0}.\n".format(" ".join(opts))

if six.PY3 and (config.getini('doctest_rst') or config.option.doctest_rst):
if not six.PY2 and (config.getini('doctest_rst') or config.option.doctest_rst):
s += "Running doctests in .rst files is not supported on Python 3.x\n"

if not six.PY3:
if six.PY2:
s = s.encode(stdoutencoding, 'replace')

return s
Expand Down Expand Up @@ -182,6 +182,3 @@ def included_he_atomic_data(test_data_path):
def tardis_config_verysimple():
return yaml.load(
open('tardis/io/tests/data/tardis_configv1_verysimple.yml'))



Binary file modified tardis/plasma/tests/data/plasma_test_data.h5
Binary file not shown.
2 changes: 1 addition & 1 deletion tardis/plasma/tests/test_plasmas_full.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ def test_nlte_plasma(self, plasma_compare_data):
np.testing.assert_allclose(
new_plasma_t_rads, old_plasma_t_rads, atol=150)
np.testing.assert_allclose(
new_plasma_levels, old_plasma_levels, rtol=0.1)
new_plasma_levels, old_plasma_levels, rtol=0.1)
Binary file modified tardis/simulation/tests/data/test_data.h5
Binary file not shown.
32 changes: 24 additions & 8 deletions tardis/simulation/tests/test_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,24 @@
from tardis.simulation import Simulation


''' I don't get the purpose of this test. It looks like it's trying to do unit
tests for the Simulation module but what i see happening is a full tardis test
with only one iteration. As a result these tests will always break if something
in the Code changes.
To fix this, the test should be written in a way that their behavoir is
independent of other modules. If that cannot be achieved, move these tests to
test_tardis_full.py
'''

import pandas as pd

@pytest.fixture
def tardis_config(kurucz_atomic_data, tardis_config_verysimple):
return config_reader.Configuration.from_config_dict(
tardis_config_verysimple, atom_data=kurucz_atomic_data)


# For independent behavior the model should be read from a file, not generated
# at runtime
@pytest.fixture()
def raw_model(tardis_config):
return Radial1DModel(tardis_config)
Expand All @@ -28,30 +37,37 @@ def simulation_one_loop(raw_model, tardis_config):

return sim


@pytest.fixture()
def simulation_compare_data_fname():
return 'tardis/simulation/tests/data/test_data.h5'


@pytest.fixture()
def simulation_compare_data(simulation_compare_data_fname):
return h5py.File(simulation_compare_data_fname, mode='r')



def test_plasma_estimates(simulation_one_loop, simulation_compare_data):
npt.assert_allclose(simulation_one_loop.runner.j_estimator,
simulation_compare_data['test1/j_estimators'], atol=0.0)
t_rad, w = simulation_one_loop.runner.calculate_radiationfield_properties()

npt.assert_allclose(simulation_one_loop.runner.nu_bar_estimator,
simulation_compare_data['test1/nubar_estimators'],
atol=0.0)
npt.assert_allclose(simulation_one_loop.runner.j_estimator,
simulation_compare_data['test1/j_estimators'],
atol=0.0)

t_rad, w = simulation_one_loop.runner.calculate_radiationfield_properties()
npt.assert_allclose(t_rad, simulation_compare_data['test1/t_rad'], atol=0.0)
npt.assert_allclose(
t_rad, simulation_compare_data['test1/t_rad'], atol=0.0)
npt.assert_allclose(w, simulation_compare_data['test1/w'], atol=0.0)


def test_packet_output(simulation_one_loop, simulation_compare_data):
npt.assert_allclose(simulation_one_loop.runner.output_nu,
simulation_compare_data['test1/output_nu'], atol=0.0)
npt.assert_allclose(
simulation_one_loop.runner.output_nu,
simulation_compare_data['test1/output_nu'],
atol=0.0)

npt.assert_allclose(simulation_one_loop.runner.output_energy,
simulation_compare_data['test1/output_energy'],
Expand Down

0 comments on commit 2ee14d5

Please sign in to comment.