def test_CS_class(nepc_connect): """Verify that the nepc.CS class has metadata and data attributes, and that each attribute is of the correct type""" # FIXME: randomly sample a few cross sections in the database cs = nepc.CS(nepc_connect[1], 1) # FIXME: add assert for each key in metadata assert isinstance(cs.metadata, dict) assert isinstance(cs.data, dict) assert isinstance(cs.metadata["cs_id"], int) assert isinstance(cs.metadata["units_e"], float) assert isinstance(cs.data["e"], list) assert isinstance(cs.data["e"][0], float) assert isinstance(cs.data["sigma"], list) assert isinstance(cs.data["sigma"][0], float) # test len() assert len(cs) == 21 # test str() message = "cross section id: 1\n" \ + "process: excitation\n" \ + "reaction: E + N2(X1Sigmag+) -> E + N2(X1Sigmag+)_jSCHULZ\n" \ + "threshold: 0.02 eV\n" \ + "ref: N/A\n" \ + "background: SCHULZ Lorem ipsum dolor sit amet, " \ + "consectetur adipiscing elit, sed do eiusmod tempor " \ + "incididunt ut labore et dolore magna aliqua. " \ + "Ut enim ad minim veniam, quis nostrud exercitation ullamco " \ + "laboris nisi ut aliquip ex ea commodo consequat. " \ + "Duis aute irure dolor in reprehenderit in voluptate " \ + "velit esse cillum dolore eu fugiat nulla pariatur.\n" assert(str(cs) == message)
def test_reaction_latex(nepc_connect): """Verify when nepc.reaction_latex is called it returns a string representing the LaTeX for the reaction from a nepc cross section""" # FIXME: verify latex is correct # FIXME: randomly sample cross sections for i in range(1, 30): cs = nepc.CS(nepc_connect[1], i) assert isinstance(nepc.reaction_latex(cs), str)
def test_reaction_text(nepc_connect): """Verify nepc.reaction_text and nepc.reaction_text_side return strings representing the LHS, RHS, or full plain text for the reaction from a nepc cross section""" # TODO: sample all process types and enough permutations cs = nepc.CS(nepc_connect[1], 1) lhsA = 'N2(X1Sigmag+)' rhsA = 'N2(X1Sigmag+)_jSCHULZ' assert nepc.reaction_text_side('LHS', cs) == (lhsA, f'E + {lhsA}') assert nepc.reaction_text_side('RHS', cs) == (rhsA, f'E + {rhsA}') assert nepc.reaction_text(cs) == (f'{lhsA} -> {rhsA}', f'E + {lhsA} -> E + {rhsA}')
def test_CS_class(nepc_connect): """Verify that the nepc.CS class has metadata and data attributes, and that each attribute is of the correct type""" # FIXME: randomly sample a few cross sections in the database cs = nepc.CS(nepc_connect[1], 1) # FIXME: add assert for each key in metadata assert isinstance(cs.metadata, dict) assert isinstance(cs.data, dict) assert isinstance(cs.metadata["cs_id"], int) assert isinstance(cs.metadata["specie"], str) assert isinstance(cs.metadata["units_e"], float) assert isinstance(cs.data["e"], list) assert isinstance(cs.data["e"][0], float) assert isinstance(cs.data["sigma"], list) assert isinstance(cs.data["sigma"][0], float) # test len() # FIXME: use length of data file to get length of sampled cross section assert len(cs) == 21
def test_reaction_text(nepc_connect): """Verify nepc.reaction_text and nepc.reaction_text_side return strings representing the LHS, RHS, or full plain text for the reaction from a nepc cross section""" # TODO: sample all process types and enough permutations for i in range(1, 30): cs = nepc.CS(nepc_connect[1], i) lhsA = cs.metadata['lhsA'] rhsA = cs.metadata['rhsA'] if cs.metadata['process'] == 'excitation_v': lhsA = lhsA.replace(")", " v=" + str(cs.metadata['lhs_v']) + ")") rhsA = rhsA.replace(")", " v=" + str(cs.metadata['rhs_v']) + ")") assert isinstance(cs.reaction_latex, str) assert cs.reaction_text_side('LHS') \ == (lhsA, f"{cs.metadata['e_on_lhs']if cs.metadata['e_on_lhs'] > 1 else ''}E + {lhsA}") assert cs.reaction_text_side('RHS') \ == (rhsA, f"{cs.metadata['e_on_rhs']if cs.metadata['e_on_rhs'] > 1 else ''}E + {rhsA}") assert cs.reaction_text == (f"{lhsA} -> {rhsA}", f"{cs.metadata['e_on_lhs']if cs.metadata['e_on_lhs'] > 1 else ''}" + \ f"E + {lhsA} -> " + \ f"{cs.metadata['e_on_rhs']if cs.metadata['e_on_rhs'] > 1 else ''}" + \ f"E + {rhsA}")
def test_reaction_latex(nepc_connect): """Verify when nepc.reaction_latex is called it returns a string representing the LaTeX for the reaction from a nepc cross section""" # FIXME: verify latex is correct # FIXME: randomly sample cross sections for i in range(1, 30): cs = nepc.CS(nepc_connect[1], i) lhsA_long = cs.metadata['lhsA_long'] rhsA_long = cs.metadata['rhsA_long'] if cs.metadata['process'] == 'excitation_v': lhsA_long = lhsA_long.replace(")", " v=" + str(cs.metadata['lhs_v']) + ")") rhsA_long = rhsA_long.replace(")", " v=" + str(cs.metadata['rhs_v']) + ")") assert isinstance(cs.reaction_latex, str) assert cs.reaction_text_side('LHS', latex=True) \ == f"{cs.metadata['e_on_lhs']if cs.metadata['e_on_lhs'] > 1 else ''}e$^-$ + {lhsA_long}" assert cs.reaction_text_side('RHS', latex=True) \ == f"{cs.metadata['e_on_rhs']if cs.metadata['e_on_rhs'] > 1 else ''}e$^-$ + {rhsA_long}" assert cs.reaction_latex == f"{cs.metadata['e_on_lhs']if cs.metadata['e_on_lhs'] > 1 else ''}" + \ f"e$^-$ + {lhsA_long} $\\rightarrow$ " + \ f"{cs.metadata['e_on_rhs']if cs.metadata['e_on_rhs'] > 1 else ''}" + \ f"e$^-$ + {rhsA_long}"