From be09fbc76a27353cc2393a11d9922115af05d48e Mon Sep 17 00:00:00 2001 From: Will Barnes Date: Fri, 19 Jan 2024 11:25:30 -0500 Subject: [PATCH] simplify tests --- fiasco/tests/test_element.py | 11 +++++++ fiasco/tests/test_ion.py | 60 ++++++++++++------------------------ 2 files changed, 31 insertions(+), 40 deletions(-) diff --git a/fiasco/tests/test_element.py b/fiasco/tests/test_element.py index d278ae46..a7194a57 100644 --- a/fiasco/tests/test_element.py +++ b/fiasco/tests/test_element.py @@ -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) diff --git a/fiasco/tests/test_ion.py b/fiasco/tests/test_ion.py index df8c503a..b6bb5590 100644 --- a/fiasco/tests/test_ion.py +++ b/fiasco/tests/test_ion.py @@ -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'