def test_add_phases_right_use(): """Test the normal use of addAqueousPhase, addGaseousPhase and addMineralPhase.""" database = Database("supcrt98.xml") # Check adding phase by giving an string with all species list_of_aqueous_species_expected = r"H2O\(l\)\s*H\+\s*OH-\s*HCO3-\s*CO2\(aq\)\s*CO3--\s*" list_of_gaseous_species_expected = r"H2O\(g\)\s*CO2\(g\)\s*" list_of_liquid_species_expected = r"H2O\(liq\)\s*CO2\(liq\)\s*" list_of_mineral_species_expected = r"Graphite\s*" editor1 = ChemicalEditor(database) editor1.addAqueousPhase("H2O(l) H+ OH- HCO3- CO2(aq) CO3--") editor1.addGaseousPhase("H2O(g) CO2(g)") editor1.addLiquidPhase("H2O(liq) CO2(liq)") editor1.addMineralPhase("Graphite") aqueous_phase_1 = editor1.aqueousPhase() gaseous_phase_1 = editor1.gaseousPhase() liquid_phase_1 = editor1.liquidPhase() mineral_phases_1 = editor1.mineralPhases() aqueous_species_added_1 = _getting_species_names(aqueous_phase_1) gaseous_species_added_1 = _getting_species_names(gaseous_phase_1) liquid_species_added_1 = _getting_species_names(liquid_phase_1) mineral_species_added_1 = _getting_species_names(mineral_phases_1[0]) assert re.match(list_of_aqueous_species_expected, aqueous_species_added_1) assert re.match(list_of_gaseous_species_expected, gaseous_species_added_1) assert re.match(list_of_liquid_species_expected, liquid_species_added_1) assert re.match(list_of_mineral_species_expected, mineral_species_added_1) # Check adding phase by giving a list of string with all species editor2 = ChemicalEditor(database) editor2.addAqueousPhase( ["H2O(l)", "H+", "OH-", "HCO3-", "CO2(aq)", "CO3--"]) editor2.addGaseousPhase(["H2O(g)", "CO2(g)"]) editor2.addLiquidPhase(["H2O(liq)", "CO2(liq)"]) editor2.addMineralPhase(["Graphite"]) aqueous_phase_2 = editor2.aqueousPhase() gaseous_phase_2 = editor2.gaseousPhase() liquid_phase_2 = editor2.liquidPhase() mineral_phases_2 = editor2.mineralPhases() aqueous_species_added_2 = _getting_species_names(aqueous_phase_2) gaseous_species_added_2 = _getting_species_names(gaseous_phase_2) liquid_species_added_2 = _getting_species_names(liquid_phase_2) mineral_species_added_2 = _getting_species_names(mineral_phases_2[0]) assert re.match(list_of_aqueous_species_expected, aqueous_species_added_2) assert re.match(list_of_gaseous_species_expected, gaseous_species_added_2) assert re.match(list_of_liquid_species_expected, liquid_species_added_2) assert re.match(list_of_mineral_species_expected, mineral_species_added_2)
def test_chemical_editor_adding_and_getting_phases(): database = Database("supcrt98.xml") editor = ChemicalEditor(database) gaseous_phase = GaseousPhase() liquid_phase = LiquidPhase() mineral_phase = MineralPhase() editor.addPhase(gaseous_phase) editor.addPhase(liquid_phase) editor.addPhase(mineral_phase) assert editor.gaseousPhase().name() == gaseous_phase.name() assert editor.liquidPhase().name() == liquid_phase.name() assert editor.mineralPhases()[0].name() == mineral_phase.name()