Skip to content

Commit

Permalink
simplify tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wtbarnes committed Jan 19, 2024
1 parent 17b0f95 commit be09fbc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 40 deletions.
11 changes: 11 additions & 0 deletions fiasco/tests/test_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,14 @@ def test_equilibrium_ionization(hdf5_dbase_root):

def test_element_repr(element):
assert element.element_name in element.__repr__()


@pytest.mark.parametrize(('value', 'dset'),[
(0.07943282347242822, 'sun_coronal_1992_feldman_ext'),
(0.08511380382023759, 'sun_photospheric_2007_grevesse'),
(1e-3, None),
])
def test_change_element_abundance(another_element, value, dset):
another_element.abundance = value if dset is None else dset
assert u.allclose(another_element.abundance, value)
assert u.allclose(another_element[1].abundance, value)
60 changes: 20 additions & 40 deletions fiasco/tests/test_ion.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,47 +389,27 @@ def test_previous_ion(ion):
assert prev_ion.atomic_number == ion.atomic_number


def test_change_ion_abundance(ion):
assert ion._dset_names['abundance'] == 'sun_coronal_1992_feldman_ext'
assert ion._instance_kwargs['abundance'] == 'sun_coronal_1992_feldman_ext'
assert u.allclose(ion.abundance, 0.0001258925411794166)
@pytest.mark.parametrize(('value', 'dset'),[
(0.0001258925411794166, 'sun_coronal_1992_feldman_ext'),
(2.818382931264455e-05, 'sun_photospheric_2007_grevesse'),
(1e-3, None),
])
def test_change_ion_abundance(ion, value, dset):
ion.abundance = value if dset is None else dset
assert u.allclose(ion.abundance, value)
assert ion._dset_names['abundance'] == dset
assert ion._instance_kwargs['abundance'] == (value if dset is None else dset)

ion.abundance = 'sun_photospheric_2007_grevesse'
assert ion._dset_names['abundance'] == 'sun_photospheric_2007_grevesse'
assert u.allclose(ion.abundance, 2.818382931264455e-05)

def test_new_instance_abundance_preserved_float(ion):
ion.abundance = 1e-3
assert u.allclose(ion.abundance, 1e-3)


def test_change_element_abundance(hdf5_dbase_root):
element = fiasco.Element('iron',
temperature,
abundance='sun_coronal_1992_feldman_ext',
hdf5_dbase_root=hdf5_dbase_root)
assert u.allclose(element.abundance, 0.0001258925411794166)
assert u.allclose(element[10].abundance, 0.0001258925411794166)

element.abundance = 1e-3
assert u.allclose(element.abundance, 1e-3)
assert u.allclose(element[10].abundance, 1e-3)

element2 = fiasco.Element('iron',
temperature,
abundance=1e-3,
hdf5_dbase_root=hdf5_dbase_root)
assert u.allclose(element2.abundance, 1e-3)
assert u.allclose(element2[10].abundance, 1e-3)

element2.abundance = 'sun_photospheric_2007_grevesse'
assert u.allclose(element2.abundance, 2.818382931264455e-05)
assert u.allclose(element2[10].abundance, 2.818382931264455e-05)


def test_new_instance_float_abundance(hdf5_dbase_root):
ion = fiasco.Ion('Fe 1',
temperature,
abundance=1e-3,
hdf5_dbase_root=hdf5_dbase_root)
new_ion = ion._new_instance()
assert u.allclose(new_ion._instance_kwargs['abundance'], 1e-3)
assert u.allclose(new_ion.abundance, ion.abundance)
assert new_ion._dset_names['abundance'] is None


def test_new_instance_abundance_preserved_string(ion):
ion.abundance = 'sun_photospheric_2007_grevesse'
new_ion = ion._new_instance()
assert u.allclose(new_ion.abundance, 2.818382931264455e-05)
assert new_ion._dset_names['abundance'] == 'sun_photospheric_2007_grevesse'

0 comments on commit be09fbc

Please sign in to comment.