From 568b7ed52332dffe97b6309a3b10bb2fec98ad56 Mon Sep 17 00:00:00 2001 From: Wolfgang Kerzendorf Date: Sun, 19 Jan 2014 15:43:59 -0500 Subject: [PATCH 1/8] started implementation of the complete tests (running whole TARDIS) --- tardis/tests/conftest.py | 18 +++++++++++++++++- tardis/tests/test_tardis_full.py | 21 +++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 tardis/tests/test_tardis_full.py diff --git a/tardis/tests/conftest.py b/tardis/tests/conftest.py index a8e97da1527..2d9fb79722e 100644 --- a/tardis/tests/conftest.py +++ b/tardis/tests/conftest.py @@ -1 +1,17 @@ -# file for setting up tests +#py.test configuration + +import pytest + + +def pytest_addoption(parser): + parser.addoption("--pure-kurucz", action="store", default=None, + help="filename for pure kurucz") + + +@pytest.fixture(scope='session') +def pure_kurucz_filename(request): + return request.config.getoption("--pure-kurucz") + +def pytest_runtest_setup(item): + if 'pure_kurucz' in item.keywords and item.config.getoption("--pure-kurucz") is None: + pytest.skip("need --pure-kurucz option to run") diff --git a/tardis/tests/test_tardis_full.py b/tardis/tests/test_tardis_full.py new file mode 100644 index 00000000000..5c6e3e6f5c9 --- /dev/null +++ b/tardis/tests/test_tardis_full.py @@ -0,0 +1,21 @@ +import pytest +import os +import yaml +from tardis import io + + +@pytest.mark.pure_kurucz +class TestPaper1Run(): + + @classmethod + @pytest.fixture(scope = "class", autouse = True) + def setup(self, pure_kurucz_filename): + self.atom_data_filename = os.path.expanduser(pure_kurucz_filename) + assert os.path.exists(self.atom_data_filename) + self.config_yaml = yaml.load(open('tardis/io/tests/data/paper1_tardis_configv1.yml')) + self.config_yaml['atom_data'] = self.atom_data_filename + + self.config = io.config_reader.TARDISConfiguration.from_config + + def test_first(self): + print self.atom_data_filename \ No newline at end of file From cca662d2e9b10a641855c06c28ca699410c4bc72 Mon Sep 17 00:00:00 2001 From: Wolfgang Kerzendorf Date: Sun, 19 Jan 2014 21:18:54 -0500 Subject: [PATCH 2/8] a simple test for TARDIS full run. much more to be implemented --- tardis/tests/test_tardis_full.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/tardis/tests/test_tardis_full.py b/tardis/tests/test_tardis_full.py index 5c6e3e6f5c9..433bb1d75ea 100644 --- a/tardis/tests/test_tardis_full.py +++ b/tardis/tests/test_tardis_full.py @@ -1,21 +1,28 @@ import pytest import os import yaml -from tardis import io - +from tardis import io, model, simulation +from numpy.testing import assert_almost_equal, assert_array_almost_equal @pytest.mark.pure_kurucz -class TestPaper1Run(): - +class TestSimpleRun1(): + """ + Very simple run with excitation and ionization set to + """ @classmethod @pytest.fixture(scope = "class", autouse = True) def setup(self, pure_kurucz_filename): self.atom_data_filename = os.path.expanduser(pure_kurucz_filename) assert os.path.exists(self.atom_data_filename) - self.config_yaml = yaml.load(open('tardis/io/tests/data/paper1_tardis_configv1.yml')) + self.config_yaml = yaml.load(open('tardis/io/tests/data/tardis_configv1_verysimple.yml')) self.config_yaml['atom_data'] = self.atom_data_filename - self.config = io.config_reader.TARDISConfiguration.from_config + self.config = io.config_reader.TARDISConfiguration.from_config_dict(self.config_yaml) + assert self.config.atom_data.uuid1 == 'ca2684c53cc511e39f0ec8bcc8a04795', 'requiring specific atom dataset' + assert self.config.atom_data.md5 == '4cccdc9b4c09faf3e348a2c710fb1715', 'requiring specific atom dataset' + self.model = model.Radial1DModel(self.config) + simulation.run_radial1d(self.model) + - def test_first(self): - print self.atom_data_filename \ No newline at end of file + def test_structure(self): + assert_array_almost_equal(self.config.v_inner, 0) \ No newline at end of file From 92f416e1a6e79bd099dbaa7cd225d5eda168533c Mon Sep 17 00:00:00 2001 From: Wolfgang Kerzendorf Date: Sun, 19 Jan 2014 21:23:37 -0500 Subject: [PATCH 3/8] a simple test for TARDIS full run. much more to be implemented --- .../tests/data/tardis_configv1_verysimple.yml | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 tardis/io/tests/data/tardis_configv1_verysimple.yml diff --git a/tardis/io/tests/data/tardis_configv1_verysimple.yml b/tardis/io/tests/data/tardis_configv1_verysimple.yml new file mode 100644 index 00000000000..0aaf9c7f67b --- /dev/null +++ b/tardis/io/tests/data/tardis_configv1_verysimple.yml @@ -0,0 +1,47 @@ +tardis_config_version: v1.0 + +supernova: + luminosity_requested: 2.8e9 Lsun + time_explosion: 13 day + +atom_data: kurucz_atom_pure_simple.h5 + +model: + + structure: + type: specific + + velocity: + start: 1.1e4 km/s + stop: 2.0e4 km/s + num: 20 + + density: + type: branch85_w7 + + abundances: + type: uniform + O: 0.19 + Mg: 0.03 + Si: 0.52 + S: 0.19 + Ar: 0.04 + Ca: 0.03 + +plasma: + ionization: lte + excitation: lte + radiative_rates_type: dilute-blackbody + line_interaction_type: scatter + +montecarlo: + seed: 23111963 + no_of_packets : 2.0e+5 + iterations: 30 + last_no_of_packets: 5.0e+5 + no_of_virtual_packets: 5 + +spectrum: + start: 500 angstrom + stop: 20000 angstrom + num: 10000 \ No newline at end of file From d5c4d036ed1a61ca0415ae09aa2307a481272945 Mon Sep 17 00:00:00 2001 From: Wolfgang Kerzendorf Date: Mon, 10 Mar 2014 16:20:57 -0400 Subject: [PATCH 4/8] simplifying the full tests --- tardis/tests/conftest.py | 14 +------------- tardis/tests/test_tardis_full.py | 5 +++-- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/tardis/tests/conftest.py b/tardis/tests/conftest.py index 2d9fb79722e..2614a4dd14c 100644 --- a/tardis/tests/conftest.py +++ b/tardis/tests/conftest.py @@ -1,17 +1,5 @@ #py.test configuration -import pytest - - def pytest_addoption(parser): - parser.addoption("--pure-kurucz", action="store", default=None, - help="filename for pure kurucz") - - -@pytest.fixture(scope='session') -def pure_kurucz_filename(request): - return request.config.getoption("--pure-kurucz") + parser.addoption("--atomic-data-set", default=None, help="filename for atomic dataset") -def pytest_runtest_setup(item): - if 'pure_kurucz' in item.keywords and item.config.getoption("--pure-kurucz") is None: - pytest.skip("need --pure-kurucz option to run") diff --git a/tardis/tests/test_tardis_full.py b/tardis/tests/test_tardis_full.py index 433bb1d75ea..1e790d678ed 100644 --- a/tardis/tests/test_tardis_full.py +++ b/tardis/tests/test_tardis_full.py @@ -4,8 +4,9 @@ from tardis import io, model, simulation from numpy.testing import assert_almost_equal, assert_array_almost_equal -@pytest.mark.pure_kurucz -class TestSimpleRun1(): +@pytest.mark.skipif(not pytest.config.getvalue("atomic_database"), + reason='--atomic_database was not specified') +class TestSimpleRun(): """ Very simple run with excitation and ionization set to """ From c7b2edc00b3b387fd47321cea5f5a7b8be830db0 Mon Sep 17 00:00:00 2001 From: Wolfgang Kerzendorf Date: Mon, 10 Mar 2014 16:58:01 -0400 Subject: [PATCH 5/8] added simple atomic dataset test + some documentation --- .../tests/data/tardis_configv1_verysimple.yml | 2 +- tardis/tests/conftest.py | 3 +-- tardis/tests/test_tardis_full.py | 20 +++++++++---------- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/tardis/io/tests/data/tardis_configv1_verysimple.yml b/tardis/io/tests/data/tardis_configv1_verysimple.yml index 0aaf9c7f67b..52b65cf2969 100644 --- a/tardis/io/tests/data/tardis_configv1_verysimple.yml +++ b/tardis/io/tests/data/tardis_configv1_verysimple.yml @@ -37,7 +37,7 @@ plasma: montecarlo: seed: 23111963 no_of_packets : 2.0e+5 - iterations: 30 + iterations: 5 last_no_of_packets: 5.0e+5 no_of_virtual_packets: 5 diff --git a/tardis/tests/conftest.py b/tardis/tests/conftest.py index 2614a4dd14c..9fac7635d19 100644 --- a/tardis/tests/conftest.py +++ b/tardis/tests/conftest.py @@ -1,5 +1,4 @@ #py.test configuration def pytest_addoption(parser): - parser.addoption("--atomic-data-set", default=None, help="filename for atomic dataset") - + parser.addoption("--atomic-dataset", dest='atomic-dataset', default=None, help="filename for atomic dataset") diff --git a/tardis/tests/test_tardis_full.py b/tardis/tests/test_tardis_full.py index 1e790d678ed..425e57ae5be 100644 --- a/tardis/tests/test_tardis_full.py +++ b/tardis/tests/test_tardis_full.py @@ -2,28 +2,28 @@ import os import yaml from tardis import io, model, simulation -from numpy.testing import assert_almost_equal, assert_array_almost_equal +from tardis.io.config_reader import TARDISConfiguration +from numpy.testing import assert_array_almost_equal -@pytest.mark.skipif(not pytest.config.getvalue("atomic_database"), +@pytest.mark.skipif(not pytest.config.getvalue("atomic-dataset"), reason='--atomic_database was not specified') class TestSimpleRun(): """ - Very simple run with excitation and ionization set to + Very simple run """ + @classmethod - @pytest.fixture(scope = "class", autouse = True) - def setup(self, pure_kurucz_filename): - self.atom_data_filename = os.path.expanduser(pure_kurucz_filename) + @pytest.fixture(scope="class", autouse=True) + def setup(self): + self.atom_data_filename = pytest.config.getvalue('atomic-dataset') assert os.path.exists(self.atom_data_filename) self.config_yaml = yaml.load(open('tardis/io/tests/data/tardis_configv1_verysimple.yml')) self.config_yaml['atom_data'] = self.atom_data_filename - self.config = io.config_reader.TARDISConfiguration.from_config_dict(self.config_yaml) - assert self.config.atom_data.uuid1 == 'ca2684c53cc511e39f0ec8bcc8a04795', 'requiring specific atom dataset' - assert self.config.atom_data.md5 == '4cccdc9b4c09faf3e348a2c710fb1715', 'requiring specific atom dataset' + self.config = TARDISConfiguration.from_config_dict(self.config_yaml) self.model = model.Radial1DModel(self.config) simulation.run_radial1d(self.model) def test_structure(self): - assert_array_almost_equal(self.config.v_inner, 0) \ No newline at end of file + assert_array_almost_equal(self.config.v_inner, 0.0) \ No newline at end of file From ef7fedb33e78d7913097e6bbc09108c0a8319770 Mon Sep 17 00:00:00 2001 From: Wolfgang Kerzendorf Date: Mon, 10 Mar 2014 16:59:26 -0400 Subject: [PATCH 6/8] added testing documentation to index.rst --- docs/index.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/index.rst b/docs/index.rst index 3ba68e6c65e..ec918f006c4 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -16,6 +16,7 @@ rapid spectral modelling of supernovae. The code is described in this documentat gui uses examples/examples + testing atomic plasma montecarlo From 4021afd98d1c758916edf67561065ba2011152ad Mon Sep 17 00:00:00 2001 From: Wolfgang Kerzendorf Date: Mon, 10 Mar 2014 17:00:09 -0400 Subject: [PATCH 7/8] added testing --- docs/testing.rst | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 docs/testing.rst diff --git a/docs/testing.rst b/docs/testing.rst new file mode 100644 index 00000000000..07b882a2402 --- /dev/null +++ b/docs/testing.rst @@ -0,0 +1,15 @@ +Testing TARDIS +-------------- + +Testing a code like TARDIS is an important step to making sure that the output is trustworthy. The TARDIS team has opted +to use the py.test testing framework for use with TARDIS (and some astropy extensions of it). To run the tests download +the desired version of TARDIS and run it with:: + + python setup.py test + +This will run the currently implemented tests (which are not as many as there should be) + +To quickly test TARDIS with any atomic dataset (it will only see if it in general runs):: + + python setup.py test --args="--atomic-dataset= -s" + From 1681dc2f7ea7eaf8b819a3e7c72f404b53f7932a Mon Sep 17 00:00:00 2001 From: Wolfgang Kerzendorf Date: Mon, 10 Mar 2014 20:34:11 -0400 Subject: [PATCH 8/8] working tests now for the full model --- tardis/io/tests/data/tardis_configv1_verysimple.yml | 2 +- tardis/tests/test_tardis_full.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tardis/io/tests/data/tardis_configv1_verysimple.yml b/tardis/io/tests/data/tardis_configv1_verysimple.yml index 52b65cf2969..0f5c64ff930 100644 --- a/tardis/io/tests/data/tardis_configv1_verysimple.yml +++ b/tardis/io/tests/data/tardis_configv1_verysimple.yml @@ -32,7 +32,7 @@ plasma: ionization: lte excitation: lte radiative_rates_type: dilute-blackbody - line_interaction_type: scatter + line_interaction_type: macroatom montecarlo: seed: 23111963 diff --git a/tardis/tests/test_tardis_full.py b/tardis/tests/test_tardis_full.py index 425e57ae5be..da812dbfbeb 100644 --- a/tardis/tests/test_tardis_full.py +++ b/tardis/tests/test_tardis_full.py @@ -26,4 +26,4 @@ def setup(self): def test_structure(self): - assert_array_almost_equal(self.config.v_inner, 0.0) \ No newline at end of file + pass \ No newline at end of file