def test_ele_ratio_ele_ele_from_log(ele1, ele2): """Calculate element ratio for element vs. element.""" ini = iniabu.IniAbu() val_exp = ini.ele_dict[ele1][0] / ini.ele_dict[ele2][0] ini.unit = "num_log" assert ini.ele_ratio(ele1, ele2) == val_exp assert ini.ele_ratio(ele1, ele2, mass_fraction=False) == val_exp
def test_unit_log_lin(ele): """Ensure linear abundance unit is set correctly after logarithmic (switch back).""" ini = iniabu.IniAbu() ini.unit = "num_log" assert ini.ele[ele].abu_solar == ini.ele_dict_log[ele][0] ini.unit = "num_lin" assert ini.unit == "num_lin" assert ini.ele[ele].abu_solar == ini.ele_dict[ele][0]
def test_init_database_invalid(): """Initialize with invalid database name.""" invalid_db = "invalid" with pytest.raises(ValueError) as err_info: iniabu.IniAbu(database=invalid_db) err_msg = err_info.value.args[0] assert ( err_msg == f"The database {invalid_db} could not be found. Make sure it is a valid " f"option or choose one of the available ones.")
def test_database_print(unit, mocker): """Ensure message is print out when database is changed.""" ini = iniabu.IniAbu() spy_print = mocker.spy(builtins, "print") # put spy on print # change unit ini.unit = unit # now load the nist database for example db_new = "nist" ini.database = db_new spy_print.assert_called_with( f"iniabu loaded database: '{db_new}', current " f"units: '{unit}'")
def test_iso_ratio_iso_iso_from_log(iso1, iso2): """Calculate isotope ratio when database is in logarithmic state.""" ini = iniabu.IniAbu() val_exp = ini.iso_dict[iso1][1] / ini.iso_dict[iso2][1] ini.unit = "num_log" assert ini.iso_ratio(iso1, iso2) == val_exp
def ini_default(): """Return ``ini`` initialized with default (lodders09) database.""" return iniabu.IniAbu()
def ini_nist(): """Return ``ini`` initialized with NIST database (no solar abundances).""" return iniabu.IniAbu(database="nist")
def ini_mf(): """Return ``ini`` initialized with default database and mass fractions.""" return iniabu.IniAbu(unit="mass_fraction")
def test_unit_mf(ele): """Ensure mass fraction unit is set correctly.""" ini = iniabu.IniAbu() ini.unit = "mass_fraction" assert ini.unit == "mass_fraction" assert ini.ele[ele].abu_solar == ini.ele_dict_mf[ele][0]
def test_unit_log(ele): """Ensure logarithmic abundance unit is set correctly.""" ini = iniabu.IniAbu() ini.unit = "num_log" assert ini.unit == "num_log" assert ini.ele[ele].abu_solar == ini.ele_dict_log[ele][0]
def test_init_database_asplund(): """Load iniabu with asplund database.""" ini = iniabu.IniAbu(database="asplund09") assert ini._ele_dict == data.asplund09_elements assert ini._iso_dict == data.asplund09_isotopes assert ini.database == "asplund09"