pymatgen.util.testing package
This module implements testing utilities for materials science codes.
While the primary use is within pymatgen, the functionality is meant to be useful for external materials science codes as well. For instance, obtaining example crystal structures to perform tests, specialized assert methods for materials science, etc.
- class PymatgenTest(methodName='runTest')[source]
Bases:
TestCase
Extends unittest.TestCase with several assert methods for array and str comparison.
Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.
- TEST_STRUCTURES: ClassVar[dict[str | Path, Structure | None]] = {PosixPath('/Users/shyue/repos/pymatgen/src/pymatgen/util/testing/../structures/BaNiO3.json'): None, PosixPath('/Users/shyue/repos/pymatgen/src/pymatgen/util/testing/../structures/CsCl.json'): None, PosixPath('/Users/shyue/repos/pymatgen/src/pymatgen/util/testing/../structures/Graphite.json'): None, PosixPath('/Users/shyue/repos/pymatgen/src/pymatgen/util/testing/../structures/He_BCC.json'): None, PosixPath('/Users/shyue/repos/pymatgen/src/pymatgen/util/testing/../structures/K2O2.json'): None, PosixPath('/Users/shyue/repos/pymatgen/src/pymatgen/util/testing/../structures/La2CoO4F.json'): None, PosixPath('/Users/shyue/repos/pymatgen/src/pymatgen/util/testing/../structures/Li10GeP2S12.json'): None, PosixPath('/Users/shyue/repos/pymatgen/src/pymatgen/util/testing/../structures/Li2O.json'): None, PosixPath('/Users/shyue/repos/pymatgen/src/pymatgen/util/testing/../structures/Li2O2.json'): None, PosixPath('/Users/shyue/repos/pymatgen/src/pymatgen/util/testing/../structures/Li3V2(PO4)3.json'): None, PosixPath('/Users/shyue/repos/pymatgen/src/pymatgen/util/testing/../structures/LiFePO4.json'): None, PosixPath('/Users/shyue/repos/pymatgen/src/pymatgen/util/testing/../structures/NaFePO4.json'): None, PosixPath('/Users/shyue/repos/pymatgen/src/pymatgen/util/testing/../structures/Pb2TiZrO6.json'): None, PosixPath('/Users/shyue/repos/pymatgen/src/pymatgen/util/testing/../structures/Si.json'): None, PosixPath('/Users/shyue/repos/pymatgen/src/pymatgen/util/testing/../structures/SiO2.json'): None, PosixPath('/Users/shyue/repos/pymatgen/src/pymatgen/util/testing/../structures/Si_SiO2_Interface.json'): None, PosixPath('/Users/shyue/repos/pymatgen/src/pymatgen/util/testing/../structures/Sn.json'): None, PosixPath('/Users/shyue/repos/pymatgen/src/pymatgen/util/testing/../structures/SrTiO3.json'): None, PosixPath('/Users/shyue/repos/pymatgen/src/pymatgen/util/testing/../structures/TiO2.json'): None, PosixPath('/Users/shyue/repos/pymatgen/src/pymatgen/util/testing/../structures/TlBiSe2.json'): None, PosixPath('/Users/shyue/repos/pymatgen/src/pymatgen/util/testing/../structures/VO2.json'): None}[source]
- assert_msonable(obj: MSONable, test_is_subclass: bool = True) str [source]
Test if obj is MSONable and verify the contract is fulfilled.
By default, the method tests whether obj is an instance of MSONable. This check can be deactivated by setting test_is_subclass=False.
- static assert_str_content_equal(actual, expected)[source]
Test if two strings are equal, ignoring things like trailing spaces, etc.
- classmethod get_structure(name: str) Structure [source]
Lazily load a structure from pymatgen/util/structures.
- Parameters:
name (str) – Name of structure file.
- Returns:
Structure
- serialize_with_pickle(objects: Any, protocols: Sequence[int] | None = None, test_eq: bool = True)[source]
Test whether the object(s) can be serialized and deserialized with pickle. This method tries to serialize the objects with pickle and the protocols specified in input. Then it deserializes the pickle format and compares the two objects with the __eq__ operator if test_eq is True.
- Parameters:
objects – Object or list of objects.
protocols – List of pickle protocols to test. If protocols is None, HIGHEST_PROTOCOL is tested.
test_eq – If True, the deserialized object is compared with the original object using the __eq__ method.
- Returns:
Nested list with the objects deserialized with the specified protocols.