def test_isotope_init_str(iso_str, sym, A, m): """Test Isotope init with one (string) argument. Isotope is identified by element symbol, A, and isomer number. Run tests for element symbol and name, in mixed case, upper case, and lower case. """ sym = str(sym) mass_number = str(A) if m is not None: if isinstance(m, int): mass_number += 'm{}'.format(m) else: mass_number += m expected = isotope.Isotope(sym, A, m) for name in [sym, element.element_name(sym)]: iso_tests = [ name + '-' + mass_number, name + mass_number, mass_number + '-' + name, mass_number + name, ] for iso in iso_tests: for iso2 in [iso, iso.upper(), iso.lower()]: print('') print('{}-{}: {}'.format(sym, mass_number, iso2)) i = isotope.Isotope(iso2) print(i) assert i == expected
def test_isotope_init_args(iso_str, sym, A, m): """Test Isotope init with 2 or 3 args, depending on whether m is None.""" sym = str(sym) name = element.element_name(sym) Z = element.element_z(sym) A = int(A) elems = [sym, sym.lower(), sym.upper(), name, name.lower(), name.upper(), Z, str(Z)] mass_numbers = [A, str(A)] if isinstance(m, int): if m == 0: m = "" else: m = "m{}".format(m) if m == "": isomer_levels = [None, "", 0] elif m.lower() == "m": isomer_levels = ["m", "M", 1] elif m.lower() == "m1": isomer_levels = ["m1", "M1"] else: isomer_levels = [m.lower(), m.upper(), int(m[1:])] for elem in elems: for mass in mass_numbers: for isomer in isomer_levels: args_list = [(elem, mass, isomer)] if isomer == "" or isomer is None: args_list.append((elem, mass)) for args in args_list: print("") print(args) i = isotope.Isotope(*args) print(i) assert i.symbol == sym assert i.A == A assert i.m == m
def test_element_name_exception(self): """Test element_name with bad input raises ElementNameError........""" for z1, sym1, name1, mass1 in element._Z_SYMBOL_NAME_MASS: with pytest.raises(element.ElementNameError): element.element_name(name1)
def test_element_name(self): """Test element_name...............................................""" for z1, sym1, name1, mass1 in element._Z_SYMBOL_NAME_MASS: assert element.element_name(z1) == name1 for sym2 in [sym1, sym1.lower(), sym1.upper()]: assert element.element_name(sym2) == name1