def test_add_to_phaselist_raises(self): """Trying to add a Phase with a name already in the PhaseList raises a ValueError. """ pl = PhaseList(names=["a"]) with pytest.raises(ValueError, match="'a' is already in the phase list"): pl.add(Phase("a"))
def test_init_empty_phaselist(self, empty_input): pl = PhaseList(empty_input) assert repr(pl) == "No phases." pl.add(Phase("al", point_group="m-3m")) assert repr(pl) == ( "Id Name Space group Point group Proper point group Color\n" " 0 al None m-3m 432 tab:blue")
def test_add_phase_in_empty_phaselist(self): """Add Phase to empty PhaseList.""" sg_no = 10 name = "a" pl = PhaseList() pl.add(Phase(name, space_group=sg_no)) assert pl.ids == [0] assert pl.names == [name] assert pl.space_groups == [GetSpaceGroup(sg_no)] assert pl.structures == [Structure()]
def test_add_list_phases_to_phaselist(self): """Add a list of Phase objects to PhaseList, also ensuring that unique colors are given. """ names = ["a", "b"] sg_no = [10, 20] colors = ["tab:blue", "tab:orange"] pl = PhaseList(names=names, space_groups=sg_no) assert pl.colors == colors new_names = ["c", "d"] new_sg_no = [30, 40] pl.add([Phase(name=n, space_group=i) for n, i in zip(new_names, new_sg_no)]) assert pl.names == names + new_names assert pl.space_groups == ( [GetSpaceGroup(i) for i in sg_no] + [GetSpaceGroup(i) for i in new_sg_no] ) assert pl.colors == colors + ["tab:green", "tab:red"]
def test_add_phaselist_to_phaselist(self): """Add a PhaseList to a PhaseList, also ensuring that new IDs are given. """ names = ["a", "b"] sg_no = [10, 20] pl1 = PhaseList(names=names, space_groups=sg_no) assert pl1.ids == [0, 1] names2 = ["c", "d"] sg_no2 = [30, 40] ids = [4, 5] pl2 = PhaseList(names=names2, space_groups=sg_no2, ids=ids) pl1.add(pl2) assert pl1.names == names + names2 assert pl1.space_groups == ([GetSpaceGroup(i) for i in sg_no] + [GetSpaceGroup(i) for i in sg_no2]) assert pl1.ids == [0, 1, 2, 3]