Skip to content

Commit

Permalink
Replace datapaths with fixtures.
Browse files Browse the repository at this point in the history
  • Loading branch information
karandesai-96 committed Apr 1, 2016
1 parent 013a625 commit 21ae59d
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 deletions tardis/tests/test_atomic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,37 @@
from tardis import atomic


chianti_he_db_h5_path = os.path.join(
os.path.dirname(os.path.realpath(__file__)), 'data', 'chianti_he_db.h5')
@pytest.fixture(scope="module")
def default_atom_h5_path():
return atomic.default_atom_h5_path


@pytest.fixture(scope="module")
def chianti_he_db_h5_path():
return os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data', 'chianti_he_db.h5')


def test_data_path():
data_path = atomic.data_path('test')
assert data_path.split('/')[-3:] == ['tardis', 'data', 'test']


def test_read_basic_atom_data():
data = atomic.read_basic_atom_data(atomic.default_atom_h5_path)
def test_read_basic_atom_data(default_atom_h5_path):
data = atomic.read_basic_atom_data(default_atom_h5_path)
assert data['atomic_number'][13] == 14
assert data['symbol'][13] == "Si"
testing.assert_almost_equal(data['mass'][13], 28.085, decimal=4)


def test_read_ionization_data():
data = atomic.read_ionization_data(atomic.default_atom_h5_path)
def test_read_ionization_data(default_atom_h5_path):
data = atomic.read_ionization_data(default_atom_h5_path)
assert data['atomic_number'][0] == 1
assert data['ion_number'][0] == 1
testing.assert_almost_equal(data['ionization_energy'][0], 13.59844, decimal=4)


def test_read_levels_data():
data = atomic.read_levels_data(atomic.default_atom_h5_path)
def test_read_levels_data(default_atom_h5_path):
data = atomic.read_levels_data(default_atom_h5_path)
assert data['atomic_number'][4] == 14
assert data['ion_number'][4] == 0
assert data['level_number'][4] == 4
Expand All @@ -37,8 +43,8 @@ def test_read_levels_data():
assert data['metastable'][4] == False


def test_read_lines_data():
data = atomic.read_lines_data(atomic.default_atom_h5_path)
def test_read_lines_data(default_atom_h5_path):
data = atomic.read_lines_data(default_atom_h5_path)
assert data['line_id'][0] == 8
assert data['atomic_number'][0] == 14
assert data['ion_number'][0] == 5
Expand All @@ -49,15 +55,15 @@ def test_read_lines_data():
assert data['level_number_upper'][0] == 36.0


def test_read_synpp_refs():
def test_read_synpp_refs(chianti_he_db_h5_path):
data = atomic.read_synpp_refs(chianti_he_db_h5_path)
assert data['atomic_number'][0] == 1
assert data['ion_number'][0] == 0
testing.assert_almost_equal(data['wavelength'][0], 6562.7973633, decimal=4)
assert data['line_id'][0] == 564995


def test_read_zeta_data():
def test_read_zeta_data(default_atom_h5_path, chianti_he_db_h5_path):
data = atomic.read_zeta_data(chianti_he_db_h5_path)
testing.assert_almost_equal(data[2000][1][1], 0.339, decimal=4)
testing.assert_almost_equal(data[2000][1][2], 0.000, decimal=4)
Expand All @@ -69,10 +75,10 @@ def test_read_zeta_data():
atomic.read_zeta_data('fakepath')

with pytest.raises(ValueError):
atomic.read_zeta_data(atomic.default_atom_h5_path)
atomic.read_zeta_data(default_atom_h5_path)


def test_read_collision_data():
def test_read_collision_data(default_atom_h5_path, chianti_he_db_h5_path):
data = atomic.read_collision_data(chianti_he_db_h5_path)
assert data[0]['atomic_number'][0] == 2
assert data[0]['ion_number'][0] == 0
Expand All @@ -90,10 +96,10 @@ def test_read_collision_data():
atomic.read_zeta_data('fakepath')

with pytest.raises(ValueError):
atomic.read_zeta_data(atomic.default_atom_h5_path)
atomic.read_zeta_data(default_atom_h5_path)


def test_read_macro_atom_data():
def test_read_macro_atom_data(default_atom_h5_path, chianti_he_db_h5_path):
data = atomic.read_macro_atom_data(chianti_he_db_h5_path)
assert data[0]['atomic_number'][0] == 2
assert data[0]['ion_number'][0] == 0
Expand All @@ -114,7 +120,7 @@ def test_read_macro_atom_data():
atomic.read_macro_atom_data('fakepath')

with pytest.raises(ValueError):
atomic.read_macro_atom_data(atomic.default_atom_h5_path)
atomic.read_macro_atom_data(default_atom_h5_path)


def test_atom_levels():
Expand Down

0 comments on commit 21ae59d

Please sign in to comment.