pymatgen.util.testing package
Common test support for pymatgen test scripts.
This single module should provide all the common functionality for pymatgen tests in a single location, so that test scripts can just import it and work right away.
- 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/janosh/dev/pmg/pymatgen/util/testing/../structures/BaNiO3.json'): None, PosixPath('/Users/janosh/dev/pmg/pymatgen/util/testing/../structures/CsCl.json'): None, PosixPath('/Users/janosh/dev/pmg/pymatgen/util/testing/../structures/Graphite.json'): None, PosixPath('/Users/janosh/dev/pmg/pymatgen/util/testing/../structures/He_BCC.json'): None, PosixPath('/Users/janosh/dev/pmg/pymatgen/util/testing/../structures/K2O2.json'): None, PosixPath('/Users/janosh/dev/pmg/pymatgen/util/testing/../structures/La2CoO4F.json'): None, PosixPath('/Users/janosh/dev/pmg/pymatgen/util/testing/../structures/Li10GeP2S12.json'): None, PosixPath('/Users/janosh/dev/pmg/pymatgen/util/testing/../structures/Li2O.json'): None, PosixPath('/Users/janosh/dev/pmg/pymatgen/util/testing/../structures/Li2O2.json'): None, PosixPath('/Users/janosh/dev/pmg/pymatgen/util/testing/../structures/Li3V2(PO4)3.json'): None, PosixPath('/Users/janosh/dev/pmg/pymatgen/util/testing/../structures/LiFePO4.json'): None, PosixPath('/Users/janosh/dev/pmg/pymatgen/util/testing/../structures/NaFePO4.json'): None, PosixPath('/Users/janosh/dev/pmg/pymatgen/util/testing/../structures/Pb2TiZrO6.json'): None, PosixPath('/Users/janosh/dev/pmg/pymatgen/util/testing/../structures/Si.json'): None, PosixPath('/Users/janosh/dev/pmg/pymatgen/util/testing/../structures/SiO2.json'): None, PosixPath('/Users/janosh/dev/pmg/pymatgen/util/testing/../structures/Si_SiO2_Interface.json'): None, PosixPath('/Users/janosh/dev/pmg/pymatgen/util/testing/../structures/Sn.json'): None, PosixPath('/Users/janosh/dev/pmg/pymatgen/util/testing/../structures/SrTiO3.json'): None, PosixPath('/Users/janosh/dev/pmg/pymatgen/util/testing/../structures/TiO2.json'): None, PosixPath('/Users/janosh/dev/pmg/pymatgen/util/testing/../structures/TlBiSe2.json'): None, PosixPath('/Users/janosh/dev/pmg/pymatgen/util/testing/../structures/VO2.json'): None}[source]
- assert_msonable(obj, test_is_subclass=True)[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]
Tests 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/testing/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.
Submodules
pymatgen.util.testing.aims module
Helper functions for testing AIMS IO.
- check_band(test_line: str, ref_line: str) bool [source]
Check if band lines are the same.
- Parameters:
test_line (str) – Line generated in the test file
ref_line (str) – Line generated for the reference file
Returns: bool: True if all points in the test and ref lines are the same
- comp_system(structure: Structure, user_params: dict[str, Any], test_name: str, work_dir: Path, ref_dir: Path, generator_cls: type, properties: list[str] | None = None, prev_dir: str | None | Path = None) None [source]
Compare files generated by tests with ones in reference directories.
- Parameters:
structure (Structure) – The system to make the test files for
user_params (dict[str, Any]) – The parameters for the input files passed by the user
test_name (str) – The name of the test (subdir for ref files in ref_dir)
work_dir (Path) – The directory to look for the test files in
ref_dir (Path) – The directory where all reference files are located
generator_cls (type) – The class of the generator
properties (list[str] | None) – The list of properties to calculate
prev_dir (str | Path | None) – The previous directory to pull outputs from
- Raises:
AssertionError – If the input files are not the same
- compare_files(test_name: str, work_dir: Path, ref_dir: Path) None [source]
Compare files generated by tests with ones in reference directories.
- Parameters:
test_name (str) – The name of the test (subdir for ref files in ref_dir)
work_dir (Path) – The directory to look for the test files in
ref_dir (Path) – The directory where all reference files are located
- Raises:
AssertionError – If a line is not the same
- compare_single_files(ref_file: str | Path, test_file: str | Path) None [source]
Compare single files generated by tests with ones in reference directories.
- Parameters:
ref_file (str | Path) – The reference file to cmpare against
test_file (str | Path) – The file to compare against the reference
- Raises:
AssertionError – If the files are not the same