From 08aebc1dd85f937277070319f7632f213fe7048a Mon Sep 17 00:00:00 2001 From: Haoyu Yang Date: Sun, 1 Dec 2024 20:05:44 +0800 Subject: [PATCH 01/31] revert for a separate migration PR From 21a36f5075a4c0f80d883161684c97aa4cbc49c8 Mon Sep 17 00:00:00 2001 From: Haoyu Yang Date: Sun, 1 Dec 2024 20:29:14 +0800 Subject: [PATCH 02/31] Revert "revert for a separate migration PR" This reverts commit 6f95ba8890000b88ca790bbada4ffbfcd06b042c. --- tests/command_line/test_enumlib_caller.py | 10 ++++------ tests/command_line/test_gulp_caller.py | 19 ++++++++----------- tests/core/test_surface.py | 4 ++-- tests/io/test_zeopp.py | 3 +-- tests/io/vasp/test_sets.py | 5 ++--- 5 files changed, 17 insertions(+), 24 deletions(-) diff --git a/tests/command_line/test_enumlib_caller.py b/tests/command_line/test_enumlib_caller.py index 010bb0bd1b8..aa3cebff4a3 100644 --- a/tests/command_line/test_enumlib_caller.py +++ b/tests/command_line/test_enumlib_caller.py @@ -1,6 +1,5 @@ from __future__ import annotations -import unittest from shutil import which import numpy as np @@ -14,12 +13,11 @@ from pymatgen.transformations.standard_transformations import SubstitutionTransformation from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest -enum_cmd = which("enum.x") or which("multienum.x") -makestr_cmd = which("makestr.x") or which("makeStr.x") or which("makeStr.py") -enumlib_present = enum_cmd and makestr_cmd +ENUM_CMD = which("enum.x") or which("multienum.x") +MAKESTR_CMD = which("makestr.x") or which("makeStr.x") or which("makeStr.py") -@pytest.mark.skipif(not enumlib_present, reason="enum_lib not present.") +@pytest.mark.skipif(not (ENUM_CMD and MAKESTR_CMD), reason="enumlib not present.") class TestEnumlibAdaptor(PymatgenTest): def test_init(self): struct = self.get_structure("LiFePO4") @@ -119,7 +117,7 @@ def test_partial_disorder(self): for struct in structures: assert struct.formula == "Ca12 Al8 Si4 Ge8 O48" - @unittest.skip("Fails seemingly at random.") + @pytest.mark.skip("Fails seemingly at random.") def test_timeout(self): struct = Structure.from_file(filename=f"{TEST_FILES_DIR}/cif/garnet.cif") SpacegroupAnalyzer(struct, 0.1) diff --git a/tests/command_line/test_gulp_caller.py b/tests/command_line/test_gulp_caller.py index 192c06ef453..1bdb45ae914 100644 --- a/tests/command_line/test_gulp_caller.py +++ b/tests/command_line/test_gulp_caller.py @@ -8,7 +8,6 @@ import os import sys -import unittest from shutil import which from unittest import TestCase @@ -30,13 +29,15 @@ TEST_DIR = f"{TEST_FILES_DIR}/command_line/gulp" -gulp_present = which("gulp") and os.getenv("GULP_LIB") and ("win" not in sys.platform) -# disable gulp tests for now. Right now, it is compiled against libgfortran3, which is no longer supported in the new -# Ubuntu 20.04. -gulp_present = False +GULP_PRESENT = which("gulp") and os.getenv("GULP_LIB") and ("win" not in sys.platform) +# Disable GULP tests for now: it is compiled against `libgfortran3``, +# which is no longer supported in Ubuntu 20.04 and onwards. +GULP_PRESENT = False + +if not GULP_PRESENT: + pytest.skip(reason="GULP not available", allow_module_level=True) -@pytest.mark.skipif(not gulp_present, reason="gulp not present.") class TestGulpCaller: def test_run(self): mgo_lattice = np.eye(3) * 4.212 @@ -105,7 +106,6 @@ def test_decimal(self): caller.run(buckingham_input) -@pytest.mark.skipif(not gulp_present, reason="gulp not present.") class TestGulpIO(TestCase): def setUp(self): self.structure = Structure.from_file(f"{VASP_IN_DIR}/POSCAR_Al12O18") @@ -280,12 +280,11 @@ def test_get_relaxed_structure(self): assert struct.lattice.a == 4.212 assert struct.lattice.alpha == 90 - @unittest.skip("Test later") + @pytest.mark.skip("Test later") def test_tersoff_input(self): self.gio.tersoff_input(self.structure) -@pytest.mark.skipif(not gulp_present, reason="gulp not present.") class TestGlobalFunctions(TestCase): def setUp(self): mgo_latt = np.eye(3) * 4.212 @@ -337,7 +336,6 @@ def test_get_energy_relax_structure_buckingham(self): assert site_len == len(self.mgo_uc) -@pytest.mark.skipif(not gulp_present, reason="gulp not present.") class TestBuckinghamPotentialLewis(TestCase): def setUp(self): self.bpl = BuckinghamPotential("lewis") @@ -365,7 +363,6 @@ def test_spring(self): assert self.bpl.spring_dict["O"] != "" -@pytest.mark.skipif(not gulp_present, reason="gulp not present.") class TestBuckinghamPotentialBush(TestCase): def setUp(self): self.bpb = BuckinghamPotential("bush") diff --git a/tests/core/test_surface.py b/tests/core/test_surface.py index 80f1819da2f..0527fc671b0 100644 --- a/tests/core/test_surface.py +++ b/tests/core/test_surface.py @@ -2,9 +2,9 @@ import json import os -import unittest import numpy as np +import pytest from numpy.testing import assert_allclose from pytest import approx @@ -697,7 +697,7 @@ def test_get_d(self): s2 = recon2.get_unreconstructed_slabs()[0] assert get_d(s1) == approx(get_d(s2)) - @unittest.skip("This test relies on neighbor orders and is hard coded. Disable temporarily") + @pytest.mark.skip("This test relies on neighbor orders and is hard coded. Disable temporarily") def test_previous_reconstructions(self): # Test to see if we generated all reconstruction types correctly and nothing changes diff --git a/tests/io/test_zeopp.py b/tests/io/test_zeopp.py index 819f13a2ee8..28bc18aad8c 100644 --- a/tests/io/test_zeopp.py +++ b/tests/io/test_zeopp.py @@ -1,6 +1,5 @@ from __future__ import annotations -import unittest from unittest import TestCase import pytest @@ -167,7 +166,7 @@ def test_get_voronoi_nodes(self): assert isinstance(vor_face_center_struct, Structure) -@unittest.skip("TODO: file free_sph.cif not present") +@pytest.mark.skip("TODO: file free_sph.cif not present") class TestGetFreeSphereParams(TestCase): def setUp(self): filepath = f"{TEST_FILES_DIR}/cif/free_sph.cif" diff --git a/tests/io/vasp/test_sets.py b/tests/io/vasp/test_sets.py index 4509e1b95f5..6b4f9ceebdb 100644 --- a/tests/io/vasp/test_sets.py +++ b/tests/io/vasp/test_sets.py @@ -2,7 +2,6 @@ import hashlib import os -import unittest from glob import glob from zipfile import ZipFile @@ -1607,7 +1606,7 @@ def test_user_incar_settings(self): assert not vis.incar["LASPH"], "LASPH user setting not applied" assert vis.incar["VDW_SR"] == 1.5, "VDW_SR user setting not applied" - @unittest.skipIf(not os.path.exists(TEST_DIR), "Test files are not present.") + @pytest.mark.skipif(not os.path.exists(TEST_DIR), reason="Test files are not present.") def test_from_prev_calc(self): prev_run = os.path.join(TEST_DIR, "fixtures", "relaxation") @@ -1624,7 +1623,7 @@ def test_from_prev_calc(self): assert "VDW_A2" in vis_bj.incar assert "VDW_S8" in vis_bj.incar - @unittest.skipIf(not os.path.exists(TEST_DIR), "Test files are not present.") + @pytest.mark.skipif(not os.path.exists(TEST_DIR), reason="Test files are not present.") def test_override_from_prev_calc(self): prev_run = os.path.join(TEST_DIR, "fixtures", "relaxation") From 8bacdbc046bb607ab84e637758785235c365a40c Mon Sep 17 00:00:00 2001 From: Haoyu Yang Date: Sun, 1 Dec 2024 20:34:16 +0800 Subject: [PATCH 03/31] remove hard-coded and failing test --- tests/command_line/test_gulp_caller.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/tests/command_line/test_gulp_caller.py b/tests/command_line/test_gulp_caller.py index 1bdb45ae914..18c3f05c268 100644 --- a/tests/command_line/test_gulp_caller.py +++ b/tests/command_line/test_gulp_caller.py @@ -132,15 +132,6 @@ def test_structure_lines_no_frac_coords(self): assert "cell" not in inp_str assert "cart" in inp_str - @unittest.skip("Not Implemented yet") - def test_specie_potential(self): - pass - - @unittest.expectedFailure - def test_library_line_explicit_path(self): - gin = self.gio.library_line("/Users/mbkumar/Research/Defects/GulpExe/Libraries/catlow.lib") - assert "lib" in gin - def test_library_line_wrong_file(self): with pytest.raises(GulpError, match="GULP library not found"): self.gio.library_line("temp_to_fail.lib") From 344a87235d4419f2ca146e33e1e3bf5011d946ab Mon Sep 17 00:00:00 2001 From: Haoyu Yang Date: Tue, 3 Dec 2024 22:33:25 +0800 Subject: [PATCH 04/31] batch remove PymatgenTest inheritance and see what fail --- tests/alchemy/test_filters.py | 6 +-- tests/alchemy/test_materials.py | 2 +- tests/alchemy/test_transmuters.py | 6 +-- .../connectivity/test_connected_components.py | 4 +- .../connectivity/test_environment_nodes.py | 3 +- .../test_structure_connectivity.py | 4 +- .../test_chemenv_strategies.py | 3 +- .../test_coordination_geometries.py | 3 +- .../test_coordination_geometry_finder.py | 4 +- .../test_read_write.py | 4 +- .../test_structure_environments.py | 4 +- .../coordination_environments/test_voronoi.py | 4 +- .../coordination_environments/test_weights.py | 4 +- .../chemenv/utils/test_chemenv_config.py | 4 +- .../utils/test_coordination_geometry_utils.py | 3 +- .../chemenv/utils/test_graph_utils.py | 5 +- .../analysis/chemenv/utils/test_math_utils.py | 3 +- tests/analysis/diffraction/test_neutron.py | 3 +- tests/analysis/diffraction/test_tem.py | 3 +- tests/analysis/diffraction/test_xrd.py | 3 +- tests/analysis/elasticity/test_elastic.py | 10 ++-- tests/analysis/elasticity/test_strain.py | 7 ++- tests/analysis/elasticity/test_stress.py | 3 +- .../ferroelectricity/test_polarization.py | 8 +-- .../interfaces/test_coherent_interface.py | 7 ++- tests/analysis/interfaces/test_zsl.py | 3 +- tests/analysis/solar/test_slme.py | 4 +- .../structure_prediction/test_substitutor.py | 2 +- .../test_volume_predictor.py | 4 +- tests/analysis/test_adsorption.py | 3 +- tests/analysis/test_bond_valence.py | 6 +-- tests/analysis/test_chempot_diagram.py | 4 +- tests/analysis/test_dimensionality.py | 8 +-- tests/analysis/test_disorder.py | 3 +- tests/analysis/test_eos.py | 3 +- tests/analysis/test_fragmenter.py | 4 +- tests/analysis/test_graphs.py | 4 +- tests/analysis/test_local_env.py | 30 +++++------ tests/analysis/test_nmr.py | 5 +- tests/analysis/test_phase_diagram.py | 4 +- tests/analysis/test_piezo.py | 3 +- tests/analysis/test_piezo_sensitivity.py | 4 +- tests/analysis/test_pourbaix_diagram.py | 4 +- tests/analysis/test_prototypes.py | 3 +- tests/analysis/test_structure_analyzer.py | 8 +-- tests/analysis/test_structure_matcher.py | 4 +- tests/analysis/test_surface_analysis.py | 10 ++-- tests/analysis/test_transition_state.py | 4 +- tests/analysis/test_wulff.py | 4 +- tests/analysis/test_xps.py | 4 +- tests/analysis/topological/test_spillage.py | 4 +- tests/analysis/xas/test_spectrum.py | 4 +- tests/apps/battery/test_analyzer.py | 4 +- tests/command_line/test_bader_caller.py | 4 +- tests/command_line/test_enumlib_caller.py | 4 +- tests/command_line/test_mcsqs_caller.py | 4 +- tests/command_line/test_vampire_caller.py | 4 +- tests/core/test_composition.py | 3 +- tests/core/test_interface.py | 8 +-- tests/core/test_lattice.py | 3 +- tests/core/test_libxcfunc.py | 3 +- tests/core/test_molecular_orbitals.py | 3 +- tests/core/test_operations.py | 5 +- tests/core/test_periodic_table.py | 5 +- tests/core/test_sites.py | 5 +- tests/core/test_spectrum.py | 3 +- tests/core/test_structure.py | 10 ++-- tests/core/test_surface.py | 10 ++-- tests/core/test_tensors.py | 8 +-- tests/core/test_trajectory.py | 4 +- tests/core/test_units.py | 9 ++-- tests/core/test_xcfunc.py | 3 +- .../test_bandstructure.py | 8 +-- tests/electronic_structure/test_cohp.py | 4 +- tests/electronic_structure/test_dos.py | 4 +- tests/electronic_structure/test_plotter.py | 8 +-- tests/entries/test_entry_tools.py | 6 +-- tests/ext/test_matproj.py | 6 +-- tests/ext/test_optimade.py | 3 +- tests/io/abinit/test_abiobjects.py | 18 +++---- tests/io/abinit/test_inputs.py | 10 ++-- tests/io/abinit/test_netcdf.py | 6 +-- tests/io/abinit/test_pseudos.py | 6 +-- tests/io/cp2k/test_inputs.py | 10 ++-- tests/io/cp2k/test_sets.py | 4 +- tests/io/exciting/test_inputs.py | 4 +- tests/io/feff/test_sets.py | 4 +- tests/io/lammps/test_data.py | 8 +-- tests/io/lammps/test_generators.py | 4 +- tests/io/lammps/test_inputs.py | 10 ++-- tests/io/lobster/test_inputs.py | 6 +-- tests/io/lobster/test_outputs.py | 22 ++++---- tests/io/pwmat/test_inputs.py | 10 ++-- tests/io/pwmat/test_outputs.py | 10 ++-- tests/io/qchem/test_inputs.py | 4 +- tests/io/qchem/test_outputs.py | 4 +- tests/io/qchem/test_sets.py | 16 +++--- tests/io/qchem/test_utils.py | 4 +- tests/io/test_adf.py | 4 +- tests/io/test_atat.py | 4 +- tests/io/test_cif.py | 8 +-- tests/io/test_core.py | 6 +-- tests/io/test_lmto.py | 6 +-- tests/io/test_packmol.py | 4 +- tests/io/test_phonopy.py | 8 +-- tests/io/test_pwscf.py | 6 +-- tests/io/test_shengbte.py | 4 +- tests/io/test_template_input.py | 4 +- tests/io/test_wannier90.py | 4 +- tests/io/test_xcrysden.py | 3 +- tests/io/vasp/test_inputs.py | 10 ++-- tests/io/vasp/test_optics.py | 4 +- tests/io/vasp/test_outputs.py | 28 +++++----- tests/io/vasp/test_sets.py | 52 +++++++++---------- tests/io/xtb/test_inputs.py | 4 +- tests/io/xtb/test_outputs.py | 4 +- tests/optimization/test_neighbors.py | 3 +- tests/phonon/test_bandstructure.py | 4 +- tests/phonon/test_dos.py | 6 +-- tests/phonon/test_gruneisen.py | 6 +-- tests/phonon/test_ir_spectra.py | 4 +- tests/phonon/test_thermal_displacements.py | 4 +- tests/symmetry/test_analyzer.py | 4 +- tests/symmetry/test_kpath_hin.py | 3 +- tests/symmetry/test_kpath_lm.py | 4 +- tests/symmetry/test_kpath_sc.py | 4 +- tests/symmetry/test_kpaths.py | 4 +- tests/symmetry/test_maggroups.py | 3 +- tests/symmetry/test_site_symmetries.py | 4 +- .../test_advanced_transformations.py | 22 ++++---- .../test_site_transformations.py | 7 ++- tests/util/test_io.py | 4 +- tests/util/test_plotting.py | 3 +- tests/vis/test_plotters.py | 4 +- 134 files changed, 387 insertions(+), 423 deletions(-) diff --git a/tests/alchemy/test_filters.py b/tests/alchemy/test_filters.py index 16737ae67fa..8810ca30551 100644 --- a/tests/alchemy/test_filters.py +++ b/tests/alchemy/test_filters.py @@ -14,10 +14,10 @@ from pymatgen.alchemy.transmuters import StandardTransmuter from pymatgen.analysis.structure_matcher import StructureMatcher from pymatgen.core import Lattice, Species, Structure -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR -class TestContainsSpecieFilter(PymatgenTest): +class TestContainsSpecieFilter: def test_filtering(self): coords = [[0, 0, 0], [0.75, 0.75, 0.75], [0.5, 0.5, 0.5], [0.25, 0.25, 0.25]] lattice = Lattice([[3.0, 0.0, 0.0], [1.0, 3.0, 0], [0, -2.0, 3.0]]) @@ -52,7 +52,7 @@ def test_as_from_dict(self): assert isinstance(ContainsSpecieFilter.from_dict(dct), ContainsSpecieFilter) -class TestSpecieProximityFilter(PymatgenTest): +class TestSpecieProximityFilter: def test_filter(self): struct = self.get_structure("Li10GeP2S12") sf = SpecieProximityFilter({"Li": 1}) diff --git a/tests/alchemy/test_materials.py b/tests/alchemy/test_materials.py index 25b8cc74ad2..2569b7ec46c 100644 --- a/tests/alchemy/test_materials.py +++ b/tests/alchemy/test_materials.py @@ -21,7 +21,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/alchemy" -class TestTransformedStructure(PymatgenTest): +class TestTransformedStructure: def setUp(self): structure = PymatgenTest.get_structure("LiFePO4") self.structure = structure diff --git a/tests/alchemy/test_transmuters.py b/tests/alchemy/test_transmuters.py index 653a98c5326..17cabc9d930 100644 --- a/tests/alchemy/test_transmuters.py +++ b/tests/alchemy/test_transmuters.py @@ -8,10 +8,10 @@ RemoveSpeciesTransformation, SubstitutionTransformation, ) -from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR -class TestCifTransmuter(PymatgenTest): +class TestCifTransmuter: def test_init(self): trafos = [SubstitutionTransformation({"Fe": "Mn", "Fe2+": "Mn2+"})] tsc = CifTransmuter.from_filenames([f"{TEST_FILES_DIR}/cif/MultiStructure.cif"], trafos) @@ -22,7 +22,7 @@ def test_init(self): assert expected == els -class TestPoscarTransmuter(PymatgenTest): +class TestPoscarTransmuter: def test_init(self): trafos = [SubstitutionTransformation({"Fe": "Mn"})] tsc = PoscarTransmuter.from_filenames([f"{VASP_IN_DIR}/POSCAR", f"{VASP_IN_DIR}/POSCAR"], trafos) diff --git a/tests/analysis/chemenv/connectivity/test_connected_components.py b/tests/analysis/chemenv/connectivity/test_connected_components.py index fc9e561c57e..311f60381fa 100644 --- a/tests/analysis/chemenv/connectivity/test_connected_components.py +++ b/tests/analysis/chemenv/connectivity/test_connected_components.py @@ -20,12 +20,12 @@ from pymatgen.core.lattice import Lattice from pymatgen.core.sites import PeriodicSite from pymatgen.core.structure import Structure -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR __author__ = "waroquiers" -class TestConnectedComponent(PymatgenTest): +class TestConnectedComponent: def test_init(self): # Generic connected component not using EnvironmentNodes # (as_dict won't work on such a ConnectedComponent instance) diff --git a/tests/analysis/chemenv/connectivity/test_environment_nodes.py b/tests/analysis/chemenv/connectivity/test_environment_nodes.py index 60af01acff7..c009a735c81 100644 --- a/tests/analysis/chemenv/connectivity/test_environment_nodes.py +++ b/tests/analysis/chemenv/connectivity/test_environment_nodes.py @@ -3,7 +3,6 @@ import json from pymatgen.analysis.chemenv.connectivity.environment_nodes import EnvironmentNode -from pymatgen.util.testing import PymatgenTest try: import bson @@ -13,7 +12,7 @@ __author__ = "waroquiers" -class TestEnvironmentNodes(PymatgenTest): +class TestEnvironmentNodes: def test_equal(self): struct = self.get_structure("SiO2") en = EnvironmentNode(central_site=struct[0], i_central_site=0, ce_symbol="T:4") diff --git a/tests/analysis/chemenv/connectivity/test_structure_connectivity.py b/tests/analysis/chemenv/connectivity/test_structure_connectivity.py index 37f8da4b98a..bb0452bb747 100644 --- a/tests/analysis/chemenv/connectivity/test_structure_connectivity.py +++ b/tests/analysis/chemenv/connectivity/test_structure_connectivity.py @@ -9,12 +9,12 @@ LightStructureEnvironments, StructureEnvironments, ) -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR __author__ = "waroquiers" -class TestStructureConnectivity(PymatgenTest): +class TestStructureConnectivity: def test_serialization(self): BaTiO3_se_fpath = f"{TEST_FILES_DIR}/analysis/chemenv/structure_environments/se_mp-5020.json" with open(BaTiO3_se_fpath) as file: diff --git a/tests/analysis/chemenv/coordination_environments/test_chemenv_strategies.py b/tests/analysis/chemenv/coordination_environments/test_chemenv_strategies.py index 64516b22c41..7c83da588b8 100644 --- a/tests/analysis/chemenv/coordination_environments/test_chemenv_strategies.py +++ b/tests/analysis/chemenv/coordination_environments/test_chemenv_strategies.py @@ -10,12 +10,11 @@ DistanceCutoffFloat, SimplestChemenvStrategy, ) -from pymatgen.util.testing import PymatgenTest __author__ = "waroquiers" -class TestStrategyOptions(PymatgenTest): +class TestStrategyOptions: def test_options(self): # DistanceCutoffFloat with pytest.raises(ValueError, match=r"Distance cutoff should be between 1 and \+infinity"): diff --git a/tests/analysis/chemenv/coordination_environments/test_coordination_geometries.py b/tests/analysis/chemenv/coordination_environments/test_coordination_geometries.py index 18fc1675835..30d54b9657b 100644 --- a/tests/analysis/chemenv/coordination_environments/test_coordination_geometries.py +++ b/tests/analysis/chemenv/coordination_environments/test_coordination_geometries.py @@ -11,7 +11,6 @@ ExplicitPermutationsAlgorithm, SeparationPlane, ) -from pymatgen.util.testing import PymatgenTest __author__ = "waroquiers" @@ -23,7 +22,7 @@ def __init__(self, coords): self.coords = coords -class TestCoordinationGeometries(PymatgenTest): +class TestCoordinationGeometries: def test_algorithms(self): expl_algo = ExplicitPermutationsAlgorithm(permutations=[[0, 1, 2], [1, 2, 3]]) expl_algo2 = ExplicitPermutationsAlgorithm.from_dict(expl_algo.as_dict()) diff --git a/tests/analysis/chemenv/coordination_environments/test_coordination_geometry_finder.py b/tests/analysis/chemenv/coordination_environments/test_coordination_geometry_finder.py index 01aedf2d245..f780d439cf7 100644 --- a/tests/analysis/chemenv/coordination_environments/test_coordination_geometry_finder.py +++ b/tests/analysis/chemenv/coordination_environments/test_coordination_geometry_finder.py @@ -19,14 +19,14 @@ symmetry_measure, ) from pymatgen.core.structure import Lattice, Structure -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR __author__ = "waroquiers" json_dir = f"{TEST_FILES_DIR}/analysis/chemenv/json" -class TestCoordinationGeometryFinder(PymatgenTest): +class TestCoordinationGeometryFinder: def setUp(self): self.lgf = LocalGeometryFinder() self.lgf.setup_parameters( diff --git a/tests/analysis/chemenv/coordination_environments/test_read_write.py b/tests/analysis/chemenv/coordination_environments/test_read_write.py index 640770fccad..c120b333953 100644 --- a/tests/analysis/chemenv/coordination_environments/test_read_write.py +++ b/tests/analysis/chemenv/coordination_environments/test_read_write.py @@ -22,7 +22,7 @@ ) from pymatgen.analysis.chemenv.coordination_environments.voronoi import DetailedVoronoiContainer from pymatgen.core.structure import Structure -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR __author__ = "waroquiers" @@ -30,7 +30,7 @@ struct_env_dir = f"{TEST_FILES_DIR}/analysis/chemenv/structure_environments" -class TestReadWriteChemenv(PymatgenTest): +class TestReadWriteChemenv: @classmethod def setUpClass(cls): cls.lgf = LocalGeometryFinder() diff --git a/tests/analysis/chemenv/coordination_environments/test_structure_environments.py b/tests/analysis/chemenv/coordination_environments/test_structure_environments.py index 3f8bde41636..4128b3e0265 100644 --- a/tests/analysis/chemenv/coordination_environments/test_structure_environments.py +++ b/tests/analysis/chemenv/coordination_environments/test_structure_environments.py @@ -17,14 +17,14 @@ StructureEnvironments, ) from pymatgen.core import Species, Structure -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR __author__ = "waroquiers" TEST_DIR = f"{TEST_FILES_DIR}/analysis/chemenv/structure_environments" -class TestStructureEnvironments(PymatgenTest): +class TestStructureEnvironments: def test_structure_environments(self): with open(f"{TEST_DIR}/se_mp-7000.json") as file: dct = json.load(file) diff --git a/tests/analysis/chemenv/coordination_environments/test_voronoi.py b/tests/analysis/chemenv/coordination_environments/test_voronoi.py index 492cc00df36..6e5a2f10779 100644 --- a/tests/analysis/chemenv/coordination_environments/test_voronoi.py +++ b/tests/analysis/chemenv/coordination_environments/test_voronoi.py @@ -5,14 +5,14 @@ from pymatgen.analysis.chemenv.coordination_environments.voronoi import DetailedVoronoiContainer from pymatgen.core.lattice import Lattice from pymatgen.core.structure import Structure -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR __author__ = "waroquiers" img_files_dir = f"{TEST_FILES_DIR}/analysis/chemenv/images" -class TestVoronoiContainer(PymatgenTest): +class TestVoronoiContainer: def test_voronoi(self): # Define a cubic lattice and a list of species (to be used for the fake structures) cubic_lattice = Lattice.cubic(10) diff --git a/tests/analysis/chemenv/coordination_environments/test_weights.py b/tests/analysis/chemenv/coordination_environments/test_weights.py index 6a5b2ffe50a..56cffa85a00 100644 --- a/tests/analysis/chemenv/coordination_environments/test_weights.py +++ b/tests/analysis/chemenv/coordination_environments/test_weights.py @@ -16,7 +16,7 @@ SelfCSMNbSetWeight, ) from pymatgen.analysis.chemenv.coordination_environments.structure_environments import StructureEnvironments -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR __author__ = "waroquiers" @@ -39,7 +39,7 @@ class DummyVoronoiContainer: pass -class StrategyWeights(PymatgenTest): +class StrategyWeights: def test_angle_weight(self): fake_nb_set = FakeNbSet() dummy_se = DummyStructureEnvironments() diff --git a/tests/analysis/chemenv/utils/test_chemenv_config.py b/tests/analysis/chemenv/utils/test_chemenv_config.py index bea8a66770f..3d495f2467f 100644 --- a/tests/analysis/chemenv/utils/test_chemenv_config.py +++ b/tests/analysis/chemenv/utils/test_chemenv_config.py @@ -2,14 +2,14 @@ from pymatgen.analysis.chemenv.utils.chemenv_config import ChemEnvConfig from pymatgen.core import SETTINGS -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR __author__ = "waroquiers" config_file_dir = f"{TEST_FILES_DIR}/analysis/chemenv/config" -class TestChemenvConfig(PymatgenTest): +class TestChemenvConfig: def test_chemenv_config(self): config = ChemEnvConfig() diff --git a/tests/analysis/chemenv/utils/test_coordination_geometry_utils.py b/tests/analysis/chemenv/utils/test_coordination_geometry_utils.py index d7cbc5b7f19..2439885c09d 100644 --- a/tests/analysis/chemenv/utils/test_coordination_geometry_utils.py +++ b/tests/analysis/chemenv/utils/test_coordination_geometry_utils.py @@ -7,12 +7,11 @@ from pytest import approx from pymatgen.analysis.chemenv.utils.coordination_geometry_utils import Plane -from pymatgen.util.testing import PymatgenTest __author__ = "David Waroquiers" -class TestPlanesUtils(PymatgenTest): +class TestPlanesUtils: def setUp(self): # Test of plane 4x + 2y - 4z + 3 = 0 (used in most test cases) self.expected_coefficients = np.array([4, 2, -4, 3], float) diff --git a/tests/analysis/chemenv/utils/test_graph_utils.py b/tests/analysis/chemenv/utils/test_graph_utils.py index b5f32fe7e94..a936a7a5d26 100644 --- a/tests/analysis/chemenv/utils/test_graph_utils.py +++ b/tests/analysis/chemenv/utils/test_graph_utils.py @@ -5,7 +5,6 @@ from pymatgen.analysis.chemenv.connectivity.environment_nodes import EnvironmentNode from pymatgen.analysis.chemenv.utils.graph_utils import MultiGraphCycle, SimpleGraphCycle, get_delta -from pymatgen.util.testing import PymatgenTest __author__ = "waroquiers" @@ -68,7 +67,7 @@ def __lt__(self, other): return self.isite % 2 < other.isite % 2 -class TestGraphUtils(PymatgenTest): +class TestGraphUtils: def test_get_delta(self): n1 = FakeNode(3) n2 = FakeNode(7) @@ -664,7 +663,7 @@ def test_multigraph_cycle(self): assert mgc.edge_indices == edges_ref, f"Edges not equal for inodes = ({str_nodes})" -class TestEnvironmentNodesGraphUtils(PymatgenTest): +class TestEnvironmentNodesGraphUtils: def test_cycle(self): e1 = EnvironmentNode(central_site="Si", i_central_site=0, ce_symbol="T:4") e2 = EnvironmentNode(central_site="Si", i_central_site=3, ce_symbol="T:4") diff --git a/tests/analysis/chemenv/utils/test_math_utils.py b/tests/analysis/chemenv/utils/test_math_utils.py index d3583a24851..90e09e38d09 100644 --- a/tests/analysis/chemenv/utils/test_math_utils.py +++ b/tests/analysis/chemenv/utils/test_math_utils.py @@ -16,12 +16,11 @@ smootherstep, smoothstep, ) -from pymatgen.util.testing import PymatgenTest __author__ = "waroquiers" -class TestMathUtils(PymatgenTest): +class TestMathUtils: def test_list_cartesian_product(self): list_of_lists = [[0, 1], [2, 5, 4], [5]] assert _cartesian_product(lists=list_of_lists) == [ diff --git a/tests/analysis/diffraction/test_neutron.py b/tests/analysis/diffraction/test_neutron.py index 4de897d85d6..0e7ced4628d 100644 --- a/tests/analysis/diffraction/test_neutron.py +++ b/tests/analysis/diffraction/test_neutron.py @@ -6,7 +6,6 @@ from pymatgen.analysis.diffraction.neutron import NDCalculator from pymatgen.core.lattice import Lattice from pymatgen.core.structure import Structure -from pymatgen.util.testing import PymatgenTest """ These calculated values were verified with VESTA and FullProf. @@ -20,7 +19,7 @@ __date__ = "4/19/18" -class TestNDCalculator(PymatgenTest): +class TestNDCalculator: def test_get_pattern(self): struct = self.get_structure("CsCl") c = NDCalculator(wavelength=1.54184) # CuKa radiation diff --git a/tests/analysis/diffraction/test_tem.py b/tests/analysis/diffraction/test_tem.py index c8cfee3b1d5..e8dee624399 100644 --- a/tests/analysis/diffraction/test_tem.py +++ b/tests/analysis/diffraction/test_tem.py @@ -11,7 +11,6 @@ from pymatgen.analysis.diffraction.tem import TEMCalculator from pymatgen.core.lattice import Lattice from pymatgen.core.structure import Structure -from pymatgen.util.testing import PymatgenTest __author__ = "Frank Wan, Jason Liang" __copyright__ = "Copyright 2019, The Materials Project" @@ -21,7 +20,7 @@ __date__ = "2/20/20" -class TestTEMCalculator(PymatgenTest): +class TestTEMCalculator: def test_wavelength_rel(self): # Test that the relativistic wavelength formula (for 200 kV electron beam) is correct tem_calc = TEMCalculator() diff --git a/tests/analysis/diffraction/test_xrd.py b/tests/analysis/diffraction/test_xrd.py index 997c43de42b..4a40a24577e 100644 --- a/tests/analysis/diffraction/test_xrd.py +++ b/tests/analysis/diffraction/test_xrd.py @@ -6,7 +6,6 @@ from pymatgen.analysis.diffraction.xrd import XRDCalculator from pymatgen.core.lattice import Lattice from pymatgen.core.structure import Structure -from pymatgen.util.testing import PymatgenTest __author__ = "Shyue Ping Ong" __copyright__ = "Copyright 2012, The Materials Project" @@ -16,7 +15,7 @@ __date__ = "5/22/14" -class TestXRDCalculator(PymatgenTest): +class TestXRDCalculator: def test_type_wavelength(self): """Test TypeError is raised if wavelength is unaccepted type.""" wavelength = [1.78, 2.78] # just a list diff --git a/tests/analysis/elasticity/test_elastic.py b/tests/analysis/elasticity/test_elastic.py index 699f97d4061..7c6c39b11d0 100644 --- a/tests/analysis/elasticity/test_elastic.py +++ b/tests/analysis/elasticity/test_elastic.py @@ -27,12 +27,12 @@ from pymatgen.core.structure import Structure from pymatgen.core.tensors import Tensor from pymatgen.core.units import FloatWithUnit -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR TEST_DIR = f"{TEST_FILES_DIR}/analysis/elasticity" -class TestElasticTensor(PymatgenTest): +class TestElasticTensor: def setUp(self): self.voigt_1 = [ [59.33, 28.08, 28.08, 0, 0, 0], @@ -263,7 +263,7 @@ def test_energy_density(self): ) -class TestElasticTensorExpansion(PymatgenTest): +class TestElasticTensorExpansion: def setUp(self): with open(f"{TEST_DIR}/test_toec_data.json") as file: self.data_dict = json.load(file) @@ -364,7 +364,7 @@ def test_get_yield_stress(self): self.exp_cu_4.get_yield_stress([1, 0, 0]) -class TestNthOrderElasticTensor(PymatgenTest): +class TestNthOrderElasticTensor: def setUp(self): with open(f"{TEST_DIR}/test_toec_data.json") as file: self.data_dict = json.load(file) @@ -401,7 +401,7 @@ def test_energy_density(self): self.c3.energy_density(self.strains[0]) -class TestDiffFit(PymatgenTest): +class TestDiffFit: """Test various functions related to diff fitting.""" def setUp(self): diff --git a/tests/analysis/elasticity/test_strain.py b/tests/analysis/elasticity/test_strain.py index 9679fb367cd..53c33a5192a 100644 --- a/tests/analysis/elasticity/test_strain.py +++ b/tests/analysis/elasticity/test_strain.py @@ -7,10 +7,9 @@ from pymatgen.analysis.elasticity.strain import Deformation, DeformedStructureSet, Strain, convert_strain_to_deformation from pymatgen.core.structure import Structure from pymatgen.core.tensors import Tensor -from pymatgen.util.testing import PymatgenTest -class TestDeformation(PymatgenTest): +class TestDeformation: def setUp(self): self.norm_defo = Deformation.from_index_amount((0, 0), 0.02) self.ind_defo = Deformation.from_index_amount((0, 1), 0.02) @@ -81,7 +80,7 @@ def test_apply_to_structure(self): assert_allclose(new_coord, defo_coord) -class TestStrain(PymatgenTest): +class TestStrain: def setUp(self): self.norm_str = Strain.from_deformation([[1.02, 0, 0], [0, 1, 0], [0, 0, 1]]) self.ind_str = Strain.from_deformation([[1, 0.02, 0], [0, 1, 0], [0, 0, 1]]) @@ -142,7 +141,7 @@ def test_convert_strain_to_deformation(self): assert_allclose(defo.green_lagrange_strain, strain) -class TestDeformedStructureSet(PymatgenTest): +class TestDeformedStructureSet: def setUp(self): self.structure = self.get_structure("Sn") self.default_dss = DeformedStructureSet(self.structure) diff --git a/tests/analysis/elasticity/test_stress.py b/tests/analysis/elasticity/test_stress.py index 9d1dc98ad33..58e0bf1507c 100644 --- a/tests/analysis/elasticity/test_stress.py +++ b/tests/analysis/elasticity/test_stress.py @@ -7,10 +7,9 @@ from pymatgen.analysis.elasticity.strain import Deformation from pymatgen.analysis.elasticity.stress import Stress -from pymatgen.util.testing import PymatgenTest -class TestStress(PymatgenTest): +class TestStress: def setUp(self): self.rand_stress = Stress(np.random.default_rng().standard_normal((3, 3))) self.symm_stress = Stress([[0.51, 2.29, 2.42], [2.29, 5.14, 5.07], [2.42, 5.07, 5.33]]) diff --git a/tests/analysis/ferroelectricity/test_polarization.py b/tests/analysis/ferroelectricity/test_polarization.py index 57236ff98c4..71bb13d45e3 100644 --- a/tests/analysis/ferroelectricity/test_polarization.py +++ b/tests/analysis/ferroelectricity/test_polarization.py @@ -13,7 +13,7 @@ from pymatgen.core.structure import Structure from pymatgen.io.vasp.inputs import Potcar from pymatgen.io.vasp.outputs import Outcar -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR TEST_DIR = f"{TEST_FILES_DIR}/io/vasp/fixtures/BTO_221_99_polarization" bto_folders = ["nonpolar_polarization"] @@ -38,7 +38,7 @@ ) -class TestUtils(PymatgenTest): +class TestUtils: def setUp(self): self.potcar = Potcar.from_file(f"{TEST_DIR}/POTCAR") self.zval_dict = {"Ba": 10, "Ti": 10, "O": 6} @@ -54,7 +54,7 @@ def test_get_total_ionic_dipole(self): assert_allclose(p_ion, self.ions[-1].ravel().tolist()) -class TestPolarization(PymatgenTest): +class TestPolarization: def setUp(self): self.p_ions = ions self.p_ions_outcar = np.array( @@ -258,7 +258,7 @@ def test_smoothness(self): assert_allclose(self.smoothness_all_in_polar, smoothness) -class TestEnergyTrend(PymatgenTest): +class TestEnergyTrend: def setUp(self): self.energies = [ -7.97738049, diff --git a/tests/analysis/interfaces/test_coherent_interface.py b/tests/analysis/interfaces/test_coherent_interface.py index e2a19a73915..2e6bc1ba1bc 100644 --- a/tests/analysis/interfaces/test_coherent_interface.py +++ b/tests/analysis/interfaces/test_coherent_interface.py @@ -1,6 +1,6 @@ from __future__ import annotations -import unittest +from unittest import TestCase from numpy.testing import assert_allclose @@ -14,10 +14,9 @@ from pymatgen.core.lattice import Lattice from pymatgen.core.structure import Structure from pymatgen.symmetry.analyzer import SpacegroupAnalyzer -from pymatgen.util.testing import PymatgenTest -class TestInterfaceBuilder(PymatgenTest): +class TestInterfaceBuilder: @classmethod def setUpClass(cls): si_struct = cls.get_structure("Si") @@ -51,7 +50,7 @@ def test_coherent_interface_builder(self): assert len(list(builder.get_interfaces(termination=("O2_Pmmm_1", "Si_R-3m_1")))) >= 6 -class TestCoherentInterfaceBuilder(unittest.TestCase): +class TestCoherentInterfaceBuilder(TestCase): def setUp(self): # build substrate & film structure basis = [[0, 0, 0], [0.25, 0.25, 0.25]] diff --git a/tests/analysis/interfaces/test_zsl.py b/tests/analysis/interfaces/test_zsl.py index 25ab77950e1..cc7c8657403 100644 --- a/tests/analysis/interfaces/test_zsl.py +++ b/tests/analysis/interfaces/test_zsl.py @@ -13,7 +13,6 @@ vec_area, ) from pymatgen.symmetry.analyzer import SpacegroupAnalyzer -from pymatgen.util.testing import PymatgenTest __author__ = "Shyam Dwaraknath" __copyright__ = "Copyright 2016, The Materials Project" @@ -23,7 +22,7 @@ __date__ = "2/5/16" -class TestZSLGen(PymatgenTest): +class TestZSLGen: def setUp(self): # Film VO2 self.film = SpacegroupAnalyzer(self.get_structure("VO2"), symprec=0.1).get_conventional_standard_structure() diff --git a/tests/analysis/solar/test_slme.py b/tests/analysis/solar/test_slme.py index 3ccf3256d11..334e7d63a4c 100644 --- a/tests/analysis/solar/test_slme.py +++ b/tests/analysis/solar/test_slme.py @@ -3,12 +3,12 @@ from pytest import approx from pymatgen.analysis.solar.slme import optics, slme -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR TEST_DIR = f"{TEST_FILES_DIR}/analysis/solar" -class TestSolar(PymatgenTest): +class TestSolar: def test_slme_from_vasprun(self): en, abz, dir_gap, indir_gap = optics(f"{TEST_DIR}/vasprun.xml") abz *= 100.0 diff --git a/tests/analysis/structure_prediction/test_substitutor.py b/tests/analysis/structure_prediction/test_substitutor.py index 6965408afcc..be05f0bc60d 100644 --- a/tests/analysis/structure_prediction/test_substitutor.py +++ b/tests/analysis/structure_prediction/test_substitutor.py @@ -20,7 +20,7 @@ def get_table(): return json.load(file) -class TestSubstitutor(PymatgenTest): +class TestSubstitutor: def setUp(self): self.substitutor = Substitutor(threshold=1e-3, lambda_table=get_table(), alpha=-5.0) diff --git a/tests/analysis/structure_prediction/test_volume_predictor.py b/tests/analysis/structure_prediction/test_volume_predictor.py index 20ecf2bd24b..f75df75cf3a 100644 --- a/tests/analysis/structure_prediction/test_volume_predictor.py +++ b/tests/analysis/structure_prediction/test_volume_predictor.py @@ -10,7 +10,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/analysis/structure_prediction" -class TestRLSVolumePredictor(PymatgenTest): +class TestRLSVolumePredictor: def test_predict(self): struct = PymatgenTest.get_structure("CsCl") nacl = PymatgenTest.get_structure("CsCl") @@ -77,7 +77,7 @@ def test_modes(self): assert vol_pred.predict(cs_cl, na_cl) == approx(342.84905395082535) -class TestDLSVolumePredictor(PymatgenTest): +class TestDLSVolumePredictor: def test_predict(self): vol_pred = DLSVolumePredictor() p_fast = DLSVolumePredictor(cutoff=0.0) # for speed on compressed cells diff --git a/tests/analysis/test_adsorption.py b/tests/analysis/test_adsorption.py index ced3948a366..6a9dd3b070d 100644 --- a/tests/analysis/test_adsorption.py +++ b/tests/analysis/test_adsorption.py @@ -8,10 +8,9 @@ from pymatgen.core.structure import Molecule, Structure from pymatgen.symmetry.analyzer import SpacegroupAnalyzer from pymatgen.util.coord import in_coord_list -from pymatgen.util.testing import PymatgenTest -class TestAdsorbateSiteFinder(PymatgenTest): +class TestAdsorbateSiteFinder: def setUp(self): self.structure = Structure.from_spacegroup("Fm-3m", Lattice.cubic(3.5), ["Ni"], [[0, 0, 0]]) lattice = Lattice.cubic(3.010) diff --git a/tests/analysis/test_bond_valence.py b/tests/analysis/test_bond_valence.py index a2e0db2ce0c..06c0fef3dc3 100644 --- a/tests/analysis/test_bond_valence.py +++ b/tests/analysis/test_bond_valence.py @@ -5,12 +5,12 @@ from pymatgen.analysis.bond_valence import BVAnalyzer, calculate_bv_sum, calculate_bv_sum_unordered from pymatgen.core import Composition, Species, Structure -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR TEST_DIR = f"{TEST_FILES_DIR}/analysis/bond_valence" -class TestBVAnalyzer(PymatgenTest): +class TestBVAnalyzer: def setUp(self): self.analyzer = BVAnalyzer() @@ -44,7 +44,7 @@ def test_get_oxi_state_structure(self): assert Species("Mn4+") in oxi_struct.composition.elements -class TestBondValenceSum(PymatgenTest): +class TestBondValenceSum: def test_calculate_bv_sum(self): struct = Structure.from_file(f"{TEST_DIR}/LiMn2O4.json") neighbors = struct.get_neighbors(struct[0], 3.0) diff --git a/tests/analysis/test_chempot_diagram.py b/tests/analysis/test_chempot_diagram.py index 43dfd957b0d..192e4aaf9de 100644 --- a/tests/analysis/test_chempot_diagram.py +++ b/tests/analysis/test_chempot_diagram.py @@ -12,12 +12,12 @@ ) from pymatgen.core.composition import Element from pymatgen.entries.entry_tools import EntrySet -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR TEST_DIR = f"{TEST_FILES_DIR}/analysis" -class TestChemicalPotentialDiagram(PymatgenTest): +class TestChemicalPotentialDiagram: def setUp(self): self.entries = EntrySet.from_csv(f"{TEST_DIR}/pd_entries_test.csv") self.cpd_ternary, self.cpd_ternary_formal = ( diff --git a/tests/analysis/test_dimensionality.py b/tests/analysis/test_dimensionality.py index 8b99c6fd5e2..0f1139e7072 100644 --- a/tests/analysis/test_dimensionality.py +++ b/tests/analysis/test_dimensionality.py @@ -15,10 +15,10 @@ from pymatgen.analysis.graphs import StructureGraph from pymatgen.analysis.local_env import CrystalNN from pymatgen.core.structure import Structure -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR -class TestLarsenDimensionality(PymatgenTest): +class TestLarsenDimensionality: def setUp(self): cnn = CrystalNN() self.lifepo = cnn.get_bonded_structure(self.get_structure("LiFePO4")) @@ -114,7 +114,7 @@ def test_zero_d_to_molecule_graph(self): assert len(mol_graph.molecule) == 12 -class TestCheonDimensionality(PymatgenTest): +class TestCheonDimensionality: def test_get_dimensionality(self): struct = self.get_structure("LiFePO4") assert get_dimensionality_cheon(struct) == "intercalated ion" @@ -152,7 +152,7 @@ def test_tricky_structure(self): assert get_dimensionality_cheon(tricky_structure, larger_cell=True) == "3D" -class TestGoraiDimensionality(PymatgenTest): +class TestGoraiDimensionality: def test_get_dimensionality(self): struct = self.get_structure("LiFePO4") assert get_dimensionality_gorai(struct) == 3 diff --git a/tests/analysis/test_disorder.py b/tests/analysis/test_disorder.py index f1fbd2f58d5..a00de0a8035 100644 --- a/tests/analysis/test_disorder.py +++ b/tests/analysis/test_disorder.py @@ -4,10 +4,9 @@ from pymatgen.analysis.disorder import get_warren_cowley_parameters from pymatgen.core import Element, Structure -from pymatgen.util.testing import PymatgenTest -class TestOrderParameter(PymatgenTest): +class TestOrderParameter: def test_compute_warren_cowley_parameters(self): struct = Structure.from_prototype("CsCl", ["Mo", "W"], a=4) aij = get_warren_cowley_parameters(struct, r=3.4, dr=0.3) diff --git a/tests/analysis/test_eos.py b/tests/analysis/test_eos.py index 9a839f8279b..da507c32035 100644 --- a/tests/analysis/test_eos.py +++ b/tests/analysis/test_eos.py @@ -5,10 +5,9 @@ from pytest import approx from pymatgen.analysis.eos import EOS, NumericalEOS -from pymatgen.util.testing import PymatgenTest -class TestEOS(PymatgenTest): +class TestEOS: def setUp(self): # Si data from Cormac self.volumes = [ diff --git a/tests/analysis/test_fragmenter.py b/tests/analysis/test_fragmenter.py index 211d7e3b7d1..c1efc2e69d6 100644 --- a/tests/analysis/test_fragmenter.py +++ b/tests/analysis/test_fragmenter.py @@ -8,7 +8,7 @@ from pymatgen.analysis.graphs import MoleculeGraph from pymatgen.analysis.local_env import OpenBabelNN from pymatgen.core.structure import Molecule -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR __author__ = "Samuel Blau" __email__ = "samblau1@gmail.com" @@ -17,7 +17,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/analysis/local_env/fragmenter_files" -class TestFragmentMolecule(PymatgenTest): +class TestFragmentMolecule: @classmethod def setUpClass(cls): cls.pc = Molecule.from_file(f"{TEST_DIR}/PC.xyz") diff --git a/tests/analysis/test_graphs.py b/tests/analysis/test_graphs.py index ad42533435c..9e0c9f9f83c 100644 --- a/tests/analysis/test_graphs.py +++ b/tests/analysis/test_graphs.py @@ -24,7 +24,7 @@ from pymatgen.command_line.critic2_caller import Critic2Analysis from pymatgen.core import Lattice, Molecule, Site, Structure from pymatgen.core.structure import FunctionalGroups -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR try: from openbabel import openbabel @@ -46,7 +46,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/analysis/graphs" -class TestStructureGraph(PymatgenTest): +class TestStructureGraph: def setUp(self): # trivial example, simple square lattice for testing structure = Structure(Lattice.tetragonal(5, 50), ["H"], [[0, 0, 0]]) diff --git a/tests/analysis/test_local_env.py b/tests/analysis/test_local_env.py index ac2ab8b099d..a6214fe1311 100644 --- a/tests/analysis/test_local_env.py +++ b/tests/analysis/test_local_env.py @@ -40,7 +40,7 @@ solid_angle, ) from pymatgen.core import Element, Lattice, Molecule, Structure -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR TEST_DIR = f"{TEST_FILES_DIR}/analysis/local_env/fragmenter_files" @@ -54,7 +54,7 @@ def test_opt_params(): assert cn_opt_params == CN_OPT_PARAMS -class TestValenceIonicRadiusEvaluator(PymatgenTest): +class TestValenceIonicRadiusEvaluator: def setUp(self): """Setup MgO rocksalt structure for testing Vacancy.""" mgo_latt = np.eye(3) * 4.212 @@ -89,7 +89,7 @@ def test_radii_ionic_structure(self): assert rad in {0.86, 1.26} -class TestVoronoiNN(PymatgenTest): +class TestVoronoiNN: def setUp(self): self.struct = self.get_structure("LiFePO4") self.nn = VoronoiNN(targets=[Element("O")]) @@ -260,7 +260,7 @@ def test_filtered(self): assert [len(x) for x in all_nns] == [8] * 16 -class TestJmolNN(PymatgenTest): +class TestJmolNN: def setUp(self): self.jmol = JmolNN() self.jmol_update = JmolNN(el_radius_updates={"Li": 1}) @@ -290,7 +290,7 @@ def test_get_nn(self): assert len(self.jmol_update.get_nn(struct, 0)) == 2 -class TestIsayevNN(PymatgenTest): +class TestIsayevNN: def test_get_nn(self): inn = IsayevNN() struct = self.get_structure("LiFePO4") @@ -301,7 +301,7 @@ def test_get_nn(self): assert len(inn.get_nn(struct, 0)) == 2 -class TestOpenBabelNN(PymatgenTest): +class TestOpenBabelNN: def setUp(self): pytest.importorskip("openbabel") self.benzene = Molecule.from_file(f"{TEST_DIR}/../benzene.xyz") @@ -333,7 +333,7 @@ def test_nn_length(self): assert strategy.get_nn_info(self.acetylene, 0)[0]["weight"] == approx(1.19, abs=1e-2) -class TestCovalentBondNN(PymatgenTest): +class TestCovalentBondNN: def setUp(self): self.benzene = Molecule.from_file(f"{TEST_DIR}/../benzene.xyz") self.acetylene = Molecule.from_file(f"{TEST_FILES_DIR}/io/xyz/acetylene.xyz") @@ -372,7 +372,7 @@ def test_bonded_structure(self): assert len(acetylene.graph.nodes) == 4 -class TestMiniDistNN(PymatgenTest): +class TestMiniDistNN: def setUp(self): self.diamond = Structure( Lattice([[2.189, 0, 1.264], [0.73, 2.064, 1.264], [0, 0, 2.528]]), @@ -485,7 +485,7 @@ def test_get_local_order_params(self): assert ops["octahedral"] == approx(0.9999995266669) -class TestMotifIdentification(PymatgenTest): +class TestMotifIdentification: def setUp(self): self.silicon = Structure( Lattice.cubic(5.47), @@ -583,7 +583,7 @@ def test_get_neighbors_of_site_with_index(self): assert len(get_neighbors_of_site_with_index(self.diamond, 0, approach="min_VIRE")) == 4 -class TestNearNeighbor(PymatgenTest): +class TestNearNeighbor: def setUp(self): self.diamond = Structure( Lattice([[2.189, 0, 1.264], [0.73, 2.064, 1.264], [0, 0, 2.528]]), @@ -617,7 +617,7 @@ def test_on_disorder_options(self): ) -class TestLocalStructOrderParams(PymatgenTest): +class TestLocalStructOrderParams: def setUp(self): self.single_bond = Structure( Lattice.cubic(10), @@ -1182,7 +1182,7 @@ def test_get_order_parameters(self): ops_101.get_order_parameters(self.bcc, 0, indices_neighs=[2]) -class TestCrystalNN(PymatgenTest): +class TestCrystalNN: def setUp(self): self.lifepo4 = self.get_structure("LiFePO4") self.lifepo4.add_oxidation_state_by_guess() @@ -1329,7 +1329,7 @@ def test_get_bonded_structure(self): cnn.get_bonded_structure(self.disordered_struct, 0, on_disorder="error") -class TestCutOffDictNN(PymatgenTest): +class TestCutOffDictNN: def setUp(self): self.diamond = Structure( Lattice([[2.189, 0, 1.264], [0.73, 2.064, 1.264], [0, 0, 2.528]]), @@ -1355,7 +1355,7 @@ def test_from_preset(self): @pytest.mark.skipif(not which("critic2"), reason="critic2 executable not present") -class TestCritic2NN(PymatgenTest): +class TestCritic2NN: def setUp(self): self.diamond = Structure( Lattice([[2.189, 0, 1.264], [0.73, 2.064, 1.264], [0, 0, 2.528]]), @@ -1369,7 +1369,7 @@ def test_cn(self): # assert nn.get_cn(self.diamond, 0) == 4 -class TestMetalEdgeExtender(PymatgenTest): +class TestMetalEdgeExtender: def setUp(self): self.LiEC = Molecule.from_file(f"{TEST_DIR}/LiEC.xyz") self.phsh = Molecule.from_file(f"{TEST_DIR}/phsh.xyz") diff --git a/tests/analysis/test_nmr.py b/tests/analysis/test_nmr.py index 14490ec7a0c..e90dfddc6ca 100644 --- a/tests/analysis/test_nmr.py +++ b/tests/analysis/test_nmr.py @@ -5,10 +5,9 @@ from pytest import approx from pymatgen.analysis.nmr import ChemicalShielding, ElectricFieldGradient -from pymatgen.util.testing import PymatgenTest -class TestChemicalShieldingNotation(PymatgenTest): +class TestChemicalShieldingNotation: def test_construction(self): cs = ChemicalShielding(np.arange(9).reshape((3, 3))) assert cs.shape == (3, 3) @@ -46,7 +45,7 @@ def test_notations(self): assert mary1.kappa == approx(0.8337, abs=1e-5) -class TestElectricFieldGradient(PymatgenTest): +class TestElectricFieldGradient: def test_construction(self): efg = ElectricFieldGradient(np.arange(9).reshape((3, 3))) assert efg.shape == (3, 3) diff --git a/tests/analysis/test_phase_diagram.py b/tests/analysis/test_phase_diagram.py index 934ba59fa9d..b534aba8ddc 100644 --- a/tests/analysis/test_phase_diagram.py +++ b/tests/analysis/test_phase_diagram.py @@ -32,7 +32,7 @@ from pymatgen.core import Composition, DummySpecies, Element from pymatgen.entries.computed_entries import ComputedEntry from pymatgen.entries.entry_tools import EntrySet -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR TEST_DIR = f"{TEST_FILES_DIR}/analysis" @@ -179,7 +179,7 @@ def test_normalize(self): assert norm_entry.composition == expected_comp -class TestPhaseDiagram(PymatgenTest): +class TestPhaseDiagram: def setUp(self): self.entries = EntrySet.from_csv(f"{TEST_DIR}/pd_entries_test.csv") self.pd = PhaseDiagram(self.entries) diff --git a/tests/analysis/test_piezo.py b/tests/analysis/test_piezo.py index bf3eb7534c2..0621591b44c 100644 --- a/tests/analysis/test_piezo.py +++ b/tests/analysis/test_piezo.py @@ -7,7 +7,6 @@ from numpy.testing import assert_allclose, assert_array_equal from pymatgen.analysis.piezo import PiezoTensor -from pymatgen.util.testing import PymatgenTest __author__ = "Shyam Dwaraknath" __version__ = "0.1" @@ -17,7 +16,7 @@ __date__ = "4/1/16" -class TestPiezo(PymatgenTest): +class TestPiezo: def setUp(self): self.piezo_struct = self.get_structure("BaNiO3") self.voigt_matrix = np.array( diff --git a/tests/analysis/test_piezo_sensitivity.py b/tests/analysis/test_piezo_sensitivity.py index 757215a30e4..b14e90e0250 100644 --- a/tests/analysis/test_piezo_sensitivity.py +++ b/tests/analysis/test_piezo_sensitivity.py @@ -17,7 +17,7 @@ rand_piezo, ) from pymatgen.io.phonopy import get_phonopy_structure -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR try: from phonopy import Phonopy @@ -34,7 +34,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/analysis/piezo_sensitivity" -class TestPiezoSensitivity(PymatgenTest): +class TestPiezoSensitivity: def setUp(self): self.piezo_struct = self.get_structure("Pb2TiZrO6") self.IST = np.load(f"{TEST_DIR}/pztist.npy", allow_pickle=True) diff --git a/tests/analysis/test_pourbaix_diagram.py b/tests/analysis/test_pourbaix_diagram.py index 22066499257..98f2dacc9cc 100644 --- a/tests/analysis/test_pourbaix_diagram.py +++ b/tests/analysis/test_pourbaix_diagram.py @@ -12,12 +12,12 @@ from pymatgen.core.composition import Composition from pymatgen.core.ion import Ion from pymatgen.entries.computed_entries import ComputedEntry -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR TEST_DIR = f"{TEST_FILES_DIR}/analysis/pourbaix_diagram" -class TestPourbaixEntry(PymatgenTest): +class TestPourbaixEntry: """Test all functions using a fictitious entry""" def setUp(self): diff --git a/tests/analysis/test_prototypes.py b/tests/analysis/test_prototypes.py index d2a16258d03..49f42675ea5 100644 --- a/tests/analysis/test_prototypes.py +++ b/tests/analysis/test_prototypes.py @@ -1,10 +1,9 @@ from __future__ import annotations from pymatgen.analysis.prototypes import AflowPrototypeMatcher -from pymatgen.util.testing import PymatgenTest -class TestAflowPrototypeMatcher(PymatgenTest): +class TestAflowPrototypeMatcher: def test_prototype_matching(self): af = AflowPrototypeMatcher() diff --git a/tests/analysis/test_structure_analyzer.py b/tests/analysis/test_structure_analyzer.py index a7da910eff0..1b01946b217 100644 --- a/tests/analysis/test_structure_analyzer.py +++ b/tests/analysis/test_structure_analyzer.py @@ -18,10 +18,10 @@ ) from pymatgen.core import Element, Lattice, Structure from pymatgen.io.vasp.outputs import Xdatcar -from pymatgen.util.testing import VASP_IN_DIR, VASP_OUT_DIR, PymatgenTest +from pymatgen.util.testing import VASP_IN_DIR, VASP_OUT_DIR -class TestVoronoiAnalyzer(PymatgenTest): +class TestVoronoiAnalyzer: def setUp(self): self.structs = Xdatcar(f"{VASP_OUT_DIR}/XDATCAR.MD").structures self.struct = self.structs[1] @@ -62,7 +62,7 @@ def test_get_percentage_bond_dist_changes(self): assert approx(v2) == -0.009204092115527862 -class TestVoronoiConnectivity(PymatgenTest): +class TestVoronoiConnectivity: def test_connectivity_array(self): vc = VoronoiConnectivity(self.get_structure("LiFePO4")) ca = vc.connectivity_array @@ -78,7 +78,7 @@ def test_connectivity_array(self): assert_allclose(site.frac_coords, expected) -class TestMiscFunction(PymatgenTest): +class TestMiscFunction: def test_average_coordination_number(self): xdatcar = Xdatcar(f"{VASP_OUT_DIR}/XDATCAR.MD") coordination_numbers = average_coordination_number(xdatcar.structures, freq=1) diff --git a/tests/analysis/test_structure_matcher.py b/tests/analysis/test_structure_matcher.py index 5a71019ebe2..c47da09efab 100644 --- a/tests/analysis/test_structure_matcher.py +++ b/tests/analysis/test_structure_matcher.py @@ -17,12 +17,12 @@ ) from pymatgen.core import Element, Lattice, Structure, SymmOp from pymatgen.util.coord import find_in_coord_list_pbc -from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR TEST_DIR = f"{TEST_FILES_DIR}/analysis/structure_matcher" -class TestStructureMatcher(PymatgenTest): +class TestStructureMatcher: def setUp(self): with open(f"{TEST_FILES_DIR}/entries/TiO2_entries.json") as file: entries = json.load(file, cls=MontyDecoder) diff --git a/tests/analysis/test_surface_analysis.py b/tests/analysis/test_surface_analysis.py index 5492d9aefa6..cc0aaa6f0e3 100644 --- a/tests/analysis/test_surface_analysis.py +++ b/tests/analysis/test_surface_analysis.py @@ -9,7 +9,7 @@ from pymatgen.analysis.surface_analysis import NanoscaleStability, SlabEntry, SurfaceEnergyPlotter, WorkFunctionAnalyzer from pymatgen.entries.computed_entries import ComputedStructureEntry -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR __author__ = "Richard Tran" __copyright__ = "Copyright 2012, The Materials Project" @@ -22,7 +22,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/surfaces" -class TestSlabEntry(PymatgenTest): +class TestSlabEntry: def setUp(self): with open(f"{TEST_DIR}/ucell_entries.txt") as file: ucell_entries = json.loads(file.read()) @@ -118,7 +118,7 @@ def test_cleaned_up_slab(self): assert slab_clean.composition.reduced_composition == clean.composition.reduced_composition -class TestSurfaceEnergyPlotter(PymatgenTest): +class TestSurfaceEnergyPlotter: def setUp(self): entry_dict = get_entry_dict(f"{TEST_DIR}/Cu_entries.txt") self.Cu_entry_dict = entry_dict @@ -292,7 +292,7 @@ def test_surface_chempot_range_map(self): analyzer.chempot_vs_gamma_facet(hkl) -class TestWorkFunctionAnalyzer(PymatgenTest): +class TestWorkFunctionAnalyzer: def setUp(self): self.kwargs = { "poscar_filename": f"{TEST_DIR}/CONTCAR.relax1.gz", @@ -309,7 +309,7 @@ def test_is_converged(self): assert self.wf_analyzer.is_converged() -class TestNanoscaleStability(PymatgenTest): +class TestNanoscaleStability: def setUp(self): # Load all entries La_hcp_entry_dict = get_entry_dict(f"{TEST_DIR}/La_hcp_entries.txt") diff --git a/tests/analysis/test_transition_state.py b/tests/analysis/test_transition_state.py index 96841bc482a..4ca1cf08339 100644 --- a/tests/analysis/test_transition_state.py +++ b/tests/analysis/test_transition_state.py @@ -6,7 +6,7 @@ from numpy.testing import assert_allclose from pymatgen.analysis.transition_state import NEBAnalysis, combine_neb_plots -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR """ TODO: Modify unittest doc. @@ -23,7 +23,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/io/vasp/fixtures/neb_analysis" -class TestNEBAnalysis(PymatgenTest): +class TestNEBAnalysis: def test_run(self): neb_analysis1 = NEBAnalysis.from_dir(f"{TEST_DIR}/neb1/neb") neb_analysis1_from_dict = NEBAnalysis.from_dict(neb_analysis1.as_dict()) diff --git a/tests/analysis/test_wulff.py b/tests/analysis/test_wulff.py index 768d079e2da..527a24fb4a7 100644 --- a/tests/analysis/test_wulff.py +++ b/tests/analysis/test_wulff.py @@ -9,7 +9,7 @@ from pymatgen.core.structure import Structure from pymatgen.symmetry.analyzer import SpacegroupAnalyzer from pymatgen.util.coord import in_coord_list -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR __author__ = "Zihan Xu, Richard Tran, Balachandran Radhakrishnan" __copyright__ = "Copyright 2013, The Materials Virtual Lab" @@ -21,7 +21,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/analysis/wulff" -class TestWulffShape(PymatgenTest): +class TestWulffShape: def setUp(self): with open(f"{TEST_DIR}/surface_samples.json") as data_file: surface_properties = json.load(data_file) diff --git a/tests/analysis/test_xps.py b/tests/analysis/test_xps.py index 45b250e3100..f2260c82717 100644 --- a/tests/analysis/test_xps.py +++ b/tests/analysis/test_xps.py @@ -2,10 +2,10 @@ from pymatgen.analysis.xps import XPS from pymatgen.io.vasp import Vasprun -from pymatgen.util.testing import VASP_OUT_DIR, PymatgenTest +from pymatgen.util.testing import VASP_OUT_DIR -class TestXPS(PymatgenTest): +class TestXPS: def test_from_dos(self): vasp_run = Vasprun(f"{VASP_OUT_DIR}/vasprun.LiF.xml.gz") dos = vasp_run.complete_dos diff --git a/tests/analysis/topological/test_spillage.py b/tests/analysis/topological/test_spillage.py index 39224cdfc52..254b6002dc3 100644 --- a/tests/analysis/topological/test_spillage.py +++ b/tests/analysis/topological/test_spillage.py @@ -3,12 +3,12 @@ from pytest import approx from pymatgen.analysis.topological.spillage import SOCSpillage -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR TEST_DIR = f"{TEST_FILES_DIR}/analysis/topological" -class TestSolar(PymatgenTest): +class TestSolar: def test_spillage_from_vasprun(self): wf_noso = f"{TEST_DIR}/WAVECAR-NonSOC" wf_so = f"{TEST_DIR}/WAVECAR-SOC" diff --git a/tests/analysis/xas/test_spectrum.py b/tests/analysis/xas/test_spectrum.py index 92a04879dc3..16553553e84 100644 --- a/tests/analysis/xas/test_spectrum.py +++ b/tests/analysis/xas/test_spectrum.py @@ -10,7 +10,7 @@ from pymatgen.analysis.xas.spectrum import XAS, site_weighted_spectrum from pymatgen.core import Element -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR TEST_DIR = f"{TEST_FILES_DIR}/analysis/spectrum_test" @@ -28,7 +28,7 @@ site2_xanes_dict = json.load(file, cls=MontyDecoder) -class TestXAS(PymatgenTest): +class TestXAS: def setUp(self): self.k_xanes = XAS.from_dict(k_xanes_dict) self.k_exafs = XAS.from_dict(k_exafs_dict) diff --git a/tests/apps/battery/test_analyzer.py b/tests/apps/battery/test_analyzer.py index eea99df2ecb..5e3fa0cd9f0 100644 --- a/tests/apps/battery/test_analyzer.py +++ b/tests/apps/battery/test_analyzer.py @@ -5,10 +5,10 @@ from pymatgen.apps.battery.analyzer import BatteryAnalyzer from pymatgen.core.structure import Structure -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR -class TestBatteryAnalyzer(PymatgenTest): +class TestBatteryAnalyzer: def load_from_cif(self, filename, oxidations, working_ion="Li"): struct = Structure.from_file(f"{TEST_FILES_DIR}/cif/{filename}") struct.add_oxidation_state_by_element(oxidations) diff --git a/tests/command_line/test_bader_caller.py b/tests/command_line/test_bader_caller.py index ad39f8c6b61..3d0f73e58ed 100644 --- a/tests/command_line/test_bader_caller.py +++ b/tests/command_line/test_bader_caller.py @@ -10,13 +10,13 @@ from pytest import approx from pymatgen.command_line.bader_caller import BaderAnalysis, bader_analysis_from_path -from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR TEST_DIR = f"{TEST_FILES_DIR}/command_line/bader" @pytest.mark.skipif(not which("bader"), reason="bader executable not present") -class TestBaderAnalysis(PymatgenTest): +class TestBaderAnalysis: def setUp(self): warnings.catch_warnings() diff --git a/tests/command_line/test_enumlib_caller.py b/tests/command_line/test_enumlib_caller.py index aa3cebff4a3..b55ff9c2fea 100644 --- a/tests/command_line/test_enumlib_caller.py +++ b/tests/command_line/test_enumlib_caller.py @@ -11,14 +11,14 @@ from pymatgen.symmetry.analyzer import SpacegroupAnalyzer from pymatgen.transformations.site_transformations import RemoveSitesTransformation from pymatgen.transformations.standard_transformations import SubstitutionTransformation -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR ENUM_CMD = which("enum.x") or which("multienum.x") MAKESTR_CMD = which("makestr.x") or which("makeStr.x") or which("makeStr.py") @pytest.mark.skipif(not (ENUM_CMD and MAKESTR_CMD), reason="enumlib not present.") -class TestEnumlibAdaptor(PymatgenTest): +class TestEnumlibAdaptor: def test_init(self): struct = self.get_structure("LiFePO4") sub_trans = SubstitutionTransformation({"Li": {"Li": 0.5}}) diff --git a/tests/command_line/test_mcsqs_caller.py b/tests/command_line/test_mcsqs_caller.py index ca9f8a018d6..b214f42b262 100644 --- a/tests/command_line/test_mcsqs_caller.py +++ b/tests/command_line/test_mcsqs_caller.py @@ -7,7 +7,7 @@ from pymatgen.command_line.mcsqs_caller import run_mcsqs from pymatgen.core.structure import Structure -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR __author__ = "Handong Ling, Rachel Woods-Robinson" __maintainer__ = "Handong Ling, Rachel Woods-Robinson" @@ -18,7 +18,7 @@ @pytest.mark.skipif(not (which("mcsqs") and which("str2cif")), reason="mcsqs executable not present") -class TestMcsqsCaller(PymatgenTest): +class TestMcsqsCaller: def setUp(self): self.pzt_structs = loadfn(f"{TEST_DIR}/pzt-structs.json") self.pzt_structs2 = loadfn(f"{TEST_DIR}/pzt-structs-2.json") diff --git a/tests/command_line/test_vampire_caller.py b/tests/command_line/test_vampire_caller.py index e2e55a18486..cc8fb7c254c 100644 --- a/tests/command_line/test_vampire_caller.py +++ b/tests/command_line/test_vampire_caller.py @@ -8,13 +8,13 @@ from pymatgen.command_line.vampire_caller import VampireCaller from pymatgen.core.structure import Structure -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR TEST_DIR = f"{TEST_FILES_DIR}/analysis/magnetic_orderings" @pytest.mark.skipif(not which("vampire-serial"), reason="vampire executable not present") -class TestVampireCaller(PymatgenTest): +class TestVampireCaller: @classmethod def setUpClass(cls): cls.Mn3Al = pd.read_json(f"{TEST_DIR}/Mn3Al.json") diff --git a/tests/core/test_composition.py b/tests/core/test_composition.py index 9c00c7678fd..dba2a3c67f6 100644 --- a/tests/core/test_composition.py +++ b/tests/core/test_composition.py @@ -13,10 +13,9 @@ from pymatgen.core import Composition, DummySpecies, Element, Species from pymatgen.core.composition import ChemicalPotential -from pymatgen.util.testing import PymatgenTest -class TestComposition(PymatgenTest): +class TestComposition: def setUp(self): self.comps = [ Composition("Li3Fe2(PO4)3"), diff --git a/tests/core/test_interface.py b/tests/core/test_interface.py index c2563cd2a7a..598759a40a8 100644 --- a/tests/core/test_interface.py +++ b/tests/core/test_interface.py @@ -8,12 +8,12 @@ from pymatgen.core.structure import Structure from pymatgen.core.surface import SlabGenerator from pymatgen.symmetry.analyzer import SpacegroupAnalyzer -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR TEST_DIR = f"{TEST_FILES_DIR}/core/grain_boundary" -class TestGrainBoundary(PymatgenTest): +class TestGrainBoundary: def setUp(self): self.Cu_conv = Structure.from_file(f"{TEST_DIR}/Cu_mp-30_conventional_standard.cif") GB_Cu_conv = GrainBoundaryGenerator(self.Cu_conv) @@ -104,7 +104,7 @@ def test_as_dict_and_from_dict(self): assert_allclose(Cu_GB2_new.lattice.matrix, self.Cu_GB2.lattice.matrix) -class TestGrainBoundaryGenerator(PymatgenTest): +class TestGrainBoundaryGenerator: @classmethod def setUpClass(cls): cls.Cu_prim = Structure.from_file(f"{TEST_DIR}/Cu_mp-30_primitive.cif") @@ -331,7 +331,7 @@ def test_get_rotation_angle_from_sigma(self): assert_allclose(close_angle, angle) -class TestInterface(PymatgenTest): +class TestInterface: def setUp(self): self.interface: Interface = self.get_structure("Si_SiO2_Interface") diff --git a/tests/core/test_lattice.py b/tests/core/test_lattice.py index 89a79e6330c..3bd111545ce 100644 --- a/tests/core/test_lattice.py +++ b/tests/core/test_lattice.py @@ -9,10 +9,9 @@ from pymatgen.core.lattice import Lattice, get_points_in_spheres from pymatgen.core.operations import SymmOp -from pymatgen.util.testing import PymatgenTest -class TestLattice(PymatgenTest): +class TestLattice: def setUp(self): self.lattice = Lattice.cubic(10.0) self.cubic = self.lattice diff --git a/tests/core/test_libxcfunc.py b/tests/core/test_libxcfunc.py index 435b71c389e..56ab6335159 100644 --- a/tests/core/test_libxcfunc.py +++ b/tests/core/test_libxcfunc.py @@ -1,10 +1,9 @@ from __future__ import annotations from pymatgen.core.libxcfunc import LibxcFunc -from pymatgen.util.testing import PymatgenTest -class TestLibxcFunc(PymatgenTest): +class TestLibxcFunc: def test_libxcfunc_api(self): """Testing libxcfunc_api.""" # LDA correlation: Hedin & Lundqvist diff --git a/tests/core/test_molecular_orbitals.py b/tests/core/test_molecular_orbitals.py index 4476c856d17..5d193409c20 100644 --- a/tests/core/test_molecular_orbitals.py +++ b/tests/core/test_molecular_orbitals.py @@ -3,12 +3,11 @@ import pytest from pymatgen.core.molecular_orbitals import MolecularOrbitals -from pymatgen.util.testing import PymatgenTest test_case = MolecularOrbitals("NaCl") -class TestMolecularOrbital(PymatgenTest): +class TestMolecularOrbital: def test_max_electronegativity(self): test_elec_neg = 2.23 assert test_elec_neg == test_case.max_electronegativity() diff --git a/tests/core/test_operations.py b/tests/core/test_operations.py index 1d775b09b92..6ece9b27eda 100644 --- a/tests/core/test_operations.py +++ b/tests/core/test_operations.py @@ -5,10 +5,9 @@ from pymatgen.core.operations import MagSymmOp, SymmOp from pymatgen.electronic_structure.core import Magmom -from pymatgen.util.testing import PymatgenTest -class TestSymmOp(PymatgenTest): +class TestSymmOp: def setUp(self): self.op = SymmOp.from_axis_angle_and_translation([0, 0, 1], 30, translation_vec=[0, 0, 1]) @@ -236,7 +235,7 @@ def test_xyz(self): assert_allclose(symm_op.translation_vector, [0.5, 0.25, 0.75]) -class TestMagSymmOp(PymatgenTest): +class TestMagSymmOp: def test_xyzt_string(self): xyzt_strings = ["x, y, z, +1", "x, y, z, -1", "-y+1/2, x+1/2, x+1/2, +1"] diff --git a/tests/core/test_periodic_table.py b/tests/core/test_periodic_table.py index a4a696a4f56..b02a017ec45 100644 --- a/tests/core/test_periodic_table.py +++ b/tests/core/test_periodic_table.py @@ -14,10 +14,9 @@ from pymatgen.core.periodic_table import ElementBase, ElementType from pymatgen.core.units import Ha_to_eV from pymatgen.io.core import ParseError -from pymatgen.util.testing import PymatgenTest -class TestElement(PymatgenTest): +class TestElement: def test_init(self): assert Element("Fe").symbol == "Fe" @@ -392,7 +391,7 @@ def test_isotope(self): ] -class TestSpecies(PymatgenTest): +class TestSpecies: def setUp(self): self.specie1 = Species.from_str("Fe2+") self.specie2 = Species("Fe", 3) diff --git a/tests/core/test_sites.py b/tests/core/test_sites.py index 28fb7b07e4c..2e619bf40aa 100644 --- a/tests/core/test_sites.py +++ b/tests/core/test_sites.py @@ -9,10 +9,9 @@ from pymatgen.core import Composition, Element, Lattice, PeriodicSite, Site, Species from pymatgen.electronic_structure.core import Magmom -from pymatgen.util.testing import PymatgenTest -class TestSite(PymatgenTest): +class TestSite: def setUp(self): self.ordered_site = Site("Fe", [0.25, 0.35, 0.45]) self.disordered_site = Site({"Fe": 0.5, "Mn": 0.5}, [0.25, 0.35, 0.45]) @@ -79,7 +78,7 @@ def test_setters(self): self.disordered_site.species = {"Cu": 0.5, "Gd": 0.6} -class TestPeriodicSite(PymatgenTest): +class TestPeriodicSite: def setUp(self): self.lattice = Lattice.cubic(10.0) self.si = Element("Si") diff --git a/tests/core/test_spectrum.py b/tests/core/test_spectrum.py index 2f8f208c175..f14b1506107 100644 --- a/tests/core/test_spectrum.py +++ b/tests/core/test_spectrum.py @@ -6,10 +6,9 @@ from scipy import stats from pymatgen.core.spectrum import Spectrum -from pymatgen.util.testing import PymatgenTest -class TestSpectrum(PymatgenTest): +class TestSpectrum: def setUp(self): rng = np.random.default_rng() self.spec1 = Spectrum(np.arange(0, 10, 0.1), rng.standard_normal(100)) diff --git a/tests/core/test_structure.py b/tests/core/test_structure.py index 7cb4abcbaf3..4b909a71411 100644 --- a/tests/core/test_structure.py +++ b/tests/core/test_structure.py @@ -44,7 +44,7 @@ mcsqs_cmd = which("mcsqs") -class TestNeighbor(PymatgenTest): +class TestNeighbor: def test_msonable(self): struct = PymatgenTest.get_structure("Li2O") nn = struct.get_neighbors(struct[0], r=3) @@ -63,7 +63,7 @@ def test_neighbor_labels(self): assert p_neighbor.label == label if label is not None else "C" -class TestIStructure(PymatgenTest): +class TestIStructure: def setUp(self): coords = [[0, 0, 0], [0.75, 0.5, 0.75]] self.lattice = Lattice( @@ -965,7 +965,7 @@ def test_sites_setter(self): assert struct.sites == new_sites -class TestStructure(PymatgenTest): +class TestStructure: def setUp(self): coords = [[0, 0, 0], [0.75, 0.5, 0.75]] lattice = Lattice( @@ -2032,7 +2032,7 @@ def test_struct_with_isotope(self): assert "Deuterium" not in [el.long_name for el in struct.composition.elements] -class TestIMolecule(PymatgenTest): +class TestIMolecule: def setUp(self): coords = [ [0, 0, 0], @@ -2327,7 +2327,7 @@ def test_to_file_alias(self): assert os.path.isfile(out_path) -class TestMolecule(PymatgenTest): +class TestMolecule: def setUp(self): coords = [ [0, 0, 0], diff --git a/tests/core/test_surface.py b/tests/core/test_surface.py index 0527fc671b0..ccc09906bbe 100644 --- a/tests/core/test_surface.py +++ b/tests/core/test_surface.py @@ -24,12 +24,12 @@ ) from pymatgen.symmetry.analyzer import SpacegroupAnalyzer from pymatgen.symmetry.groups import SpaceGroup -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR PMG_CORE_DIR = os.path.dirname(pymatgen.core.__file__) -class TestSlab(PymatgenTest): +class TestSlab: def setUp(self): zno1 = Structure.from_file(f"{TEST_FILES_DIR}/surfaces/ZnO-wz.cif", primitive=False) zno55 = SlabGenerator(zno1, [1, 0, 0], 5, 5, lll_reduce=False, center_slab=False).get_slab() @@ -346,7 +346,7 @@ def test_as_dict(self): assert slab == Slab.from_dict(d) -class TestSlabGenerator(PymatgenTest): +class TestSlabGenerator: def setUp(self): lattice = Lattice.cubic(3.010) frac_coords = [ @@ -634,7 +634,7 @@ def test_bonds_broken(self): assert slabs[1].energy, 6.0 -class ReconstructionGeneratorTests(PymatgenTest): +class ReconstructionGeneratorTests: def setUp(self): lattice = Lattice.cubic(3.51) species = ["Ni"] @@ -723,7 +723,7 @@ def test_previous_reconstructions(self): assert any(len(match.group_structures([struct, slab])) == 1 for slab in slabs) -class TestMillerIndexFinder(PymatgenTest): +class TestMillerIndexFinder: def setUp(self): self.cscl = Structure.from_spacegroup("Pm-3m", Lattice.cubic(4.2), ["Cs", "Cl"], [[0, 0, 0], [0.5, 0.5, 0.5]]) self.Fe = Structure.from_spacegroup("Im-3m", Lattice.cubic(2.82), ["Fe"], [[0, 0, 0]]) diff --git a/tests/core/test_tensors.py b/tests/core/test_tensors.py index 1c840dcfa2b..1c78a299ed9 100644 --- a/tests/core/test_tensors.py +++ b/tests/core/test_tensors.py @@ -11,10 +11,10 @@ from pymatgen.core.operations import SymmOp from pymatgen.core.tensors import SquareTensor, Tensor, TensorCollection, TensorMapping, itertools, symmetry_reduce from pymatgen.symmetry.analyzer import SpacegroupAnalyzer -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR -class TestTensor(PymatgenTest): +class TestTensor: def setUp(self): rng = np.random.default_rng() @@ -379,7 +379,7 @@ def test_round(self): assert isinstance(rounded, Tensor) -class TestTensorCollection(PymatgenTest): +class TestTensorCollection: def setUp(self): self.seq_tc = list(np.arange(4 * 3**3).reshape((4, 3, 3, 3))) self.seq_tc = TensorCollection(self.seq_tc) @@ -472,7 +472,7 @@ def test_serialization(self): assert_allclose(t, t_new) -class TestSquareTensor(PymatgenTest): +class TestSquareTensor: def setUp(self): self.rand_sqtensor = SquareTensor(np.random.default_rng().standard_normal((3, 3))) self.symm_sqtensor = SquareTensor([[0.1, 0.3, 0.4], [0.3, 0.5, 0.2], [0.4, 0.2, 0.6]]) diff --git a/tests/core/test_trajectory.py b/tests/core/test_trajectory.py index cac745a8a75..2cb7baae889 100644 --- a/tests/core/test_trajectory.py +++ b/tests/core/test_trajectory.py @@ -12,12 +12,12 @@ from pymatgen.core.trajectory import Trajectory from pymatgen.io.qchem.outputs import QCOutput from pymatgen.io.vasp.outputs import Xdatcar -from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR TEST_DIR = f"{TEST_FILES_DIR}/core/trajectory" -class TestTrajectory(PymatgenTest): +class TestTrajectory: def setUp(self): xdatcar = Xdatcar(f"{VASP_OUT_DIR}/XDATCAR_traj") self.traj = Trajectory.from_file(f"{VASP_OUT_DIR}/XDATCAR_traj") diff --git a/tests/core/test_units.py b/tests/core/test_units.py index 88e06d92517..1f3c7f2ac5b 100644 --- a/tests/core/test_units.py +++ b/tests/core/test_units.py @@ -26,7 +26,6 @@ eV_to_Ha, unitized, ) -from pymatgen.util.testing import PymatgenTest def test_unit_conversions(): @@ -37,7 +36,7 @@ def test_unit_conversions(): assert amu_to_kg == approx(1.66053906660e-27) -class TestUnit(PymatgenTest): +class TestUnit: def test_init(self): u1 = Unit((("m", 1), ("s", -1))) assert str(u1) == "m s^-1" @@ -53,7 +52,7 @@ def test_init(self): assert str(newton * Unit("m")) == "N m" -class TestFloatWithUnit(PymatgenTest): +class TestFloatWithUnit: def test_energy(self): a = Energy(1.1, "eV") b = a.to("Ha") @@ -185,7 +184,7 @@ def test_neg(self): assert FloatWithUnit(-5, "MPa") == -x -class TestArrayWithUnit(PymatgenTest): +class TestArrayWithUnit: def test_energy(self): """Similar to TestFloatWithUnit.test_energy. Check whether EnergyArray and FloatWithUnit have same behavior. @@ -293,7 +292,7 @@ def test_as_base_units(self): assert_array_equal(ArrayWithUnit([5000000, 10000000], "Pa"), pressure_arr.as_base_units) -class TestDataPersistence(PymatgenTest): +class TestDataPersistence: def test_pickle(self): """Test whether FloatWithUnit and ArrayWithUnit support pickle.""" for cls in [FloatWithUnit, ArrayWithUnit]: diff --git a/tests/core/test_xcfunc.py b/tests/core/test_xcfunc.py index 94627874bab..fd4c15e0d76 100644 --- a/tests/core/test_xcfunc.py +++ b/tests/core/test_xcfunc.py @@ -3,10 +3,9 @@ import pytest from pymatgen.core.xcfunc import XcFunc -from pymatgen.util.testing import PymatgenTest -class TestLibxcFunc(PymatgenTest): +class TestLibxcFunc: def setUp(self) -> None: self.ixc_11 = XcFunc.from_abinit_ixc(11) diff --git a/tests/electronic_structure/test_bandstructure.py b/tests/electronic_structure/test_bandstructure.py index c5de50385ce..2cacd115159 100644 --- a/tests/electronic_structure/test_bandstructure.py +++ b/tests/electronic_structure/test_bandstructure.py @@ -20,7 +20,7 @@ from pymatgen.electronic_structure.core import Orbital, Spin from pymatgen.electronic_structure.plotter import BSPlotterProjected from pymatgen.io.vasp import BSVasprun -from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR TEST_DIR = f"{TEST_FILES_DIR}/electronic_structure/bandstructure" @@ -68,7 +68,7 @@ def test_from_dict(self): assert kpoint.label == "X" -class TestBandStructureSymmLine(PymatgenTest): +class TestBandStructureSymmLine: def setUp(self): self.bs: BandStructureSymmLine = loadfn(f"{TEST_DIR}/Cu2O_361_bandstructure.json") self.bs2: BandStructureSymmLine = loadfn(f"{TEST_DIR}/CaO_2605_bandstructure.json") @@ -258,7 +258,7 @@ def test_apply_scissor_spin_polarized(self): assert bs_scissored.efermi != approx(orig_efermi) -class TestReconstructBandStructure(PymatgenTest): +class TestReconstructBandStructure: def setUp(self): self.bs_cu: BandStructureSymmLine = loadfn(f"{TEST_DIR}/Cu_30_bandstructure.json") self.bs_cu2: BandStructureSymmLine = loadfn(f"{TEST_DIR}/Cu_30_bandstructure.json") @@ -277,7 +277,7 @@ def test_vasprun_bs(self): bs.get_projection_on_elements() -class TestLobsterBandStructureSymmLine(PymatgenTest): +class TestLobsterBandStructureSymmLine: def setUp(self): with open( f"{TEST_FILES_DIR}/electronic_structure/cohp/Fatband_SiO2/Test_p/lobster_band_structure_spin.json", diff --git a/tests/electronic_structure/test_cohp.py b/tests/electronic_structure/test_cohp.py index 16f0ce2ca34..1da7a34b55f 100644 --- a/tests/electronic_structure/test_cohp.py +++ b/tests/electronic_structure/test_cohp.py @@ -15,7 +15,7 @@ get_integrated_cohp_in_energy_range, ) from pymatgen.electronic_structure.core import Orbital, Spin -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR TEST_DIR = f"{TEST_FILES_DIR}/electronic_structure/cohp" @@ -797,7 +797,7 @@ def test_extremum_icohpvalue(self): assert self.icoopcollection_Fe.extremum_icohpvalue(summed_spin_channels=False, spin=Spin.down) == -0.05756 -class TestCompleteCohp(PymatgenTest): +class TestCompleteCohp: def setUp(self): filepath = f"{TEST_DIR}/complete_cohp_lobster.json" with open(filepath) as file: diff --git a/tests/electronic_structure/test_dos.py b/tests/electronic_structure/test_dos.py index a7c8dec41b1..229738439c0 100644 --- a/tests/electronic_structure/test_dos.py +++ b/tests/electronic_structure/test_dos.py @@ -14,7 +14,7 @@ from pymatgen.core import Element, Structure from pymatgen.electronic_structure.core import Orbital, OrbitalType, Spin from pymatgen.electronic_structure.dos import DOS, CompleteDos, FermiDos, LobsterCompleteDos -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR TEST_DIR = f"{TEST_FILES_DIR}/electronic_structure/dos" @@ -323,7 +323,7 @@ def test_dos_fp_exceptions(self): self.dos.get_dos_fp_similarity(dos_fp, dos_fp2, col=1, metric=metric, normalize=False) -class TestDOS(PymatgenTest): +class TestDOS: def setUp(self): with open(f"{TEST_DIR}/complete_dos.json") as file: dct = json.load(file) diff --git a/tests/electronic_structure/test_plotter.py b/tests/electronic_structure/test_plotter.py index 59763e9ea59..2e80564a90c 100644 --- a/tests/electronic_structure/test_plotter.py +++ b/tests/electronic_structure/test_plotter.py @@ -30,14 +30,14 @@ plot_ellipsoid, ) from pymatgen.io.vasp import Vasprun -from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR BAND_TEST_DIR = f"{TEST_FILES_DIR}/electronic_structure/bandstructure" rc("text", usetex=False) # Disabling latex is needed for this test to work. -class TestDosPlotter(PymatgenTest): +class TestDosPlotter: def setUp(self): with open(f"{BAND_TEST_DIR}/../dos/complete_dos.json") as file: self.dos = CompleteDos.from_dict(json.load(file)) @@ -91,7 +91,7 @@ def get_plot_attributes(ax: plt.Axes): } -class TestBSPlotter(PymatgenTest): +class TestBSPlotter: def setUp(self): with open(f"{BAND_TEST_DIR}/CaO_2605_bandstructure.json") as file: dct = json.loads(file.read()) @@ -444,7 +444,7 @@ def test_plot_zt_temp(self): plt.close() -class TestCohpPlotter(PymatgenTest): +class TestCohpPlotter: def setUp(self): path = f"{TEST_FILES_DIR}/electronic_structure/cohp/complete_cohp_lobster.json" with open(path) as file: diff --git a/tests/entries/test_entry_tools.py b/tests/entries/test_entry_tools.py index 73d2d721d7b..3731857f98b 100644 --- a/tests/entries/test_entry_tools.py +++ b/tests/entries/test_entry_tools.py @@ -9,12 +9,12 @@ from pymatgen.core import Element from pymatgen.entries.computed_entries import ComputedEntry from pymatgen.entries.entry_tools import EntrySet, group_entries_by_composition, group_entries_by_structure -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR TEST_DIR = f"{TEST_FILES_DIR}/entries" -class TestFunc(PymatgenTest): +class TestFunc: def test_group_entries_by_structure(self): entries = loadfn(f"{TEST_DIR}/TiO2_entries.json") groups = group_entries_by_structure(entries) @@ -49,7 +49,7 @@ def test_group_entries_by_composition(self): assert group == sorted(group, key=lambda e: e.energy_per_atom) -class TestEntrySet(PymatgenTest): +class TestEntrySet: def setUp(self): entries = loadfn(f"{TEST_DIR}/Li-Fe-P-O_entries.json") self.entry_set = EntrySet(entries) diff --git a/tests/ext/test_matproj.py b/tests/ext/test_matproj.py index 18558a41525..0f0395577e0 100644 --- a/tests/ext/test_matproj.py +++ b/tests/ext/test_matproj.py @@ -23,7 +23,7 @@ from pymatgen.ext.matproj_legacy import MPRestError, TaskType, _MPResterLegacy from pymatgen.phonon.bandstructure import PhononBandStructureSymmLine from pymatgen.phonon.dos import CompletePhononDos -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR PMG_MAPI_KEY = SETTINGS.get("PMG_MAPI_KEY", "") if (10 < len(PMG_MAPI_KEY) <= 20) and "PMG_MAPI_KEY" in SETTINGS: @@ -48,7 +48,7 @@ not 10 < len(PMG_MAPI_KEY) <= 20, reason="Legacy PMG_MAPI_KEY environment variable not set.", ) -class TestMPResterOld(PymatgenTest): +class TestMPResterOld: def setUp(self): self.rester = _MPResterLegacy() @@ -528,7 +528,7 @@ def test_api_key_is_none(self): not len(PMG_MAPI_KEY) > 20, reason="PMG_MAPI_KEY environment variable not set.", ) -class TestMPResterNewBasic(PymatgenTest): +class TestMPResterNewBasic: def setUp(self): self.rester = _MPResterBasic() diff --git a/tests/ext/test_optimade.py b/tests/ext/test_optimade.py index e2710ddeaff..4a81116c5ce 100644 --- a/tests/ext/test_optimade.py +++ b/tests/ext/test_optimade.py @@ -4,7 +4,6 @@ import requests from pymatgen.ext.optimade import OptimadeRester -from pymatgen.util.testing import PymatgenTest try: # 403 is returned when server detects bot-like behavior @@ -36,7 +35,7 @@ mc2d_down = True -class TestOptimade(PymatgenTest): +class TestOptimade: @pytest.mark.skipif(mp_website_down, reason="MP OPTIMADE is down.") def test_get_structures_mp(self): with OptimadeRester("mp") as optimade: diff --git a/tests/io/abinit/test_abiobjects.py b/tests/io/abinit/test_abiobjects.py index ad38c49dafe..03b90aefe4b 100644 --- a/tests/io/abinit/test_abiobjects.py +++ b/tests/io/abinit/test_abiobjects.py @@ -19,10 +19,10 @@ species_by_znucl, structure_to_abivars, ) -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR -class TestLatticeFromAbivars(PymatgenTest): +class TestLatticeFromAbivars: def test_rprim_acell(self): l1 = lattice_from_abivars(acell=3 * [10], rprim=np.eye(3)) assert l1.volume == approx(bohr_to_ang**3 * 1000) @@ -108,7 +108,7 @@ def test_znucl_typat(self): structure_to_abivars(gan, enforce_znucl=enforce_znucl, enforce_typat=None) -class TestSpinMode(PymatgenTest): +class TestSpinMode: def test_base(self): polarized = SpinMode.as_spinmode("polarized") other_polarized = SpinMode.as_spinmode("polarized") @@ -128,7 +128,7 @@ def test_base(self): self.assert_msonable(unpolarized) -class TestSmearing(PymatgenTest): +class TestSmearing: def test_base(self): fd1ev = Smearing.as_smearing("fermi_dirac:1 eV") fd1ev.to_abivars() @@ -156,7 +156,7 @@ def test_base(self): self.assert_msonable(fd1ev) -class TestElectronsAlgorithm(PymatgenTest): +class TestElectronsAlgorithm: def test_base(self): algo = ElectronsAlgorithm(nstep=70) _ = algo.to_abivars() @@ -168,7 +168,7 @@ def test_base(self): self.assert_msonable(algo) -class TestElectrons(PymatgenTest): +class TestElectrons: def test_base(self): default_electrons = Electrons() assert default_electrons.nsppol == 2 @@ -195,7 +195,7 @@ def test_base(self): self.assert_msonable(custom_electrons) -class TestKSampling(PymatgenTest): +class TestKSampling: def test_base(self): monkhorst = KSampling.monkhorst((3, 3, 3), (0.5, 0.5, 0.5), 0, use_symmetries=False, use_time_reversal=False) gamma_centered = KSampling.gamma_centered((3, 3, 3), use_symmetries=False, use_time_reversal=False) @@ -207,7 +207,7 @@ def test_base(self): self.assert_msonable(gamma_centered) -class TestRelaxation(PymatgenTest): +class TestRelaxation: def test_base(self): atoms_and_cell = RelaxationMethod.atoms_and_cell() atoms_only = RelaxationMethod.atoms_only() @@ -227,7 +227,7 @@ def test_base(self): self.assert_msonable(atoms_only) -class TestPPModel(PymatgenTest): +class TestPPModel: def test_base(self): godby = PPModel.as_ppmodel("godby:12 eV") godby.to_abivars() diff --git a/tests/io/abinit/test_inputs.py b/tests/io/abinit/test_inputs.py index 762ea2acad8..abcb129f4fb 100644 --- a/tests/io/abinit/test_inputs.py +++ b/tests/io/abinit/test_inputs.py @@ -18,7 +18,7 @@ ion_ioncell_relax_input, num_valence_electrons, ) -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR TEST_DIR = f"{TEST_FILES_DIR}/io/abinit" @@ -33,7 +33,7 @@ def abiref_files(*filenames): return [f"{TEST_DIR}/{file}" for file in filenames] -class TestAbinitInput(PymatgenTest): +class TestAbinitInput: """Unit tests for BasicAbinitInput.""" def test_api(self): @@ -168,7 +168,7 @@ def test_helper_functions(self): assert len(inp["kptbounds"]) == 12 -class TestMultiDataset(PymatgenTest): +class TestMultiDataset: """Unit tests for BasicMultiDataset.""" def test_api(self): @@ -251,7 +251,7 @@ def test_api(self): self.serialize_with_pickle(multi, test_eq=False) -class TestShiftMode(PymatgenTest): +class TestShiftMode: def test_shiftmode(self): gamma = ShiftMode.GammaCentered assert ShiftMode.from_object("G") == gamma @@ -260,7 +260,7 @@ def test_shiftmode(self): ShiftMode.from_object({}) -class TestFactory(PymatgenTest): +class TestFactory: def setUp(self): # Si ebands self.si_structure = Structure.from_file(abiref_file("si.cif")) diff --git a/tests/io/abinit/test_netcdf.py b/tests/io/abinit/test_netcdf.py index b4b2ffa68c1..2006d5bdbb0 100644 --- a/tests/io/abinit/test_netcdf.py +++ b/tests/io/abinit/test_netcdf.py @@ -11,7 +11,7 @@ from pymatgen.core.structure import Structure from pymatgen.io.abinit import EtsfReader from pymatgen.io.abinit.netcdf import AbinitHeader -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR try: import netCDF4 @@ -21,7 +21,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/io/abinit" -class TestEtsfReader(PymatgenTest): +class TestEtsfReader: def setUp(self): formulas = ["Si2"] self.GSR_paths = dct = {} @@ -117,7 +117,7 @@ def test_read_fe(self): assert structure.site_properties["magmom"] == ref_magmom_noncollinear -class TestAbinitHeader(PymatgenTest): +class TestAbinitHeader: def test_api(self): head = AbinitHeader(foo=1, bar=2) assert head.foo == 1 diff --git a/tests/io/abinit/test_pseudos.py b/tests/io/abinit/test_pseudos.py index 8cd9bace814..7d874908c0d 100644 --- a/tests/io/abinit/test_pseudos.py +++ b/tests/io/abinit/test_pseudos.py @@ -9,12 +9,12 @@ from pytest import approx from pymatgen.io.abinit.pseudos import Pseudo, PseudoTable -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR TEST_DIR = f"{TEST_FILES_DIR}/io/abinit" -class TestPseudo(PymatgenTest): +class TestPseudo: def setUp(self): nc_pseudo_fnames = defaultdict(list) nc_pseudo_fnames["Si"] = [f"{TEST_DIR}/{file}" for file in ("14si.pspnc", "14si.4.hgh", "14-Si.LDA.fhi")] @@ -198,7 +198,7 @@ def test_oncvpsp_pseudo_fr(self): assert pb.supports_soc -class TestPseudoTable(PymatgenTest): +class TestPseudoTable: def test_methods(self): """Test PseudoTable methods.""" table = PseudoTable([f"{TEST_DIR}/{file}" for file in ("14si.pspnc", "14si.4.hgh", "14-Si.LDA.fhi")]) diff --git a/tests/io/cp2k/test_inputs.py b/tests/io/cp2k/test_inputs.py index ec0b772c617..7da41494b62 100644 --- a/tests/io/cp2k/test_inputs.py +++ b/tests/io/cp2k/test_inputs.py @@ -22,7 +22,7 @@ Section, SectionList, ) -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR TEST_DIR = f"{TEST_FILES_DIR}/io/cp2k" @@ -41,7 +41,7 @@ """ -class TestBasis(PymatgenTest): +class TestBasis: def test_basis_info(self): # Ensure basis metadata can be read from string basis_info = BasisInfo.from_str("cc-pc-DZVP-MOLOPT-q1-SCAN") @@ -92,7 +92,7 @@ def test_basis(self): mol_opt.info.admm = False -class TestPotential(PymatgenTest): +class TestPotential: all_hydrogen_str = """ H ALLELECTRON ALL 1 0 0 @@ -144,7 +144,7 @@ def test_potentials(self): assert kw.values[0] == "ALL" -class TestCp2kInput(PymatgenTest): +class TestCp2kInput: si_struct = Structure( lattice=[ [0, 2.734364, 2.734364], @@ -268,7 +268,7 @@ def test_mongo(self): assert cp2k_input.check("global/subsec2") -class TestDataFile(PymatgenTest): +class TestDataFile: def test_data_file(self): # make temp file with BASIS_FILE_STR data_file = self.tmp_path / "data-file" diff --git a/tests/io/cp2k/test_sets.py b/tests/io/cp2k/test_sets.py index e2c74bc31a6..943facb4b87 100644 --- a/tests/io/cp2k/test_sets.py +++ b/tests/io/cp2k/test_sets.py @@ -6,7 +6,7 @@ from pymatgen.core.structure import Molecule, Structure from pymatgen.io.cp2k.sets import SETTINGS, Cp2kValidationError, DftSet, GaussianTypeOrbitalBasisSet, GthPotential -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR CP2K_TEST_DIR = f"{TEST_FILES_DIR}/io/cp2k" @@ -46,7 +46,7 @@ } -class TestDftSet(PymatgenTest): +class TestDftSet: def test_dft_set(self) -> None: """Test various DFT set configurations.""" SETTINGS["PMG_CP2K_DATA_DIR"] = CP2K_TEST_DIR diff --git a/tests/io/exciting/test_inputs.py b/tests/io/exciting/test_inputs.py index ccbac253944..e3b134f8429 100644 --- a/tests/io/exciting/test_inputs.py +++ b/tests/io/exciting/test_inputs.py @@ -6,7 +6,7 @@ from pymatgen.core import Lattice, Structure from pymatgen.io.exciting import ExcitingInput -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR __author__ = "Christian Vorwerk" __copyright__ = "Copyright 2016" @@ -19,7 +19,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/io/exciting" -class TestExcitingInput(PymatgenTest): +class TestExcitingInput: def test_fromfile(self): # Test for the import of a structure directly from an exciting # input file diff --git a/tests/io/feff/test_sets.py b/tests/io/feff/test_sets.py index e57e560996c..8dae8b7e546 100644 --- a/tests/io/feff/test_sets.py +++ b/tests/io/feff/test_sets.py @@ -9,12 +9,12 @@ from pymatgen.core.structure import Lattice, Molecule, Structure from pymatgen.io.feff.inputs import Atoms, Header, Potential, Tags from pymatgen.io.feff.sets import FEFFDictSet, MPELNESSet, MPEXAFSSet, MPXANESSet -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR FEFF_TEST_DIR = f"{TEST_FILES_DIR}/io/feff" -class TestFeffInputSet(PymatgenTest): +class TestFeffInputSet: @classmethod def setUpClass(cls): cls.header_string = """* This FEFF.inp file generated by pymatgen diff --git a/tests/io/lammps/test_data.py b/tests/io/lammps/test_data.py index 3be78db967c..a121b7ef680 100644 --- a/tests/io/lammps/test_data.py +++ b/tests/io/lammps/test_data.py @@ -14,12 +14,12 @@ from pymatgen.core import Element, Lattice, Molecule, Structure from pymatgen.io.lammps.data import CombinedData, ForceField, LammpsBox, LammpsData, Topology, lattice_2_lmpbox -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR TEST_DIR = f"{TEST_FILES_DIR}/io/lammps" -class TestLammpsBox(PymatgenTest): +class TestLammpsBox: @classmethod def setUpClass(cls): cls.peptide = LammpsBox( @@ -73,7 +73,7 @@ def test_to_lattice(self): ) -class TestLammpsData(PymatgenTest): +class TestLammpsData: @classmethod def setUpClass(cls): cls.peptide = LammpsData.from_file(filename=f"{TEST_DIR}/data.peptide") @@ -665,7 +665,7 @@ def test_from_bonding(self): assert "Dihedrals" not in topo_etoh2.topologies -class TestForceField(PymatgenTest): +class TestForceField: @classmethod def setUpClass(cls): mass_info = [ diff --git a/tests/io/lammps/test_generators.py b/tests/io/lammps/test_generators.py index d19eddbf8df..3db0fae78d8 100644 --- a/tests/io/lammps/test_generators.py +++ b/tests/io/lammps/test_generators.py @@ -3,12 +3,12 @@ from pymatgen.core.structure import Structure from pymatgen.io.lammps.data import LammpsData from pymatgen.io.lammps.generators import LammpsMinimization -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR TEST_DIR = f"{TEST_FILES_DIR}/io/lammps" -class TestLammpsMinimization(PymatgenTest): +class TestLammpsMinimization: @classmethod def setUpClass(cls): cls.filename = f"{TEST_DIR}/lgps.in" diff --git a/tests/io/lammps/test_inputs.py b/tests/io/lammps/test_inputs.py index 15f8ef3fac4..fb25b788732 100644 --- a/tests/io/lammps/test_inputs.py +++ b/tests/io/lammps/test_inputs.py @@ -11,12 +11,12 @@ from pymatgen.core.structure import Structure from pymatgen.io.lammps.data import LammpsData from pymatgen.io.lammps.inputs import LammpsInputFile, LammpsRun, LammpsTemplateGen, write_lammps_inputs -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR TEST_DIR = f"{TEST_FILES_DIR}/io/lammps" -class TestLammpsInputFile(PymatgenTest): +class TestLammpsInputFile: @classmethod def setUpClass(cls): cls.filename = f"{TEST_DIR}/lgps.in" @@ -640,7 +640,7 @@ def test_add_comment(self): ] -class TestLammpsRun(PymatgenTest): +class TestLammpsRun: def test_md(self): struct = Structure.from_spacegroup(225, Lattice.cubic(3.62126), ["Cu"], [[0, 0, 0]]) ld = LammpsData.from_structure(struct, atom_style="atomic") @@ -690,7 +690,7 @@ def test_md(self): assert os.path.isfile(f"{self.tmp_path}/md/md.data") -class TestFunc(PymatgenTest): +class TestFunc: @pytest.mark.filterwarnings("ignore:write_lammps_inputs is deprecated") def test_write_lammps_inputs(self): # script template @@ -727,7 +727,7 @@ def test_write_lammps_inputs(self): pd.testing.assert_frame_equal(obj_read.atoms, obj.atoms) -class TestLammpsTemplateGen(PymatgenTest): +class TestLammpsTemplateGen: def test_write_inputs(self): # simple script without data file lis = LammpsTemplateGen().get_input_set( diff --git a/tests/io/lobster/test_inputs.py b/tests/io/lobster/test_inputs.py index 59960d5970f..72feec95f87 100644 --- a/tests/io/lobster/test_inputs.py +++ b/tests/io/lobster/test_inputs.py @@ -8,7 +8,7 @@ from pymatgen.io.lobster import Lobsterin from pymatgen.io.lobster.inputs import get_all_possible_basis_combinations from pymatgen.io.vasp.inputs import Incar, Kpoints, Potcar -from pymatgen.util.testing import FAKE_POTCAR_DIR, TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR, PymatgenTest +from pymatgen.util.testing import FAKE_POTCAR_DIR, TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR TEST_DIR = f"{TEST_FILES_DIR}/electronic_structure/cohp" @@ -19,7 +19,7 @@ __date__ = "Dec 10, 2017" -class TestLobsterin(PymatgenTest): +class TestLobsterin: def setUp(self): self.Lobsterin = Lobsterin.from_file(f"{TEST_DIR}/lobsterin.1") self.Lobsterin2 = Lobsterin.from_file(f"{TEST_DIR}/lobsterin.2") @@ -579,7 +579,7 @@ def test_as_from_dict(self): new_lobsterin.to_json() -class TestUtils(PymatgenTest): +class TestUtils: def test_get_all_possible_basis_combinations(self): # this basis is just for testing (not correct) min_basis = ["Li 1s 2s ", "Na 1s 2s", "Si 1s 2s"] diff --git a/tests/io/lobster/test_outputs.py b/tests/io/lobster/test_outputs.py index 4dac8c4a01b..ac9ff882d82 100644 --- a/tests/io/lobster/test_outputs.py +++ b/tests/io/lobster/test_outputs.py @@ -31,7 +31,7 @@ Wavefunction, ) from pymatgen.io.vasp import Vasprun -from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR TEST_DIR = f"{TEST_FILES_DIR}/electronic_structure/cohp" @@ -42,7 +42,7 @@ __date__ = "Dec 10, 2017" -class TestBwdf(PymatgenTest): +class TestBwdf: def setUp(self): self.bwdf_coop = Bwdf(filename=f"{TEST_DIR}/BWDF.lobster.AlN.gz") self.bwdf_cohp = Bwdf(filename=f"{TEST_DIR}/BWDFCOHP.lobster.NaCl.gz") @@ -57,7 +57,7 @@ def test_attributes(self): assert self.bwdf_cohp.bwdf[Spin.up][103] == approx(-0.01392, abs=1e-4) -class TestCohpcar(PymatgenTest): +class TestCohpcar: def setUp(self): self.cohp_bise = Cohpcar(filename=f"{TEST_DIR}/COHPCAR.lobster.BiSe.gz") self.coop_bise = Cohpcar( @@ -637,7 +637,7 @@ def test_is_spin_polarized(self): assert not self.DOSCAR_nonspin_pol.is_spin_polarized -class TestCharge(PymatgenTest): +class TestCharge: def setUp(self): self.charge2 = Charge(filename=f"{TEST_DIR}/CHARGE.lobster.MnO") # gzipped file @@ -716,7 +716,7 @@ def test_msonable(self): assert getattr(charge_from_dict, attr_name) == attr_value -class TestLobsterout(PymatgenTest): +class TestLobsterout: def setUp(self): self.lobsterout_normal = Lobsterout(filename=f"{TEST_DIR}/lobsterout.normal") # make sure .gz files are also read correctly @@ -1245,7 +1245,7 @@ def test_msonable(self): Lobsterout(filename=None, invalid="val") -class TestFatband(PymatgenTest): +class TestFatband: def setUp(self): self.structure = Vasprun( filename=f"{TEST_DIR}/Fatband_SiO2/Test_p_x/vasprun.xml", @@ -2204,7 +2204,7 @@ def test_ncicobilist(self): ) -class TestWavefunction(PymatgenTest): +class TestWavefunction: def test_parse_file(self): grid, points, real, imaginary, distance = Wavefunction._parse_file( f"{TEST_DIR}/LCAOWaveFunctionAfterLSO1PlotOfSpin1Kpoint1band1.gz" @@ -2272,7 +2272,7 @@ def test_write_file(self): assert os.path.isfile(density_wavecar_path) -class TestSitePotentials(PymatgenTest): +class TestSitePotentials: def setUp(self) -> None: self.sitepotential = SitePotential(filename=f"{TEST_DIR}/SitePotentials.lobster.perovskite") @@ -2323,7 +2323,7 @@ def test_msonable(self): assert getattr(sitepotential_from_dict, attr_name) == attr_value -class TestMadelungEnergies(PymatgenTest): +class TestMadelungEnergies: def setUp(self) -> None: self.madelungenergies = MadelungEnergies(filename=f"{TEST_DIR}/MadelungEnergies.lobster.perovskite") @@ -2340,7 +2340,7 @@ def test_msonable(self): assert getattr(madelung_from_dict, attr_name) == attr_value -class TestLobsterMatrices(PymatgenTest): +class TestLobsterMatrices: def setUp(self) -> None: self.hamilton_matrices = LobsterMatrices( filename=f"{TEST_DIR}/Na_hamiltonMatrices.lobster.gz", e_fermi=-2.79650354 @@ -2490,7 +2490,7 @@ def test_raises(self): self.hamilton_matrices = LobsterMatrices(filename=f"{TEST_DIR}/hamiltonMatrices.lobster") -class TestPolarization(PymatgenTest): +class TestPolarization: def setUp(self) -> None: self.polarization = Polarization(filename=f"{TEST_DIR}/POLARIZATION.lobster.AlN.gz") diff --git a/tests/io/pwmat/test_inputs.py b/tests/io/pwmat/test_inputs.py index 7618e7ecdf6..8e21dc0428f 100644 --- a/tests/io/pwmat/test_inputs.py +++ b/tests/io/pwmat/test_inputs.py @@ -18,7 +18,7 @@ LineLocator, ListLocator, ) -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR TEST_DIR = f"{TEST_FILES_DIR}/io/pwmat" @@ -43,7 +43,7 @@ def test_list_locator(exclusion: str, expected_idx: int): assert aim_idx == expected_idx -class TestACstrExtractor(PymatgenTest): +class TestACstrExtractor: def test_extract(self): filepath = f"{TEST_DIR}/atom.config" ac_extractor = ACExtractor(file_path=filepath) @@ -60,7 +60,7 @@ def test_extract(self): assert ac_extractor.magmoms[idx] == ac_str_extractor.get_magmoms()[idx] -class TestAtomConfig(PymatgenTest): +class TestAtomConfig: def test_init(self): filepath = f"{TEST_DIR}/atom.config" structure = Structure.from_file(filepath) @@ -82,7 +82,7 @@ def test_write_file(self): assert_allclose(atom_config.structure.lattice.abc, tmp_atom_config.structure.lattice.abc, 5) -class TestGenKpt(PymatgenTest): +class TestGenKpt: def test_from_structure(self): pytest.importorskip("seekpath") filepath = f"{TEST_DIR}/atom.config" @@ -107,7 +107,7 @@ def test_write_file(self): assert gen_kpt.get_str() == tmp_gen_kpt_str -class TestHighSymmetryPoint(PymatgenTest): +class TestHighSymmetryPoint: def test_from_structure(self): pytest.importorskip("seekpath") filepath = f"{TEST_DIR}/atom.config" diff --git a/tests/io/pwmat/test_outputs.py b/tests/io/pwmat/test_outputs.py index b2a97f891fe..ea7d0150122 100644 --- a/tests/io/pwmat/test_outputs.py +++ b/tests/io/pwmat/test_outputs.py @@ -1,12 +1,12 @@ from __future__ import annotations from pymatgen.io.pwmat.outputs import DosSpin, Movement, OutFermi, Report -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR TEST_DIR = f"{TEST_FILES_DIR}/io/pwmat" -class TestMovement(PymatgenTest): +class TestMovement: def test_init_and_properties(self): filepath = f"{TEST_DIR}/MOVEMENT.lzma" movement = Movement(filepath) @@ -26,14 +26,14 @@ def test_init_and_properties(self): assert movement.ionic_steps[0]["e_tot"] == -357677.2281 -class TestOutFermi(PymatgenTest): +class TestOutFermi: def test_init_and_properties(self): filepath = f"{TEST_DIR}/OUT.FERMI.lzma" out_fermi = OutFermi(filepath) assert out_fermi.e_fermi == -2.359 -class TestReport(PymatgenTest): +class TestReport: def test_init_and_properties(self): filepath = f"{TEST_DIR}/REPORT" report = Report(filepath) @@ -46,7 +46,7 @@ def test_init_and_properties(self): assert report.hsps == {} -class TestDosSpin(PymatgenTest): +class TestDosSpin: def test_init_and_properties(self): filepath = f"{TEST_DIR}/DOS.spinup_projected" dos_spin = DosSpin(filepath) diff --git a/tests/io/qchem/test_inputs.py b/tests/io/qchem/test_inputs.py index fe87a29a095..49737711af7 100644 --- a/tests/io/qchem/test_inputs.py +++ b/tests/io/qchem/test_inputs.py @@ -8,7 +8,7 @@ from pymatgen.core.structure import Molecule from pymatgen.io.qchem.inputs import QCInput from pymatgen.io.qchem.sets import OptSet -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR TEST_DIR = f"{TEST_FILES_DIR}/io/qchem" @@ -20,7 +20,7 @@ __credits__ = "Xiaohui Qu" -class TestQCInput(PymatgenTest): +class TestQCInput: def test_molecule_template(self): species = ["C", "O"] coords = [ diff --git a/tests/io/qchem/test_outputs.py b/tests/io/qchem/test_outputs.py index 22f681f8918..0c727a1bdce 100644 --- a/tests/io/qchem/test_outputs.py +++ b/tests/io/qchem/test_outputs.py @@ -17,7 +17,7 @@ hessian_parser, orbital_coeffs_parser, ) -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR try: from openbabel import openbabel @@ -260,7 +260,7 @@ } -class TestQCOutput(PymatgenTest): +class TestQCOutput: @staticmethod def generate_single_job_dict(): """Used to generate test dictionary for single jobs.""" diff --git a/tests/io/qchem/test_sets.py b/tests/io/qchem/test_sets.py index 9a677b02ab8..f969e5a1c78 100644 --- a/tests/io/qchem/test_sets.py +++ b/tests/io/qchem/test_sets.py @@ -14,7 +14,7 @@ SinglePointSet, TransitionStateSet, ) -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR __author__ = "Samuel Blau, Brandon Wood, Shyam Dwaraknath, Evan Spotte-Smith, Ryan Kingsbury" __copyright__ = "Copyright 2018-2022, The Materials Project" @@ -26,7 +26,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/io/qchem/new_qchem_files" -class TestQChemDictSet(PymatgenTest): +class TestQChemDictSet: def test_init(self): test_molecule = QCInput.from_file(f"{TEST_DIR}/pcm.qin").molecule test_dict_set = QChemDictSet( @@ -469,7 +469,7 @@ def test_solvation_warnings(self): ) -class TestSinglePointSet(PymatgenTest): +class TestSinglePointSet: def test_init(self): test_molecule = QCInput.from_file(f"{TEST_DIR}/pcm.qin").molecule test_sp_set = SinglePointSet(molecule=test_molecule) @@ -671,7 +671,7 @@ def test_plots_init(self): assert test_sp_set.molecule == test_molecule -class TestOptSet(PymatgenTest): +class TestOptSet: def test_init(self): test_molecule = QCInput.from_file(f"{TEST_DIR}/pcm.qin").molecule test_opt_set = OptSet(molecule=test_molecule) @@ -846,7 +846,7 @@ def test_v5_vs_v6(self): assert v6_opt_set_modified.geom_opt == ref_dict -class TestTransitionStateSet(PymatgenTest): +class TestTransitionStateSet: def test_init(self): test_molecule = QCInput.from_file(f"{TEST_DIR}/pcm.qin").molecule test_ts_set = TransitionStateSet(molecule=test_molecule) @@ -927,7 +927,7 @@ def test_smd_init(self): assert test_ts_set.molecule == test_molecule -class TestForceSet(PymatgenTest): +class TestForceSet: def test_init(self): test_molecule = QCInput.from_file(f"{TEST_DIR}/pcm.qin").molecule test_forceset = ForceSet(molecule=test_molecule) @@ -1004,7 +1004,7 @@ def test_smd_init(self): assert test_forceset.molecule == test_molecule -class TestPESScanSet(PymatgenTest): +class TestPESScanSet: def test_init(self): test_molecule = QCInput.from_file(f"{TEST_DIR}/pes_scan.qin").molecule @@ -1097,7 +1097,7 @@ def test_smd_init(self): assert test_pes_scan.molecule == test_molecule -class TestFreqSet(PymatgenTest): +class TestFreqSet: def test_init(self): test_molecule = QCInput.from_file(f"{TEST_DIR}/pcm.qin").molecule test_freq_set = FreqSet(molecule=test_molecule) diff --git a/tests/io/qchem/test_utils.py b/tests/io/qchem/test_utils.py index 4ad091b8242..c12dc788063 100644 --- a/tests/io/qchem/test_utils.py +++ b/tests/io/qchem/test_utils.py @@ -6,7 +6,7 @@ from monty.io import zopen from pymatgen.io.qchem.utils import lower_and_check_unique, process_parsed_hess -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR __author__ = "Ryan Kingsbury, Samuel Blau" __copyright__ = "Copyright 2018-2022, The Materials Project" @@ -15,7 +15,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/io/qchem/new_qchem_files" -class TestUtil(PymatgenTest): +class TestUtil: """test utils.""" def test_lower_and_check_unique(self): diff --git a/tests/io/test_adf.py b/tests/io/test_adf.py index d3b6785320f..43d210e8a3e 100644 --- a/tests/io/test_adf.py +++ b/tests/io/test_adf.py @@ -4,7 +4,7 @@ from pymatgen.core.structure import Molecule from pymatgen.io.adf import AdfInput, AdfKey, AdfOutput, AdfTask -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR __author__ = "Xin Chen, chenxin13@mails.tsinghua.edu.cn" @@ -242,7 +242,7 @@ def test_serialization(self): } -class TestAdfInput(PymatgenTest): +class TestAdfInput: def test_main(self): tmp_file = f"{self.tmp_path}/adf.temp" mol = Molecule.from_str(rhb18_xyz, "xyz") diff --git a/tests/io/test_atat.py b/tests/io/test_atat.py index a9562f92511..23c9ca9472e 100644 --- a/tests/io/test_atat.py +++ b/tests/io/test_atat.py @@ -5,12 +5,12 @@ from pymatgen.core.structure import Structure from pymatgen.io.atat import Mcsqs -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR TEST_DIR = f"{TEST_FILES_DIR}/io/atat/mcsqs" -class TestAtat(PymatgenTest): +class TestAtat: def test_mcsqs_import(self): test_str = """1.000000 0.000000 0.000000 0.000000 1.000000 0.000000 diff --git a/tests/io/test_cif.py b/tests/io/test_cif.py index 690c67c302d..3dd01454bb9 100644 --- a/tests/io/test_cif.py +++ b/tests/io/test_cif.py @@ -9,7 +9,7 @@ from pymatgen.electronic_structure.core import Magmom from pymatgen.io.cif import CifBlock, CifParser, CifWriter from pymatgen.symmetry.structure import SymmetrizedStructure -from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR try: import pybtex @@ -20,7 +20,7 @@ MCIF_TEST_DIR = f"{TEST_FILES_DIR}/io/cif/mcif" -class TestCifBlock(PymatgenTest): +class TestCifBlock: def test_to_str(self): with open(f"{TEST_FILES_DIR}/cif/Graphite.cif") as file: cif_str = file.read() @@ -164,7 +164,7 @@ def test_long_loop(self): assert str(CifBlock(data, loops, "test")) == cif_str -class TestCifIO(PymatgenTest): +class TestCifIO: def test_cif_parser(self): parser = CifParser(f"{TEST_FILES_DIR}/cif/LiFePO4.cif") for struct in parser.parse_structures(): @@ -999,7 +999,7 @@ def test_cif_writer_site_properties(self): assert "O O23 1 0.95662769 0.25000000 0.29286233 1 -1.0" in cif_str -class TestMagCif(PymatgenTest): +class TestMagCif: def setUp(self): self.mcif = CifParser(f"{MCIF_TEST_DIR}/magnetic.example.NiO.mcif") self.mcif_ncl = CifParser(f"{MCIF_TEST_DIR}/magnetic.ncl.example.GdB4.mcif") diff --git a/tests/io/test_core.py b/tests/io/test_core.py index bd4ad9ea7fa..77e6b410b96 100644 --- a/tests/io/test_core.py +++ b/tests/io/test_core.py @@ -10,7 +10,7 @@ from pymatgen.core.structure import Structure from pymatgen.io.cif import CifParser, CifWriter from pymatgen.io.core import InputFile, InputSet -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR if TYPE_CHECKING: from typing_extensions import Self @@ -44,7 +44,7 @@ def __str__(self): return f"{self.a}\n{self.b}" -class TestInputFile(PymatgenTest): +class TestInputFile: def test_file_io(self): with pytest.raises(FileNotFoundError, match="No such file or directory: 'fakepath.cif'"): StructInputFile.from_file("fakepath.cif") @@ -64,7 +64,7 @@ def test_msonable(self): assert sif.structure == temp_sif.structure -class TestInputSet(PymatgenTest): +class TestInputSet: @classmethod def setUpClass(cls): cls.sif1 = StructInputFile.from_file(f"{TEST_FILES_DIR}/cif/Li.cif") diff --git a/tests/io/test_lmto.py b/tests/io/test_lmto.py index 1ddc8c2abcf..7a73dfa791b 100644 --- a/tests/io/test_lmto.py +++ b/tests/io/test_lmto.py @@ -10,7 +10,7 @@ from pymatgen.electronic_structure.core import Spin from pymatgen.io.lmto import LMTOCopl, LMTOCtrl from pymatgen.util.num import round_to_sigfigs -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR __author__ = "Marco Esters" __copyright__ = "Copyright 2017, The Materials Project" @@ -23,7 +23,7 @@ MODULE_DIR = os.path.dirname(os.path.abspath(__file__)) -class TestCtrl(PymatgenTest): +class TestCtrl: def setUp(self): os.chdir(TEST_DIR) self.ref_bise = LMTOCtrl.from_file(filename="CTRL.BiSe") @@ -47,7 +47,7 @@ def test_read_write(self): assert self.ref_bise.structure.matches(ctrl_file.structure) -class TestCopl(PymatgenTest): +class TestCopl: def setUp(self): os.chdir(TEST_DIR) self.copl_bise = LMTOCopl("COPL.BiSe") diff --git a/tests/io/test_packmol.py b/tests/io/test_packmol.py index c6d25953dcd..5c709436d83 100644 --- a/tests/io/test_packmol.py +++ b/tests/io/test_packmol.py @@ -10,7 +10,7 @@ from pymatgen.analysis.molecule_matcher import MoleculeMatcher from pymatgen.core import Molecule from pymatgen.io.packmol import PackmolBoxGen -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR TEST_DIR = f"{TEST_FILES_DIR}/io/packmol" # error message is different in CI for unknown reasons (as of 2024-04-12) @@ -48,7 +48,7 @@ water = Molecule(water_atoms, water_coords) -class TestPackmolSet(PymatgenTest): +class TestPackmolSet: def test_packmol_with_molecule(self): """Test coords input as Molecule.""" pw = PackmolBoxGen().get_input_set( diff --git a/tests/io/test_phonopy.py b/tests/io/test_phonopy.py index 802e43049e2..588a027adc3 100644 --- a/tests/io/test_phonopy.py +++ b/tests/io/test_phonopy.py @@ -42,7 +42,7 @@ PHONON_DIR = f"{TEST_FILES_DIR}/phonon" -class TestPhonopyParser(PymatgenTest): +class TestPhonopyParser: def test_get_ph_bs(self): ph_bs = get_ph_bs_symm_line(f"{TEST_DIR}/NaCl_band.yaml", has_nac=True) @@ -98,7 +98,7 @@ def test_get_complete_dos(self): @pytest.mark.skipif(Phonopy is None, reason="Phonopy not present") -class TestStructureConversion(PymatgenTest): +class TestStructureConversion: def test_structure_conversion(self): struct_pmg = PymatgenTest.get_structure("LiFePO4") # add magmoms to site_properties @@ -126,7 +126,7 @@ def test_structure_conversion(self): @pytest.mark.skipif(Phonopy is None, reason="Phonopy not present") -class TestGetDisplacedStructures(PymatgenTest): +class TestGetDisplacedStructures: def test_get_displaced_structures(self): pmg_s = Structure.from_file(f"{TEST_DIR}/POSCAR-unitcell", primitive=False) supercell_matrix = np.diag((2, 1, 2)) @@ -246,7 +246,7 @@ def test_gruneisen_parameter(self): @pytest.mark.skipif(Phonopy is None, reason="Phonopy not present") -class TestThermalDisplacementMatrices(PymatgenTest): +class TestThermalDisplacementMatrices: def test_get_thermal_displacement_matrix(self): list_matrices = get_thermal_displacement_matrices( f"{PHONON_DIR}/thermal_displacement_matrices/thermal_displacement_matrices.yaml", diff --git a/tests/io/test_pwscf.py b/tests/io/test_pwscf.py index 6e39c8b4019..15743c7a9b6 100644 --- a/tests/io/test_pwscf.py +++ b/tests/io/test_pwscf.py @@ -6,12 +6,12 @@ from pytest import approx from pymatgen.io.pwscf import PWInput, PWInputError, PWOutput -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR TEST_DIR = f"{TEST_FILES_DIR}/io/pwscf" -class TestPWInput(PymatgenTest): +class TestPWInput: def test_init(self): struct = self.get_structure("Li2O") with pytest.raises(PWInputError, match="Missing O2- in pseudo specification"): @@ -542,7 +542,7 @@ def test_custom_decimal_precision_write_and_read_str(self): assert pw_str.strip() == str(PWInput.from_str(pw_str)).strip() -class TestPWOutput(PymatgenTest): +class TestPWOutput: def setUp(self): self.pw_out = PWOutput(f"{TEST_DIR}/Si.pwscf.out") diff --git a/tests/io/test_shengbte.py b/tests/io/test_shengbte.py index 303c9d094aa..961792df336 100644 --- a/tests/io/test_shengbte.py +++ b/tests/io/test_shengbte.py @@ -4,13 +4,13 @@ from numpy.testing import assert_array_equal from pymatgen.io.shengbte import Control -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR f90nml = pytest.importorskip("f90nml") TEST_DIR = f"{TEST_FILES_DIR}/io/shengbte" -class TestShengBTE(PymatgenTest): +class TestShengBTE: def setUp(self): self.filename = f"{TEST_DIR}/CONTROL-CSLD_Si" self.test_dict = { diff --git a/tests/io/test_template_input.py b/tests/io/test_template_input.py index 3be8ae45374..f6ea6e84cf6 100644 --- a/tests/io/test_template_input.py +++ b/tests/io/test_template_input.py @@ -5,12 +5,12 @@ import pytest from pymatgen.io.template import TemplateInputGen -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR TEST_DIR = f"{TEST_FILES_DIR}/io" -class TestTemplateInputGen(PymatgenTest): +class TestTemplateInputGen: def test_write_inputs(self): input_set = TemplateInputGen().get_input_set( template=f"{TEST_DIR}/template_input_file.txt", diff --git a/tests/io/test_wannier90.py b/tests/io/test_wannier90.py index 93ac0e256e7..8a43bf62a22 100644 --- a/tests/io/test_wannier90.py +++ b/tests/io/test_wannier90.py @@ -8,12 +8,12 @@ from pytest import approx from pymatgen.io.wannier90 import Unk -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR TEST_DIR = f"{TEST_FILES_DIR}/io/wannier90" -class TestUnk(PymatgenTest): +class TestUnk: def setUp(self): rng = np.random.default_rng() self.data_std = rng.random((10, 5, 5, 5)) diff --git a/tests/io/test_xcrysden.py b/tests/io/test_xcrysden.py index 3a13a2cf7b5..095e8f73b6a 100644 --- a/tests/io/test_xcrysden.py +++ b/tests/io/test_xcrysden.py @@ -4,10 +4,9 @@ from pymatgen.core.structure import Structure from pymatgen.io.xcrysden import XSF -from pymatgen.util.testing import PymatgenTest -class TestXSF(PymatgenTest): +class TestXSF: def setUp(self): self.coords = [[0, 0, 0], [0.75, 0.5, 0.75]] self.lattice = [ diff --git a/tests/io/vasp/test_inputs.py b/tests/io/vasp/test_inputs.py index 1616ff4e5e7..13e28f4a4eb 100644 --- a/tests/io/vasp/test_inputs.py +++ b/tests/io/vasp/test_inputs.py @@ -38,7 +38,7 @@ VaspInput, _gen_potcar_summary_stats, ) -from pymatgen.util.testing import FAKE_POTCAR_DIR, TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR, PymatgenTest +from pymatgen.util.testing import FAKE_POTCAR_DIR, TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR # Filter some expected warnings warnings.filterwarnings( @@ -72,7 +72,7 @@ def _mock_complete_potcar_summary_stats(monkeypatch: pytest.MonkeyPatch) -> None @pytest.mark.filterwarnings( "ignore:POTCAR data with symbol .* is not known to pymatgen:pymatgen.io.vasp.inputs.UnknownPotcarWarning" ) -class TestPoscar(PymatgenTest): +class TestPoscar: def test_init(self): comp = Structure.from_file(f"{VASP_IN_DIR}/POSCAR").composition assert comp == Composition("Fe4P4O16") @@ -649,7 +649,7 @@ def test_vasp_6_4_2_format(self): assert poscar.structure.formula == "Li4 Fe4 P4 O16" -class TestIncar(PymatgenTest): +class TestIncar: def setUp(self): self.incar = Incar.from_file(f"{VASP_IN_DIR}/INCAR") @@ -1537,7 +1537,7 @@ def test_copy(self): @pytest.mark.filterwarnings( "ignore:POTCAR data with symbol .* is not known to pymatgen:pymatgen.io.vasp.inputs.UnknownPotcarWarning" ) -class TestPotcar(PymatgenTest): +class TestPotcar: def setUp(self): SETTINGS.setdefault("PMG_VASP_PSP_DIR", str(TEST_FILES_DIR)) self.filepath = f"{FAKE_POTCAR_DIR}/POTCAR.gz" @@ -1616,7 +1616,7 @@ def test_pickle(self): @pytest.mark.filterwarnings( "ignore:POTCAR data with symbol .* is not known to pymatgen:pymatgen.io.vasp.inputs.UnknownPotcarWarning" ) -class TestVaspInput(PymatgenTest): +class TestVaspInput: def setUp(self): filepath = f"{VASP_IN_DIR}/INCAR" incar = Incar.from_file(filepath) diff --git a/tests/io/vasp/test_optics.py b/tests/io/vasp/test_optics.py index 3a2caf7a94a..a898c5fb7eb 100644 --- a/tests/io/vasp/test_optics.py +++ b/tests/io/vasp/test_optics.py @@ -7,7 +7,7 @@ from pymatgen.io.vasp.optics import DielectricFunctionCalculator, delta_func, delta_methfessel_paxton, step_func from pymatgen.io.vasp.outputs import Vasprun -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR __author__ = "Jimmy-Xuan Shen" __copyright__ = "Copyright 2022, The Materials Project" @@ -16,7 +16,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/io/vasp" -class TestVasprun(PymatgenTest): +class TestVasprun: def test_optics(self): eps_data_path = f"{TEST_DIR}/fixtures/reproduce_eps" vrun = Vasprun(f"{eps_data_path}/vasprun.xml") diff --git a/tests/io/vasp/test_outputs.py b/tests/io/vasp/test_outputs.py index e02b9ac027a..e67c241bf8a 100644 --- a/tests/io/vasp/test_outputs.py +++ b/tests/io/vasp/test_outputs.py @@ -41,7 +41,7 @@ Xdatcar, ) from pymatgen.io.wannier90 import Unk -from pymatgen.util.testing import FAKE_POTCAR_DIR, TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR, PymatgenTest +from pymatgen.util.testing import FAKE_POTCAR_DIR, TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR try: import h5py @@ -53,7 +53,7 @@ kpts_opt_vrun_path = f"{TEST_DIR}/fixtures/kpoints_opt/vasprun.xml.gz" -class TestVasprun(PymatgenTest): +class TestVasprun: def test_vasprun_ml(self): # Test for ML MD simulation # The trajectory data is stored in md_data @@ -832,7 +832,7 @@ def test_parse_potcar_cwd_relative(self): assert vrun.potcar_spec[ipot]["summary_stats"] == potcar[ipot]._summary_stats -class TestOutcar(PymatgenTest): +class TestOutcar: def test_init(self): outcar = Outcar(f"{VASP_OUT_DIR}/OUTCAR.gz") expected_mag = ( @@ -1423,7 +1423,7 @@ def test_read_table_pattern(self): ) -class TestBSVasprun(PymatgenTest): +class TestBSVasprun: def test_get_band_structure(self): filepath = f"{VASP_OUT_DIR}/vasprun_Si_bands.xml.gz" vasprun = BSVasprun(filepath, parse_potcar_file=False) @@ -1477,7 +1477,7 @@ def test_kpoints_opt(self): assert {*vrun_dct["output"]} >= {"eigenvalues", "eigenvalues_kpoints_opt"} -class TestOszicar(PymatgenTest): +class TestOszicar: def test_init(self): fpath = f"{VASP_OUT_DIR}/OSZICAR" oszicar = Oszicar(fpath) @@ -1493,7 +1493,7 @@ def test_static(self): assert set(oszicar.ionic_steps[-1]) == set({"F", "E0", "dE", "mag"}) -class TestLocpot(PymatgenTest): +class TestLocpot: def test_init(self): filepath = f"{VASP_OUT_DIR}/LOCPOT.gz" locpot = Locpot.from_file(filepath) @@ -1514,7 +1514,7 @@ def test_vasp_6x_style(self): assert {str(ele) for ele in locpot.structure.composition} == {"Mg", "Si"} -class TestChgcar(PymatgenTest): +class TestChgcar: @classmethod def setUpClass(cls): filepath = f"{VASP_OUT_DIR}/CHGCAR.nospin.gz" @@ -1638,7 +1638,7 @@ def test_as_dict_and_from_dict(self): ) -class TestAeccars(PymatgenTest): +class TestAeccars: # https://github.com/materialsproject/pymatgen/pull/3343 def test_read_write_file(self): aeccar0_test = Chgcar.from_file(f"{TEST_FILES_DIR}/command_line/bader/AECCAR0.gz") @@ -1654,7 +1654,7 @@ def test_read_write_file(self): assert_allclose(aeccar2.data["total"], aeccar2_read.data["total"]) -class TestElfcar(PymatgenTest): +class TestElfcar: def test_init(self): elfcar = Elfcar.from_file(f"{VASP_OUT_DIR}/ELFCAR.gz") assert approx(np.mean(elfcar.data["total"])) == 0.19076207645194002 @@ -1674,7 +1674,7 @@ def test_interpolation(self): assert len(elfcar.linear_slice([0.0, 0.0, 0.0], [1.0, 1.0, 1.0])) == 100 -class TestProcar(PymatgenTest): +class TestProcar: def test_init(self): filepath = f"{VASP_OUT_DIR}/PROCAR.simple" procar = Procar(filepath) @@ -1817,7 +1817,7 @@ def test_init(self): # TODO: test get_phonon_frequencies once cross-checked -class TestWavecar(PymatgenTest): +class TestWavecar: def setUp(self): latt_mat = np.array(np.eye(3) * 10, dtype=float) # lattice vectors self.vol = np.dot(latt_mat[0, :], np.cross(latt_mat[1, :], latt_mat[2, :])) # unit cell volume @@ -2095,7 +2095,7 @@ def test_write_unks(self): assert unk == unk_ncl -class TestEigenval(PymatgenTest): +class TestEigenval: def test_init(self): eig = Eigenval(f"{VASP_OUT_DIR}/EIGENVAL.gz") assert eig.ispin == 1 @@ -2135,7 +2135,7 @@ def test_eigenvalue_band_properties_separate_spins(self): assert props[3][1] -class TestWaveder(PymatgenTest): +class TestWaveder: def setUp(self): wder = Waveder.from_binary(f"{VASP_OUT_DIR}/WAVEDER", "float64") assert wder.nbands == 36 @@ -2168,7 +2168,7 @@ def _check(wder): _check(wderf) -class TestWSWQ(PymatgenTest): +class TestWSWQ: def setUp(self): self.wswq = WSWQ.from_file(f"{VASP_OUT_DIR}/WSWQ.gz") diff --git a/tests/io/vasp/test_sets.py b/tests/io/vasp/test_sets.py index 6b4f9ceebdb..6dd438c052b 100644 --- a/tests/io/vasp/test_sets.py +++ b/tests/io/vasp/test_sets.py @@ -91,7 +91,7 @@ def test_yb_2_warning(input_set: VaspInputSet) -> None: assert expected in str(record[0].message) -class TestSetChangeCheck(PymatgenTest): +class TestSetChangeCheck: def test_sets_changed(self): msg = ( "WARNING! These tests will fail when you change an input set. They are included " @@ -128,7 +128,7 @@ def test_sets_changed(self): assert hash_str == known_hashes[input_set], f"{input_set=}\n{msg}" -class TestVaspInputSet(PymatgenTest): +class TestVaspInputSet: @classmethod def setUpClass(cls): filepath = f"{VASP_IN_DIR}/POSCAR" @@ -165,7 +165,7 @@ def test_as_dict(self): assert dict_set.potcar_functional == dict_set.user_potcar_functional -class TestMITMPRelaxSet(PymatgenTest): +class TestMITMPRelaxSet: @classmethod def setUpClass(cls): cls.set = MITRelaxSet @@ -718,7 +718,7 @@ def test_get_nedos(self): assert vis._get_nedos(0.1) == pytest.approx(741, abs=1) -class TestMPStaticSet(PymatgenTest): +class TestMPStaticSet: def setUp(self): self.set = MPStaticSet @@ -870,7 +870,7 @@ def test_grid_size_from_struct(self): ) -class TestMatPESStaticSet(PymatgenTest): +class TestMatPESStaticSet: def setUp(self): self.struct = Structure.from_file(f"{VASP_IN_DIR}/POSCAR") self.prev_incar = Incar.from_file(f"{VASP_IN_DIR}/INCAR") @@ -987,7 +987,7 @@ def test_from_prev_calc(self): assert vis.kpoints is None -class TestMPNonSCFSet(PymatgenTest): +class TestMPNonSCFSet: def setUp(self): self.set = MPNonSCFSet @@ -1153,7 +1153,7 @@ def test_user_kpoint_override(self): assert vis.kpoints.style == Kpoints.supported_modes.Gamma -class TestMagmomLdau(PymatgenTest): +class TestMagmomLdau: def test_structure_from_prev_run(self): vrun = Vasprun(f"{VASP_OUT_DIR}/vasprun.magmom_ldau.xml.gz") structure = vrun.final_structure @@ -1188,7 +1188,7 @@ def test_ln_magmom(self): assert vis.incar["MAGMOM"] == magmom_ans -class TestMITMDSet(PymatgenTest): +class TestMITMDSet: def setUp(self): self.set = MITMDSet filepath = f"{VASP_IN_DIR}/POSCAR" @@ -1230,7 +1230,7 @@ def test_user_heat_speed(self): @skip_if_no_psp_dir -class TestMVLNPTMDSet(PymatgenTest): +class TestMVLNPTMDSet: def setUp(self): file_path = f"{VASP_IN_DIR}/POSCAR" self.struct = Structure.from_file(file_path) @@ -1266,7 +1266,7 @@ def test_as_from_dict(self): assert input_set.incar["NSW"] == 1000 -class TestMPMDSet(PymatgenTest): +class TestMPMDSet: def setUp(self): filepath = f"{VASP_IN_DIR}/POSCAR" self.struct = Structure.from_file(filepath) @@ -1308,7 +1308,7 @@ def test_as_from_dict(self): assert v.incar["NSW"] == 1000 -class TestMITNEBSet(PymatgenTest): +class TestMITNEBSet: def setUp(self): c1 = [[0.5] * 3, [0.9] * 3] c2 = [[0.5] * 3, [0.9, 0.1, 0.1]] @@ -1356,7 +1356,7 @@ def test_write_input(self): assert not os.path.isfile("04/POSCAR") -class TestMPSOCSet(PymatgenTest): +class TestMPSOCSet: def setUp(self): self.set = MPSOCSet @@ -1393,7 +1393,7 @@ def test_override_from_prev_calc(self): assert vis.incar["SIGMA"] == 0.025 -class TestMPNMRSet(PymatgenTest): +class TestMPNMRSet: def test_incar(self): filepath = f"{TEST_FILES_DIR}/cif/Li.cif" structure = Structure.from_file(filepath) @@ -1415,7 +1415,7 @@ def test_incar(self): @skip_if_no_psp_dir -class TestMVLSlabSet(PymatgenTest): +class TestMVLSlabSet: def setUp(self): self.set = MVLSlabSet struct = self.get_structure("Li2O") @@ -1487,7 +1487,7 @@ def test_as_from_dict(self): assert "structure" not in self.vis.as_dict(verbosity=1) -class TestMVLElasticSet(PymatgenTest): +class TestMVLElasticSet: def test_incar(self): mvlparam = MVLElasticSet(self.get_structure("Graphite")) incar = mvlparam.incar @@ -1498,7 +1498,7 @@ def test_incar(self): @skip_if_no_psp_dir -class TestMVLGWSet(PymatgenTest): +class TestMVLGWSet: def setUp(self): self.set = MVLGWSet self.struct = PymatgenTest.get_structure("Li2O") @@ -1576,7 +1576,7 @@ def test_bse(self): assert mvlgwgbse1.incar["ALGO"] == "Bse" -class TestMPHSERelaxSet(PymatgenTest): +class TestMPHSERelaxSet: def setUp(self): self.structure = dummy_structure self.set = MPHSERelaxSet @@ -1643,7 +1643,7 @@ def test_override_from_prev_calc(self): assert "VDW_S8" in vis_bj.incar -class TestMPHSEBS(PymatgenTest): +class TestMPHSEBS: def setUp(self): self.set = MPHSEBSSet @@ -1699,7 +1699,7 @@ def test_override_from_prev_calc(self): assert len(vis.kpoints.kpts) == 180 -class TestMVLScanRelaxSet(PymatgenTest): +class TestMVLScanRelaxSet: def setUp(self): self.set = MVLScanRelaxSet file_path = f"{VASP_IN_DIR}/POSCAR" @@ -1777,7 +1777,7 @@ def test_as_from_dict(self): assert v.user_incar_settings["NSW"] == 500 -class TestMPScanRelaxSet(PymatgenTest): +class TestMPScanRelaxSet: def setUp(self): file_path = f"{VASP_IN_DIR}/POSCAR" self.struct = Structure.from_file(file_path) @@ -1898,7 +1898,7 @@ def test_write_input(self): assert os.path.isfile(f"{self.tmp_path}/POSCAR") -class TestMPScanStaticSet(PymatgenTest): +class TestMPScanStaticSet: def setUp(self): self.set = MPScanStaticSet self.prev_run = f"{TEST_DIR}/fixtures/scan_relaxation" @@ -1988,7 +1988,7 @@ def test_override_from_prev_calc(self): assert lepsilon_vis.incar.get("NPAR") is None -class TestFunc(PymatgenTest): +class TestFunc: @skip_if_no_psp_dir def test_batch_write_input(self): structs = list(map(PymatgenTest.get_structure, ("Li2O", "LiFePO4"))) @@ -2000,7 +2000,7 @@ def test_batch_write_input(self): @skip_if_no_psp_dir -class TestMVLGBSet(PymatgenTest): +class TestMVLGBSet: def setUp(self): filepath = f"{TEST_FILES_DIR}/cif/Li.cif" self.struct = Structure.from_file(filepath) @@ -2026,7 +2026,7 @@ def test_kpoints(self): assert kpoints.kpts == [(k_a, k_b, 1)] -class TestMVLRelax52Set(PymatgenTest): +class TestMVLRelax52Set: def setUp(self): self.set = MVLRelax52Set file_path = f"{VASP_IN_DIR}/POSCAR" @@ -2064,7 +2064,7 @@ def test_as_from_dict(self): assert vasp_input.incar["NSW"] == 500 -class TestLobsterSet(PymatgenTest): +class TestLobsterSet: def setUp(self): self.set = LobsterSet file_path = f"{VASP_IN_DIR}/POSCAR" @@ -2163,7 +2163,7 @@ def test_as_from_dict(self): @skip_if_no_psp_dir -class TestMPAbsorptionSet(PymatgenTest): +class TestMPAbsorptionSet: def setUp(self): file_path = f"{TEST_DIR}/fixtures/absorption/static/POSCAR" self.structure = Structure.from_file(file_path) diff --git a/tests/io/xtb/test_inputs.py b/tests/io/xtb/test_inputs.py index 546386c6391..16d5be8e0fe 100644 --- a/tests/io/xtb/test_inputs.py +++ b/tests/io/xtb/test_inputs.py @@ -2,7 +2,7 @@ from pymatgen.core.structure import Molecule from pymatgen.io.xtb.inputs import CRESTInput -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR __author__ = "Alex Epstein" __copyright__ = "Copyright 2020, The Materials Project" @@ -12,7 +12,7 @@ EXPECTED_DIR = f"{TEST_FILES_DIR}/io/xtb/expected_output" -class TestCRESTInput(PymatgenTest): +class TestCRESTInput: """ Checks that all attributes of CRESTInput match the expected values for sample inputs. diff --git a/tests/io/xtb/test_outputs.py b/tests/io/xtb/test_outputs.py index c4d3fe69777..e617996b8f1 100644 --- a/tests/io/xtb/test_outputs.py +++ b/tests/io/xtb/test_outputs.py @@ -7,7 +7,7 @@ from pymatgen.core.structure import Molecule from pymatgen.io.qchem.outputs import check_for_structure_changes from pymatgen.io.xtb.outputs import CRESTOutput -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR try: from openbabel import openbabel @@ -23,7 +23,7 @@ EXPECTED_DIR = f"{TEST_FILES_DIR}/io/xtb/expected_output" -class TestCRESTOutput(PymatgenTest): +class TestCRESTOutput: """ Checks that all attributes of CRESTOutput match the expected values for a sample CREST output directory. diff --git a/tests/optimization/test_neighbors.py b/tests/optimization/test_neighbors.py index 3542acd20ff..5ddd14f638e 100644 --- a/tests/optimization/test_neighbors.py +++ b/tests/optimization/test_neighbors.py @@ -4,10 +4,9 @@ from pymatgen.core.lattice import Lattice from pymatgen.optimization.neighbors import find_points_in_spheres -from pymatgen.util.testing import PymatgenTest -class TestNeighbors(PymatgenTest): +class TestNeighbors: def setUp(self): self.lattice = Lattice.cubic(10.0) self.cubic = self.lattice diff --git a/tests/phonon/test_bandstructure.py b/tests/phonon/test_bandstructure.py index 7f449792544..6545edb1e27 100644 --- a/tests/phonon/test_bandstructure.py +++ b/tests/phonon/test_bandstructure.py @@ -8,12 +8,12 @@ from pymatgen.electronic_structure.bandstructure import Kpoint from pymatgen.phonon.bandstructure import PhononBandStructureSymmLine -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR TEST_DIR = f"{TEST_FILES_DIR}/electronic_structure/bandstructure" -class TestPhononBandStructureSymmLine(PymatgenTest): +class TestPhononBandStructureSymmLine: def setUp(self): with open(f"{TEST_DIR}/NaCl_phonon_bandstructure.json") as file: dct = json.load(file) diff --git a/tests/phonon/test_dos.py b/tests/phonon/test_dos.py index e586604d81e..a301540e4f0 100644 --- a/tests/phonon/test_dos.py +++ b/tests/phonon/test_dos.py @@ -9,12 +9,12 @@ from pymatgen.core import Element from pymatgen.phonon.dos import CompletePhononDos, PhononDos -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR TEST_DIR = f"{TEST_FILES_DIR}/phonon/dos" -class TestPhononDos(PymatgenTest): +class TestPhononDos: def setUp(self): with open(f"{TEST_DIR}/NaCl_ph_dos.json") as file: self.dos = PhononDos.from_dict(json.load(file)) @@ -182,7 +182,7 @@ def test_dos_fp_exceptions(self): self.dos.get_dos_fp_similarity(dos_fp, dos_fp2, col=1, metric=metric, normalize=False) -class TestCompletePhononDos(PymatgenTest): +class TestCompletePhononDos: def setUp(self): with open(f"{TEST_DIR}/NaCl_complete_ph_dos.json") as file: self.cdos = CompletePhononDos.from_dict(json.load(file)) diff --git a/tests/phonon/test_gruneisen.py b/tests/phonon/test_gruneisen.py index 748fd68c8c2..164790bfc91 100644 --- a/tests/phonon/test_gruneisen.py +++ b/tests/phonon/test_gruneisen.py @@ -9,7 +9,7 @@ from pymatgen.io.phonopy import get_gruneisen_ph_bs_symm_line, get_gruneisenparameter from pymatgen.phonon.gruneisen import GruneisenParameter from pymatgen.phonon.plotter import GruneisenPhononBandStructureSymmLine, GruneisenPhononBSPlotter, GruneisenPlotter -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR try: import phonopy @@ -21,7 +21,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/phonon/gruneisen" -class TestGruneisenPhononBandStructureSymmLine(PymatgenTest): +class TestGruneisenPhononBandStructureSymmLine: def setUp(self) -> None: self.bs_symm_line = get_gruneisen_ph_bs_symm_line( gruneisen_path=f"{TEST_DIR}/gruneisen_eq_plus_minus_InP.yaml", @@ -76,7 +76,7 @@ def test_as_dict_from_dict(self): @pytest.mark.skipif(TotalDos is None, reason="Phonopy not present") -class TestGruneisenParameter(PymatgenTest): +class TestGruneisenParameter: def setUp(self) -> None: self.gruneisen_obj = get_gruneisenparameter( f"{TEST_DIR}/gruneisen_mesh_InP.yaml", diff --git a/tests/phonon/test_ir_spectra.py b/tests/phonon/test_ir_spectra.py index 7a7eb40f4ce..491bbc24e7d 100644 --- a/tests/phonon/test_ir_spectra.py +++ b/tests/phonon/test_ir_spectra.py @@ -2,10 +2,10 @@ from monty.serialization import loadfn -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR -class TestIRDielectricTensor(PymatgenTest): +class TestIRDielectricTensor: def setUp(self): self.ir_spectra = loadfn(f"{TEST_FILES_DIR}/phonon/dos/ir_spectra_mp-991652_DDB.json") diff --git a/tests/phonon/test_thermal_displacements.py b/tests/phonon/test_thermal_displacements.py index aeb26a4dffc..7f138a9012a 100644 --- a/tests/phonon/test_thermal_displacements.py +++ b/tests/phonon/test_thermal_displacements.py @@ -6,12 +6,12 @@ from pymatgen.core.structure import Structure from pymatgen.phonon.thermal_displacements import ThermalDisplacementMatrices -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR TEST_DIR = f"{TEST_FILES_DIR}/phonon/thermal_displacement_matrices" -class TestThermalDisplacement(PymatgenTest): +class TestThermalDisplacement: """Test data from J. George's matlab code https://github.com/JaGeo/MolecularToolbox.""" def setUp(self) -> None: diff --git a/tests/symmetry/test_analyzer.py b/tests/symmetry/test_analyzer.py index 7966c815ce9..759e6e64a27 100644 --- a/tests/symmetry/test_analyzer.py +++ b/tests/symmetry/test_analyzer.py @@ -24,7 +24,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/symmetry/analyzer" -class TestSpacegroupAnalyzer(PymatgenTest): +class TestSpacegroupAnalyzer: def setUp(self): self.structure = Structure.from_file(f"{VASP_IN_DIR}/POSCAR") self.sg = SpacegroupAnalyzer(self.structure, 0.001) @@ -537,7 +537,7 @@ def test_are_symmetrically_equivalent(self): ) -class TestPointGroupAnalyzer(PymatgenTest): +class TestPointGroupAnalyzer: def test_spherical(self): pg_analyzer = PointGroupAnalyzer(CH4) assert pg_analyzer.sch_symbol == "Td" diff --git a/tests/symmetry/test_kpath_hin.py b/tests/symmetry/test_kpath_hin.py index 2a7cce41712..1cadbc40f7e 100644 --- a/tests/symmetry/test_kpath_hin.py +++ b/tests/symmetry/test_kpath_hin.py @@ -6,12 +6,11 @@ from pymatgen.core.lattice import Lattice from pymatgen.core.structure import Structure from pymatgen.symmetry.kpath import KPathSeek -from pymatgen.util.testing import PymatgenTest pytest.importorskip("seekpath", reason="seekpath not installed") -class TestKPathSeek(PymatgenTest): +class TestKPathSeek: def test_kpath_generation(self): triclinic = [1, 2] monoclinic = range(3, 16) diff --git a/tests/symmetry/test_kpath_lm.py b/tests/symmetry/test_kpath_lm.py index 479ffecb65d..b203ddcae72 100644 --- a/tests/symmetry/test_kpath_lm.py +++ b/tests/symmetry/test_kpath_lm.py @@ -8,10 +8,10 @@ from pymatgen.core.structure import Structure from pymatgen.symmetry.analyzer import SpacegroupAnalyzer from pymatgen.symmetry.kpath import KPathLatimerMunro -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR -class TestKPathLatimerMunro(PymatgenTest): +class TestKPathLatimerMunro: def test_kpath_generation(self): triclinic = [1, 2] monoclinic = range(3, 16) diff --git a/tests/symmetry/test_kpath_sc.py b/tests/symmetry/test_kpath_sc.py index d88c97f79dd..72b1b4eb716 100644 --- a/tests/symmetry/test_kpath_sc.py +++ b/tests/symmetry/test_kpath_sc.py @@ -6,12 +6,12 @@ from pymatgen.core.lattice import Lattice from pymatgen.core.structure import Structure from pymatgen.symmetry.kpath import KPathSetyawanCurtarolo -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR TEST_DIR = f"{TEST_FILES_DIR}/symmetry/space_group_structs" -class TestBandStructureSC(PymatgenTest): +class TestBandStructureSC: def test_kpath_generation(self): triclinic = [1, 2] monoclinic = range(3, 16) diff --git a/tests/symmetry/test_kpaths.py b/tests/symmetry/test_kpaths.py index 87c8bd16480..46a0f51671b 100644 --- a/tests/symmetry/test_kpaths.py +++ b/tests/symmetry/test_kpaths.py @@ -7,7 +7,7 @@ from pymatgen.core.lattice import Lattice from pymatgen.core.structure import Structure from pymatgen.symmetry.bandstructure import HighSymmKpath -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR try: from seekpath import get_path @@ -17,7 +17,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/electronic_structure/bandstructure" -class TestHighSymmKpath(PymatgenTest): +class TestHighSymmKpath: @pytest.mark.skipif(get_path is None, reason="No seek path present.") def test_kpath_generation(self): triclinic = [1, 2] diff --git a/tests/symmetry/test_maggroups.py b/tests/symmetry/test_maggroups.py index 72f184d553f..3e664592d3b 100644 --- a/tests/symmetry/test_maggroups.py +++ b/tests/symmetry/test_maggroups.py @@ -6,7 +6,6 @@ from pymatgen.core.lattice import Lattice from pymatgen.symmetry.groups import SpaceGroup from pymatgen.symmetry.maggroups import MagneticSpaceGroup -from pymatgen.util.testing import PymatgenTest __author__ = "Matthew Horton" __copyright__ = "Copyright 2017, The Materials Project" @@ -17,7 +16,7 @@ __date__ = "Feb 2017" -class TestMagneticSpaceGroup(PymatgenTest): +class TestMagneticSpaceGroup: def setUp(self): self.msg_1 = MagneticSpaceGroup([70, 530]) self.msg_2 = MagneticSpaceGroup([62, 448]) diff --git a/tests/symmetry/test_site_symmetries.py b/tests/symmetry/test_site_symmetries.py index 1b33f3a11f0..3bdd7c5f7f9 100644 --- a/tests/symmetry/test_site_symmetries.py +++ b/tests/symmetry/test_site_symmetries.py @@ -6,7 +6,7 @@ from monty.json import MontyDecoder from pymatgen.symmetry import site_symmetries as ss -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR __author__ = "Handong Ling" __version__ = "0.1" @@ -18,7 +18,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/symmetry/site_symmetries" -class TestSiteSymmetries(PymatgenTest): +class TestSiteSymmetries: def setUp(self): with gzip.open(f"{TEST_DIR}/point_ops.json.gz", mode="rt") as file: self.point_ops = MontyDecoder().process_decoded(json.load(file)) diff --git a/tests/transformations/test_advanced_transformations.py b/tests/transformations/test_advanced_transformations.py index 2f73ace7cd3..479fbde5302 100644 --- a/tests/transformations/test_advanced_transformations.py +++ b/tests/transformations/test_advanced_transformations.py @@ -276,7 +276,7 @@ def test_as_dict(self): @pytest.mark.skipif(not enumlib_present, reason="enum_lib not present.") -class TestMagOrderingTransformation(PymatgenTest): +class TestMagOrderingTransformation: def setUp(self): lattice = Lattice.cubic(4.17) species = ["Ni", "O"] @@ -488,7 +488,7 @@ def test_advanced_usage(self): @pytest.mark.skipif(not enumlib_present, reason="enum_lib not present.") -class TestDopingTransformation(PymatgenTest): +class TestDopingTransformation: def test_apply_transformation(self): structure = PymatgenTest.get_structure("LiFePO4") spga = SpacegroupAnalyzer(structure, 0.1) @@ -551,7 +551,7 @@ def test_find_codopant(self): assert find_codopant(Species("Fe", 2), 3) == Species("In", 3) -class TestSlabTransformation(PymatgenTest): +class TestSlabTransformation: def test_apply_transformation(self): struct = self.get_structure("LiFePO4") trans = SlabTransformation([0, 0, 1], 10, 10, shift=0.25) @@ -570,7 +570,7 @@ def test_apply_transformation(self): assert_allclose(slab_from_gen.cart_coords, slab_from_trans.cart_coords) -class TestGrainBoundaryTransformation(PymatgenTest): +class TestGrainBoundaryTransformation: def test_apply_transformation(self): Al_bulk = Structure.from_spacegroup("Fm-3m", Lattice.cubic(2.8575585), ["Al"], [[0, 0, 0]]) gb_gen_params_s5 = { @@ -590,7 +590,7 @@ def test_apply_transformation(self): assert_allclose(gb_from_generator.cart_coords, gb_from_trans.cart_coords) -class TestDisorderedOrderedTransformation(PymatgenTest): +class TestDisorderedOrderedTransformation: def test_apply_transformation(self): # nonsensical example just for testing purposes struct = self.get_structure("BaNiO3") @@ -603,7 +603,7 @@ def test_apply_transformation(self): @pytest.mark.skipif(not mcsqs_cmd, reason="mcsqs not present.") -class TestSQSTransformation(PymatgenTest): +class TestSQSTransformation: def test_apply_transformation(self): pzt_structs = loadfn(f"{TEST_FILES_DIR}/io/atat/mcsqs/pzt-structs.json") trans = SQSTransformation(scaling=[2, 1, 1], search_time=0.01, instances=1, wd=0) @@ -649,7 +649,7 @@ def test_spin(self): @pytest.mark.skipif(ClusterSpace is None, reason="icet not installed.") -class TestSQSTransformationIcet(PymatgenTest): +class TestSQSTransformationIcet: stored_run: dict = loadfn(f"{TEST_FILES_DIR}/transformations/icet-sqs-fcc-Mg_75-Al_25-scaling_8.json.gz") scaling: int = 8 @@ -699,7 +699,7 @@ def test_monte_carlo(self): assert isinstance(sqs_output[0][key], val) -class TestCubicSupercellTransformation(PymatgenTest): +class TestCubicSupercellTransformation: def test_apply_transformation_cubic_supercell(self): structure = self.get_structure("TlBiSe2") min_atoms = 100 @@ -848,7 +848,7 @@ def test_apply_transformation_orthorhombic_supercell(self): assert transformed_cubic.lattice.angles == transformed_orthorhombic.lattice.angles -class TestAddAdsorbateTransformation(PymatgenTest): +class TestAddAdsorbateTransformation: def test_apply_transformation(self): co = Molecule(["C", "O"], [[0, 0, 0], [0, 0, 1.23]]) trans = AddAdsorbateTransformation(co) @@ -859,7 +859,7 @@ def test_apply_transformation(self): assert out.reduced_formula == "Pt4CO" -class TestSubstituteSurfaceSiteTransformation(PymatgenTest): +class TestSubstituteSurfaceSiteTransformation: def test_apply_transformation(self): trans = SubstituteSurfaceSiteTransformation("Au") pt = Structure(Lattice.cubic(5), ["Pt"], [[0, 0, 0]]) # fictitious @@ -870,7 +870,7 @@ def test_apply_transformation(self): @pytest.mark.skipif(not hiphive, reason="hiphive not present") -class TestMonteCarloRattleTransformation(PymatgenTest): +class TestMonteCarloRattleTransformation: def test_apply_transformation(self): struct = self.get_structure("Si") mcrt = MonteCarloRattleTransformation(0.01, 2, seed=1) diff --git a/tests/transformations/test_site_transformations.py b/tests/transformations/test_site_transformations.py index 0e97aceabc0..fc778b97257 100644 --- a/tests/transformations/test_site_transformations.py +++ b/tests/transformations/test_site_transformations.py @@ -17,14 +17,13 @@ ReplaceSiteSpeciesTransformation, TranslateSitesTransformation, ) -from pymatgen.util.testing import PymatgenTest enum_cmd = which("enum.x") or which("multienum.x") makestr_cmd = which("makestr.x") or which("makeStr.x") or which("makeStr.py") enumlib_present = enum_cmd and makestr_cmd -class TestTranslateSitesTransformation(PymatgenTest): +class TestTranslateSitesTransformation: def setUp(self): coords = [ [0, 0, 0], @@ -264,7 +263,7 @@ def test_str(self): ) -class TestAddSitePropertyTransformation(PymatgenTest): +class TestAddSitePropertyTransformation: def test_apply_transformation(self): struct = self.get_structure("Li2O2") sd = [[True, True, True] for _ in struct] @@ -279,7 +278,7 @@ def test_apply_transformation(self): assert_allclose(trans_set.site_properties[prop], manually_set.site_properties[prop]) -class TestRadialSiteDistortionTransformation(PymatgenTest): +class TestRadialSiteDistortionTransformation: def setUp(self): self.molecule = Molecule( species=["C", "H", "H", "H", "H", "H", "H", "H", "H", "H", "H", "H", "H"], diff --git a/tests/util/test_io.py b/tests/util/test_io.py index 09458240656..1c810ab98a3 100644 --- a/tests/util/test_io.py +++ b/tests/util/test_io.py @@ -1,10 +1,10 @@ from __future__ import annotations from pymatgen.util.io_utils import micro_pyawk -from pymatgen.util.testing import VASP_OUT_DIR, PymatgenTest +from pymatgen.util.testing import VASP_OUT_DIR -class TestFunc(PymatgenTest): +class TestFunc: def test_micro_pyawk(self): data = [] diff --git a/tests/util/test_plotting.py b/tests/util/test_plotting.py index ec68c960d88..e9771589e06 100644 --- a/tests/util/test_plotting.py +++ b/tests/util/test_plotting.py @@ -3,7 +3,6 @@ import matplotlib.pyplot as plt from pymatgen.util.plotting import periodic_table_heatmap, van_arkel_triangle -from pymatgen.util.testing import PymatgenTest try: import pymatviz @@ -12,7 +11,7 @@ pymatviz = None -class TestFunc(PymatgenTest): +class TestFunc: def test_plot_periodic_heatmap(self): random_data = {"Te": 0.11083, "Au": 0.75756, "Th": 1.24758, "Ni": -2.0354} fig = periodic_table_heatmap(random_data) diff --git a/tests/vis/test_plotters.py b/tests/vis/test_plotters.py index 87311cc4d66..7fc28013d07 100644 --- a/tests/vis/test_plotters.py +++ b/tests/vis/test_plotters.py @@ -8,14 +8,14 @@ from monty.json import MontyDecoder from pymatgen.analysis.xas.spectrum import XAS -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR from pymatgen.vis.plotters import SpectrumPlotter with open(f"{TEST_FILES_DIR}/analysis/spectrum_test/LiCoO2_k_xanes.json") as file: spect_data_dict = json.load(file, cls=MontyDecoder) -class TestSpectrumPlotter(PymatgenTest): +class TestSpectrumPlotter: def setUp(self): self.xanes = XAS.from_dict(spect_data_dict) From ab8bb0e7565c0bd04bd4c7fe0718af16ddee1bca Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Wed, 4 Dec 2024 22:07:23 +0800 Subject: [PATCH 05/31] migrate alchemy and command_line --- tests/alchemy/test_filters.py | 8 ++++---- tests/alchemy/test_materials.py | 6 +++--- tests/command_line/test_bader_caller.py | 8 ++------ tests/command_line/test_critic2_caller.py | 5 ++--- tests/command_line/test_enumlib_caller.py | 4 ++-- tests/command_line/test_gulp_caller.py | 17 ++++++++--------- tests/command_line/test_mcsqs_caller.py | 8 ++++---- tests/command_line/test_vampire_caller.py | 2 +- 8 files changed, 26 insertions(+), 32 deletions(-) diff --git a/tests/alchemy/test_filters.py b/tests/alchemy/test_filters.py index 8810ca30551..25a6ce1e9e6 100644 --- a/tests/alchemy/test_filters.py +++ b/tests/alchemy/test_filters.py @@ -14,7 +14,7 @@ from pymatgen.alchemy.transmuters import StandardTransmuter from pymatgen.analysis.structure_matcher import StructureMatcher from pymatgen.core import Lattice, Species, Structure -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest class TestContainsSpecieFilter: @@ -52,7 +52,7 @@ def test_as_from_dict(self): assert isinstance(ContainsSpecieFilter.from_dict(dct), ContainsSpecieFilter) -class TestSpecieProximityFilter: +class TestSpecieProximityFilter(MatSciTest): def test_filter(self): struct = self.get_structure("Li10GeP2S12") sf = SpecieProximityFilter({"Li": 1}) @@ -70,8 +70,8 @@ def test_as_from_dict(self): assert isinstance(SpecieProximityFilter.from_dict(dct), SpecieProximityFilter) -class TestRemoveDuplicatesFilter(TestCase): - def setUp(self): +class TestRemoveDuplicatesFilter: + def setup_method(self): with open(f"{TEST_FILES_DIR}/entries/TiO2_entries.json") as file: entries = json.load(file, cls=MontyDecoder) self._struct_list = [entry.structure for entry in entries] diff --git a/tests/alchemy/test_materials.py b/tests/alchemy/test_materials.py index 2569b7ec46c..73cd79161fd 100644 --- a/tests/alchemy/test_materials.py +++ b/tests/alchemy/test_materials.py @@ -16,14 +16,14 @@ SupercellTransformation, ) from pymatgen.util.provenance import StructureNL -from pymatgen.util.testing import FAKE_POTCAR_DIR, TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import FAKE_POTCAR_DIR, TEST_FILES_DIR, MatSciTest TEST_DIR = f"{TEST_FILES_DIR}/alchemy" class TestTransformedStructure: - def setUp(self): - structure = PymatgenTest.get_structure("LiFePO4") + def setup_method(self): + structure = MatSciTest.get_structure("LiFePO4") self.structure = structure trafos = [SubstitutionTransformation({"Li": "Na"})] self.trans = TransformedStructure(structure, trafos) diff --git a/tests/command_line/test_bader_caller.py b/tests/command_line/test_bader_caller.py index 3d0f73e58ed..41c01270e0a 100644 --- a/tests/command_line/test_bader_caller.py +++ b/tests/command_line/test_bader_caller.py @@ -1,6 +1,5 @@ from __future__ import annotations -import warnings from shutil import which import numpy as np @@ -10,16 +9,13 @@ from pytest import approx from pymatgen.command_line.bader_caller import BaderAnalysis, bader_analysis_from_path -from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR +from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR, MatSciTest TEST_DIR = f"{TEST_FILES_DIR}/command_line/bader" @pytest.mark.skipif(not which("bader"), reason="bader executable not present") -class TestBaderAnalysis: - def setUp(self): - warnings.catch_warnings() - +class TestBaderAnalysis(MatSciTest): def test_init(self): # test with reference file analysis = BaderAnalysis( diff --git a/tests/command_line/test_critic2_caller.py b/tests/command_line/test_critic2_caller.py index 430b052d4bf..55346936b92 100644 --- a/tests/command_line/test_critic2_caller.py +++ b/tests/command_line/test_critic2_caller.py @@ -1,7 +1,6 @@ from __future__ import annotations from shutil import which -from unittest import TestCase import pytest from pytest import approx @@ -75,8 +74,8 @@ def test_from_structure(self): assert "ERROR : load int.CHGCAR id chg_int zpsp Mo 6 S 6" in c2c._input_script -class TestCritic2Analysis(TestCase): - def setUp(self): +class TestCritic2Analysis: + def setup_method(self): stdout_file = f"{TEST_DIR}/MoS2_critic2_stdout.txt" stdout_file_new_format = f"{TEST_DIR}/MoS2_critic2_stdout_new_format.txt" with open(stdout_file) as file: diff --git a/tests/command_line/test_enumlib_caller.py b/tests/command_line/test_enumlib_caller.py index b55ff9c2fea..2e538207603 100644 --- a/tests/command_line/test_enumlib_caller.py +++ b/tests/command_line/test_enumlib_caller.py @@ -11,14 +11,14 @@ from pymatgen.symmetry.analyzer import SpacegroupAnalyzer from pymatgen.transformations.site_transformations import RemoveSitesTransformation from pymatgen.transformations.standard_transformations import SubstitutionTransformation -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest ENUM_CMD = which("enum.x") or which("multienum.x") MAKESTR_CMD = which("makestr.x") or which("makeStr.x") or which("makeStr.py") @pytest.mark.skipif(not (ENUM_CMD and MAKESTR_CMD), reason="enumlib not present.") -class TestEnumlibAdaptor: +class TestEnumlibAdaptor(MatSciTest): def test_init(self): struct = self.get_structure("LiFePO4") sub_trans = SubstitutionTransformation({"Li": {"Li": 0.5}}) diff --git a/tests/command_line/test_gulp_caller.py b/tests/command_line/test_gulp_caller.py index 18c3f05c268..4dc27857afa 100644 --- a/tests/command_line/test_gulp_caller.py +++ b/tests/command_line/test_gulp_caller.py @@ -9,7 +9,6 @@ import os import sys from shutil import which -from unittest import TestCase import numpy as np import pytest @@ -106,8 +105,8 @@ def test_decimal(self): caller.run(buckingham_input) -class TestGulpIO(TestCase): - def setUp(self): +class TestGulpIO: + def setup_method(self): self.structure = Structure.from_file(f"{VASP_IN_DIR}/POSCAR_Al12O18") self.gio = GulpIO() @@ -276,8 +275,8 @@ def test_tersoff_input(self): self.gio.tersoff_input(self.structure) -class TestGlobalFunctions(TestCase): - def setUp(self): +class TestGlobalFunctions: + def setup_method(self): mgo_latt = np.eye(3) * 4.212 mgo_specie = ["Mg", "O"] * 4 mgo_frac_cord = [ @@ -327,8 +326,8 @@ def test_get_energy_relax_structure_buckingham(self): assert site_len == len(self.mgo_uc) -class TestBuckinghamPotentialLewis(TestCase): - def setUp(self): +class TestBuckinghamPotentialLewis: + def setup_method(self): self.bpl = BuckinghamPotential("lewis") def test_existing_element(self): @@ -354,8 +353,8 @@ def test_spring(self): assert self.bpl.spring_dict["O"] != "" -class TestBuckinghamPotentialBush(TestCase): - def setUp(self): +class TestBuckinghamPotentialBush: + def setup_method(self): self.bpb = BuckinghamPotential("bush") def test_existing_element(self): diff --git a/tests/command_line/test_mcsqs_caller.py b/tests/command_line/test_mcsqs_caller.py index b214f42b262..04cc9c7c042 100644 --- a/tests/command_line/test_mcsqs_caller.py +++ b/tests/command_line/test_mcsqs_caller.py @@ -7,7 +7,7 @@ from pymatgen.command_line.mcsqs_caller import run_mcsqs from pymatgen.core.structure import Structure -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest __author__ = "Handong Ling, Rachel Woods-Robinson" __maintainer__ = "Handong Ling, Rachel Woods-Robinson" @@ -18,8 +18,8 @@ @pytest.mark.skipif(not (which("mcsqs") and which("str2cif")), reason="mcsqs executable not present") -class TestMcsqsCaller: - def setUp(self): +class TestMcsqsCaller(MatSciTest): + def setup_method(self): self.pzt_structs = loadfn(f"{TEST_DIR}/pzt-structs.json") self.pzt_structs2 = loadfn(f"{TEST_DIR}/pzt-structs-2.json") self.struct = self.get_structure("Pb2TiZrO6") @@ -103,5 +103,5 @@ def test_mcsqs_caller_runtime_error(self): struct.replace_species({"Ti": {"Ti": 0.5, "Zr": 0.5}, "Zr": {"Ti": 0.5, "Zr": 0.5}}) struct.replace_species({"Pb": {"Ti": 0.2, "Pb": 0.8}}) struct.replace_species({"O": {"F": 0.8, "O": 0.2}}) - with pytest.raises(RuntimeError, match="mcsqs exited before timeout reached"): + with pytest.raises(RuntimeError, match="mcsqs did not generate output files"): run_mcsqs(struct, {2: 6, 3: 4}, 10, 0.000001) diff --git a/tests/command_line/test_vampire_caller.py b/tests/command_line/test_vampire_caller.py index cc8fb7c254c..6021f65a366 100644 --- a/tests/command_line/test_vampire_caller.py +++ b/tests/command_line/test_vampire_caller.py @@ -16,7 +16,7 @@ @pytest.mark.skipif(not which("vampire-serial"), reason="vampire executable not present") class TestVampireCaller: @classmethod - def setUpClass(cls): + def setup_class(cls): cls.Mn3Al = pd.read_json(f"{TEST_DIR}/Mn3Al.json") cls.compounds = [cls.Mn3Al] From 9ed871dc033f149f6cbccf81755c438c0dbeebd0 Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Wed, 4 Dec 2024 22:47:21 +0800 Subject: [PATCH 06/31] deprecate pymatgen with matscitest --- src/pymatgen/util/testing/__init__.py | 127 +++++++++++++++++++++++++- 1 file changed, 125 insertions(+), 2 deletions(-) diff --git a/src/pymatgen/util/testing/__init__.py b/src/pymatgen/util/testing/__init__.py index acf83e32c93..af6b0c61667 100644 --- a/src/pymatgen/util/testing/__init__.py +++ b/src/pymatgen/util/testing/__init__.py @@ -35,8 +35,15 @@ FAKE_POTCAR_DIR = f"{VASP_IN_DIR}/fake_potcars" -class PymatgenTest(TestCase): - """Extends unittest.TestCase with several assert methods for array and str comparison.""" +class MatSciTest: + """TODO: name might need discussion. + + TODO: finish docstring + + TODO: reduce code duplicate + + TODO: add deprecation warning + """ # dict of lazily-loaded test structures (initialized to None) TEST_STRUCTURES: ClassVar[dict[str | Path, Structure | None]] = dict.fromkeys(STRUCTURES_DIR.glob("*")) @@ -149,3 +156,119 @@ def assert_msonable(self, obj: MSONable, test_is_subclass: bool = True) -> str: if not issubclass(type(round_trip), type(obj)): raise TypeError(f"{type(round_trip)} != {type(obj)}") return json_str + + +class PymatgenTest(TestCase): + """Extends unittest.TestCase with several assert methods for array and str comparison. + + Deprecated: please use `MatSciTest` instead (migrate from `unittest` to `pytest`). + """ + + # dict of lazily-loaded test structures (initialized to None) + TEST_STRUCTURES: ClassVar[dict[str | Path, Structure | None]] = dict.fromkeys(STRUCTURES_DIR.glob("*")) + + @pytest.fixture(autouse=True) # make all tests run a in a temporary directory accessible via self.tmp_path + def _tmp_dir(self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None: + # https://pytest.org/en/latest/how-to/unittest.html#using-autouse-fixtures-and-accessing-other-fixtures + monkeypatch.chdir(tmp_path) # change to pytest-provided temporary directory + self.tmp_path = tmp_path + + @classmethod + def get_structure(cls, name: str) -> Structure: + """ + Lazily load a structure from pymatgen/util/structures. + + Args: + name (str): Name of structure file. + + Returns: + Structure + """ + return MatSciTest.get_structure(name) + + @staticmethod + def assert_str_content_equal(actual, expected): + """Test if two strings are equal, ignoring things like trailing spaces, etc.""" + MatSciTest.assert_str_content_equal(actual, expected) + + def serialize_with_pickle(self, objects: Any, protocols: Sequence[int] | None = None, test_eq: bool = True): + """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. + + Args: + 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. + """ + # Build a list even when we receive a single object. + got_single_object = False + if not isinstance(objects, list | tuple): + got_single_object = True + objects = [objects] + + protocols = protocols or [pickle.HIGHEST_PROTOCOL] + + # This list will contain the objects deserialized with the different protocols. + objects_by_protocol, errors = [], [] + + for protocol in protocols: + # Serialize and deserialize the object. + tmpfile = self.tmp_path / f"tempfile_{protocol}.pkl" + + try: + with open(tmpfile, "wb") as file: + pickle.dump(objects, file, protocol=protocol) + except Exception as exc: + errors.append(f"pickle.dump with {protocol=} raised:\n{exc}") + continue + + try: + with open(tmpfile, "rb") as file: + unpickled_objs = pickle.load(file) # noqa: S301 + except Exception as exc: + errors.append(f"pickle.load with {protocol=} raised:\n{exc}") + continue + + # Test for equality + if test_eq: + for orig, unpickled in zip(objects, unpickled_objs, strict=True): + if orig != unpickled: + raise ValueError( + f"Unpickled and original objects are unequal for {protocol=}\n{orig=}\n{unpickled=}" + ) + + # Save the deserialized objects and test for equality. + objects_by_protocol.append(unpickled_objs) + + if errors: + raise ValueError("\n".join(errors)) + + # Return nested list so that client code can perform additional tests. + if got_single_object: + return [o[0] for o in objects_by_protocol] + return objects_by_protocol + + def assert_msonable(self, obj: MSONable, test_is_subclass: bool = True) -> str: + """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. + """ + if test_is_subclass and not isinstance(obj, MSONable): + raise TypeError("obj is not MSONable") + if obj.as_dict() != type(obj).from_dict(obj.as_dict()).as_dict(): + raise ValueError("obj could not be reconstructed accurately from its dict representation.") + json_str = json.dumps(obj.as_dict(), cls=MontyEncoder) + round_trip = json.loads(json_str, cls=MontyDecoder) + if not issubclass(type(round_trip), type(obj)): + raise TypeError(f"{type(round_trip)} != {type(obj)}") + return json_str From 26669830f2a10994cebea21252da4ddca8587cc0 Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Wed, 4 Dec 2024 22:51:00 +0800 Subject: [PATCH 07/31] migrate utils --- tests/util/test_coord.py | 6 ++---- tests/util/test_provenance.py | 5 ++--- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/tests/util/test_coord.py b/tests/util/test_coord.py index c97914e6319..b8c9b08aaba 100644 --- a/tests/util/test_coord.py +++ b/tests/util/test_coord.py @@ -1,7 +1,5 @@ from __future__ import annotations -from unittest import TestCase - import numpy as np import pytest from numpy.testing import assert_allclose, assert_array_equal @@ -250,8 +248,8 @@ def test_get_angle(self): assert coord.get_angle(v1, v2, units="radians") == approx(0.9553166181245092) -class TestSimplex(TestCase): - def setUp(self): +class TestSimplex: + def setup_method(self): coords = [[0, 0, 0], [0, 1, 0], [0, 0, 1], [1, 0, 0]] self.simplex = coord.Simplex(coords) diff --git a/tests/util/test_provenance.py b/tests/util/test_provenance.py index 7a276f8eeb8..c6c2d59bd72 100644 --- a/tests/util/test_provenance.py +++ b/tests/util/test_provenance.py @@ -3,7 +3,6 @@ from __future__ import annotations from datetime import datetime, timedelta, timezone -from unittest import TestCase import numpy as np import pytest @@ -20,8 +19,8 @@ __date__ = "2/14/13" -class TestStructureNL(TestCase): - def setUp(self): +class TestStructureNL: + def setup_method(self): # set up a Structure self.struct = Structure(np.eye(3, 3) * 3, ["Fe"], [[0, 0, 0]]) self.s2 = Structure(np.eye(3, 3) * 3, ["Al"], [[0, 0, 0]]) From 21123bd5df67f698f3cc0812c340be8616338b79 Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Wed, 4 Dec 2024 22:55:08 +0800 Subject: [PATCH 08/31] migrate optimization --- tests/optimization/test_linear_assignment.py | 8 +++----- tests/optimization/test_neighbors.py | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/optimization/test_linear_assignment.py b/tests/optimization/test_linear_assignment.py index 961a5032b6d..ce0f7dfdc4d 100644 --- a/tests/optimization/test_linear_assignment.py +++ b/tests/optimization/test_linear_assignment.py @@ -1,7 +1,5 @@ from __future__ import annotations -from unittest import TestCase - import numpy as np import pytest from pytest import approx @@ -9,8 +7,8 @@ from pymatgen.optimization.linear_assignment import LinearAssignment -class TestLinearAssignment(TestCase): - def test(self): +class TestLinearAssignment: + def test_case_one(self): w0 = np.array( [ [19, 95, 9, 43, 62, 90, 10, 77, 71, 27], @@ -102,7 +100,7 @@ def test_rectangular(self): with pytest.raises(ValueError, match="cost matrix must have at least as many columns as rows"): LinearAssignment(w0.T) - def another_test_case(self): + def test_case_two(self): w1 = np.array( [ [ diff --git a/tests/optimization/test_neighbors.py b/tests/optimization/test_neighbors.py index 5ddd14f638e..7f84787bb16 100644 --- a/tests/optimization/test_neighbors.py +++ b/tests/optimization/test_neighbors.py @@ -7,7 +7,7 @@ class TestNeighbors: - def setUp(self): + def setup_method(self): self.lattice = Lattice.cubic(10.0) self.cubic = self.lattice self.tetragonal = Lattice.tetragonal(10, 20) From 614f4f71647e1c7780928372343dab5f0f103812 Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Wed, 4 Dec 2024 23:02:21 +0800 Subject: [PATCH 09/31] migrate vis --- tests/vis/test_plotters.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/vis/test_plotters.py b/tests/vis/test_plotters.py index 7fc28013d07..9789d4ba4e5 100644 --- a/tests/vis/test_plotters.py +++ b/tests/vis/test_plotters.py @@ -8,15 +8,15 @@ from monty.json import MontyDecoder from pymatgen.analysis.xas.spectrum import XAS -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest from pymatgen.vis.plotters import SpectrumPlotter -with open(f"{TEST_FILES_DIR}/analysis/spectrum_test/LiCoO2_k_xanes.json") as file: +with open(f"{TEST_FILES_DIR}/analysis/spectrum_test/LiCoO2_k_xanes.json", encoding="utf-8") as file: spect_data_dict = json.load(file, cls=MontyDecoder) -class TestSpectrumPlotter: - def setUp(self): +class TestSpectrumPlotter(MatSciTest): + def setup_method(self): self.xanes = XAS.from_dict(spect_data_dict) def test_get_plot(self): From a2ea374b839de7cacc4b6172cdb5d598d3cdf4cc Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Wed, 4 Dec 2024 23:10:47 +0800 Subject: [PATCH 10/31] global replacement of setUp and TearDown, setupClass --- tests/alchemy/test_filters.py | 5 +-- .../test_coordination_geometry_finder.py | 2 +- .../test_read_write.py | 2 +- .../utils/test_coordination_geometry_utils.py | 2 +- tests/analysis/elasticity/test_elastic.py | 8 ++-- tests/analysis/elasticity/test_strain.py | 6 +-- tests/analysis/elasticity/test_stress.py | 2 +- .../ferroelectricity/test_polarization.py | 6 +-- .../interfaces/test_coherent_interface.py | 4 +- tests/analysis/interfaces/test_zsl.py | 2 +- tests/analysis/magnetism/test_analyzer.py | 2 +- tests/analysis/magnetism/test_heisenberg.py | 2 +- tests/analysis/magnetism/test_jahnteller.py | 2 +- .../test_dopant_predictor.py | 2 +- .../structure_prediction/test_substitutor.py | 2 +- tests/analysis/test_adsorption.py | 2 +- tests/analysis/test_bond_dissociation.py | 5 +-- tests/analysis/test_bond_valence.py | 2 +- tests/analysis/test_chempot_diagram.py | 2 +- tests/analysis/test_cost.py | 8 ++-- tests/analysis/test_dimensionality.py | 2 +- tests/analysis/test_eos.py | 2 +- tests/analysis/test_ewald.py | 8 ++-- tests/analysis/test_fragmenter.py | 2 +- tests/analysis/test_functional_groups.py | 5 +-- tests/analysis/test_graphs.py | 7 ++-- tests/analysis/test_interface_reactions.py | 6 +-- tests/analysis/test_local_env.py | 26 ++++++------ tests/analysis/test_molecule_matcher.py | 16 +++---- tests/analysis/test_phase_diagram.py | 16 +++---- tests/analysis/test_piezo.py | 2 +- tests/analysis/test_piezo_sensitivity.py | 2 +- tests/analysis/test_pourbaix_diagram.py | 6 +-- .../test_quasi_harmonic_debye_approx.py | 4 +- tests/analysis/test_quasirrho.py | 2 +- tests/analysis/test_reaction_calculator.py | 4 +- tests/analysis/test_structure_analyzer.py | 4 +- tests/analysis/test_structure_matcher.py | 2 +- tests/analysis/test_surface_analysis.py | 8 ++-- tests/analysis/test_wulff.py | 2 +- tests/analysis/xas/test_spectrum.py | 2 +- tests/apps/battery/test_analyzer.py | 2 +- tests/apps/battery/test_conversion_battery.py | 2 +- tests/apps/battery/test_insertion_battery.py | 2 +- tests/apps/battery/test_plotter.py | 2 +- tests/apps/borg/test_hive.py | 6 +-- tests/core/test_composition.py | 2 +- tests/core/test_interface.py | 6 +-- tests/core/test_ion.py | 2 +- tests/core/test_lattice.py | 2 +- tests/core/test_operations.py | 2 +- tests/core/test_periodic_table.py | 2 +- tests/core/test_sites.py | 4 +- tests/core/test_spectrum.py | 2 +- tests/core/test_structure.py | 8 ++-- tests/core/test_surface.py | 8 ++-- tests/core/test_tensors.py | 6 +-- tests/core/test_trajectory.py | 2 +- tests/core/test_xcfunc.py | 2 +- .../test_bandstructure.py | 8 ++-- tests/electronic_structure/test_boltztrap.py | 2 +- tests/electronic_structure/test_boltztrap2.py | 10 ++--- tests/electronic_structure/test_cohp.py | 10 ++--- tests/electronic_structure/test_dos.py | 10 ++--- tests/electronic_structure/test_plotter.py | 12 +++--- tests/entries/test_compatibility.py | 20 ++++----- tests/entries/test_computed_entries.py | 6 +-- tests/entries/test_correction_calculator.py | 2 +- tests/entries/test_entry_tools.py | 2 +- tests/entries/test_exp_entries.py | 2 +- tests/ext/test_matproj.py | 8 ++-- tests/io/abinit/test_inputs.py | 2 +- tests/io/abinit/test_netcdf.py | 2 +- tests/io/abinit/test_pseudos.py | 2 +- tests/io/cp2k/test_inputs.py | 2 +- tests/io/cp2k/test_outputs.py | 2 +- tests/io/feff/test_inputs.py | 4 +- tests/io/feff/test_sets.py | 2 +- tests/io/lammps/test_data.py | 8 ++-- tests/io/lammps/test_generators.py | 2 +- tests/io/lammps/test_inputs.py | 2 +- tests/io/lammps/test_outputs.py | 2 +- tests/io/lammps/test_utils.py | 4 +- tests/io/lobster/test_inputs.py | 2 +- tests/io/lobster/test_lobsterenv.py | 2 +- tests/io/lobster/test_outputs.py | 28 ++++++------- tests/io/test_babel.py | 2 +- tests/io/test_cif.py | 2 +- tests/io/test_core.py | 2 +- tests/io/test_cssr.py | 2 +- tests/io/test_fiesta.py | 4 +- tests/io/test_gaussian.py | 4 +- tests/io/test_lmto.py | 8 ++-- tests/io/test_nwchem.py | 4 +- tests/io/test_phonopy.py | 2 +- tests/io/test_pwscf.py | 2 +- tests/io/test_shengbte.py | 2 +- tests/io/test_wannier90.py | 2 +- tests/io/test_xcrysden.py | 2 +- tests/io/test_xr.py | 2 +- tests/io/test_xyz.py | 2 +- tests/io/test_zeopp.py | 14 +++---- tests/io/vasp/test_inputs.py | 8 ++-- tests/io/vasp/test_outputs.py | 8 ++-- tests/io/vasp/test_sets.py | 42 +++++++++---------- tests/phonon/test_bandstructure.py | 2 +- tests/phonon/test_dos.py | 4 +- tests/phonon/test_gruneisen.py | 4 +- tests/phonon/test_ir_spectra.py | 2 +- tests/phonon/test_plotter.py | 6 +-- tests/phonon/test_thermal_displacements.py | 2 +- tests/symmetry/test_analyzer.py | 4 +- tests/symmetry/test_maggroups.py | 2 +- tests/symmetry/test_settings.py | 2 +- tests/symmetry/test_site_symmetries.py | 2 +- .../test_advanced_transformations.py | 2 +- .../test_site_transformations.py | 21 +++++----- .../test_standard_transformations.py | 6 +-- 118 files changed, 289 insertions(+), 300 deletions(-) diff --git a/tests/alchemy/test_filters.py b/tests/alchemy/test_filters.py index 25a6ce1e9e6..53c1c517a0c 100644 --- a/tests/alchemy/test_filters.py +++ b/tests/alchemy/test_filters.py @@ -1,7 +1,6 @@ from __future__ import annotations import json -from unittest import TestCase from monty.json import MontyDecoder @@ -89,8 +88,8 @@ def test_as_from_dict(self): assert isinstance(RemoveDuplicatesFilter().from_dict(dct), RemoveDuplicatesFilter) -class TestRemoveExistingFilter(TestCase): - def setUp(self): +class TestRemoveExistingFilter: + def setup_method(self): with open(f"{TEST_FILES_DIR}/entries/TiO2_entries.json") as file: entries = json.load(file, cls=MontyDecoder) self._struct_list = [entry.structure for entry in entries] diff --git a/tests/analysis/chemenv/coordination_environments/test_coordination_geometry_finder.py b/tests/analysis/chemenv/coordination_environments/test_coordination_geometry_finder.py index f780d439cf7..8e8b470b753 100644 --- a/tests/analysis/chemenv/coordination_environments/test_coordination_geometry_finder.py +++ b/tests/analysis/chemenv/coordination_environments/test_coordination_geometry_finder.py @@ -27,7 +27,7 @@ class TestCoordinationGeometryFinder: - def setUp(self): + def setup_method(self): self.lgf = LocalGeometryFinder() self.lgf.setup_parameters( centering_type="standard", diff --git a/tests/analysis/chemenv/coordination_environments/test_read_write.py b/tests/analysis/chemenv/coordination_environments/test_read_write.py index c120b333953..cca5a8f19b0 100644 --- a/tests/analysis/chemenv/coordination_environments/test_read_write.py +++ b/tests/analysis/chemenv/coordination_environments/test_read_write.py @@ -32,7 +32,7 @@ class TestReadWriteChemenv: @classmethod - def setUpClass(cls): + def setup_class(cls): cls.lgf = LocalGeometryFinder() cls.lgf.setup_parameters(centering_type="standard") diff --git a/tests/analysis/chemenv/utils/test_coordination_geometry_utils.py b/tests/analysis/chemenv/utils/test_coordination_geometry_utils.py index 2439885c09d..7772e46384a 100644 --- a/tests/analysis/chemenv/utils/test_coordination_geometry_utils.py +++ b/tests/analysis/chemenv/utils/test_coordination_geometry_utils.py @@ -12,7 +12,7 @@ class TestPlanesUtils: - def setUp(self): + def setup_method(self): # Test of plane 4x + 2y - 4z + 3 = 0 (used in most test cases) self.expected_coefficients = np.array([4, 2, -4, 3], float) self.p1 = np.array([0, 0, 0.75]) diff --git a/tests/analysis/elasticity/test_elastic.py b/tests/analysis/elasticity/test_elastic.py index 7c6c39b11d0..b654c62f073 100644 --- a/tests/analysis/elasticity/test_elastic.py +++ b/tests/analysis/elasticity/test_elastic.py @@ -33,7 +33,7 @@ class TestElasticTensor: - def setUp(self): + def setup_method(self): self.voigt_1 = [ [59.33, 28.08, 28.08, 0, 0, 0], [28.08, 59.31, 28.07, 0, 0, 0], @@ -264,7 +264,7 @@ def test_energy_density(self): class TestElasticTensorExpansion: - def setUp(self): + def setup_method(self): with open(f"{TEST_DIR}/test_toec_data.json") as file: self.data_dict = json.load(file) self.strains = [Strain(sm) for sm in self.data_dict["strains"]] @@ -365,7 +365,7 @@ def test_get_yield_stress(self): class TestNthOrderElasticTensor: - def setUp(self): + def setup_method(self): with open(f"{TEST_DIR}/test_toec_data.json") as file: self.data_dict = json.load(file) self.strains = [Strain(sm) for sm in self.data_dict["strains"]] @@ -404,7 +404,7 @@ def test_energy_density(self): class TestDiffFit: """Test various functions related to diff fitting.""" - def setUp(self): + def setup_method(self): with open(f"{TEST_DIR}/test_toec_data.json") as file: self.data_dict = json.load(file) self.strains = [Strain(sm) for sm in self.data_dict["strains"]] diff --git a/tests/analysis/elasticity/test_strain.py b/tests/analysis/elasticity/test_strain.py index 53c33a5192a..e7198cdd231 100644 --- a/tests/analysis/elasticity/test_strain.py +++ b/tests/analysis/elasticity/test_strain.py @@ -10,7 +10,7 @@ class TestDeformation: - def setUp(self): + def setup_method(self): self.norm_defo = Deformation.from_index_amount((0, 0), 0.02) self.ind_defo = Deformation.from_index_amount((0, 1), 0.02) self.non_ind_defo = Deformation([[1, 0.02, 0.02], [0, 1, 0], [0, 0, 1]]) @@ -81,7 +81,7 @@ def test_apply_to_structure(self): class TestStrain: - def setUp(self): + def setup_method(self): self.norm_str = Strain.from_deformation([[1.02, 0, 0], [0, 1, 0], [0, 0, 1]]) self.ind_str = Strain.from_deformation([[1, 0.02, 0], [0, 1, 0], [0, 0, 1]]) @@ -142,7 +142,7 @@ def test_convert_strain_to_deformation(self): class TestDeformedStructureSet: - def setUp(self): + def setup_method(self): self.structure = self.get_structure("Sn") self.default_dss = DeformedStructureSet(self.structure) diff --git a/tests/analysis/elasticity/test_stress.py b/tests/analysis/elasticity/test_stress.py index 58e0bf1507c..5b0225ceef1 100644 --- a/tests/analysis/elasticity/test_stress.py +++ b/tests/analysis/elasticity/test_stress.py @@ -10,7 +10,7 @@ class TestStress: - def setUp(self): + def setup_method(self): self.rand_stress = Stress(np.random.default_rng().standard_normal((3, 3))) self.symm_stress = Stress([[0.51, 2.29, 2.42], [2.29, 5.14, 5.07], [2.42, 5.07, 5.33]]) self.non_symm = Stress([[0.1, 0.2, 0.3], [0.4, 0.5, 0.6], [0.2, 0.5, 0.5]]) diff --git a/tests/analysis/ferroelectricity/test_polarization.py b/tests/analysis/ferroelectricity/test_polarization.py index 71bb13d45e3..cfe17418561 100644 --- a/tests/analysis/ferroelectricity/test_polarization.py +++ b/tests/analysis/ferroelectricity/test_polarization.py @@ -39,7 +39,7 @@ class TestUtils: - def setUp(self): + def setup_method(self): self.potcar = Potcar.from_file(f"{TEST_DIR}/POTCAR") self.zval_dict = {"Ba": 10, "Ti": 10, "O": 6} self.ions = ions @@ -55,7 +55,7 @@ def test_get_total_ionic_dipole(self): class TestPolarization: - def setUp(self): + def setup_method(self): self.p_ions = ions self.p_ions_outcar = np.array( [ @@ -259,7 +259,7 @@ def test_smoothness(self): class TestEnergyTrend: - def setUp(self): + def setup_method(self): self.energies = [ -7.97738049, -7.988621176, diff --git a/tests/analysis/interfaces/test_coherent_interface.py b/tests/analysis/interfaces/test_coherent_interface.py index 2e6bc1ba1bc..3abfb7a6ebd 100644 --- a/tests/analysis/interfaces/test_coherent_interface.py +++ b/tests/analysis/interfaces/test_coherent_interface.py @@ -18,7 +18,7 @@ class TestInterfaceBuilder: @classmethod - def setUpClass(cls): + def setup_class(cls): si_struct = cls.get_structure("Si") sio2_struct = cls.get_structure("SiO2") cls.si_conventional = SpacegroupAnalyzer(si_struct).get_conventional_standard_structure() @@ -51,7 +51,7 @@ def test_coherent_interface_builder(self): class TestCoherentInterfaceBuilder(TestCase): - def setUp(self): + def setup_method(self): # build substrate & film structure basis = [[0, 0, 0], [0.25, 0.25, 0.25]] self.substrate = Structure(Lattice.cubic(a=5.431), ["Si", "Si"], basis) diff --git a/tests/analysis/interfaces/test_zsl.py b/tests/analysis/interfaces/test_zsl.py index cc7c8657403..2f187ff9522 100644 --- a/tests/analysis/interfaces/test_zsl.py +++ b/tests/analysis/interfaces/test_zsl.py @@ -23,7 +23,7 @@ class TestZSLGen: - def setUp(self): + def setup_method(self): # Film VO2 self.film = SpacegroupAnalyzer(self.get_structure("VO2"), symprec=0.1).get_conventional_standard_structure() diff --git a/tests/analysis/magnetism/test_analyzer.py b/tests/analysis/magnetism/test_analyzer.py index 3286409d05f..e71dfadaa6d 100644 --- a/tests/analysis/magnetism/test_analyzer.py +++ b/tests/analysis/magnetism/test_analyzer.py @@ -25,7 +25,7 @@ class TestCollinearMagneticStructureAnalyzer(TestCase): - def setUp(self): + def setup_method(self): self.Fe = Structure.from_file(f"{TEST_FILES_DIR}/cif/Fe.cif", primitive=True) self.LiFePO4 = Structure.from_file(f"{TEST_FILES_DIR}/cif/LiFePO4.cif", primitive=True) diff --git a/tests/analysis/magnetism/test_heisenberg.py b/tests/analysis/magnetism/test_heisenberg.py index 248bb559227..fa46f8b91b6 100644 --- a/tests/analysis/magnetism/test_heisenberg.py +++ b/tests/analysis/magnetism/test_heisenberg.py @@ -13,7 +13,7 @@ class TestHeisenbergMapper(TestCase): @classmethod - def setUpClass(cls): + def setup_class(cls): cls.df = pd.read_json(f"{TEST_DIR}/mag_orderings_test_cases.json") # Good tests diff --git a/tests/analysis/magnetism/test_jahnteller.py b/tests/analysis/magnetism/test_jahnteller.py index ac3555cce47..f1938dbafe5 100644 --- a/tests/analysis/magnetism/test_jahnteller.py +++ b/tests/analysis/magnetism/test_jahnteller.py @@ -11,7 +11,7 @@ class TestJahnTeller(TestCase): - def setUp(self): + def setup_method(self): self.jt = JahnTellerAnalyzer() def test_jahn_teller_species_analysis(self): diff --git a/tests/analysis/structure_prediction/test_dopant_predictor.py b/tests/analysis/structure_prediction/test_dopant_predictor.py index f19d032624d..a88e424a9c6 100644 --- a/tests/analysis/structure_prediction/test_dopant_predictor.py +++ b/tests/analysis/structure_prediction/test_dopant_predictor.py @@ -13,7 +13,7 @@ class TestDopantPrediction(TestCase): - def setUp(self): + def setup_method(self): self.tin_dioxide = Structure( [3.24, 0, 0, 0, 4.83, 0, 0, 0, 4.84], ["O", "O", "O", "O", "Sn", "Sn"], diff --git a/tests/analysis/structure_prediction/test_substitutor.py b/tests/analysis/structure_prediction/test_substitutor.py index be05f0bc60d..e82117651a4 100644 --- a/tests/analysis/structure_prediction/test_substitutor.py +++ b/tests/analysis/structure_prediction/test_substitutor.py @@ -21,7 +21,7 @@ def get_table(): class TestSubstitutor: - def setUp(self): + def setup_method(self): self.substitutor = Substitutor(threshold=1e-3, lambda_table=get_table(), alpha=-5.0) def test_substitutor(self): diff --git a/tests/analysis/test_adsorption.py b/tests/analysis/test_adsorption.py index 6a9dd3b070d..87cb73594cb 100644 --- a/tests/analysis/test_adsorption.py +++ b/tests/analysis/test_adsorption.py @@ -11,7 +11,7 @@ class TestAdsorbateSiteFinder: - def setUp(self): + def setup_method(self): self.structure = Structure.from_spacegroup("Fm-3m", Lattice.cubic(3.5), ["Ni"], [[0, 0, 0]]) lattice = Lattice.cubic(3.010) frac_coords = [ diff --git a/tests/analysis/test_bond_dissociation.py b/tests/analysis/test_bond_dissociation.py index 01cb71aaea6..9ac3a059a8a 100644 --- a/tests/analysis/test_bond_dissociation.py +++ b/tests/analysis/test_bond_dissociation.py @@ -1,7 +1,6 @@ from __future__ import annotations import platform -from unittest import TestCase import pytest from monty.serialization import loadfn @@ -12,8 +11,8 @@ TEST_DIR = f"{TEST_FILES_DIR}/analysis/bond_dissociation" -class TestBondDissociation(TestCase): - def setUp(self): +class TestBondDissociation: + def setup_method(self): pytest.importorskip("openbabel") self.PC_65_principle = loadfn(f"{TEST_DIR}/PC_65_principle.json") self.PC_65_principle["initial_molecule"] = self.PC_65_principle["initial_molecule"].as_dict() diff --git a/tests/analysis/test_bond_valence.py b/tests/analysis/test_bond_valence.py index 06c0fef3dc3..0be83e3b34e 100644 --- a/tests/analysis/test_bond_valence.py +++ b/tests/analysis/test_bond_valence.py @@ -11,7 +11,7 @@ class TestBVAnalyzer: - def setUp(self): + def setup_method(self): self.analyzer = BVAnalyzer() def test_get_valences(self): diff --git a/tests/analysis/test_chempot_diagram.py b/tests/analysis/test_chempot_diagram.py index 192e4aaf9de..1c9a7f0db64 100644 --- a/tests/analysis/test_chempot_diagram.py +++ b/tests/analysis/test_chempot_diagram.py @@ -18,7 +18,7 @@ class TestChemicalPotentialDiagram: - def setUp(self): + def setup_method(self): self.entries = EntrySet.from_csv(f"{TEST_DIR}/pd_entries_test.csv") self.cpd_ternary, self.cpd_ternary_formal = ( ChemicalPotentialDiagram(entries=self.entries, default_min_limit=-25, formal_chempots=formal) diff --git a/tests/analysis/test_cost.py b/tests/analysis/test_cost.py index c20bed2fd54..074a98cd9c7 100644 --- a/tests/analysis/test_cost.py +++ b/tests/analysis/test_cost.py @@ -1,7 +1,5 @@ from __future__ import annotations -from unittest import TestCase - from pytest import approx from pymatgen.analysis.cost import CostAnalyzer, CostDBCSV, CostDBElements @@ -10,8 +8,8 @@ TEST_DIR = f"{TEST_FILES_DIR}/analysis/cost" -class TestCostAnalyzer(TestCase): - def setUp(self): +class TestCostAnalyzer: + def setup_method(self): self.ca1 = CostAnalyzer(CostDBCSV(f"{TEST_DIR}/costdb_1.csv")) self.ca2 = CostAnalyzer(CostDBCSV(f"{TEST_DIR}/costdb_2.csv")) @@ -31,7 +29,7 @@ def test_sanity(self): assert self.ca1.get_cost_per_kg("Ag") == self.ca2.get_cost_per_kg("Ag") -class TestCostDB(TestCase): +class TestCostDB: def test_sanity(self): ca = CostAnalyzer(CostDBElements()) assert ca.get_cost_per_kg("PtO") > ca.get_cost_per_kg("MgO") diff --git a/tests/analysis/test_dimensionality.py b/tests/analysis/test_dimensionality.py index 0f1139e7072..6b5357e3134 100644 --- a/tests/analysis/test_dimensionality.py +++ b/tests/analysis/test_dimensionality.py @@ -19,7 +19,7 @@ class TestLarsenDimensionality: - def setUp(self): + def setup_method(self): cnn = CrystalNN() self.lifepo = cnn.get_bonded_structure(self.get_structure("LiFePO4")) self.graphite = cnn.get_bonded_structure(self.get_structure("Graphite")) diff --git a/tests/analysis/test_eos.py b/tests/analysis/test_eos.py index da507c32035..ddcc8bae77d 100644 --- a/tests/analysis/test_eos.py +++ b/tests/analysis/test_eos.py @@ -8,7 +8,7 @@ class TestEOS: - def setUp(self): + def setup_method(self): # Si data from Cormac self.volumes = [ 25.987454833, diff --git a/tests/analysis/test_ewald.py b/tests/analysis/test_ewald.py index 285152bb8fd..6e5ea7e5a0b 100644 --- a/tests/analysis/test_ewald.py +++ b/tests/analysis/test_ewald.py @@ -1,7 +1,5 @@ from __future__ import annotations -from unittest import TestCase - import numpy as np import pytest from pytest import approx @@ -11,8 +9,8 @@ from pymatgen.util.testing import VASP_IN_DIR -class TestEwaldSummation(TestCase): - def setUp(self): +class TestEwaldSummation: + def setup_method(self): filepath = f"{VASP_IN_DIR}/POSCAR" self.original_struct = Structure.from_file(filepath) self.struct = self.original_struct.copy() @@ -80,7 +78,7 @@ def test_as_dict(self): assert ham.as_dict() == EwaldSummation.from_dict(dct).as_dict() -class TestEwaldMinimizer(TestCase): +class TestEwaldMinimizer: def test_init(self): matrix = np.array( [ diff --git a/tests/analysis/test_fragmenter.py b/tests/analysis/test_fragmenter.py index c1efc2e69d6..d038babfc6d 100644 --- a/tests/analysis/test_fragmenter.py +++ b/tests/analysis/test_fragmenter.py @@ -19,7 +19,7 @@ class TestFragmentMolecule: @classmethod - def setUpClass(cls): + def setup_class(cls): cls.pc = Molecule.from_file(f"{TEST_DIR}/PC.xyz") cls.ec = Molecule.from_file(f"{TEST_DIR}/EC.xyz") cls.pos_pc = Molecule.from_file(f"{TEST_DIR}/PC.xyz") diff --git a/tests/analysis/test_functional_groups.py b/tests/analysis/test_functional_groups.py index a5fcb316e38..5b04e8290c2 100644 --- a/tests/analysis/test_functional_groups.py +++ b/tests/analysis/test_functional_groups.py @@ -1,7 +1,6 @@ from __future__ import annotations import platform -from unittest import TestCase import pytest @@ -25,8 +24,8 @@ __credit__ = "Peiyuan Yu" -class TestFunctionalGroupExtractor(TestCase): - def setUp(self): +class TestFunctionalGroupExtractor: + def setup_method(self): self.file = f"{TEST_DIR}/func_group_test.mol" self.mol = Molecule.from_file(self.file) self.strategy = OpenBabelNN() diff --git a/tests/analysis/test_graphs.py b/tests/analysis/test_graphs.py index 9e0c9f9f83c..476db66968b 100644 --- a/tests/analysis/test_graphs.py +++ b/tests/analysis/test_graphs.py @@ -4,7 +4,6 @@ import re from glob import glob from shutil import which -from unittest import TestCase import networkx as nx import networkx.algorithms.isomorphism as iso @@ -47,7 +46,7 @@ class TestStructureGraph: - def setUp(self): + def setup_method(self): # trivial example, simple square lattice for testing structure = Structure(Lattice.tetragonal(5, 50), ["H"], [[0, 0, 0]]) self.square_sg = StructureGraph.from_empty_graph(structure, edge_weight_name="", edge_weight_units="") @@ -504,8 +503,8 @@ def test_sort(self): assert list(sg.graph.edges)[-2:] == [(1, 3, 0), (1, 2, 0)] -class TestMoleculeGraph(TestCase): - def setUp(self): +class TestMoleculeGraph: + def setup_method(self): cyclohexene_xyz = f"{TEST_DIR}/cyclohexene.xyz" cyclohexene = Molecule.from_file(cyclohexene_xyz) self.cyclohexene = MoleculeGraph.from_empty_graph( diff --git a/tests/analysis/test_interface_reactions.py b/tests/analysis/test_interface_reactions.py index a402fd34420..3f9e5939da2 100644 --- a/tests/analysis/test_interface_reactions.py +++ b/tests/analysis/test_interface_reactions.py @@ -1,7 +1,5 @@ from __future__ import annotations -from unittest import TestCase - import numpy as np import pytest from matplotlib.figure import Figure as MplFigure @@ -17,8 +15,8 @@ from pymatgen.entries.computed_entries import ComputedEntry -class TestInterfaceReaction(TestCase): - def setUp(self): +class TestInterfaceReaction: + def setup_method(self): self.entries = [ ComputedEntry(Composition("Li"), 0), ComputedEntry(Composition("Mn"), 0), diff --git a/tests/analysis/test_local_env.py b/tests/analysis/test_local_env.py index a6214fe1311..925f7da98cc 100644 --- a/tests/analysis/test_local_env.py +++ b/tests/analysis/test_local_env.py @@ -55,7 +55,7 @@ def test_opt_params(): class TestValenceIonicRadiusEvaluator: - def setUp(self): + def setup_method(self): """Setup MgO rocksalt structure for testing Vacancy.""" mgo_latt = np.eye(3) * 4.212 mgo_specie = ["Mg"] * 4 + ["O"] * 4 @@ -90,7 +90,7 @@ def test_radii_ionic_structure(self): class TestVoronoiNN: - def setUp(self): + def setup_method(self): self.struct = self.get_structure("LiFePO4") self.nn = VoronoiNN(targets=[Element("O")]) self.s_sic = self.get_structure("Si") @@ -261,7 +261,7 @@ def test_filtered(self): class TestJmolNN: - def setUp(self): + def setup_method(self): self.jmol = JmolNN() self.jmol_update = JmolNN(el_radius_updates={"Li": 1}) @@ -302,7 +302,7 @@ def test_get_nn(self): class TestOpenBabelNN: - def setUp(self): + def setup_method(self): pytest.importorskip("openbabel") self.benzene = Molecule.from_file(f"{TEST_DIR}/../benzene.xyz") self.acetylene = Molecule.from_file(f"{TEST_FILES_DIR}/io/xyz/acetylene.xyz") @@ -334,7 +334,7 @@ def test_nn_length(self): class TestCovalentBondNN: - def setUp(self): + def setup_method(self): self.benzene = Molecule.from_file(f"{TEST_DIR}/../benzene.xyz") self.acetylene = Molecule.from_file(f"{TEST_FILES_DIR}/io/xyz/acetylene.xyz") @@ -373,7 +373,7 @@ def test_bonded_structure(self): class TestMiniDistNN: - def setUp(self): + def setup_method(self): self.diamond = Structure( Lattice([[2.189, 0, 1.264], [0.73, 2.064, 1.264], [0, 0, 2.528]]), ["C0+", "C0+"], @@ -486,7 +486,7 @@ def test_get_local_order_params(self): class TestMotifIdentification: - def setUp(self): + def setup_method(self): self.silicon = Structure( Lattice.cubic(5.47), ["Si", "Si", "Si", "Si", "Si", "Si", "Si", "Si"], @@ -584,7 +584,7 @@ def test_get_neighbors_of_site_with_index(self): class TestNearNeighbor: - def setUp(self): + def setup_method(self): self.diamond = Structure( Lattice([[2.189, 0, 1.264], [0.73, 2.064, 1.264], [0, 0, 2.528]]), ["C0+", "C0+"], @@ -618,7 +618,7 @@ def test_on_disorder_options(self): class TestLocalStructOrderParams: - def setUp(self): + def setup_method(self): self.single_bond = Structure( Lattice.cubic(10), ["H", "H", "H"], @@ -1183,7 +1183,7 @@ def test_get_order_parameters(self): class TestCrystalNN: - def setUp(self): + def setup_method(self): self.lifepo4 = self.get_structure("LiFePO4") self.lifepo4.add_oxidation_state_by_guess() self.he_bcc = self.get_structure("He_BCC") @@ -1330,7 +1330,7 @@ def test_get_bonded_structure(self): class TestCutOffDictNN: - def setUp(self): + def setup_method(self): self.diamond = Structure( Lattice([[2.189, 0, 1.264], [0.73, 2.064, 1.264], [0, 0, 2.528]]), ["C", "C"], @@ -1356,7 +1356,7 @@ def test_from_preset(self): @pytest.mark.skipif(not which("critic2"), reason="critic2 executable not present") class TestCritic2NN: - def setUp(self): + def setup_method(self): self.diamond = Structure( Lattice([[2.189, 0, 1.264], [0.73, 2.064, 1.264], [0, 0, 2.528]]), ["C", "C"], @@ -1370,7 +1370,7 @@ def test_cn(self): class TestMetalEdgeExtender: - def setUp(self): + def setup_method(self): self.LiEC = Molecule.from_file(f"{TEST_DIR}/LiEC.xyz") self.phsh = Molecule.from_file(f"{TEST_DIR}/phsh.xyz") self.phsh_graph = MoleculeGraph.from_edges( diff --git a/tests/analysis/test_molecule_matcher.py b/tests/analysis/test_molecule_matcher.py index 36a5db2c4c0..aaffbe0a7b3 100644 --- a/tests/analysis/test_molecule_matcher.py +++ b/tests/analysis/test_molecule_matcher.py @@ -558,7 +558,7 @@ def test_fit(self): class TestKabschMatcherSi(TestCase): @classmethod - def setUpClass(cls): + def setup_class(cls): cls.mol1 = Molecule.from_file(f"{TEST_DIR}/Si_cluster.xyz") cls.mol_matcher = KabschMatcher(cls.mol1) @@ -595,7 +595,7 @@ def test_permuted_atoms_order(self): class TestBruteForceOrderMatcherSi(TestCase): @classmethod - def setUpClass(cls): + def setup_class(cls): cls.mol1 = Molecule.from_file(f"{TEST_DIR}/Si_cluster.xyz") cls.mol_matcher = BruteForceOrderMatcher(cls.mol1) @@ -616,7 +616,7 @@ def test_random_match(self): class TestHungarianOrderMatcherSi(TestCase): @classmethod - def setUpClass(cls): + def setup_class(cls): cls.mol1 = Molecule.from_file(f"{TEST_DIR}/Si_cluster.xyz") cls.mol_matcher = HungarianOrderMatcher(cls.mol1) @@ -655,7 +655,7 @@ def test_random_match(self): class TestGeneticOrderMatcherSi(TestCase): @classmethod - def setUpClass(cls): + def setup_class(cls): cls.mol1 = Molecule.from_file(f"{TEST_DIR}/Si_cluster.xyz") cls.mol_matcher = GeneticOrderMatcher(cls.mol1, threshold=0.3) @@ -692,7 +692,7 @@ def test_random_match(self): class TestKabschMatcherSi2O(TestCase): @classmethod - def setUpClass(cls): + def setup_class(cls): cls.mol1 = Molecule.from_file(f"{TEST_DIR}/Si2O_cluster.xyz") cls.mol_matcher = KabschMatcher(cls.mol1) @@ -727,7 +727,7 @@ def test_permuted_atoms_order(self): class TestBruteForceOrderMatcherSi2O(TestCase): @classmethod - def setUpClass(cls): + def setup_class(cls): cls.mol1 = Molecule.from_file(f"{TEST_DIR}/Si2O_cluster.xyz") cls.mol_matcher = BruteForceOrderMatcher(cls.mol1) @@ -759,7 +759,7 @@ def test_random_match(self): class TestHungarianOrderMatcherSi2O(TestCase): @classmethod - def setUpClass(cls): + def setup_class(cls): cls.mol1 = Molecule.from_file(f"{TEST_DIR}/Si2O_cluster.xyz") cls.mol_matcher = HungarianOrderMatcher(cls.mol1) @@ -791,7 +791,7 @@ def test_random_match(self): class TestGeneticOrderMatcherSi2O(TestCase): @classmethod - def setUpClass(cls): + def setup_class(cls): cls.mol1 = Molecule.from_file(f"{TEST_DIR}/Si2O_cluster.xyz") cls.mol_matcher = GeneticOrderMatcher(cls.mol1, threshold=0.3) diff --git a/tests/analysis/test_phase_diagram.py b/tests/analysis/test_phase_diagram.py index b534aba8ddc..f7162862aaf 100644 --- a/tests/analysis/test_phase_diagram.py +++ b/tests/analysis/test_phase_diagram.py @@ -38,7 +38,7 @@ class TestPDEntry(TestCase): - def setUp(self): + def setup_method(self): comp = Composition("LiFeO2") self.entry = PDEntry(comp, 53, name="mp-757614") self.gp_entry = GrandPotPDEntry(self.entry, {Element("O"): 1.5}) @@ -114,7 +114,7 @@ def test_read_csv(self): class TestTransformedPDEntry(TestCase): - def setUp(self): + def setup_method(self): comp = Composition("LiFeO2") entry = PDEntry(comp, 53) @@ -180,7 +180,7 @@ def test_normalize(self): class TestPhaseDiagram: - def setUp(self): + def setup_method(self): self.entries = EntrySet.from_csv(f"{TEST_DIR}/pd_entries_test.csv") self.pd = PhaseDiagram(self.entries) @@ -668,7 +668,7 @@ def test_val_err_on_no_entries(self): class TestGrandPotentialPhaseDiagram(TestCase): - def setUp(self): + def setup_method(self): self.entries = EntrySet.from_csv(f"{TEST_DIR}/pd_entries_test.csv") self.pd = GrandPotentialPhaseDiagram(self.entries, {Element("O"): -5}) self.pd6 = GrandPotentialPhaseDiagram(self.entries, {Element("O"): -6}) @@ -704,7 +704,7 @@ def test_str(self): class TestCompoundPhaseDiagram(TestCase): - def setUp(self): + def setup_method(self): self.entries = EntrySet.from_csv(f"{TEST_DIR}/pd_entries_test.csv") self.pd = CompoundPhaseDiagram(self.entries, [Composition("Li2O"), Composition("Fe2O3")]) @@ -742,7 +742,7 @@ def test_num2str(self): class TestPatchedPhaseDiagram(TestCase): - def setUp(self): + def setup_method(self): self.entries = EntrySet.from_csv(f"{TEST_DIR}/phase_diagram/reaction_entries_test.csv") # NOTE add He to test for correct behavior despite no patches involving He self.no_patch_entry = he_entry = PDEntry("He", -1.23) @@ -892,7 +892,7 @@ def test_remove_redundant_spaces(self): class TestReactionDiagram(TestCase): - def setUp(self): + def setup_method(self): self.entries = list(EntrySet.from_csv(f"{TEST_DIR}/phase_diagram/reaction_entries_test.csv").entries) for entry in self.entries: if entry.reduced_formula == "VPO5": @@ -932,7 +932,7 @@ def test_formula(self): class TestPDPlotter(TestCase): - def setUp(self): + def setup_method(self): entries = list(EntrySet.from_csv(f"{TEST_DIR}/pd_entries_test.csv")) elemental_entries = [entry for entry in entries if entry.elements == [Element("Li")]] diff --git a/tests/analysis/test_piezo.py b/tests/analysis/test_piezo.py index 0621591b44c..c03dd3f3f49 100644 --- a/tests/analysis/test_piezo.py +++ b/tests/analysis/test_piezo.py @@ -17,7 +17,7 @@ class TestPiezo: - def setUp(self): + def setup_method(self): self.piezo_struct = self.get_structure("BaNiO3") self.voigt_matrix = np.array( [ diff --git a/tests/analysis/test_piezo_sensitivity.py b/tests/analysis/test_piezo_sensitivity.py index b14e90e0250..7c9ced77fb6 100644 --- a/tests/analysis/test_piezo_sensitivity.py +++ b/tests/analysis/test_piezo_sensitivity.py @@ -35,7 +35,7 @@ class TestPiezoSensitivity: - def setUp(self): + def setup_method(self): self.piezo_struct = self.get_structure("Pb2TiZrO6") self.IST = np.load(f"{TEST_DIR}/pztist.npy", allow_pickle=True) self.BEC = np.load(f"{TEST_DIR}/pztborn.npy", allow_pickle=True) diff --git a/tests/analysis/test_pourbaix_diagram.py b/tests/analysis/test_pourbaix_diagram.py index 98f2dacc9cc..65ab81aa569 100644 --- a/tests/analysis/test_pourbaix_diagram.py +++ b/tests/analysis/test_pourbaix_diagram.py @@ -20,7 +20,7 @@ class TestPourbaixEntry: """Test all functions using a fictitious entry""" - def setUp(self): + def setup_method(self): # comp = Composition("Mn2O3") self.sol_entry = ComputedEntry("Mn2O3", 49) ion = Ion.from_formula("MnO4-") @@ -99,7 +99,7 @@ def test_get_elt_fraction(self): class TestPourbaixDiagram(TestCase): @classmethod - def setUpClass(cls): + def setup_class(cls): cls.test_data = loadfn(f"{TEST_DIR}/pourbaix_test_data.json") cls.pbx = PourbaixDiagram(cls.test_data["Zn"], filter_solids=True) cls.pbx_no_filter = PourbaixDiagram(cls.test_data["Zn"], filter_solids=False) @@ -294,7 +294,7 @@ def test_serialization(self): class TestPourbaixPlotter(TestCase): - def setUp(self): + def setup_method(self): self.test_data = loadfn(f"{TEST_DIR}/pourbaix_test_data.json") self.pd = PourbaixDiagram(self.test_data["Zn"]) self.plotter = PourbaixPlotter(self.pd) diff --git a/tests/analysis/test_quasi_harmonic_debye_approx.py b/tests/analysis/test_quasi_harmonic_debye_approx.py index 6c0c5816d2d..52c4cfc7aba 100644 --- a/tests/analysis/test_quasi_harmonic_debye_approx.py +++ b/tests/analysis/test_quasi_harmonic_debye_approx.py @@ -13,7 +13,7 @@ class TestQuasiHarmonicDebyeApprox(TestCase): - def setUp(self): + def setup_method(self): struct = Structure.from_dict( { "lattice": { @@ -138,7 +138,7 @@ def test_vibrational_free_energy(self): class TestAnharmonicQuasiHarmonicDebyeApprox(TestCase): - def setUp(self): + def setup_method(self): struct = Structure.from_str( """FCC Al 1.0 diff --git a/tests/analysis/test_quasirrho.py b/tests/analysis/test_quasirrho.py index 63cd0015ad4..110382f263a 100644 --- a/tests/analysis/test_quasirrho.py +++ b/tests/analysis/test_quasirrho.py @@ -15,7 +15,7 @@ class TestQuasiRRHO(TestCase): """Test class for QuasiRRHO""" - def setUp(self): + def setup_method(self): self.gout = GaussianOutput(f"{TEST_DIR}/quasirrho_gaufreq.log") self.linear_gout = GaussianOutput(f"{TEST_DIR}/co2.log.gz") self.qout = QCOutput(f"{TEST_DIR}/Frequency_no_equal.qout") diff --git a/tests/analysis/test_reaction_calculator.py b/tests/analysis/test_reaction_calculator.py index 82fc1e03bea..b4f6e4ceb1c 100644 --- a/tests/analysis/test_reaction_calculator.py +++ b/tests/analysis/test_reaction_calculator.py @@ -288,7 +288,7 @@ def test_underdetermined_reactants(self): class TestBalancedReaction(TestCase): - def setUp(self) -> None: + def setup_method(self) -> None: rct = {"K2SO4": 3, "Na2S": 1, "Li": 24} prod = {"KNaS": 2, "K2S": 2, "Li2O": 12} self.rxn = BalancedReaction(rct, prod) @@ -335,7 +335,7 @@ def test_hash(self): class TestComputedReaction(TestCase): - def setUp(self): + def setup_method(self): dct = [ { "correction": 0, diff --git a/tests/analysis/test_structure_analyzer.py b/tests/analysis/test_structure_analyzer.py index 1b01946b217..79c9846b1f3 100644 --- a/tests/analysis/test_structure_analyzer.py +++ b/tests/analysis/test_structure_analyzer.py @@ -22,7 +22,7 @@ class TestVoronoiAnalyzer: - def setUp(self): + def setup_method(self): self.structs = Xdatcar(f"{VASP_OUT_DIR}/XDATCAR.MD").structures self.struct = self.structs[1] self.va = VoronoiAnalyzer(cutoff=4) @@ -41,7 +41,7 @@ def test_analyze(self): class TestRelaxationAnalyzer(TestCase): - def setUp(self): + def setup_method(self): s1 = Structure.from_file(f"{VASP_IN_DIR}/POSCAR_Li2O") s2 = Structure.from_file(f"{VASP_OUT_DIR}/CONTCAR_Li2O") self.analyzer = RelaxationAnalyzer(s1, s2) diff --git a/tests/analysis/test_structure_matcher.py b/tests/analysis/test_structure_matcher.py index c47da09efab..f39e4808f6b 100644 --- a/tests/analysis/test_structure_matcher.py +++ b/tests/analysis/test_structure_matcher.py @@ -23,7 +23,7 @@ class TestStructureMatcher: - def setUp(self): + def setup_method(self): with open(f"{TEST_FILES_DIR}/entries/TiO2_entries.json") as file: entries = json.load(file, cls=MontyDecoder) self.struct_list = [ent.structure for ent in entries] diff --git a/tests/analysis/test_surface_analysis.py b/tests/analysis/test_surface_analysis.py index cc0aaa6f0e3..b4afe4d8295 100644 --- a/tests/analysis/test_surface_analysis.py +++ b/tests/analysis/test_surface_analysis.py @@ -23,7 +23,7 @@ class TestSlabEntry: - def setUp(self): + def setup_method(self): with open(f"{TEST_DIR}/ucell_entries.txt") as file: ucell_entries = json.loads(file.read()) self.ucell_entries = ucell_entries @@ -119,7 +119,7 @@ def test_cleaned_up_slab(self): class TestSurfaceEnergyPlotter: - def setUp(self): + def setup_method(self): entry_dict = get_entry_dict(f"{TEST_DIR}/Cu_entries.txt") self.Cu_entry_dict = entry_dict with open(f"{TEST_DIR}/ucell_entries.txt") as file: @@ -293,7 +293,7 @@ def test_surface_chempot_range_map(self): class TestWorkFunctionAnalyzer: - def setUp(self): + def setup_method(self): self.kwargs = { "poscar_filename": f"{TEST_DIR}/CONTCAR.relax1.gz", "locpot_filename": f"{TEST_DIR}/LOCPOT.gz", @@ -310,7 +310,7 @@ def test_is_converged(self): class TestNanoscaleStability: - def setUp(self): + def setup_method(self): # Load all entries La_hcp_entry_dict = get_entry_dict(f"{TEST_DIR}/La_hcp_entries.txt") La_fcc_entry_dict = get_entry_dict(f"{TEST_DIR}/La_fcc_entries.txt") diff --git a/tests/analysis/test_wulff.py b/tests/analysis/test_wulff.py index 527a24fb4a7..b08f0b4bc39 100644 --- a/tests/analysis/test_wulff.py +++ b/tests/analysis/test_wulff.py @@ -22,7 +22,7 @@ class TestWulffShape: - def setUp(self): + def setup_method(self): with open(f"{TEST_DIR}/surface_samples.json") as data_file: surface_properties = json.load(data_file) diff --git a/tests/analysis/xas/test_spectrum.py b/tests/analysis/xas/test_spectrum.py index 16553553e84..bcc0c1d4933 100644 --- a/tests/analysis/xas/test_spectrum.py +++ b/tests/analysis/xas/test_spectrum.py @@ -29,7 +29,7 @@ class TestXAS: - def setUp(self): + def setup_method(self): self.k_xanes = XAS.from_dict(k_xanes_dict) self.k_exafs = XAS.from_dict(k_exafs_dict) self.l2_xanes = XAS.from_dict(l2_xanes_dict) diff --git a/tests/apps/battery/test_analyzer.py b/tests/apps/battery/test_analyzer.py index 5e3fa0cd9f0..2fc5a1375d5 100644 --- a/tests/apps/battery/test_analyzer.py +++ b/tests/apps/battery/test_analyzer.py @@ -19,7 +19,7 @@ def load_from_internal(self, name, oxidations, working_ion="Li"): struct.add_oxidation_state_by_element(oxidations) return BatteryAnalyzer(struct, working_ion) - def setUp(self): + def setup_method(self): self.li_fe_p_o4 = self.load_from_internal("LiFePO4", {"Li": 1, "Fe": 2, "P": 5, "O": -2}) self.na_fe_p_o4 = self.load_from_internal("NaFePO4", {"Na": 1, "Fe": 2, "P": 5, "O": -2}, working_ion="Na") self.la2coo4f = self.load_from_internal("La2CoO4F", {"La": 3, "Co": 3, "O": -2, "F": -1}, working_ion="F") diff --git a/tests/apps/battery/test_conversion_battery.py b/tests/apps/battery/test_conversion_battery.py index d2d1b817ff8..2fc7efb10c9 100644 --- a/tests/apps/battery/test_conversion_battery.py +++ b/tests/apps/battery/test_conversion_battery.py @@ -14,7 +14,7 @@ class TestConversionElectrode(TestCase): - def setUp(self): + def setup_method(self): self.formulas = ["LiCoO2", "FeF3", "MnO2"] self.conversion_electrodes = {} for formula in self.formulas: diff --git a/tests/apps/battery/test_insertion_battery.py b/tests/apps/battery/test_insertion_battery.py index 4c6b9caa951..d7028b835e9 100644 --- a/tests/apps/battery/test_insertion_battery.py +++ b/tests/apps/battery/test_insertion_battery.py @@ -14,7 +14,7 @@ class TestInsertionElectrode(TestCase): - def setUp(self): + def setup_method(self): self.entry_Li = ComputedEntry("Li", -1.90753119) self.entry_Ca = ComputedEntry("Ca", -1.99689568) diff --git a/tests/apps/battery/test_plotter.py b/tests/apps/battery/test_plotter.py index 8b93b20f8bf..a0f3daad6a0 100644 --- a/tests/apps/battery/test_plotter.py +++ b/tests/apps/battery/test_plotter.py @@ -16,7 +16,7 @@ class TestVoltageProfilePlotter(TestCase): - def setUp(self): + def setup_method(self): entry_Li = ComputedEntry("Li", -1.90753119) with open(f"{TEST_DIR}/LiTiO2_batt.json") as file: diff --git a/tests/apps/borg/test_hive.py b/tests/apps/borg/test_hive.py index 6005eaf3f2c..3e47e6e8e33 100644 --- a/tests/apps/borg/test_hive.py +++ b/tests/apps/borg/test_hive.py @@ -21,7 +21,7 @@ class TestVaspToComputedEntryDrone(TestCase): - def setUp(self): + def setup_method(self): self.drone = VaspToComputedEntryDrone(data=["efermi"]) self.structure_drone = VaspToComputedEntryDrone(inc_structure=True) @@ -54,7 +54,7 @@ def test_as_from_dict(self): class TestSimpleVaspToComputedEntryDrone(TestCase): - def setUp(self): + def setup_method(self): self.drone = SimpleVaspToComputedEntryDrone() self.structure_drone = SimpleVaspToComputedEntryDrone(inc_structure=True) @@ -74,7 +74,7 @@ def test_as_from_dict(self): class TestGaussianToComputedEntryDrone(TestCase): - def setUp(self): + def setup_method(self): self.drone = GaussianToComputedEntryDrone(data=["corrections"]) self.structure_drone = GaussianToComputedEntryDrone(inc_structure=True) diff --git a/tests/core/test_composition.py b/tests/core/test_composition.py index dba2a3c67f6..cf055a82706 100644 --- a/tests/core/test_composition.py +++ b/tests/core/test_composition.py @@ -16,7 +16,7 @@ class TestComposition: - def setUp(self): + def setup_method(self): self.comps = [ Composition("Li3Fe2(PO4)3"), Composition("Li3Fe(PO4)O"), diff --git a/tests/core/test_interface.py b/tests/core/test_interface.py index 598759a40a8..2cb1f2cff0e 100644 --- a/tests/core/test_interface.py +++ b/tests/core/test_interface.py @@ -14,7 +14,7 @@ class TestGrainBoundary: - def setUp(self): + def setup_method(self): self.Cu_conv = Structure.from_file(f"{TEST_DIR}/Cu_mp-30_conventional_standard.cif") GB_Cu_conv = GrainBoundaryGenerator(self.Cu_conv) self.Cu_GB1 = GB_Cu_conv.gb_from_parameters( @@ -106,7 +106,7 @@ def test_as_dict_and_from_dict(self): class TestGrainBoundaryGenerator: @classmethod - def setUpClass(cls): + def setup_class(cls): cls.Cu_prim = Structure.from_file(f"{TEST_DIR}/Cu_mp-30_primitive.cif") cls.GB_Cu_prim = GrainBoundaryGenerator(cls.Cu_prim) cls.Cu_conv = Structure.from_file(f"{TEST_DIR}/Cu_mp-30_conventional_standard.cif") @@ -332,7 +332,7 @@ def test_get_rotation_angle_from_sigma(self): class TestInterface: - def setUp(self): + def setup_method(self): self.interface: Interface = self.get_structure("Si_SiO2_Interface") def test_basic_props(self): diff --git a/tests/core/test_ion.py b/tests/core/test_ion.py index a547bfe9005..2d2291c6da9 100644 --- a/tests/core/test_ion.py +++ b/tests/core/test_ion.py @@ -10,7 +10,7 @@ class TestIon(TestCase): - def setUp(self): + def setup_method(self): self.comp = [] self.comp.append(Ion.from_formula("Li+")) self.comp.append(Ion.from_formula("MnO4-")) diff --git a/tests/core/test_lattice.py b/tests/core/test_lattice.py index 3bd111545ce..a1c39a7fcdb 100644 --- a/tests/core/test_lattice.py +++ b/tests/core/test_lattice.py @@ -12,7 +12,7 @@ class TestLattice: - def setUp(self): + def setup_method(self): self.lattice = Lattice.cubic(10.0) self.cubic = self.lattice self.tetragonal = Lattice.tetragonal(10, 20) diff --git a/tests/core/test_operations.py b/tests/core/test_operations.py index 6ece9b27eda..c0a6b74a2f2 100644 --- a/tests/core/test_operations.py +++ b/tests/core/test_operations.py @@ -8,7 +8,7 @@ class TestSymmOp: - def setUp(self): + def setup_method(self): self.op = SymmOp.from_axis_angle_and_translation([0, 0, 1], 30, translation_vec=[0, 0, 1]) def test_properties(self): diff --git a/tests/core/test_periodic_table.py b/tests/core/test_periodic_table.py index b02a017ec45..62d7e32b446 100644 --- a/tests/core/test_periodic_table.py +++ b/tests/core/test_periodic_table.py @@ -392,7 +392,7 @@ def test_isotope(self): class TestSpecies: - def setUp(self): + def setup_method(self): self.specie1 = Species.from_str("Fe2+") self.specie2 = Species("Fe", 3) self.specie3 = Species("Fe", 2) diff --git a/tests/core/test_sites.py b/tests/core/test_sites.py index 2e619bf40aa..c93552229da 100644 --- a/tests/core/test_sites.py +++ b/tests/core/test_sites.py @@ -12,7 +12,7 @@ class TestSite: - def setUp(self): + def setup_method(self): self.ordered_site = Site("Fe", [0.25, 0.35, 0.45]) self.disordered_site = Site({"Fe": 0.5, "Mn": 0.5}, [0.25, 0.35, 0.45]) self.propertied_site = Site("Fe2+", [0.25, 0.35, 0.45], {"magmom": 5.1, "charge": 4.2}) @@ -79,7 +79,7 @@ def test_setters(self): class TestPeriodicSite: - def setUp(self): + def setup_method(self): self.lattice = Lattice.cubic(10.0) self.si = Element("Si") self.site = PeriodicSite("Fe", [0.25, 0.35, 0.45], self.lattice) diff --git a/tests/core/test_spectrum.py b/tests/core/test_spectrum.py index f14b1506107..e38883a7371 100644 --- a/tests/core/test_spectrum.py +++ b/tests/core/test_spectrum.py @@ -9,7 +9,7 @@ class TestSpectrum: - def setUp(self): + def setup_method(self): rng = np.random.default_rng() self.spec1 = Spectrum(np.arange(0, 10, 0.1), rng.standard_normal(100)) self.spec2 = Spectrum(np.arange(0, 10, 0.1), rng.standard_normal(100)) diff --git a/tests/core/test_structure.py b/tests/core/test_structure.py index 4b909a71411..83995882799 100644 --- a/tests/core/test_structure.py +++ b/tests/core/test_structure.py @@ -64,7 +64,7 @@ def test_neighbor_labels(self): class TestIStructure: - def setUp(self): + def setup_method(self): coords = [[0, 0, 0], [0.75, 0.5, 0.75]] self.lattice = Lattice( [ @@ -966,7 +966,7 @@ def test_sites_setter(self): class TestStructure: - def setUp(self): + def setup_method(self): coords = [[0, 0, 0], [0.75, 0.5, 0.75]] lattice = Lattice( [ @@ -2033,7 +2033,7 @@ def test_struct_with_isotope(self): class TestIMolecule: - def setUp(self): + def setup_method(self): coords = [ [0, 0, 0], [0, 0, 1.089], @@ -2328,7 +2328,7 @@ def test_to_file_alias(self): class TestMolecule: - def setUp(self): + def setup_method(self): coords = [ [0, 0, 0], [0, 0, 1.089000], diff --git a/tests/core/test_surface.py b/tests/core/test_surface.py index ccc09906bbe..bc540df589e 100644 --- a/tests/core/test_surface.py +++ b/tests/core/test_surface.py @@ -30,7 +30,7 @@ class TestSlab: - def setUp(self): + def setup_method(self): zno1 = Structure.from_file(f"{TEST_FILES_DIR}/surfaces/ZnO-wz.cif", primitive=False) zno55 = SlabGenerator(zno1, [1, 0, 0], 5, 5, lll_reduce=False, center_slab=False).get_slab() @@ -347,7 +347,7 @@ def test_as_dict(self): class TestSlabGenerator: - def setUp(self): + def setup_method(self): lattice = Lattice.cubic(3.010) frac_coords = [ [0.00000, 0.00000, 0.00000], @@ -635,7 +635,7 @@ def test_bonds_broken(self): class ReconstructionGeneratorTests: - def setUp(self): + def setup_method(self): lattice = Lattice.cubic(3.51) species = ["Ni"] coords = [[0, 0, 0]] @@ -724,7 +724,7 @@ def test_previous_reconstructions(self): class TestMillerIndexFinder: - def setUp(self): + def setup_method(self): self.cscl = Structure.from_spacegroup("Pm-3m", Lattice.cubic(4.2), ["Cs", "Cl"], [[0, 0, 0], [0.5, 0.5, 0.5]]) self.Fe = Structure.from_spacegroup("Im-3m", Lattice.cubic(2.82), ["Fe"], [[0, 0, 0]]) mg_lattice = Lattice.from_parameters(3.2, 3.2, 5.13, 90, 90, 120) diff --git a/tests/core/test_tensors.py b/tests/core/test_tensors.py index 1c78a299ed9..b5aab2feef8 100644 --- a/tests/core/test_tensors.py +++ b/tests/core/test_tensors.py @@ -15,7 +15,7 @@ class TestTensor: - def setUp(self): + def setup_method(self): rng = np.random.default_rng() self.vec = Tensor([1.0, 0.0, 0.0]) @@ -380,7 +380,7 @@ def test_round(self): class TestTensorCollection: - def setUp(self): + def setup_method(self): self.seq_tc = list(np.arange(4 * 3**3).reshape((4, 3, 3, 3))) self.seq_tc = TensorCollection(self.seq_tc) self.rand_tc = TensorCollection(list(np.random.default_rng().random((4, 3, 3)))) @@ -473,7 +473,7 @@ def test_serialization(self): class TestSquareTensor: - def setUp(self): + def setup_method(self): self.rand_sqtensor = SquareTensor(np.random.default_rng().standard_normal((3, 3))) self.symm_sqtensor = SquareTensor([[0.1, 0.3, 0.4], [0.3, 0.5, 0.2], [0.4, 0.2, 0.6]]) self.non_invertible = SquareTensor([[0.1, 0, 0], [0.2, 0, 0], [0, 0, 0]]) diff --git a/tests/core/test_trajectory.py b/tests/core/test_trajectory.py index 2cb7baae889..7d26af7236e 100644 --- a/tests/core/test_trajectory.py +++ b/tests/core/test_trajectory.py @@ -18,7 +18,7 @@ class TestTrajectory: - def setUp(self): + def setup_method(self): xdatcar = Xdatcar(f"{VASP_OUT_DIR}/XDATCAR_traj") self.traj = Trajectory.from_file(f"{VASP_OUT_DIR}/XDATCAR_traj") self.structures = xdatcar.structures diff --git a/tests/core/test_xcfunc.py b/tests/core/test_xcfunc.py index fd4c15e0d76..3ce0314049c 100644 --- a/tests/core/test_xcfunc.py +++ b/tests/core/test_xcfunc.py @@ -6,7 +6,7 @@ class TestLibxcFunc: - def setUp(self) -> None: + def setup_method(self) -> None: self.ixc_11 = XcFunc.from_abinit_ixc(11) def test_aliases(self): diff --git a/tests/electronic_structure/test_bandstructure.py b/tests/electronic_structure/test_bandstructure.py index 2cacd115159..cb1cdb0f338 100644 --- a/tests/electronic_structure/test_bandstructure.py +++ b/tests/electronic_structure/test_bandstructure.py @@ -26,7 +26,7 @@ class TestKpoint(TestCase): - def setUp(self): + def setup_method(self): self.lattice = Lattice.cubic(10.0) self.kpoint = Kpoint([0.1, 0.4, -0.5], self.lattice, label="X") @@ -69,7 +69,7 @@ def test_from_dict(self): class TestBandStructureSymmLine: - def setUp(self): + def setup_method(self): self.bs: BandStructureSymmLine = loadfn(f"{TEST_DIR}/Cu2O_361_bandstructure.json") self.bs2: BandStructureSymmLine = loadfn(f"{TEST_DIR}/CaO_2605_bandstructure.json") self.bs_spin: BandStructureSymmLine = loadfn(f"{TEST_DIR}/NiO_19009_bandstructure.json") @@ -259,7 +259,7 @@ def test_apply_scissor_spin_polarized(self): class TestReconstructBandStructure: - def setUp(self): + def setup_method(self): self.bs_cu: BandStructureSymmLine = loadfn(f"{TEST_DIR}/Cu_30_bandstructure.json") self.bs_cu2: BandStructureSymmLine = loadfn(f"{TEST_DIR}/Cu_30_bandstructure.json") @@ -278,7 +278,7 @@ def test_vasprun_bs(self): class TestLobsterBandStructureSymmLine: - def setUp(self): + def setup_method(self): with open( f"{TEST_FILES_DIR}/electronic_structure/cohp/Fatband_SiO2/Test_p/lobster_band_structure_spin.json", ) as file: diff --git a/tests/electronic_structure/test_boltztrap.py b/tests/electronic_structure/test_boltztrap.py index a5983320da9..dbc28997df1 100644 --- a/tests/electronic_structure/test_boltztrap.py +++ b/tests/electronic_structure/test_boltztrap.py @@ -26,7 +26,7 @@ @pytest.mark.skipif(not which("x_trans"), reason="No x_trans.") class TestBoltztrapAnalyzer(TestCase): @classmethod - def setUpClass(cls): + def setup_class(cls): cls.bz = BoltztrapAnalyzer.from_files(f"{TEST_DIR}/transp/") cls.bz_bands = BoltztrapAnalyzer.from_files(f"{TEST_DIR}/bands/") cls.bz_up = BoltztrapAnalyzer.from_files(f"{TEST_DIR}/dos_up/", dos_spin=1) diff --git a/tests/electronic_structure/test_boltztrap2.py b/tests/electronic_structure/test_boltztrap2.py index cdb75a24532..0fb225b0379 100644 --- a/tests/electronic_structure/test_boltztrap2.py +++ b/tests/electronic_structure/test_boltztrap2.py @@ -42,7 +42,7 @@ class TestVasprunBSLoader(TestCase): - def setUp(self): + def setup_method(self): self.loader = VasprunBSLoader(VASP_RUN) assert self.loader is not None self.loader = VasprunBSLoader(BAND_STRUCT, VASP_RUN.final_structure) @@ -81,7 +81,7 @@ def test_get_volume(self): class TestBandstructureLoader(TestCase): - def setUp(self): + def setup_method(self): self.loader = BandstructureLoader(BAND_STRUCT, VASP_RUN.structures[-1]) assert self.loader is not None @@ -108,7 +108,7 @@ def test_set_upper_lower_bands(self): class TestVasprunLoader(TestCase): - def setUp(self): + def setup_method(self): self.loader = VasprunLoader(VASP_RUN) assert self.loader.proj.shape == (120, 20, 2, 9) assert self.loader is not None @@ -127,7 +127,7 @@ def test_from_file(self): class TestBztInterpolator(TestCase): - def setUp(self): + def setup_method(self): with ScratchDir("."): shutil.copy(BZT_INTERP_FN, ".") @@ -206,7 +206,7 @@ def test_tot_proj_dos(self): class TestBztTransportProperties(TestCase): - def setUp(self): + def setup_method(self): with ScratchDir("."): shutil.copy(BZT_TRANSP_FN, ".") diff --git a/tests/electronic_structure/test_cohp.py b/tests/electronic_structure/test_cohp.py index 1da7a34b55f..270abd76692 100644 --- a/tests/electronic_structure/test_cohp.py +++ b/tests/electronic_structure/test_cohp.py @@ -21,7 +21,7 @@ class TestCohp(TestCase): - def setUp(self): + def setup_method(self): with open(f"{TEST_DIR}/cohp.json") as file: self.cohp = Cohp.from_dict(json.load(file)) self.cohp_only = Cohp(self.cohp.efermi, self.cohp.energies, self.cohp.cohp) @@ -91,7 +91,7 @@ def test_antibnd_states_below_efermi(self): class TestIcohpValue(TestCase): - def setUp(self): + def setup_method(self): # without spin polarization label = "1" atom1 = "K1" @@ -169,7 +169,7 @@ def test_str(self): class TestCombinedIcohp(TestCase): - def setUp(self): + def setup_method(self): # without spin polarization: are_coops = are_cobis = is_spin_polarized = False list_atom2 = ["K2", "K2", "K2", "K2", "K2", "K2"] @@ -798,7 +798,7 @@ def test_extremum_icohpvalue(self): class TestCompleteCohp: - def setUp(self): + def setup_method(self): filepath = f"{TEST_DIR}/complete_cohp_lobster.json" with open(filepath) as file: self.cohp_lobster_dict = CompleteCohp.from_dict(json.load(file)) @@ -1263,7 +1263,7 @@ def test_orbital_resolved_cohp_summed_spin_channels(self): class TestMethod(TestCase): - def setUp(self): + def setup_method(self): filepath = f"{TEST_DIR}/COHPCAR.lobster.gz" structure = f"{TEST_DIR}/POSCAR" self.cohp_lobster = CompleteCohp.from_file("lobster", filename=filepath, structure_file=structure) diff --git a/tests/electronic_structure/test_dos.py b/tests/electronic_structure/test_dos.py index 229738439c0..31c0f4edf6d 100644 --- a/tests/electronic_structure/test_dos.py +++ b/tests/electronic_structure/test_dos.py @@ -20,7 +20,7 @@ class TestDos(TestCase): - def setUp(self): + def setup_method(self): with open(f"{TEST_DIR}/complete_dos.json") as file: self.dos = CompleteDos.from_dict(json.load(file)) @@ -58,7 +58,7 @@ def test_as_dict(self): class TestFermiDos(TestCase): - def setUp(self): + def setup_method(self): with open(f"{TEST_DIR}/complete_dos.json") as file: self.dos = CompleteDos.from_dict(json.load(file)) self.dos = FermiDos(self.dos) @@ -105,7 +105,7 @@ def test_as_dict(self): class TestCompleteDos(TestCase): - def setUp(self): + def setup_method(self): with open(f"{TEST_DIR}/complete_dos.json") as file: self.dos = CompleteDos.from_dict(json.load(file)) with zopen(f"{TEST_DIR}/pdag3_complete_dos.json.gz") as file: @@ -324,7 +324,7 @@ def test_dos_fp_exceptions(self): class TestDOS: - def setUp(self): + def setup_method(self): with open(f"{TEST_DIR}/complete_dos.json") as file: dct = json.load(file) ys = list(zip(dct["densities"]["1"], dct["densities"]["-1"], strict=True)) @@ -359,7 +359,7 @@ def test_spin_polarization(self): class TestLobsterCompleteDos(TestCase): - def setUp(self): + def setup_method(self): with open(f"{TEST_DIR}/LobsterCompleteDos_spin.json") as file: data_spin = json.load(file) self.LobsterCompleteDOS_spin = LobsterCompleteDos.from_dict(data_spin) diff --git a/tests/electronic_structure/test_plotter.py b/tests/electronic_structure/test_plotter.py index 2e80564a90c..8c87e20ec67 100644 --- a/tests/electronic_structure/test_plotter.py +++ b/tests/electronic_structure/test_plotter.py @@ -38,7 +38,7 @@ class TestDosPlotter: - def setUp(self): + def setup_method(self): with open(f"{BAND_TEST_DIR}/../dos/complete_dos.json") as file: self.dos = CompleteDos.from_dict(json.load(file)) self.plotter = DosPlotter(sigma=0.2, stack=True) @@ -92,7 +92,7 @@ def get_plot_attributes(ax: plt.Axes): class TestBSPlotter: - def setUp(self): + def setup_method(self): with open(f"{BAND_TEST_DIR}/CaO_2605_bandstructure.json") as file: dct = json.loads(file.read()) self.bs = BandStructureSymmLine.from_dict(dct) @@ -185,7 +185,7 @@ def test_get_plot(self): class TestBSPlotterProjected(TestCase): - def setUp(self): + def setup_method(self): with open(f"{BAND_TEST_DIR}/Cu2O_361_bandstructure.json") as file: self.bs_Cu2O = BandStructureSymmLine.from_dict(json.load(file)) self.plotter_Cu2O = BSPlotterProjected(self.bs_Cu2O) @@ -258,7 +258,7 @@ def test_methods(self): class TestPlotBZ(TestCase): - def setUp(self): + def setup_method(self): self.rec_latt = Structure.from_file(f"{TEST_FILES_DIR}/io/cssr/Si.cssr").lattice.reciprocal_lattice self.kpath = [[[0.0, 0.0, 0.0], [0.5, 0.0, 0.5], [0.5, 0.25, 0.75], [0.375, 0.375, 0.75]]] self.labels = { @@ -304,7 +304,7 @@ def test_fold_point(self): @pytest.mark.skip("TODO: need someone to fix this") @pytest.mark.skipif(not which("x_trans"), reason="No x_trans executable found") class TestBoltztrapPlotter(TestCase): - def setUp(self): + def setup_method(self): bz = BoltztrapAnalyzer.from_files(f"{TEST_FILES_DIR}/boltztrap/transp/") self.plotter = BoltztrapPlotter(bz) @@ -445,7 +445,7 @@ def test_plot_zt_temp(self): class TestCohpPlotter: - def setUp(self): + def setup_method(self): path = f"{TEST_FILES_DIR}/electronic_structure/cohp/complete_cohp_lobster.json" with open(path) as file: self.cohp = CompleteCohp.from_dict(json.load(file)) diff --git a/tests/entries/test_compatibility.py b/tests/entries/test_compatibility.py index 2aaa4cb02ce..45d031e6caa 100644 --- a/tests/entries/test_compatibility.py +++ b/tests/entries/test_compatibility.py @@ -46,7 +46,7 @@ class TestCorrectionSpecificity(TestCase): """Make sure corrections are only applied to GGA or GGA+U entries.""" - def setUp(self): + def setup_method(self): self.entry1 = ComputedEntry( "Fe2O3", -1, @@ -205,7 +205,7 @@ def test_overlapping_adjustments(): @pytest.mark.filterwarnings("ignore:MaterialsProjectCompatibility is deprecated") class TestMaterialsProjectCompatibility(TestCase): - def setUp(self): + def setup_method(self): self.entry1 = ComputedEntry( "Fe2O3", -1, @@ -622,7 +622,7 @@ def test_msonable(self): class TestMaterialsProjectCompatibility2020(TestCase): - def setUp(self): + def setup_method(self): self.entry1 = ComputedEntry( "Fe2O3", -1, @@ -1316,7 +1316,7 @@ def test_many_anions(self): class TestMITCompatibility(TestCase): - def setUp(self): + def setup_method(self): self.compat = MITCompatibility(check_potcar_hash=True) self.gga_compat = MITCompatibility("GGA", check_potcar_hash=True) self.entry_O = ComputedEntry( @@ -1656,7 +1656,7 @@ def test_msonable(self): class TestOxideTypeCorrection(TestCase): - def setUp(self): + def setup_method(self): self.compat = MITCompatibility(check_potcar_hash=True) def test_no_struct_compat(self): @@ -1827,7 +1827,7 @@ def test_process_entry_oxide(self): class TestSulfideTypeCorrection2020(TestCase): - def setUp(self): + def setup_method(self): self.compat = MaterialsProject2020Compatibility(check_potcar_hash=False) def test_struct_no_struct(self): @@ -1987,7 +1987,7 @@ def test_struct_no_struct(self): class TestOxideTypeCorrectionNoPeroxideCorr(TestCase): - def setUp(self): + def setup_method(self): self.compat = MITCompatibility(correct_peroxide=False) def test_oxide_energy_corr(self): @@ -2255,7 +2255,7 @@ def test_parallel_process_entries(self): class TestAqueousCorrection(TestCase): - def setUp(self): + def setup_method(self): fp = f"{PMG_ENTRIES_DIR}/MITCompatibility.yaml" self.corr = AqueousCorrection(fp) @@ -2282,7 +2282,7 @@ def test_compound_energy(self): class TestMITAqueousCompatibility(TestCase): - def setUp(self): + def setup_method(self): self.compat = MITCompatibility(check_potcar_hash=True) self.aqcompat = MITAqueousCompatibility(check_potcar_hash=True) fp = f"{PMG_ENTRIES_DIR}/MITCompatibility.yaml" @@ -2393,7 +2393,7 @@ def test_dont_error_on_weird_elements(self): class TestCorrectionErrors2020Compatibility(TestCase): - def setUp(self): + def setup_method(self): self.compat = MaterialsProject2020Compatibility() params = { diff --git a/tests/entries/test_computed_entries.py b/tests/entries/test_computed_entries.py index 9cf63caca6f..63ce5c21d8f 100644 --- a/tests/entries/test_computed_entries.py +++ b/tests/entries/test_computed_entries.py @@ -96,7 +96,7 @@ def test_temp_energy_adjustment(): class TestComputedEntry(TestCase): - def setUp(self): + def setup_method(self): self.entry = ComputedEntry( vasp_run.final_structure.composition, vasp_run.final_energy, @@ -257,7 +257,7 @@ def test_from_dict_null_fields(self): class TestComputedStructureEntry(TestCase): - def setUp(self): + def setup_method(self): self.entry = ComputedStructureEntry(vasp_run.final_structure, vasp_run.final_energy, parameters=vasp_run.incar) def test_energy(self): @@ -454,7 +454,7 @@ def test_eq(self): class TestGibbsComputedStructureEntry(TestCase): - def setUp(self): + def setup_method(self): self.temps = [300, 600, 900, 1200, 1500, 1800] self.struct = vasp_run.final_structure self.num_atoms = self.struct.composition.num_atoms diff --git a/tests/entries/test_correction_calculator.py b/tests/entries/test_correction_calculator.py index 209f781be41..66718efe212 100644 --- a/tests/entries/test_correction_calculator.py +++ b/tests/entries/test_correction_calculator.py @@ -11,7 +11,7 @@ class TestCorrectionCalculator(TestCase): - def setUp(self): + def setup_method(self): self.exclude_polyanions = [ "SO4", "CO3", diff --git a/tests/entries/test_entry_tools.py b/tests/entries/test_entry_tools.py index 3731857f98b..6dec5a42b78 100644 --- a/tests/entries/test_entry_tools.py +++ b/tests/entries/test_entry_tools.py @@ -50,7 +50,7 @@ def test_group_entries_by_composition(self): class TestEntrySet: - def setUp(self): + def setup_method(self): entries = loadfn(f"{TEST_DIR}/Li-Fe-P-O_entries.json") self.entry_set = EntrySet(entries) diff --git a/tests/entries/test_exp_entries.py b/tests/entries/test_exp_entries.py index b73be4ad8a4..b9752eae71f 100644 --- a/tests/entries/test_exp_entries.py +++ b/tests/entries/test_exp_entries.py @@ -11,7 +11,7 @@ class TestExpEntry(TestCase): - def setUp(self): + def setup_method(self): with open(f"{TEST_FILES_DIR}/entries/Fe2O3_exp.json") as file: thermo_data = json.load(file, cls=MontyDecoder) self.entry = ExpEntry("Fe2O3", thermo_data) diff --git a/tests/ext/test_matproj.py b/tests/ext/test_matproj.py index 0f0395577e0..0551919b6f3 100644 --- a/tests/ext/test_matproj.py +++ b/tests/ext/test_matproj.py @@ -49,7 +49,7 @@ reason="Legacy PMG_MAPI_KEY environment variable not set.", ) class TestMPResterOld: - def setUp(self): + def setup_method(self): self.rester = _MPResterLegacy() def test_get_all_materials_ids_doc(self): @@ -529,7 +529,7 @@ def test_api_key_is_none(self): reason="PMG_MAPI_KEY environment variable not set.", ) class TestMPResterNewBasic: - def setUp(self): + def setup_method(self): self.rester = _MPResterBasic() def test_get_summary(self): @@ -903,10 +903,10 @@ def test_pourbaix_mpr_pipeline(self): def test_parity_with_mp_api(self): try: - from mp_api.client import MPRester as MpApi + from mp_api.client import MPRester except Exception: pytest.skip("mp_api.client.MPRester cannot be imported for this test.") - mpr_mp_api = MpApi(PMG_MAPI_KEY) + mpr_mp_api = MPRester(PMG_MAPI_KEY) # Test summary mp_data = mpr_mp_api.summary.search(formula="Al2O3") pmg_data = self.rester.get_summary({"formula": "Al2O3"}) diff --git a/tests/io/abinit/test_inputs.py b/tests/io/abinit/test_inputs.py index abcb129f4fb..0b83f596e80 100644 --- a/tests/io/abinit/test_inputs.py +++ b/tests/io/abinit/test_inputs.py @@ -261,7 +261,7 @@ def test_shiftmode(self): class TestFactory: - def setUp(self): + def setup_method(self): # Si ebands self.si_structure = Structure.from_file(abiref_file("si.cif")) self.si_pseudo = abiref_file("14si.pspnc") diff --git a/tests/io/abinit/test_netcdf.py b/tests/io/abinit/test_netcdf.py index 2006d5bdbb0..2e32d6bcc50 100644 --- a/tests/io/abinit/test_netcdf.py +++ b/tests/io/abinit/test_netcdf.py @@ -22,7 +22,7 @@ class TestEtsfReader: - def setUp(self): + def setup_method(self): formulas = ["Si2"] self.GSR_paths = dct = {} for formula in formulas: diff --git a/tests/io/abinit/test_pseudos.py b/tests/io/abinit/test_pseudos.py index 7d874908c0d..bdd92728d81 100644 --- a/tests/io/abinit/test_pseudos.py +++ b/tests/io/abinit/test_pseudos.py @@ -15,7 +15,7 @@ class TestPseudo: - def setUp(self): + def setup_method(self): nc_pseudo_fnames = defaultdict(list) nc_pseudo_fnames["Si"] = [f"{TEST_DIR}/{file}" for file in ("14si.pspnc", "14si.4.hgh", "14-Si.LDA.fhi")] diff --git a/tests/io/cp2k/test_inputs.py b/tests/io/cp2k/test_inputs.py index 7da41494b62..10eedefb468 100644 --- a/tests/io/cp2k/test_inputs.py +++ b/tests/io/cp2k/test_inputs.py @@ -170,7 +170,7 @@ class TestCp2kInput: &END """ - def setUp(self): + def setup_method(self): self.ci = Cp2kInput.from_file(f"{TEST_DIR}/cp2k.inp") def test_basic_sections(self): diff --git a/tests/io/cp2k/test_outputs.py b/tests/io/cp2k/test_outputs.py index 84c3fab0e18..19762d1bfb2 100644 --- a/tests/io/cp2k/test_outputs.py +++ b/tests/io/cp2k/test_outputs.py @@ -13,7 +13,7 @@ class TestCp2kOutput(TestCase): - def setUp(self): + def setup_method(self): self.out = Cp2kOutput(f"{TEST_DIR}/cp2k.out", auto_load=True) def test_files(self): diff --git a/tests/io/feff/test_inputs.py b/tests/io/feff/test_inputs.py index 0128bb60fed..ea95c1b25e6 100644 --- a/tests/io/feff/test_inputs.py +++ b/tests/io/feff/test_inputs.py @@ -58,7 +58,7 @@ def test_as_dict_and_from_dict(self): class TestFeffAtoms(TestCase): @classmethod - def setUpClass(cls): + def setup_class(cls): cls.structure = Structure.from_file(f"{TEST_FILES_DIR}/cif/CoO19128.cif") cls.atoms = Atoms(cls.structure, "O", 12.0) @@ -246,7 +246,7 @@ def test_as_dict_and_from_dict(self): class TestPaths(TestCase): - def setUp(self): + def setup_method(self): feo = Structure.from_dict( { "lattice": { diff --git a/tests/io/feff/test_sets.py b/tests/io/feff/test_sets.py index 8dae8b7e546..5e47de2ca40 100644 --- a/tests/io/feff/test_sets.py +++ b/tests/io/feff/test_sets.py @@ -16,7 +16,7 @@ class TestFeffInputSet: @classmethod - def setUpClass(cls): + def setup_class(cls): cls.header_string = """* This FEFF.inp file generated by pymatgen TITLE comment: From cif file TITLE Source: CoO19128.cif diff --git a/tests/io/lammps/test_data.py b/tests/io/lammps/test_data.py index a121b7ef680..3fbf53aa4f4 100644 --- a/tests/io/lammps/test_data.py +++ b/tests/io/lammps/test_data.py @@ -21,7 +21,7 @@ class TestLammpsBox: @classmethod - def setUpClass(cls): + def setup_class(cls): cls.peptide = LammpsBox( bounds=[ [36.840194, 64.211560], @@ -75,7 +75,7 @@ def test_to_lattice(self): class TestLammpsData: @classmethod - def setUpClass(cls): + def setup_class(cls): cls.peptide = LammpsData.from_file(filename=f"{TEST_DIR}/data.peptide") cls.ethane = LammpsData.from_file(filename=f"{TEST_DIR}/ethane.data") cls.quartz = LammpsData.from_file(filename=f"{TEST_DIR}/data.quartz", atom_style="atomic") @@ -667,7 +667,7 @@ def test_from_bonding(self): class TestForceField: @classmethod - def setUpClass(cls): + def setup_class(cls): mass_info = [ ("A", "H"), ("B", Element("C")), @@ -820,7 +820,7 @@ def test_lattice_2_lmpbox(self): class TestCombinedData(TestCase): @classmethod - def setUpClass(cls): + def setup_class(cls): cls.ec = LammpsData.from_file(filename=f"{TEST_DIR}/ec.data.gz") cls.fec = LammpsData.from_file(filename=f"{TEST_DIR}/fec.data.gz") cls.li = LammpsData.from_file(filename=f"{TEST_DIR}/li.data") diff --git a/tests/io/lammps/test_generators.py b/tests/io/lammps/test_generators.py index 3db0fae78d8..41be716ae11 100644 --- a/tests/io/lammps/test_generators.py +++ b/tests/io/lammps/test_generators.py @@ -10,7 +10,7 @@ class TestLammpsMinimization: @classmethod - def setUpClass(cls): + def setup_class(cls): cls.filename = f"{TEST_DIR}/lgps.in" cls.cif = f"{TEST_DIR}/lgps.cif" cls.structure = Structure.from_file(cls.cif) diff --git a/tests/io/lammps/test_inputs.py b/tests/io/lammps/test_inputs.py index fb25b788732..485a2177fe3 100644 --- a/tests/io/lammps/test_inputs.py +++ b/tests/io/lammps/test_inputs.py @@ -18,7 +18,7 @@ class TestLammpsInputFile: @classmethod - def setUpClass(cls): + def setup_class(cls): cls.filename = f"{TEST_DIR}/lgps.in" def test_from_file(self): diff --git a/tests/io/lammps/test_outputs.py b/tests/io/lammps/test_outputs.py index 6d5e83c3089..15b482c3d7c 100644 --- a/tests/io/lammps/test_outputs.py +++ b/tests/io/lammps/test_outputs.py @@ -16,7 +16,7 @@ class TestLammpsDump(TestCase): @classmethod - def setUpClass(cls): + def setup_class(cls): with open(f"{TEST_DIR}/dump.rdx_wc.100") as file: rdx_str = file.read() cls.rdx = LammpsDump.from_str(string=rdx_str) diff --git a/tests/io/lammps/test_utils.py b/tests/io/lammps/test_utils.py index 4a116c021a6..ed3f6790580 100644 --- a/tests/io/lammps/test_utils.py +++ b/tests/io/lammps/test_utils.py @@ -12,7 +12,7 @@ class TestPolymer(TestCase): @classmethod - def setUpClass(cls): + def setup_class(cls): # head molecule cls.peo_head = Molecule.from_file(f"{TEST_DIR}/peo_head.xyz") charges = [-0.1187, 0.0861, 0.0861, 0.0861, -0.2792, -0.0326, 0.0861, 0.0861] @@ -84,7 +84,7 @@ def test_polymer_chain_topologies(self): class TestPackmolOutput(TestCase): @classmethod - def setUpClass(cls): + def setup_class(cls): ethanol_coords = [ [0.00720, -0.56870, 0.00000], [-1.28540, 0.24990, 0.00000], diff --git a/tests/io/lobster/test_inputs.py b/tests/io/lobster/test_inputs.py index 72feec95f87..98720a0d5d6 100644 --- a/tests/io/lobster/test_inputs.py +++ b/tests/io/lobster/test_inputs.py @@ -20,7 +20,7 @@ class TestLobsterin: - def setUp(self): + def setup_method(self): self.Lobsterin = Lobsterin.from_file(f"{TEST_DIR}/lobsterin.1") self.Lobsterin2 = Lobsterin.from_file(f"{TEST_DIR}/lobsterin.2") self.Lobsterin3 = Lobsterin.from_file(f"{TEST_DIR}/lobsterin.3") diff --git a/tests/io/lobster/test_lobsterenv.py b/tests/io/lobster/test_lobsterenv.py index 4f9cc9959b8..52505d4670e 100644 --- a/tests/io/lobster/test_lobsterenv.py +++ b/tests/io/lobster/test_lobsterenv.py @@ -25,7 +25,7 @@ class TestLobsterNeighbors(TestCase): - def setUp(self): + def setup_method(self): # test additional conditions first # only consider cation anion bonds diff --git a/tests/io/lobster/test_outputs.py b/tests/io/lobster/test_outputs.py index ac9ff882d82..2119f05b413 100644 --- a/tests/io/lobster/test_outputs.py +++ b/tests/io/lobster/test_outputs.py @@ -43,7 +43,7 @@ class TestBwdf: - def setUp(self): + def setup_method(self): self.bwdf_coop = Bwdf(filename=f"{TEST_DIR}/BWDF.lobster.AlN.gz") self.bwdf_cohp = Bwdf(filename=f"{TEST_DIR}/BWDFCOHP.lobster.NaCl.gz") @@ -58,7 +58,7 @@ def test_attributes(self): class TestCohpcar: - def setUp(self): + def setup_method(self): self.cohp_bise = Cohpcar(filename=f"{TEST_DIR}/COHPCAR.lobster.BiSe.gz") self.coop_bise = Cohpcar( filename=f"{TEST_DIR}/COOPCAR.lobster.BiSe.gz", @@ -399,7 +399,7 @@ def test_orbital_resolved_cohp(self): class TestDoscar(TestCase): - def setUp(self): + def setup_method(self): # first for spin polarized version doscar = f"{VASP_OUT_DIR}/DOSCAR.lobster.spin" poscar = f"{VASP_IN_DIR}/POSCAR.lobster.spin_DOS" @@ -638,7 +638,7 @@ def test_is_spin_polarized(self): class TestCharge: - def setUp(self): + def setup_method(self): self.charge2 = Charge(filename=f"{TEST_DIR}/CHARGE.lobster.MnO") # gzipped file self.charge = Charge(filename=f"{TEST_DIR}/CHARGE.lobster.MnO2.gz") @@ -717,7 +717,7 @@ def test_msonable(self): class TestLobsterout: - def setUp(self): + def setup_method(self): self.lobsterout_normal = Lobsterout(filename=f"{TEST_DIR}/lobsterout.normal") # make sure .gz files are also read correctly self.lobsterout_normal = Lobsterout(filename=f"{TEST_DIR}/lobsterout.normal2.gz") @@ -1246,7 +1246,7 @@ def test_msonable(self): class TestFatband: - def setUp(self): + def setup_method(self): self.structure = Vasprun( filename=f"{TEST_DIR}/Fatband_SiO2/Test_p_x/vasprun.xml", ionic_step_skip=None, @@ -1481,7 +1481,7 @@ def test_get_bandstructure(self): class TestBandoverlaps(TestCase): - def setUp(self): + def setup_method(self): # test spin-polarized calc and non spin-polarized calc self.band_overlaps1 = Bandoverlaps(f"{TEST_DIR}/bandOverlaps.lobster.1") @@ -1714,7 +1714,7 @@ def test_keys(self): class TestGrosspop(TestCase): - def setUp(self): + def setup_method(self): self.grosspop1 = Grosspop(f"{TEST_DIR}/GROSSPOP.lobster") self.grosspop_511_sp = Grosspop(f"{TEST_DIR}/GROSSPOP_511_sp.lobster.AlN.gz") self.grosspop_511_nsp = Grosspop(f"{TEST_DIR}/GROSSPOP_511_nsp.lobster.NaCl.gz") @@ -1864,7 +1864,7 @@ def test_msonable(self): class TestIcohplist(TestCase): - def setUp(self): + def setup_method(self): self.icohp_bise = Icohplist(filename=f"{TEST_DIR}/ICOHPLIST.lobster.BiSe") self.icoop_bise = Icohplist( filename=f"{TEST_DIR}/ICOOPLIST.lobster.BiSe", @@ -2169,7 +2169,7 @@ def test_msonable(self): class TestNciCobiList(TestCase): - def setUp(self): + def setup_method(self): self.ncicobi = NciCobiList(filename=f"{TEST_DIR}/NcICOBILIST.lobster") self.ncicobi_gz = NciCobiList(filename=f"{TEST_DIR}/NcICOBILIST.lobster.gz") self.ncicobi_no_spin = NciCobiList(filename=f"{TEST_DIR}/NcICOBILIST.lobster.nospin") @@ -2273,7 +2273,7 @@ def test_write_file(self): class TestSitePotentials: - def setUp(self) -> None: + def setup_method(self) -> None: self.sitepotential = SitePotential(filename=f"{TEST_DIR}/SitePotentials.lobster.perovskite") def test_attributes(self): @@ -2324,7 +2324,7 @@ def test_msonable(self): class TestMadelungEnergies: - def setUp(self) -> None: + def setup_method(self) -> None: self.madelungenergies = MadelungEnergies(filename=f"{TEST_DIR}/MadelungEnergies.lobster.perovskite") def test_attributes(self): @@ -2341,7 +2341,7 @@ def test_msonable(self): class TestLobsterMatrices: - def setUp(self) -> None: + def setup_method(self) -> None: self.hamilton_matrices = LobsterMatrices( filename=f"{TEST_DIR}/Na_hamiltonMatrices.lobster.gz", e_fermi=-2.79650354 ) @@ -2491,7 +2491,7 @@ def test_raises(self): class TestPolarization: - def setUp(self) -> None: + def setup_method(self) -> None: self.polarization = Polarization(filename=f"{TEST_DIR}/POLARIZATION.lobster.AlN.gz") def test_attributes(self): diff --git a/tests/io/test_babel.py b/tests/io/test_babel.py index 6a130dd8914..32087bd3ac4 100644 --- a/tests/io/test_babel.py +++ b/tests/io/test_babel.py @@ -18,7 +18,7 @@ class TestBabelMolAdaptor(TestCase): - def setUp(self): + def setup_method(self): coords = [ [0.000000, 0.000000, 0.000000], [0.000000, 0.000000, 1.089000], diff --git a/tests/io/test_cif.py b/tests/io/test_cif.py index 3dd01454bb9..b9d448e01a5 100644 --- a/tests/io/test_cif.py +++ b/tests/io/test_cif.py @@ -1000,7 +1000,7 @@ def test_cif_writer_site_properties(self): class TestMagCif: - def setUp(self): + def setup_method(self): self.mcif = CifParser(f"{MCIF_TEST_DIR}/magnetic.example.NiO.mcif") self.mcif_ncl = CifParser(f"{MCIF_TEST_DIR}/magnetic.ncl.example.GdB4.mcif") self.mcif_incommensurate = CifParser(f"{MCIF_TEST_DIR}/magnetic.incommensurate.example.Cr.mcif") diff --git a/tests/io/test_core.py b/tests/io/test_core.py index 77e6b410b96..24fb290dc15 100644 --- a/tests/io/test_core.py +++ b/tests/io/test_core.py @@ -66,7 +66,7 @@ def test_msonable(self): class TestInputSet: @classmethod - def setUpClass(cls): + def setup_class(cls): cls.sif1 = StructInputFile.from_file(f"{TEST_FILES_DIR}/cif/Li.cif") cls.sif2 = StructInputFile.from_file(f"{TEST_FILES_DIR}/cif/LiFePO4.cif") cls.sif3 = StructInputFile.from_file(f"{TEST_FILES_DIR}/cif/Li2O.cif") diff --git a/tests/io/test_cssr.py b/tests/io/test_cssr.py index 467be18ae3e..951dab817e8 100644 --- a/tests/io/test_cssr.py +++ b/tests/io/test_cssr.py @@ -19,7 +19,7 @@ class TestCssr(TestCase): - def setUp(self): + def setup_method(self): filepath = f"{VASP_IN_DIR}/POSCAR" self.cssr = Cssr(Structure.from_file(filepath)) diff --git a/tests/io/test_fiesta.py b/tests/io/test_fiesta.py index bcc6904a076..d5bce31b5ba 100644 --- a/tests/io/test_fiesta.py +++ b/tests/io/test_fiesta.py @@ -10,7 +10,7 @@ class TestFiestaInput(TestCase): - def setUp(self): + def setup_method(self): coords = [ [0.000000, 0.000000, 0.000000], [0.000000, 0.000000, 1.089000], @@ -72,7 +72,7 @@ def test_str_and_from_str(self): class TestFiestaOutput(TestCase): - def setUp(self): + def setup_method(self): self.log_fiesta = FiestaOutput(f"{TEST_DIR}/log_fiesta") def test_props(self): diff --git a/tests/io/test_gaussian.py b/tests/io/test_gaussian.py index b44db9f2c32..9a5ec7ad0e1 100644 --- a/tests/io/test_gaussian.py +++ b/tests/io/test_gaussian.py @@ -14,7 +14,7 @@ class TestGaussianInput(TestCase): - def setUp(self): + def setup_method(self): coords = [ [0, 0, 0], [0, 0, 1.089], @@ -281,7 +281,7 @@ def test_no_molecule_func_bset_charge_mult(self): class TestGaussianOutput(TestCase): # TODO: Add unittest for PCM type output. - def setUp(self): + def setup_method(self): self.gau_out = GaussianOutput(f"{TEST_DIR}/methane.log") def test_resume(self): diff --git a/tests/io/test_lmto.py b/tests/io/test_lmto.py index 7a73dfa791b..5903fa9daec 100644 --- a/tests/io/test_lmto.py +++ b/tests/io/test_lmto.py @@ -24,12 +24,12 @@ class TestCtrl: - def setUp(self): + def setup_method(self): os.chdir(TEST_DIR) self.ref_bise = LMTOCtrl.from_file(filename="CTRL.BiSe") self.ref_fe = LMTOCtrl.from_file() - def tearDown(self): + def teardown_method(self): os.chdir(MODULE_DIR) def test_dict(self): @@ -48,13 +48,13 @@ def test_read_write(self): class TestCopl: - def setUp(self): + def setup_method(self): os.chdir(TEST_DIR) self.copl_bise = LMTOCopl("COPL.BiSe") self.copl_bise_eV = LMTOCopl(filename="COPL.BiSe", to_eV=True) self.copl_fe = LMTOCopl() - def tearDown(self): + def teardown_method(self): os.chdir(MODULE_DIR) def test_attributes(self): diff --git a/tests/io/test_nwchem.py b/tests/io/test_nwchem.py index 7304ec4a10e..beb3e40366a 100644 --- a/tests/io/test_nwchem.py +++ b/tests/io/test_nwchem.py @@ -23,7 +23,7 @@ class TestNwTask(TestCase): - def setUp(self): + def setup_method(self): self.task = NwTask( 0, 1, @@ -137,7 +137,7 @@ def test_esp_task(self): class TestNwInput(TestCase): - def setUp(self): + def setup_method(self): tasks = [ NwTask.dft_task(mol, operation="optimize", xc="b3lyp", basis_set="6-31++G*"), NwTask.dft_task(mol, operation="freq", xc="b3lyp", basis_set="6-31++G*"), diff --git a/tests/io/test_phonopy.py b/tests/io/test_phonopy.py index 588a027adc3..4c3000097d1 100644 --- a/tests/io/test_phonopy.py +++ b/tests/io/test_phonopy.py @@ -163,7 +163,7 @@ def test_get_displaced_structures(self): reason="See https://github.com/conda-forge/phonopy-feedstock/pull/158#issuecomment-2227506701", ) class TestPhonopyFromForceConstants(TestCase): - def setUp(self) -> None: + def setup_method(self) -> None: test_path = Path(TEST_DIR) structure_file = test_path / "POSCAR-NaCl" fc_file = test_path / "FORCE_CONSTANTS" diff --git a/tests/io/test_pwscf.py b/tests/io/test_pwscf.py index 15743c7a9b6..8cde518b0c5 100644 --- a/tests/io/test_pwscf.py +++ b/tests/io/test_pwscf.py @@ -543,7 +543,7 @@ def test_custom_decimal_precision_write_and_read_str(self): class TestPWOutput: - def setUp(self): + def setup_method(self): self.pw_out = PWOutput(f"{TEST_DIR}/Si.pwscf.out") def test_properties(self): diff --git a/tests/io/test_shengbte.py b/tests/io/test_shengbte.py index 961792df336..e3419d93c8d 100644 --- a/tests/io/test_shengbte.py +++ b/tests/io/test_shengbte.py @@ -11,7 +11,7 @@ class TestShengBTE: - def setUp(self): + def setup_method(self): self.filename = f"{TEST_DIR}/CONTROL-CSLD_Si" self.test_dict = { "nelements": 1, diff --git a/tests/io/test_wannier90.py b/tests/io/test_wannier90.py index 8a43bf62a22..6459e3b9c98 100644 --- a/tests/io/test_wannier90.py +++ b/tests/io/test_wannier90.py @@ -14,7 +14,7 @@ class TestUnk: - def setUp(self): + def setup_method(self): rng = np.random.default_rng() self.data_std = rng.random((10, 5, 5, 5)) self.unk_std = Unk(1, self.data_std) diff --git a/tests/io/test_xcrysden.py b/tests/io/test_xcrysden.py index 095e8f73b6a..35a82e2d59a 100644 --- a/tests/io/test_xcrysden.py +++ b/tests/io/test_xcrysden.py @@ -7,7 +7,7 @@ class TestXSF: - def setUp(self): + def setup_method(self): self.coords = [[0, 0, 0], [0.75, 0.5, 0.75]] self.lattice = [ [3.8401979337, 0.00, 0.00], diff --git a/tests/io/test_xr.py b/tests/io/test_xr.py index 05cfa8bfc8e..8321c2340af 100644 --- a/tests/io/test_xr.py +++ b/tests/io/test_xr.py @@ -15,7 +15,7 @@ class TestXr(TestCase): - def setUp(self): + def setup_method(self): struct = Structure.from_file(f"{VASP_IN_DIR}/POSCAR") self.xr = Xr(struct) diff --git a/tests/io/test_xyz.py b/tests/io/test_xyz.py index ad57feca5af..e0ad2ea6f1a 100644 --- a/tests/io/test_xyz.py +++ b/tests/io/test_xyz.py @@ -13,7 +13,7 @@ class TestXYZ(TestCase): - def setUp(self): + def setup_method(self): coords = [ [0, 0, 0], [0, 0, 1.089000], diff --git a/tests/io/test_zeopp.py b/tests/io/test_zeopp.py index 28bc18aad8c..f049ffccc97 100644 --- a/tests/io/test_zeopp.py +++ b/tests/io/test_zeopp.py @@ -29,7 +29,7 @@ class TestZeoCssr(TestCase): - def setUp(self): + def setup_method(self): filepath = f"{VASP_IN_DIR}/POSCAR" self.zeo_cssr = ZeoCssr(Structure.from_file(filepath)) @@ -71,7 +71,7 @@ def test_from_file(self): class TestZeoCssrOxi(TestCase): - def setUp(self): + def setup_method(self): filepath = f"{VASP_IN_DIR}/POSCAR" structure = BVAnalyzer().get_oxi_state_decorated_structure(Structure.from_file(filepath)) self.zeo_cssr = ZeoCssr(structure) @@ -114,7 +114,7 @@ def test_from_file(self): class TestZeoVoronoiXYZ(TestCase): - def setUp(self): + def setup_method(self): coords = [ [0.000000, 0.000000, 0.000000], [0.000000, 0.000000, 1.089000], @@ -144,7 +144,7 @@ def test_from_file(self): class TestGetVoronoiNodes(TestCase): - def setUp(self): + def setup_method(self): filepath = f"{VASP_IN_DIR}/POSCAR" self.structure = Structure.from_file(filepath) bv = BVAnalyzer() @@ -168,7 +168,7 @@ def test_get_voronoi_nodes(self): @pytest.mark.skip("TODO: file free_sph.cif not present") class TestGetFreeSphereParams(TestCase): - def setUp(self): + def setup_method(self): filepath = f"{TEST_FILES_DIR}/cif/free_sph.cif" self.structure = Structure.from_file(filepath) self.rad_dict = { @@ -189,7 +189,7 @@ def test_get_free_sphere_params(self): class TestGetHighAccuracyVoronoiNodes(TestCase): - def setUp(self): + def setup_method(self): filepath = f"{VASP_IN_DIR}/POSCAR" self.structure = Structure.from_file(filepath) bv = BVAnalyzer() @@ -208,7 +208,7 @@ def test_get_voronoi_nodes(self): class TestGetVoronoiNodesMultiOxi(TestCase): - def setUp(self): + def setup_method(self): filepath = f"{VASP_IN_DIR}/POSCAR" self.structure = Structure.from_file(filepath) bv = BVAnalyzer() diff --git a/tests/io/vasp/test_inputs.py b/tests/io/vasp/test_inputs.py index 13e28f4a4eb..11f1bff0de1 100644 --- a/tests/io/vasp/test_inputs.py +++ b/tests/io/vasp/test_inputs.py @@ -650,7 +650,7 @@ def test_vasp_6_4_2_format(self): class TestIncar: - def setUp(self): + def setup_method(self): self.incar = Incar.from_file(f"{VASP_IN_DIR}/INCAR") def test_init(self): @@ -1298,7 +1298,7 @@ def test_automatic_monkhorst_vs_gamma_style_selection(self): "ignore:POTCAR data with symbol .* is not known to pymatgen:pymatgen.io.vasp.inputs.UnknownPotcarWarning" ) class TestPotcarSingle(TestCase): - def setUp(self): + def setup_method(self): self.psingle_Mn_pv = PotcarSingle.from_file(f"{FAKE_POTCAR_DIR}/POT_GGA_PAW_PBE/POTCAR.Mn_pv.gz") self.psingle_Fe = PotcarSingle.from_file(f"{FAKE_POTCAR_DIR}/POT_GGA_PAW_PBE/POTCAR.Fe.gz") self.psingle_Fe_54 = PotcarSingle.from_file(f"{FAKE_POTCAR_DIR}/POT_GGA_PAW_PBE_54/POTCAR.Fe.gz") @@ -1538,7 +1538,7 @@ def test_copy(self): "ignore:POTCAR data with symbol .* is not known to pymatgen:pymatgen.io.vasp.inputs.UnknownPotcarWarning" ) class TestPotcar: - def setUp(self): + def setup_method(self): SETTINGS.setdefault("PMG_VASP_PSP_DIR", str(TEST_FILES_DIR)) self.filepath = f"{FAKE_POTCAR_DIR}/POTCAR.gz" self.potcar = Potcar.from_file(self.filepath) @@ -1617,7 +1617,7 @@ def test_pickle(self): "ignore:POTCAR data with symbol .* is not known to pymatgen:pymatgen.io.vasp.inputs.UnknownPotcarWarning" ) class TestVaspInput: - def setUp(self): + def setup_method(self): filepath = f"{VASP_IN_DIR}/INCAR" incar = Incar.from_file(filepath) filepath = f"{VASP_IN_DIR}/POSCAR" diff --git a/tests/io/vasp/test_outputs.py b/tests/io/vasp/test_outputs.py index e67c241bf8a..11ebfec2b80 100644 --- a/tests/io/vasp/test_outputs.py +++ b/tests/io/vasp/test_outputs.py @@ -1516,7 +1516,7 @@ def test_vasp_6x_style(self): class TestChgcar: @classmethod - def setUpClass(cls): + def setup_class(cls): filepath = f"{VASP_OUT_DIR}/CHGCAR.nospin.gz" cls.chgcar_no_spin = Chgcar.from_file(filepath) @@ -1818,7 +1818,7 @@ def test_init(self): class TestWavecar: - def setUp(self): + def setup_method(self): latt_mat = np.array(np.eye(3) * 10, dtype=float) # lattice vectors self.vol = np.dot(latt_mat[0, :], np.cross(latt_mat[1, :], latt_mat[2, :])) # unit cell volume # reciprocal lattice vectors @@ -2136,7 +2136,7 @@ def test_eigenvalue_band_properties_separate_spins(self): class TestWaveder: - def setUp(self): + def setup_method(self): wder = Waveder.from_binary(f"{VASP_OUT_DIR}/WAVEDER", "float64") assert wder.nbands == 36 assert wder.nkpoints == 56 @@ -2169,7 +2169,7 @@ def _check(wder): class TestWSWQ: - def setUp(self): + def setup_method(self): self.wswq = WSWQ.from_file(f"{VASP_OUT_DIR}/WSWQ.gz") def test_consistency(self): diff --git a/tests/io/vasp/test_sets.py b/tests/io/vasp/test_sets.py index 6dd438c052b..65334e7059c 100644 --- a/tests/io/vasp/test_sets.py +++ b/tests/io/vasp/test_sets.py @@ -130,7 +130,7 @@ def test_sets_changed(self): class TestVaspInputSet: @classmethod - def setUpClass(cls): + def setup_class(cls): filepath = f"{VASP_IN_DIR}/POSCAR" cls.structure = Structure.from_file(filepath) @@ -167,7 +167,7 @@ def test_as_dict(self): class TestMITMPRelaxSet: @classmethod - def setUpClass(cls): + def setup_class(cls): cls.set = MITRelaxSet cls.mp_set = MPRelaxSet @@ -719,7 +719,7 @@ def test_get_nedos(self): class TestMPStaticSet: - def setUp(self): + def setup_method(self): self.set = MPStaticSet def test_init(self): @@ -871,7 +871,7 @@ def test_grid_size_from_struct(self): class TestMatPESStaticSet: - def setUp(self): + def setup_method(self): self.struct = Structure.from_file(f"{VASP_IN_DIR}/POSCAR") self.prev_incar = Incar.from_file(f"{VASP_IN_DIR}/INCAR") @@ -988,7 +988,7 @@ def test_from_prev_calc(self): class TestMPNonSCFSet: - def setUp(self): + def setup_method(self): self.set = MPNonSCFSet @skip_if_no_psp_dir @@ -1189,7 +1189,7 @@ def test_ln_magmom(self): class TestMITMDSet: - def setUp(self): + def setup_method(self): self.set = MITMDSet filepath = f"{VASP_IN_DIR}/POSCAR" self.struct = Structure.from_file(filepath) @@ -1231,7 +1231,7 @@ def test_user_heat_speed(self): @skip_if_no_psp_dir class TestMVLNPTMDSet: - def setUp(self): + def setup_method(self): file_path = f"{VASP_IN_DIR}/POSCAR" self.struct = Structure.from_file(file_path) self.mvl_npt_set = MVLNPTMDSet(self.struct, start_temp=0, end_temp=300, nsteps=1000) @@ -1267,7 +1267,7 @@ def test_as_from_dict(self): class TestMPMDSet: - def setUp(self): + def setup_method(self): filepath = f"{VASP_IN_DIR}/POSCAR" self.struct = Structure.from_file(filepath) self.struct_with_H = Structure.from_file(f"{VASP_IN_DIR}/POSCAR_hcp") @@ -1309,7 +1309,7 @@ def test_as_from_dict(self): class TestMITNEBSet: - def setUp(self): + def setup_method(self): c1 = [[0.5] * 3, [0.9] * 3] c2 = [[0.5] * 3, [0.9, 0.1, 0.1]] s1 = Structure(Lattice.cubic(5), ["Si", "Si"], c1) @@ -1357,7 +1357,7 @@ def test_write_input(self): class TestMPSOCSet: - def setUp(self): + def setup_method(self): self.set = MPSOCSet def test_from_prev_calc(self): @@ -1416,7 +1416,7 @@ def test_incar(self): @skip_if_no_psp_dir class TestMVLSlabSet: - def setUp(self): + def setup_method(self): self.set = MVLSlabSet struct = self.get_structure("Li2O") gen = SlabGenerator(struct, (1, 0, 0), 10, 10) @@ -1499,7 +1499,7 @@ def test_incar(self): @skip_if_no_psp_dir class TestMVLGWSet: - def setUp(self): + def setup_method(self): self.set = MVLGWSet self.struct = PymatgenTest.get_structure("Li2O") @@ -1577,7 +1577,7 @@ def test_bse(self): class TestMPHSERelaxSet: - def setUp(self): + def setup_method(self): self.structure = dummy_structure self.set = MPHSERelaxSet @@ -1644,7 +1644,7 @@ def test_override_from_prev_calc(self): class TestMPHSEBS: - def setUp(self): + def setup_method(self): self.set = MPHSEBSSet def test_init(self): @@ -1700,7 +1700,7 @@ def test_override_from_prev_calc(self): class TestMVLScanRelaxSet: - def setUp(self): + def setup_method(self): self.set = MVLScanRelaxSet file_path = f"{VASP_IN_DIR}/POSCAR" self.struct = Structure.from_file(file_path) @@ -1778,7 +1778,7 @@ def test_as_from_dict(self): class TestMPScanRelaxSet: - def setUp(self): + def setup_method(self): file_path = f"{VASP_IN_DIR}/POSCAR" self.struct = Structure.from_file(file_path) self.mp_scan_set = MPScanRelaxSet( @@ -1899,7 +1899,7 @@ def test_write_input(self): class TestMPScanStaticSet: - def setUp(self): + def setup_method(self): self.set = MPScanStaticSet self.prev_run = f"{TEST_DIR}/fixtures/scan_relaxation" # test inheriting from a previous SCAN relaxation @@ -2001,7 +2001,7 @@ def test_batch_write_input(self): @skip_if_no_psp_dir class TestMVLGBSet: - def setUp(self): + def setup_method(self): filepath = f"{TEST_FILES_DIR}/cif/Li.cif" self.struct = Structure.from_file(filepath) @@ -2027,7 +2027,7 @@ def test_kpoints(self): class TestMVLRelax52Set: - def setUp(self): + def setup_method(self): self.set = MVLRelax52Set file_path = f"{VASP_IN_DIR}/POSCAR" self.struct = Structure.from_file(file_path) @@ -2065,7 +2065,7 @@ def test_as_from_dict(self): class TestLobsterSet: - def setUp(self): + def setup_method(self): self.set = LobsterSet file_path = f"{VASP_IN_DIR}/POSCAR" file_path2 = f"{VASP_IN_DIR}/POSCAR.lobster.spin_DOS" @@ -2164,7 +2164,7 @@ def test_as_from_dict(self): @skip_if_no_psp_dir class TestMPAbsorptionSet: - def setUp(self): + def setup_method(self): file_path = f"{TEST_DIR}/fixtures/absorption/static/POSCAR" self.structure = Structure.from_file(file_path) self.set = MPAbsorptionSet diff --git a/tests/phonon/test_bandstructure.py b/tests/phonon/test_bandstructure.py index 6545edb1e27..ccebf1ec8af 100644 --- a/tests/phonon/test_bandstructure.py +++ b/tests/phonon/test_bandstructure.py @@ -14,7 +14,7 @@ class TestPhononBandStructureSymmLine: - def setUp(self): + def setup_method(self): with open(f"{TEST_DIR}/NaCl_phonon_bandstructure.json") as file: dct = json.load(file) self.bs = PhononBandStructureSymmLine.from_dict(dct) diff --git a/tests/phonon/test_dos.py b/tests/phonon/test_dos.py index a301540e4f0..9875eca9fff 100644 --- a/tests/phonon/test_dos.py +++ b/tests/phonon/test_dos.py @@ -15,7 +15,7 @@ class TestPhononDos: - def setUp(self): + def setup_method(self): with open(f"{TEST_DIR}/NaCl_ph_dos.json") as file: self.dos = PhononDos.from_dict(json.load(file)) with open(f"{TEST_DIR}/NaCl_complete_ph_dos.json") as file: @@ -183,7 +183,7 @@ def test_dos_fp_exceptions(self): class TestCompletePhononDos: - def setUp(self): + def setup_method(self): with open(f"{TEST_DIR}/NaCl_complete_ph_dos.json") as file: self.cdos = CompletePhononDos.from_dict(json.load(file)) diff --git a/tests/phonon/test_gruneisen.py b/tests/phonon/test_gruneisen.py index 164790bfc91..18446f81d5e 100644 --- a/tests/phonon/test_gruneisen.py +++ b/tests/phonon/test_gruneisen.py @@ -22,7 +22,7 @@ class TestGruneisenPhononBandStructureSymmLine: - def setUp(self) -> None: + def setup_method(self) -> None: self.bs_symm_line = get_gruneisen_ph_bs_symm_line( gruneisen_path=f"{TEST_DIR}/gruneisen_eq_plus_minus_InP.yaml", structure_path=f"{TEST_DIR}/eq/POSCAR_InP", @@ -77,7 +77,7 @@ def test_as_dict_from_dict(self): @pytest.mark.skipif(TotalDos is None, reason="Phonopy not present") class TestGruneisenParameter: - def setUp(self) -> None: + def setup_method(self) -> None: self.gruneisen_obj = get_gruneisenparameter( f"{TEST_DIR}/gruneisen_mesh_InP.yaml", structure_path=f"{TEST_DIR}/eq/POSCAR_InP", diff --git a/tests/phonon/test_ir_spectra.py b/tests/phonon/test_ir_spectra.py index 491bbc24e7d..86c909432e4 100644 --- a/tests/phonon/test_ir_spectra.py +++ b/tests/phonon/test_ir_spectra.py @@ -6,7 +6,7 @@ class TestIRDielectricTensor: - def setUp(self): + def setup_method(self): self.ir_spectra = loadfn(f"{TEST_FILES_DIR}/phonon/dos/ir_spectra_mp-991652_DDB.json") def test_basic(self): diff --git a/tests/phonon/test_plotter.py b/tests/phonon/test_plotter.py index 1afdd7c62bd..49e32b1c326 100644 --- a/tests/phonon/test_plotter.py +++ b/tests/phonon/test_plotter.py @@ -17,7 +17,7 @@ class TestPhononDosPlotter(TestCase): - def setUp(self): + def setup_method(self): with open(f"{TEST_DIR}/NaCl_complete_ph_dos.json") as file: self.dos = CompletePhononDos.from_dict(json.load(file)) self.plotter = PhononDosPlotter(sigma=0.2, stack=True) @@ -55,7 +55,7 @@ def test_plot(self): class TestPhononBSPlotter(TestCase): - def setUp(self): + def setup_method(self): with open(f"{TEST_FILES_DIR}/electronic_structure/bandstructure/NaCl_phonon_bandstructure.json") as file: dct = json.loads(file.read()) self.bs = PhononBandStructureSymmLine.from_dict(dct) @@ -114,7 +114,7 @@ def test_plot_compare(self): class TestThermoPlotter(TestCase): - def setUp(self): + def setup_method(self): with open(f"{TEST_DIR}/NaCl_complete_ph_dos.json") as file: self.dos = CompletePhononDos.from_dict(json.load(file)) self.plotter = ThermoPlotter(self.dos, self.dos.structure) diff --git a/tests/phonon/test_thermal_displacements.py b/tests/phonon/test_thermal_displacements.py index 7f138a9012a..7d4b4fb2f15 100644 --- a/tests/phonon/test_thermal_displacements.py +++ b/tests/phonon/test_thermal_displacements.py @@ -14,7 +14,7 @@ class TestThermalDisplacement: """Test data from J. George's matlab code https://github.com/JaGeo/MolecularToolbox.""" - def setUp(self) -> None: + def setup_method(self) -> None: self.thermal = ThermalDisplacementMatrices( thermal_displacement_matrix_cart=[ [5.16e-03, 6.13e-03, 4.15e-03, -1.10e-04, -1.58e-03, -8.10e-04], diff --git a/tests/symmetry/test_analyzer.py b/tests/symmetry/test_analyzer.py index 759e6e64a27..964ef209dab 100644 --- a/tests/symmetry/test_analyzer.py +++ b/tests/symmetry/test_analyzer.py @@ -25,7 +25,7 @@ class TestSpacegroupAnalyzer: - def setUp(self): + def setup_method(self): self.structure = Structure.from_file(f"{VASP_IN_DIR}/POSCAR") self.sg = SpacegroupAnalyzer(self.structure, 0.001) self.disordered_structure = self.get_structure("Li10GeP2S12") @@ -445,7 +445,7 @@ def test_bad_structure(self): class TestSpacegroup(TestCase): - def setUp(self): + def setup_method(self): self.structure = Structure.from_file(f"{VASP_IN_DIR}/POSCAR") self.sg1 = SpacegroupAnalyzer(self.structure, 0.001).get_space_group_operations() diff --git a/tests/symmetry/test_maggroups.py b/tests/symmetry/test_maggroups.py index 3e664592d3b..c868f5d62fa 100644 --- a/tests/symmetry/test_maggroups.py +++ b/tests/symmetry/test_maggroups.py @@ -17,7 +17,7 @@ class TestMagneticSpaceGroup: - def setUp(self): + def setup_method(self): self.msg_1 = MagneticSpaceGroup([70, 530]) self.msg_2 = MagneticSpaceGroup([62, 448]) self.msg_3 = MagneticSpaceGroup([20, 37]) diff --git a/tests/symmetry/test_settings.py b/tests/symmetry/test_settings.py index 79a6b56c138..be51dfbb1df 100644 --- a/tests/symmetry/test_settings.py +++ b/tests/symmetry/test_settings.py @@ -17,7 +17,7 @@ class TestJonesFaithfulTransformation(TestCase): - def setUp(self): + def setup_method(self): self.test_strings = [ "a,b,c;0,0,0", # identity "a-b,a+b,2c;0,0,1/2", diff --git a/tests/symmetry/test_site_symmetries.py b/tests/symmetry/test_site_symmetries.py index 3bdd7c5f7f9..455f45ba512 100644 --- a/tests/symmetry/test_site_symmetries.py +++ b/tests/symmetry/test_site_symmetries.py @@ -19,7 +19,7 @@ class TestSiteSymmetries: - def setUp(self): + def setup_method(self): with gzip.open(f"{TEST_DIR}/point_ops.json.gz", mode="rt") as file: self.point_ops = MontyDecoder().process_decoded(json.load(file)) diff --git a/tests/transformations/test_advanced_transformations.py b/tests/transformations/test_advanced_transformations.py index 479fbde5302..96222afdadb 100644 --- a/tests/transformations/test_advanced_transformations.py +++ b/tests/transformations/test_advanced_transformations.py @@ -277,7 +277,7 @@ def test_as_dict(self): @pytest.mark.skipif(not enumlib_present, reason="enum_lib not present.") class TestMagOrderingTransformation: - def setUp(self): + def setup_method(self): lattice = Lattice.cubic(4.17) species = ["Ni", "O"] coords = [[0, 0, 0], [0.5, 0.5, 0.5]] diff --git a/tests/transformations/test_site_transformations.py b/tests/transformations/test_site_transformations.py index fc778b97257..1baef5b7297 100644 --- a/tests/transformations/test_site_transformations.py +++ b/tests/transformations/test_site_transformations.py @@ -1,7 +1,6 @@ from __future__ import annotations from shutil import which -from unittest import TestCase import numpy as np import pytest @@ -24,7 +23,7 @@ class TestTranslateSitesTransformation: - def setUp(self): + def setup_method(self): coords = [ [0, 0, 0], [0.375, 0.375, 0.375], @@ -77,8 +76,8 @@ def test_as_from_dict(self): str(t2) -class TestReplaceSiteSpeciesTransformation(TestCase): - def setUp(self): +class TestReplaceSiteSpeciesTransformation: + def setup_method(self): coords = [ [0, 0, 0], [0.375, 0.375, 0.375], @@ -109,8 +108,8 @@ def test_as_from_dict(self): assert struct.formula == "Na1 Li3 O4" -class TestRemoveSitesTransformation(TestCase): - def setUp(self): +class TestRemoveSitesTransformation: + def setup_method(self): coords = [ [0, 0, 0], [0.375, 0.375, 0.375], @@ -141,8 +140,8 @@ def test_as_from_dict(self): assert struct.formula == "Li2 O4" -class TestInsertSitesTransformation(TestCase): - def setUp(self): +class TestInsertSitesTransformation: + def setup_method(self): coords = [ [0, 0, 0], [0.375, 0.375, 0.375], @@ -178,8 +177,8 @@ def test_as_from_dict(self): assert struct.formula == "Li4 Mn1 Fe1 O4" -class TestPartialRemoveSitesTransformation(TestCase): - def setUp(self): +class TestPartialRemoveSitesTransformation: + def setup_method(self): coords = [ [0, 0, 0], [0.375, 0.375, 0.375], @@ -279,7 +278,7 @@ def test_apply_transformation(self): class TestRadialSiteDistortionTransformation: - def setUp(self): + def setup_method(self): self.molecule = Molecule( species=["C", "H", "H", "H", "H", "H", "H", "H", "H", "H", "H", "H", "H"], coords=[ diff --git a/tests/transformations/test_standard_transformations.py b/tests/transformations/test_standard_transformations.py index 0074eece962..653d58ae7ec 100644 --- a/tests/transformations/test_standard_transformations.py +++ b/tests/transformations/test_standard_transformations.py @@ -41,8 +41,8 @@ enumlib_present = which("enum.x") and which("makestr.x") -class TestRotationTransformations(TestCase): - def setUp(self): +class TestRotationTransformations: + def setup_method(self): coords = [[0, 0, 0], [0.75, 0.5, 0.75]] lattice = [ [3.8401979337, 0, 0], @@ -109,7 +109,7 @@ def test_fractional_substitution(self): class TestSupercellTransformation(TestCase): - def setUp(self): + def setup_method(self): coords = [[0, 0, 0], [0.75, 0.75, 0.75], [0.5, 0.5, 0.5], [0.25, 0.25, 0.25]] lattice = [ [3.8401979337, 0, 0], From 6f2bfe923efae67c5ff902c7864b8207d34e8655 Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Wed, 4 Dec 2024 23:20:03 +0800 Subject: [PATCH 11/31] revert all changes to before global replace PymatgenTest --- src/pymatgen/util/testing/__init__.py | 127 +----------------- tests/alchemy/test_filters.py | 15 ++- tests/alchemy/test_materials.py | 8 +- tests/alchemy/test_transmuters.py | 6 +- .../connectivity/test_connected_components.py | 4 +- .../connectivity/test_environment_nodes.py | 3 +- .../test_structure_connectivity.py | 4 +- .../test_chemenv_strategies.py | 3 +- .../test_coordination_geometries.py | 3 +- .../test_coordination_geometry_finder.py | 6 +- .../test_read_write.py | 6 +- .../test_structure_environments.py | 4 +- .../coordination_environments/test_voronoi.py | 4 +- .../coordination_environments/test_weights.py | 4 +- .../chemenv/utils/test_chemenv_config.py | 4 +- .../utils/test_coordination_geometry_utils.py | 5 +- .../chemenv/utils/test_graph_utils.py | 5 +- .../analysis/chemenv/utils/test_math_utils.py | 3 +- tests/analysis/diffraction/test_neutron.py | 3 +- tests/analysis/diffraction/test_tem.py | 3 +- tests/analysis/diffraction/test_xrd.py | 3 +- tests/analysis/elasticity/test_elastic.py | 18 +-- tests/analysis/elasticity/test_strain.py | 13 +- tests/analysis/elasticity/test_stress.py | 5 +- .../ferroelectricity/test_polarization.py | 14 +- .../interfaces/test_coherent_interface.py | 11 +- tests/analysis/interfaces/test_zsl.py | 5 +- tests/analysis/magnetism/test_analyzer.py | 2 +- tests/analysis/magnetism/test_heisenberg.py | 2 +- tests/analysis/magnetism/test_jahnteller.py | 2 +- tests/analysis/solar/test_slme.py | 4 +- .../test_dopant_predictor.py | 2 +- .../structure_prediction/test_substitutor.py | 4 +- .../test_volume_predictor.py | 4 +- tests/analysis/test_adsorption.py | 5 +- tests/analysis/test_bond_dissociation.py | 5 +- tests/analysis/test_bond_valence.py | 8 +- tests/analysis/test_chempot_diagram.py | 6 +- tests/analysis/test_cost.py | 8 +- tests/analysis/test_dimensionality.py | 10 +- tests/analysis/test_disorder.py | 3 +- tests/analysis/test_eos.py | 5 +- tests/analysis/test_ewald.py | 8 +- tests/analysis/test_fragmenter.py | 6 +- tests/analysis/test_functional_groups.py | 5 +- tests/analysis/test_graphs.py | 11 +- tests/analysis/test_interface_reactions.py | 6 +- tests/analysis/test_local_env.py | 56 ++++---- tests/analysis/test_molecule_matcher.py | 16 +-- tests/analysis/test_nmr.py | 5 +- tests/analysis/test_phase_diagram.py | 20 +-- tests/analysis/test_piezo.py | 5 +- tests/analysis/test_piezo_sensitivity.py | 6 +- tests/analysis/test_pourbaix_diagram.py | 10 +- tests/analysis/test_prototypes.py | 3 +- .../test_quasi_harmonic_debye_approx.py | 4 +- tests/analysis/test_quasirrho.py | 2 +- tests/analysis/test_reaction_calculator.py | 4 +- tests/analysis/test_structure_analyzer.py | 12 +- tests/analysis/test_structure_matcher.py | 6 +- tests/analysis/test_surface_analysis.py | 18 +-- tests/analysis/test_transition_state.py | 4 +- tests/analysis/test_wulff.py | 6 +- tests/analysis/test_xps.py | 4 +- tests/analysis/topological/test_spillage.py | 4 +- tests/analysis/xas/test_spectrum.py | 6 +- tests/apps/battery/test_analyzer.py | 6 +- tests/apps/battery/test_conversion_battery.py | 2 +- tests/apps/battery/test_insertion_battery.py | 2 +- tests/apps/battery/test_plotter.py | 2 +- tests/apps/borg/test_hive.py | 6 +- tests/command_line/test_bader_caller.py | 8 +- tests/command_line/test_critic2_caller.py | 5 +- tests/command_line/test_enumlib_caller.py | 4 +- tests/command_line/test_gulp_caller.py | 17 +-- tests/command_line/test_mcsqs_caller.py | 8 +- tests/command_line/test_vampire_caller.py | 6 +- tests/core/test_composition.py | 5 +- tests/core/test_interface.py | 14 +- tests/core/test_ion.py | 2 +- tests/core/test_lattice.py | 5 +- tests/core/test_libxcfunc.py | 3 +- tests/core/test_molecular_orbitals.py | 3 +- tests/core/test_operations.py | 7 +- tests/core/test_periodic_table.py | 7 +- tests/core/test_sites.py | 9 +- tests/core/test_spectrum.py | 5 +- tests/core/test_structure.py | 18 +-- tests/core/test_surface.py | 18 +-- tests/core/test_tensors.py | 14 +- tests/core/test_trajectory.py | 6 +- tests/core/test_units.py | 9 +- tests/core/test_xcfunc.py | 5 +- .../test_bandstructure.py | 16 +-- tests/electronic_structure/test_boltztrap.py | 2 +- tests/electronic_structure/test_boltztrap2.py | 10 +- tests/electronic_structure/test_cohp.py | 14 +- tests/electronic_structure/test_dos.py | 14 +- tests/electronic_structure/test_plotter.py | 20 +-- tests/entries/test_compatibility.py | 20 +-- tests/entries/test_computed_entries.py | 6 +- tests/entries/test_correction_calculator.py | 2 +- tests/entries/test_entry_tools.py | 8 +- tests/entries/test_exp_entries.py | 2 +- tests/ext/test_matproj.py | 14 +- tests/ext/test_optimade.py | 3 +- tests/io/abinit/test_abiobjects.py | 18 +-- tests/io/abinit/test_inputs.py | 12 +- tests/io/abinit/test_netcdf.py | 8 +- tests/io/abinit/test_pseudos.py | 8 +- tests/io/cp2k/test_inputs.py | 12 +- tests/io/cp2k/test_outputs.py | 2 +- tests/io/cp2k/test_sets.py | 4 +- tests/io/exciting/test_inputs.py | 4 +- tests/io/feff/test_inputs.py | 4 +- tests/io/feff/test_sets.py | 6 +- tests/io/lammps/test_data.py | 16 +-- tests/io/lammps/test_generators.py | 6 +- tests/io/lammps/test_inputs.py | 12 +- tests/io/lammps/test_outputs.py | 2 +- tests/io/lammps/test_utils.py | 4 +- tests/io/lobster/test_inputs.py | 8 +- tests/io/lobster/test_lobsterenv.py | 2 +- tests/io/lobster/test_outputs.py | 50 +++---- tests/io/pwmat/test_inputs.py | 10 +- tests/io/pwmat/test_outputs.py | 10 +- tests/io/qchem/test_inputs.py | 4 +- tests/io/qchem/test_outputs.py | 4 +- tests/io/qchem/test_sets.py | 16 +-- tests/io/qchem/test_utils.py | 4 +- tests/io/test_adf.py | 4 +- tests/io/test_atat.py | 4 +- tests/io/test_babel.py | 2 +- tests/io/test_cif.py | 10 +- tests/io/test_core.py | 8 +- tests/io/test_cssr.py | 2 +- tests/io/test_fiesta.py | 4 +- tests/io/test_gaussian.py | 4 +- tests/io/test_lmto.py | 14 +- tests/io/test_nwchem.py | 4 +- tests/io/test_packmol.py | 4 +- tests/io/test_phonopy.py | 10 +- tests/io/test_pwscf.py | 8 +- tests/io/test_shengbte.py | 6 +- tests/io/test_template_input.py | 4 +- tests/io/test_wannier90.py | 6 +- tests/io/test_xcrysden.py | 5 +- tests/io/test_xr.py | 2 +- tests/io/test_xyz.py | 2 +- tests/io/test_zeopp.py | 14 +- tests/io/vasp/test_inputs.py | 18 +-- tests/io/vasp/test_optics.py | 4 +- tests/io/vasp/test_outputs.py | 36 ++--- tests/io/vasp/test_sets.py | 94 ++++++------- tests/io/xtb/test_inputs.py | 4 +- tests/io/xtb/test_outputs.py | 4 +- tests/optimization/test_linear_assignment.py | 8 +- tests/optimization/test_neighbors.py | 5 +- tests/phonon/test_bandstructure.py | 6 +- tests/phonon/test_dos.py | 10 +- tests/phonon/test_gruneisen.py | 10 +- tests/phonon/test_ir_spectra.py | 6 +- tests/phonon/test_plotter.py | 6 +- tests/phonon/test_thermal_displacements.py | 6 +- tests/symmetry/test_analyzer.py | 8 +- tests/symmetry/test_kpath_hin.py | 3 +- tests/symmetry/test_kpath_lm.py | 4 +- tests/symmetry/test_kpath_sc.py | 4 +- tests/symmetry/test_kpaths.py | 4 +- tests/symmetry/test_maggroups.py | 5 +- tests/symmetry/test_settings.py | 2 +- tests/symmetry/test_site_symmetries.py | 6 +- .../test_advanced_transformations.py | 24 ++-- .../test_site_transformations.py | 28 ++-- .../test_standard_transformations.py | 6 +- tests/util/test_coord.py | 6 +- tests/util/test_io.py | 4 +- tests/util/test_plotting.py | 3 +- tests/util/test_provenance.py | 5 +- tests/vis/test_plotters.py | 8 +- 180 files changed, 764 insertions(+), 829 deletions(-) diff --git a/src/pymatgen/util/testing/__init__.py b/src/pymatgen/util/testing/__init__.py index af6b0c61667..acf83e32c93 100644 --- a/src/pymatgen/util/testing/__init__.py +++ b/src/pymatgen/util/testing/__init__.py @@ -35,15 +35,8 @@ FAKE_POTCAR_DIR = f"{VASP_IN_DIR}/fake_potcars" -class MatSciTest: - """TODO: name might need discussion. - - TODO: finish docstring - - TODO: reduce code duplicate - - TODO: add deprecation warning - """ +class PymatgenTest(TestCase): + """Extends unittest.TestCase with several assert methods for array and str comparison.""" # dict of lazily-loaded test structures (initialized to None) TEST_STRUCTURES: ClassVar[dict[str | Path, Structure | None]] = dict.fromkeys(STRUCTURES_DIR.glob("*")) @@ -156,119 +149,3 @@ def assert_msonable(self, obj: MSONable, test_is_subclass: bool = True) -> str: if not issubclass(type(round_trip), type(obj)): raise TypeError(f"{type(round_trip)} != {type(obj)}") return json_str - - -class PymatgenTest(TestCase): - """Extends unittest.TestCase with several assert methods for array and str comparison. - - Deprecated: please use `MatSciTest` instead (migrate from `unittest` to `pytest`). - """ - - # dict of lazily-loaded test structures (initialized to None) - TEST_STRUCTURES: ClassVar[dict[str | Path, Structure | None]] = dict.fromkeys(STRUCTURES_DIR.glob("*")) - - @pytest.fixture(autouse=True) # make all tests run a in a temporary directory accessible via self.tmp_path - def _tmp_dir(self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None: - # https://pytest.org/en/latest/how-to/unittest.html#using-autouse-fixtures-and-accessing-other-fixtures - monkeypatch.chdir(tmp_path) # change to pytest-provided temporary directory - self.tmp_path = tmp_path - - @classmethod - def get_structure(cls, name: str) -> Structure: - """ - Lazily load a structure from pymatgen/util/structures. - - Args: - name (str): Name of structure file. - - Returns: - Structure - """ - return MatSciTest.get_structure(name) - - @staticmethod - def assert_str_content_equal(actual, expected): - """Test if two strings are equal, ignoring things like trailing spaces, etc.""" - MatSciTest.assert_str_content_equal(actual, expected) - - def serialize_with_pickle(self, objects: Any, protocols: Sequence[int] | None = None, test_eq: bool = True): - """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. - - Args: - 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. - """ - # Build a list even when we receive a single object. - got_single_object = False - if not isinstance(objects, list | tuple): - got_single_object = True - objects = [objects] - - protocols = protocols or [pickle.HIGHEST_PROTOCOL] - - # This list will contain the objects deserialized with the different protocols. - objects_by_protocol, errors = [], [] - - for protocol in protocols: - # Serialize and deserialize the object. - tmpfile = self.tmp_path / f"tempfile_{protocol}.pkl" - - try: - with open(tmpfile, "wb") as file: - pickle.dump(objects, file, protocol=protocol) - except Exception as exc: - errors.append(f"pickle.dump with {protocol=} raised:\n{exc}") - continue - - try: - with open(tmpfile, "rb") as file: - unpickled_objs = pickle.load(file) # noqa: S301 - except Exception as exc: - errors.append(f"pickle.load with {protocol=} raised:\n{exc}") - continue - - # Test for equality - if test_eq: - for orig, unpickled in zip(objects, unpickled_objs, strict=True): - if orig != unpickled: - raise ValueError( - f"Unpickled and original objects are unequal for {protocol=}\n{orig=}\n{unpickled=}" - ) - - # Save the deserialized objects and test for equality. - objects_by_protocol.append(unpickled_objs) - - if errors: - raise ValueError("\n".join(errors)) - - # Return nested list so that client code can perform additional tests. - if got_single_object: - return [o[0] for o in objects_by_protocol] - return objects_by_protocol - - def assert_msonable(self, obj: MSONable, test_is_subclass: bool = True) -> str: - """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. - """ - if test_is_subclass and not isinstance(obj, MSONable): - raise TypeError("obj is not MSONable") - if obj.as_dict() != type(obj).from_dict(obj.as_dict()).as_dict(): - raise ValueError("obj could not be reconstructed accurately from its dict representation.") - json_str = json.dumps(obj.as_dict(), cls=MontyEncoder) - round_trip = json.loads(json_str, cls=MontyDecoder) - if not issubclass(type(round_trip), type(obj)): - raise TypeError(f"{type(round_trip)} != {type(obj)}") - return json_str diff --git a/tests/alchemy/test_filters.py b/tests/alchemy/test_filters.py index 53c1c517a0c..16737ae67fa 100644 --- a/tests/alchemy/test_filters.py +++ b/tests/alchemy/test_filters.py @@ -1,6 +1,7 @@ from __future__ import annotations import json +from unittest import TestCase from monty.json import MontyDecoder @@ -13,10 +14,10 @@ from pymatgen.alchemy.transmuters import StandardTransmuter from pymatgen.analysis.structure_matcher import StructureMatcher from pymatgen.core import Lattice, Species, Structure -from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest -class TestContainsSpecieFilter: +class TestContainsSpecieFilter(PymatgenTest): def test_filtering(self): coords = [[0, 0, 0], [0.75, 0.75, 0.75], [0.5, 0.5, 0.5], [0.25, 0.25, 0.25]] lattice = Lattice([[3.0, 0.0, 0.0], [1.0, 3.0, 0], [0, -2.0, 3.0]]) @@ -51,7 +52,7 @@ def test_as_from_dict(self): assert isinstance(ContainsSpecieFilter.from_dict(dct), ContainsSpecieFilter) -class TestSpecieProximityFilter(MatSciTest): +class TestSpecieProximityFilter(PymatgenTest): def test_filter(self): struct = self.get_structure("Li10GeP2S12") sf = SpecieProximityFilter({"Li": 1}) @@ -69,8 +70,8 @@ def test_as_from_dict(self): assert isinstance(SpecieProximityFilter.from_dict(dct), SpecieProximityFilter) -class TestRemoveDuplicatesFilter: - def setup_method(self): +class TestRemoveDuplicatesFilter(TestCase): + def setUp(self): with open(f"{TEST_FILES_DIR}/entries/TiO2_entries.json") as file: entries = json.load(file, cls=MontyDecoder) self._struct_list = [entry.structure for entry in entries] @@ -88,8 +89,8 @@ def test_as_from_dict(self): assert isinstance(RemoveDuplicatesFilter().from_dict(dct), RemoveDuplicatesFilter) -class TestRemoveExistingFilter: - def setup_method(self): +class TestRemoveExistingFilter(TestCase): + def setUp(self): with open(f"{TEST_FILES_DIR}/entries/TiO2_entries.json") as file: entries = json.load(file, cls=MontyDecoder) self._struct_list = [entry.structure for entry in entries] diff --git a/tests/alchemy/test_materials.py b/tests/alchemy/test_materials.py index 73cd79161fd..25b8cc74ad2 100644 --- a/tests/alchemy/test_materials.py +++ b/tests/alchemy/test_materials.py @@ -16,14 +16,14 @@ SupercellTransformation, ) from pymatgen.util.provenance import StructureNL -from pymatgen.util.testing import FAKE_POTCAR_DIR, TEST_FILES_DIR, MatSciTest +from pymatgen.util.testing import FAKE_POTCAR_DIR, TEST_FILES_DIR, PymatgenTest TEST_DIR = f"{TEST_FILES_DIR}/alchemy" -class TestTransformedStructure: - def setup_method(self): - structure = MatSciTest.get_structure("LiFePO4") +class TestTransformedStructure(PymatgenTest): + def setUp(self): + structure = PymatgenTest.get_structure("LiFePO4") self.structure = structure trafos = [SubstitutionTransformation({"Li": "Na"})] self.trans = TransformedStructure(structure, trafos) diff --git a/tests/alchemy/test_transmuters.py b/tests/alchemy/test_transmuters.py index 17cabc9d930..653a98c5326 100644 --- a/tests/alchemy/test_transmuters.py +++ b/tests/alchemy/test_transmuters.py @@ -8,10 +8,10 @@ RemoveSpeciesTransformation, SubstitutionTransformation, ) -from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR +from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, PymatgenTest -class TestCifTransmuter: +class TestCifTransmuter(PymatgenTest): def test_init(self): trafos = [SubstitutionTransformation({"Fe": "Mn", "Fe2+": "Mn2+"})] tsc = CifTransmuter.from_filenames([f"{TEST_FILES_DIR}/cif/MultiStructure.cif"], trafos) @@ -22,7 +22,7 @@ def test_init(self): assert expected == els -class TestPoscarTransmuter: +class TestPoscarTransmuter(PymatgenTest): def test_init(self): trafos = [SubstitutionTransformation({"Fe": "Mn"})] tsc = PoscarTransmuter.from_filenames([f"{VASP_IN_DIR}/POSCAR", f"{VASP_IN_DIR}/POSCAR"], trafos) diff --git a/tests/analysis/chemenv/connectivity/test_connected_components.py b/tests/analysis/chemenv/connectivity/test_connected_components.py index 311f60381fa..fc9e561c57e 100644 --- a/tests/analysis/chemenv/connectivity/test_connected_components.py +++ b/tests/analysis/chemenv/connectivity/test_connected_components.py @@ -20,12 +20,12 @@ from pymatgen.core.lattice import Lattice from pymatgen.core.sites import PeriodicSite from pymatgen.core.structure import Structure -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest __author__ = "waroquiers" -class TestConnectedComponent: +class TestConnectedComponent(PymatgenTest): def test_init(self): # Generic connected component not using EnvironmentNodes # (as_dict won't work on such a ConnectedComponent instance) diff --git a/tests/analysis/chemenv/connectivity/test_environment_nodes.py b/tests/analysis/chemenv/connectivity/test_environment_nodes.py index c009a735c81..60af01acff7 100644 --- a/tests/analysis/chemenv/connectivity/test_environment_nodes.py +++ b/tests/analysis/chemenv/connectivity/test_environment_nodes.py @@ -3,6 +3,7 @@ import json from pymatgen.analysis.chemenv.connectivity.environment_nodes import EnvironmentNode +from pymatgen.util.testing import PymatgenTest try: import bson @@ -12,7 +13,7 @@ __author__ = "waroquiers" -class TestEnvironmentNodes: +class TestEnvironmentNodes(PymatgenTest): def test_equal(self): struct = self.get_structure("SiO2") en = EnvironmentNode(central_site=struct[0], i_central_site=0, ce_symbol="T:4") diff --git a/tests/analysis/chemenv/connectivity/test_structure_connectivity.py b/tests/analysis/chemenv/connectivity/test_structure_connectivity.py index bb0452bb747..37f8da4b98a 100644 --- a/tests/analysis/chemenv/connectivity/test_structure_connectivity.py +++ b/tests/analysis/chemenv/connectivity/test_structure_connectivity.py @@ -9,12 +9,12 @@ LightStructureEnvironments, StructureEnvironments, ) -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest __author__ = "waroquiers" -class TestStructureConnectivity: +class TestStructureConnectivity(PymatgenTest): def test_serialization(self): BaTiO3_se_fpath = f"{TEST_FILES_DIR}/analysis/chemenv/structure_environments/se_mp-5020.json" with open(BaTiO3_se_fpath) as file: diff --git a/tests/analysis/chemenv/coordination_environments/test_chemenv_strategies.py b/tests/analysis/chemenv/coordination_environments/test_chemenv_strategies.py index 7c83da588b8..64516b22c41 100644 --- a/tests/analysis/chemenv/coordination_environments/test_chemenv_strategies.py +++ b/tests/analysis/chemenv/coordination_environments/test_chemenv_strategies.py @@ -10,11 +10,12 @@ DistanceCutoffFloat, SimplestChemenvStrategy, ) +from pymatgen.util.testing import PymatgenTest __author__ = "waroquiers" -class TestStrategyOptions: +class TestStrategyOptions(PymatgenTest): def test_options(self): # DistanceCutoffFloat with pytest.raises(ValueError, match=r"Distance cutoff should be between 1 and \+infinity"): diff --git a/tests/analysis/chemenv/coordination_environments/test_coordination_geometries.py b/tests/analysis/chemenv/coordination_environments/test_coordination_geometries.py index 30d54b9657b..18fc1675835 100644 --- a/tests/analysis/chemenv/coordination_environments/test_coordination_geometries.py +++ b/tests/analysis/chemenv/coordination_environments/test_coordination_geometries.py @@ -11,6 +11,7 @@ ExplicitPermutationsAlgorithm, SeparationPlane, ) +from pymatgen.util.testing import PymatgenTest __author__ = "waroquiers" @@ -22,7 +23,7 @@ def __init__(self, coords): self.coords = coords -class TestCoordinationGeometries: +class TestCoordinationGeometries(PymatgenTest): def test_algorithms(self): expl_algo = ExplicitPermutationsAlgorithm(permutations=[[0, 1, 2], [1, 2, 3]]) expl_algo2 = ExplicitPermutationsAlgorithm.from_dict(expl_algo.as_dict()) diff --git a/tests/analysis/chemenv/coordination_environments/test_coordination_geometry_finder.py b/tests/analysis/chemenv/coordination_environments/test_coordination_geometry_finder.py index 8e8b470b753..01aedf2d245 100644 --- a/tests/analysis/chemenv/coordination_environments/test_coordination_geometry_finder.py +++ b/tests/analysis/chemenv/coordination_environments/test_coordination_geometry_finder.py @@ -19,15 +19,15 @@ symmetry_measure, ) from pymatgen.core.structure import Lattice, Structure -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest __author__ = "waroquiers" json_dir = f"{TEST_FILES_DIR}/analysis/chemenv/json" -class TestCoordinationGeometryFinder: - def setup_method(self): +class TestCoordinationGeometryFinder(PymatgenTest): + def setUp(self): self.lgf = LocalGeometryFinder() self.lgf.setup_parameters( centering_type="standard", diff --git a/tests/analysis/chemenv/coordination_environments/test_read_write.py b/tests/analysis/chemenv/coordination_environments/test_read_write.py index cca5a8f19b0..640770fccad 100644 --- a/tests/analysis/chemenv/coordination_environments/test_read_write.py +++ b/tests/analysis/chemenv/coordination_environments/test_read_write.py @@ -22,7 +22,7 @@ ) from pymatgen.analysis.chemenv.coordination_environments.voronoi import DetailedVoronoiContainer from pymatgen.core.structure import Structure -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest __author__ = "waroquiers" @@ -30,9 +30,9 @@ struct_env_dir = f"{TEST_FILES_DIR}/analysis/chemenv/structure_environments" -class TestReadWriteChemenv: +class TestReadWriteChemenv(PymatgenTest): @classmethod - def setup_class(cls): + def setUpClass(cls): cls.lgf = LocalGeometryFinder() cls.lgf.setup_parameters(centering_type="standard") diff --git a/tests/analysis/chemenv/coordination_environments/test_structure_environments.py b/tests/analysis/chemenv/coordination_environments/test_structure_environments.py index 4128b3e0265..3f8bde41636 100644 --- a/tests/analysis/chemenv/coordination_environments/test_structure_environments.py +++ b/tests/analysis/chemenv/coordination_environments/test_structure_environments.py @@ -17,14 +17,14 @@ StructureEnvironments, ) from pymatgen.core import Species, Structure -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest __author__ = "waroquiers" TEST_DIR = f"{TEST_FILES_DIR}/analysis/chemenv/structure_environments" -class TestStructureEnvironments: +class TestStructureEnvironments(PymatgenTest): def test_structure_environments(self): with open(f"{TEST_DIR}/se_mp-7000.json") as file: dct = json.load(file) diff --git a/tests/analysis/chemenv/coordination_environments/test_voronoi.py b/tests/analysis/chemenv/coordination_environments/test_voronoi.py index 6e5a2f10779..492cc00df36 100644 --- a/tests/analysis/chemenv/coordination_environments/test_voronoi.py +++ b/tests/analysis/chemenv/coordination_environments/test_voronoi.py @@ -5,14 +5,14 @@ from pymatgen.analysis.chemenv.coordination_environments.voronoi import DetailedVoronoiContainer from pymatgen.core.lattice import Lattice from pymatgen.core.structure import Structure -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest __author__ = "waroquiers" img_files_dir = f"{TEST_FILES_DIR}/analysis/chemenv/images" -class TestVoronoiContainer: +class TestVoronoiContainer(PymatgenTest): def test_voronoi(self): # Define a cubic lattice and a list of species (to be used for the fake structures) cubic_lattice = Lattice.cubic(10) diff --git a/tests/analysis/chemenv/coordination_environments/test_weights.py b/tests/analysis/chemenv/coordination_environments/test_weights.py index 56cffa85a00..6a5b2ffe50a 100644 --- a/tests/analysis/chemenv/coordination_environments/test_weights.py +++ b/tests/analysis/chemenv/coordination_environments/test_weights.py @@ -16,7 +16,7 @@ SelfCSMNbSetWeight, ) from pymatgen.analysis.chemenv.coordination_environments.structure_environments import StructureEnvironments -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest __author__ = "waroquiers" @@ -39,7 +39,7 @@ class DummyVoronoiContainer: pass -class StrategyWeights: +class StrategyWeights(PymatgenTest): def test_angle_weight(self): fake_nb_set = FakeNbSet() dummy_se = DummyStructureEnvironments() diff --git a/tests/analysis/chemenv/utils/test_chemenv_config.py b/tests/analysis/chemenv/utils/test_chemenv_config.py index 3d495f2467f..bea8a66770f 100644 --- a/tests/analysis/chemenv/utils/test_chemenv_config.py +++ b/tests/analysis/chemenv/utils/test_chemenv_config.py @@ -2,14 +2,14 @@ from pymatgen.analysis.chemenv.utils.chemenv_config import ChemEnvConfig from pymatgen.core import SETTINGS -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest __author__ = "waroquiers" config_file_dir = f"{TEST_FILES_DIR}/analysis/chemenv/config" -class TestChemenvConfig: +class TestChemenvConfig(PymatgenTest): def test_chemenv_config(self): config = ChemEnvConfig() diff --git a/tests/analysis/chemenv/utils/test_coordination_geometry_utils.py b/tests/analysis/chemenv/utils/test_coordination_geometry_utils.py index 7772e46384a..d7cbc5b7f19 100644 --- a/tests/analysis/chemenv/utils/test_coordination_geometry_utils.py +++ b/tests/analysis/chemenv/utils/test_coordination_geometry_utils.py @@ -7,12 +7,13 @@ from pytest import approx from pymatgen.analysis.chemenv.utils.coordination_geometry_utils import Plane +from pymatgen.util.testing import PymatgenTest __author__ = "David Waroquiers" -class TestPlanesUtils: - def setup_method(self): +class TestPlanesUtils(PymatgenTest): + def setUp(self): # Test of plane 4x + 2y - 4z + 3 = 0 (used in most test cases) self.expected_coefficients = np.array([4, 2, -4, 3], float) self.p1 = np.array([0, 0, 0.75]) diff --git a/tests/analysis/chemenv/utils/test_graph_utils.py b/tests/analysis/chemenv/utils/test_graph_utils.py index a936a7a5d26..b5f32fe7e94 100644 --- a/tests/analysis/chemenv/utils/test_graph_utils.py +++ b/tests/analysis/chemenv/utils/test_graph_utils.py @@ -5,6 +5,7 @@ from pymatgen.analysis.chemenv.connectivity.environment_nodes import EnvironmentNode from pymatgen.analysis.chemenv.utils.graph_utils import MultiGraphCycle, SimpleGraphCycle, get_delta +from pymatgen.util.testing import PymatgenTest __author__ = "waroquiers" @@ -67,7 +68,7 @@ def __lt__(self, other): return self.isite % 2 < other.isite % 2 -class TestGraphUtils: +class TestGraphUtils(PymatgenTest): def test_get_delta(self): n1 = FakeNode(3) n2 = FakeNode(7) @@ -663,7 +664,7 @@ def test_multigraph_cycle(self): assert mgc.edge_indices == edges_ref, f"Edges not equal for inodes = ({str_nodes})" -class TestEnvironmentNodesGraphUtils: +class TestEnvironmentNodesGraphUtils(PymatgenTest): def test_cycle(self): e1 = EnvironmentNode(central_site="Si", i_central_site=0, ce_symbol="T:4") e2 = EnvironmentNode(central_site="Si", i_central_site=3, ce_symbol="T:4") diff --git a/tests/analysis/chemenv/utils/test_math_utils.py b/tests/analysis/chemenv/utils/test_math_utils.py index 90e09e38d09..d3583a24851 100644 --- a/tests/analysis/chemenv/utils/test_math_utils.py +++ b/tests/analysis/chemenv/utils/test_math_utils.py @@ -16,11 +16,12 @@ smootherstep, smoothstep, ) +from pymatgen.util.testing import PymatgenTest __author__ = "waroquiers" -class TestMathUtils: +class TestMathUtils(PymatgenTest): def test_list_cartesian_product(self): list_of_lists = [[0, 1], [2, 5, 4], [5]] assert _cartesian_product(lists=list_of_lists) == [ diff --git a/tests/analysis/diffraction/test_neutron.py b/tests/analysis/diffraction/test_neutron.py index 0e7ced4628d..4de897d85d6 100644 --- a/tests/analysis/diffraction/test_neutron.py +++ b/tests/analysis/diffraction/test_neutron.py @@ -6,6 +6,7 @@ from pymatgen.analysis.diffraction.neutron import NDCalculator from pymatgen.core.lattice import Lattice from pymatgen.core.structure import Structure +from pymatgen.util.testing import PymatgenTest """ These calculated values were verified with VESTA and FullProf. @@ -19,7 +20,7 @@ __date__ = "4/19/18" -class TestNDCalculator: +class TestNDCalculator(PymatgenTest): def test_get_pattern(self): struct = self.get_structure("CsCl") c = NDCalculator(wavelength=1.54184) # CuKa radiation diff --git a/tests/analysis/diffraction/test_tem.py b/tests/analysis/diffraction/test_tem.py index e8dee624399..c8cfee3b1d5 100644 --- a/tests/analysis/diffraction/test_tem.py +++ b/tests/analysis/diffraction/test_tem.py @@ -11,6 +11,7 @@ from pymatgen.analysis.diffraction.tem import TEMCalculator from pymatgen.core.lattice import Lattice from pymatgen.core.structure import Structure +from pymatgen.util.testing import PymatgenTest __author__ = "Frank Wan, Jason Liang" __copyright__ = "Copyright 2019, The Materials Project" @@ -20,7 +21,7 @@ __date__ = "2/20/20" -class TestTEMCalculator: +class TestTEMCalculator(PymatgenTest): def test_wavelength_rel(self): # Test that the relativistic wavelength formula (for 200 kV electron beam) is correct tem_calc = TEMCalculator() diff --git a/tests/analysis/diffraction/test_xrd.py b/tests/analysis/diffraction/test_xrd.py index 4a40a24577e..997c43de42b 100644 --- a/tests/analysis/diffraction/test_xrd.py +++ b/tests/analysis/diffraction/test_xrd.py @@ -6,6 +6,7 @@ from pymatgen.analysis.diffraction.xrd import XRDCalculator from pymatgen.core.lattice import Lattice from pymatgen.core.structure import Structure +from pymatgen.util.testing import PymatgenTest __author__ = "Shyue Ping Ong" __copyright__ = "Copyright 2012, The Materials Project" @@ -15,7 +16,7 @@ __date__ = "5/22/14" -class TestXRDCalculator: +class TestXRDCalculator(PymatgenTest): def test_type_wavelength(self): """Test TypeError is raised if wavelength is unaccepted type.""" wavelength = [1.78, 2.78] # just a list diff --git a/tests/analysis/elasticity/test_elastic.py b/tests/analysis/elasticity/test_elastic.py index b654c62f073..699f97d4061 100644 --- a/tests/analysis/elasticity/test_elastic.py +++ b/tests/analysis/elasticity/test_elastic.py @@ -27,13 +27,13 @@ from pymatgen.core.structure import Structure from pymatgen.core.tensors import Tensor from pymatgen.core.units import FloatWithUnit -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest TEST_DIR = f"{TEST_FILES_DIR}/analysis/elasticity" -class TestElasticTensor: - def setup_method(self): +class TestElasticTensor(PymatgenTest): + def setUp(self): self.voigt_1 = [ [59.33, 28.08, 28.08, 0, 0, 0], [28.08, 59.31, 28.07, 0, 0, 0], @@ -263,8 +263,8 @@ def test_energy_density(self): ) -class TestElasticTensorExpansion: - def setup_method(self): +class TestElasticTensorExpansion(PymatgenTest): + def setUp(self): with open(f"{TEST_DIR}/test_toec_data.json") as file: self.data_dict = json.load(file) self.strains = [Strain(sm) for sm in self.data_dict["strains"]] @@ -364,8 +364,8 @@ def test_get_yield_stress(self): self.exp_cu_4.get_yield_stress([1, 0, 0]) -class TestNthOrderElasticTensor: - def setup_method(self): +class TestNthOrderElasticTensor(PymatgenTest): + def setUp(self): with open(f"{TEST_DIR}/test_toec_data.json") as file: self.data_dict = json.load(file) self.strains = [Strain(sm) for sm in self.data_dict["strains"]] @@ -401,10 +401,10 @@ def test_energy_density(self): self.c3.energy_density(self.strains[0]) -class TestDiffFit: +class TestDiffFit(PymatgenTest): """Test various functions related to diff fitting.""" - def setup_method(self): + def setUp(self): with open(f"{TEST_DIR}/test_toec_data.json") as file: self.data_dict = json.load(file) self.strains = [Strain(sm) for sm in self.data_dict["strains"]] diff --git a/tests/analysis/elasticity/test_strain.py b/tests/analysis/elasticity/test_strain.py index e7198cdd231..9679fb367cd 100644 --- a/tests/analysis/elasticity/test_strain.py +++ b/tests/analysis/elasticity/test_strain.py @@ -7,10 +7,11 @@ from pymatgen.analysis.elasticity.strain import Deformation, DeformedStructureSet, Strain, convert_strain_to_deformation from pymatgen.core.structure import Structure from pymatgen.core.tensors import Tensor +from pymatgen.util.testing import PymatgenTest -class TestDeformation: - def setup_method(self): +class TestDeformation(PymatgenTest): + def setUp(self): self.norm_defo = Deformation.from_index_amount((0, 0), 0.02) self.ind_defo = Deformation.from_index_amount((0, 1), 0.02) self.non_ind_defo = Deformation([[1, 0.02, 0.02], [0, 1, 0], [0, 0, 1]]) @@ -80,8 +81,8 @@ def test_apply_to_structure(self): assert_allclose(new_coord, defo_coord) -class TestStrain: - def setup_method(self): +class TestStrain(PymatgenTest): + def setUp(self): self.norm_str = Strain.from_deformation([[1.02, 0, 0], [0, 1, 0], [0, 0, 1]]) self.ind_str = Strain.from_deformation([[1, 0.02, 0], [0, 1, 0], [0, 0, 1]]) @@ -141,8 +142,8 @@ def test_convert_strain_to_deformation(self): assert_allclose(defo.green_lagrange_strain, strain) -class TestDeformedStructureSet: - def setup_method(self): +class TestDeformedStructureSet(PymatgenTest): + def setUp(self): self.structure = self.get_structure("Sn") self.default_dss = DeformedStructureSet(self.structure) diff --git a/tests/analysis/elasticity/test_stress.py b/tests/analysis/elasticity/test_stress.py index 5b0225ceef1..9d1dc98ad33 100644 --- a/tests/analysis/elasticity/test_stress.py +++ b/tests/analysis/elasticity/test_stress.py @@ -7,10 +7,11 @@ from pymatgen.analysis.elasticity.strain import Deformation from pymatgen.analysis.elasticity.stress import Stress +from pymatgen.util.testing import PymatgenTest -class TestStress: - def setup_method(self): +class TestStress(PymatgenTest): + def setUp(self): self.rand_stress = Stress(np.random.default_rng().standard_normal((3, 3))) self.symm_stress = Stress([[0.51, 2.29, 2.42], [2.29, 5.14, 5.07], [2.42, 5.07, 5.33]]) self.non_symm = Stress([[0.1, 0.2, 0.3], [0.4, 0.5, 0.6], [0.2, 0.5, 0.5]]) diff --git a/tests/analysis/ferroelectricity/test_polarization.py b/tests/analysis/ferroelectricity/test_polarization.py index cfe17418561..57236ff98c4 100644 --- a/tests/analysis/ferroelectricity/test_polarization.py +++ b/tests/analysis/ferroelectricity/test_polarization.py @@ -13,7 +13,7 @@ from pymatgen.core.structure import Structure from pymatgen.io.vasp.inputs import Potcar from pymatgen.io.vasp.outputs import Outcar -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest TEST_DIR = f"{TEST_FILES_DIR}/io/vasp/fixtures/BTO_221_99_polarization" bto_folders = ["nonpolar_polarization"] @@ -38,8 +38,8 @@ ) -class TestUtils: - def setup_method(self): +class TestUtils(PymatgenTest): + def setUp(self): self.potcar = Potcar.from_file(f"{TEST_DIR}/POTCAR") self.zval_dict = {"Ba": 10, "Ti": 10, "O": 6} self.ions = ions @@ -54,8 +54,8 @@ def test_get_total_ionic_dipole(self): assert_allclose(p_ion, self.ions[-1].ravel().tolist()) -class TestPolarization: - def setup_method(self): +class TestPolarization(PymatgenTest): + def setUp(self): self.p_ions = ions self.p_ions_outcar = np.array( [ @@ -258,8 +258,8 @@ def test_smoothness(self): assert_allclose(self.smoothness_all_in_polar, smoothness) -class TestEnergyTrend: - def setup_method(self): +class TestEnergyTrend(PymatgenTest): + def setUp(self): self.energies = [ -7.97738049, -7.988621176, diff --git a/tests/analysis/interfaces/test_coherent_interface.py b/tests/analysis/interfaces/test_coherent_interface.py index 3abfb7a6ebd..e2a19a73915 100644 --- a/tests/analysis/interfaces/test_coherent_interface.py +++ b/tests/analysis/interfaces/test_coherent_interface.py @@ -1,6 +1,6 @@ from __future__ import annotations -from unittest import TestCase +import unittest from numpy.testing import assert_allclose @@ -14,11 +14,12 @@ from pymatgen.core.lattice import Lattice from pymatgen.core.structure import Structure from pymatgen.symmetry.analyzer import SpacegroupAnalyzer +from pymatgen.util.testing import PymatgenTest -class TestInterfaceBuilder: +class TestInterfaceBuilder(PymatgenTest): @classmethod - def setup_class(cls): + def setUpClass(cls): si_struct = cls.get_structure("Si") sio2_struct = cls.get_structure("SiO2") cls.si_conventional = SpacegroupAnalyzer(si_struct).get_conventional_standard_structure() @@ -50,8 +51,8 @@ def test_coherent_interface_builder(self): assert len(list(builder.get_interfaces(termination=("O2_Pmmm_1", "Si_R-3m_1")))) >= 6 -class TestCoherentInterfaceBuilder(TestCase): - def setup_method(self): +class TestCoherentInterfaceBuilder(unittest.TestCase): + def setUp(self): # build substrate & film structure basis = [[0, 0, 0], [0.25, 0.25, 0.25]] self.substrate = Structure(Lattice.cubic(a=5.431), ["Si", "Si"], basis) diff --git a/tests/analysis/interfaces/test_zsl.py b/tests/analysis/interfaces/test_zsl.py index 2f187ff9522..25ab77950e1 100644 --- a/tests/analysis/interfaces/test_zsl.py +++ b/tests/analysis/interfaces/test_zsl.py @@ -13,6 +13,7 @@ vec_area, ) from pymatgen.symmetry.analyzer import SpacegroupAnalyzer +from pymatgen.util.testing import PymatgenTest __author__ = "Shyam Dwaraknath" __copyright__ = "Copyright 2016, The Materials Project" @@ -22,8 +23,8 @@ __date__ = "2/5/16" -class TestZSLGen: - def setup_method(self): +class TestZSLGen(PymatgenTest): + def setUp(self): # Film VO2 self.film = SpacegroupAnalyzer(self.get_structure("VO2"), symprec=0.1).get_conventional_standard_structure() diff --git a/tests/analysis/magnetism/test_analyzer.py b/tests/analysis/magnetism/test_analyzer.py index e71dfadaa6d..3286409d05f 100644 --- a/tests/analysis/magnetism/test_analyzer.py +++ b/tests/analysis/magnetism/test_analyzer.py @@ -25,7 +25,7 @@ class TestCollinearMagneticStructureAnalyzer(TestCase): - def setup_method(self): + def setUp(self): self.Fe = Structure.from_file(f"{TEST_FILES_DIR}/cif/Fe.cif", primitive=True) self.LiFePO4 = Structure.from_file(f"{TEST_FILES_DIR}/cif/LiFePO4.cif", primitive=True) diff --git a/tests/analysis/magnetism/test_heisenberg.py b/tests/analysis/magnetism/test_heisenberg.py index fa46f8b91b6..248bb559227 100644 --- a/tests/analysis/magnetism/test_heisenberg.py +++ b/tests/analysis/magnetism/test_heisenberg.py @@ -13,7 +13,7 @@ class TestHeisenbergMapper(TestCase): @classmethod - def setup_class(cls): + def setUpClass(cls): cls.df = pd.read_json(f"{TEST_DIR}/mag_orderings_test_cases.json") # Good tests diff --git a/tests/analysis/magnetism/test_jahnteller.py b/tests/analysis/magnetism/test_jahnteller.py index f1938dbafe5..ac3555cce47 100644 --- a/tests/analysis/magnetism/test_jahnteller.py +++ b/tests/analysis/magnetism/test_jahnteller.py @@ -11,7 +11,7 @@ class TestJahnTeller(TestCase): - def setup_method(self): + def setUp(self): self.jt = JahnTellerAnalyzer() def test_jahn_teller_species_analysis(self): diff --git a/tests/analysis/solar/test_slme.py b/tests/analysis/solar/test_slme.py index 334e7d63a4c..3ccf3256d11 100644 --- a/tests/analysis/solar/test_slme.py +++ b/tests/analysis/solar/test_slme.py @@ -3,12 +3,12 @@ from pytest import approx from pymatgen.analysis.solar.slme import optics, slme -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest TEST_DIR = f"{TEST_FILES_DIR}/analysis/solar" -class TestSolar: +class TestSolar(PymatgenTest): def test_slme_from_vasprun(self): en, abz, dir_gap, indir_gap = optics(f"{TEST_DIR}/vasprun.xml") abz *= 100.0 diff --git a/tests/analysis/structure_prediction/test_dopant_predictor.py b/tests/analysis/structure_prediction/test_dopant_predictor.py index a88e424a9c6..f19d032624d 100644 --- a/tests/analysis/structure_prediction/test_dopant_predictor.py +++ b/tests/analysis/structure_prediction/test_dopant_predictor.py @@ -13,7 +13,7 @@ class TestDopantPrediction(TestCase): - def setup_method(self): + def setUp(self): self.tin_dioxide = Structure( [3.24, 0, 0, 0, 4.83, 0, 0, 0, 4.84], ["O", "O", "O", "O", "Sn", "Sn"], diff --git a/tests/analysis/structure_prediction/test_substitutor.py b/tests/analysis/structure_prediction/test_substitutor.py index e82117651a4..6965408afcc 100644 --- a/tests/analysis/structure_prediction/test_substitutor.py +++ b/tests/analysis/structure_prediction/test_substitutor.py @@ -20,8 +20,8 @@ def get_table(): return json.load(file) -class TestSubstitutor: - def setup_method(self): +class TestSubstitutor(PymatgenTest): + def setUp(self): self.substitutor = Substitutor(threshold=1e-3, lambda_table=get_table(), alpha=-5.0) def test_substitutor(self): diff --git a/tests/analysis/structure_prediction/test_volume_predictor.py b/tests/analysis/structure_prediction/test_volume_predictor.py index f75df75cf3a..20ecf2bd24b 100644 --- a/tests/analysis/structure_prediction/test_volume_predictor.py +++ b/tests/analysis/structure_prediction/test_volume_predictor.py @@ -10,7 +10,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/analysis/structure_prediction" -class TestRLSVolumePredictor: +class TestRLSVolumePredictor(PymatgenTest): def test_predict(self): struct = PymatgenTest.get_structure("CsCl") nacl = PymatgenTest.get_structure("CsCl") @@ -77,7 +77,7 @@ def test_modes(self): assert vol_pred.predict(cs_cl, na_cl) == approx(342.84905395082535) -class TestDLSVolumePredictor: +class TestDLSVolumePredictor(PymatgenTest): def test_predict(self): vol_pred = DLSVolumePredictor() p_fast = DLSVolumePredictor(cutoff=0.0) # for speed on compressed cells diff --git a/tests/analysis/test_adsorption.py b/tests/analysis/test_adsorption.py index 87cb73594cb..ced3948a366 100644 --- a/tests/analysis/test_adsorption.py +++ b/tests/analysis/test_adsorption.py @@ -8,10 +8,11 @@ from pymatgen.core.structure import Molecule, Structure from pymatgen.symmetry.analyzer import SpacegroupAnalyzer from pymatgen.util.coord import in_coord_list +from pymatgen.util.testing import PymatgenTest -class TestAdsorbateSiteFinder: - def setup_method(self): +class TestAdsorbateSiteFinder(PymatgenTest): + def setUp(self): self.structure = Structure.from_spacegroup("Fm-3m", Lattice.cubic(3.5), ["Ni"], [[0, 0, 0]]) lattice = Lattice.cubic(3.010) frac_coords = [ diff --git a/tests/analysis/test_bond_dissociation.py b/tests/analysis/test_bond_dissociation.py index 9ac3a059a8a..01cb71aaea6 100644 --- a/tests/analysis/test_bond_dissociation.py +++ b/tests/analysis/test_bond_dissociation.py @@ -1,6 +1,7 @@ from __future__ import annotations import platform +from unittest import TestCase import pytest from monty.serialization import loadfn @@ -11,8 +12,8 @@ TEST_DIR = f"{TEST_FILES_DIR}/analysis/bond_dissociation" -class TestBondDissociation: - def setup_method(self): +class TestBondDissociation(TestCase): + def setUp(self): pytest.importorskip("openbabel") self.PC_65_principle = loadfn(f"{TEST_DIR}/PC_65_principle.json") self.PC_65_principle["initial_molecule"] = self.PC_65_principle["initial_molecule"].as_dict() diff --git a/tests/analysis/test_bond_valence.py b/tests/analysis/test_bond_valence.py index 0be83e3b34e..a2e0db2ce0c 100644 --- a/tests/analysis/test_bond_valence.py +++ b/tests/analysis/test_bond_valence.py @@ -5,13 +5,13 @@ from pymatgen.analysis.bond_valence import BVAnalyzer, calculate_bv_sum, calculate_bv_sum_unordered from pymatgen.core import Composition, Species, Structure -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest TEST_DIR = f"{TEST_FILES_DIR}/analysis/bond_valence" -class TestBVAnalyzer: - def setup_method(self): +class TestBVAnalyzer(PymatgenTest): + def setUp(self): self.analyzer = BVAnalyzer() def test_get_valences(self): @@ -44,7 +44,7 @@ def test_get_oxi_state_structure(self): assert Species("Mn4+") in oxi_struct.composition.elements -class TestBondValenceSum: +class TestBondValenceSum(PymatgenTest): def test_calculate_bv_sum(self): struct = Structure.from_file(f"{TEST_DIR}/LiMn2O4.json") neighbors = struct.get_neighbors(struct[0], 3.0) diff --git a/tests/analysis/test_chempot_diagram.py b/tests/analysis/test_chempot_diagram.py index 1c9a7f0db64..43dfd957b0d 100644 --- a/tests/analysis/test_chempot_diagram.py +++ b/tests/analysis/test_chempot_diagram.py @@ -12,13 +12,13 @@ ) from pymatgen.core.composition import Element from pymatgen.entries.entry_tools import EntrySet -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest TEST_DIR = f"{TEST_FILES_DIR}/analysis" -class TestChemicalPotentialDiagram: - def setup_method(self): +class TestChemicalPotentialDiagram(PymatgenTest): + def setUp(self): self.entries = EntrySet.from_csv(f"{TEST_DIR}/pd_entries_test.csv") self.cpd_ternary, self.cpd_ternary_formal = ( ChemicalPotentialDiagram(entries=self.entries, default_min_limit=-25, formal_chempots=formal) diff --git a/tests/analysis/test_cost.py b/tests/analysis/test_cost.py index 074a98cd9c7..c20bed2fd54 100644 --- a/tests/analysis/test_cost.py +++ b/tests/analysis/test_cost.py @@ -1,5 +1,7 @@ from __future__ import annotations +from unittest import TestCase + from pytest import approx from pymatgen.analysis.cost import CostAnalyzer, CostDBCSV, CostDBElements @@ -8,8 +10,8 @@ TEST_DIR = f"{TEST_FILES_DIR}/analysis/cost" -class TestCostAnalyzer: - def setup_method(self): +class TestCostAnalyzer(TestCase): + def setUp(self): self.ca1 = CostAnalyzer(CostDBCSV(f"{TEST_DIR}/costdb_1.csv")) self.ca2 = CostAnalyzer(CostDBCSV(f"{TEST_DIR}/costdb_2.csv")) @@ -29,7 +31,7 @@ def test_sanity(self): assert self.ca1.get_cost_per_kg("Ag") == self.ca2.get_cost_per_kg("Ag") -class TestCostDB: +class TestCostDB(TestCase): def test_sanity(self): ca = CostAnalyzer(CostDBElements()) assert ca.get_cost_per_kg("PtO") > ca.get_cost_per_kg("MgO") diff --git a/tests/analysis/test_dimensionality.py b/tests/analysis/test_dimensionality.py index 6b5357e3134..8b99c6fd5e2 100644 --- a/tests/analysis/test_dimensionality.py +++ b/tests/analysis/test_dimensionality.py @@ -15,11 +15,11 @@ from pymatgen.analysis.graphs import StructureGraph from pymatgen.analysis.local_env import CrystalNN from pymatgen.core.structure import Structure -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest -class TestLarsenDimensionality: - def setup_method(self): +class TestLarsenDimensionality(PymatgenTest): + def setUp(self): cnn = CrystalNN() self.lifepo = cnn.get_bonded_structure(self.get_structure("LiFePO4")) self.graphite = cnn.get_bonded_structure(self.get_structure("Graphite")) @@ -114,7 +114,7 @@ def test_zero_d_to_molecule_graph(self): assert len(mol_graph.molecule) == 12 -class TestCheonDimensionality: +class TestCheonDimensionality(PymatgenTest): def test_get_dimensionality(self): struct = self.get_structure("LiFePO4") assert get_dimensionality_cheon(struct) == "intercalated ion" @@ -152,7 +152,7 @@ def test_tricky_structure(self): assert get_dimensionality_cheon(tricky_structure, larger_cell=True) == "3D" -class TestGoraiDimensionality: +class TestGoraiDimensionality(PymatgenTest): def test_get_dimensionality(self): struct = self.get_structure("LiFePO4") assert get_dimensionality_gorai(struct) == 3 diff --git a/tests/analysis/test_disorder.py b/tests/analysis/test_disorder.py index a00de0a8035..f1fbd2f58d5 100644 --- a/tests/analysis/test_disorder.py +++ b/tests/analysis/test_disorder.py @@ -4,9 +4,10 @@ from pymatgen.analysis.disorder import get_warren_cowley_parameters from pymatgen.core import Element, Structure +from pymatgen.util.testing import PymatgenTest -class TestOrderParameter: +class TestOrderParameter(PymatgenTest): def test_compute_warren_cowley_parameters(self): struct = Structure.from_prototype("CsCl", ["Mo", "W"], a=4) aij = get_warren_cowley_parameters(struct, r=3.4, dr=0.3) diff --git a/tests/analysis/test_eos.py b/tests/analysis/test_eos.py index ddcc8bae77d..9a839f8279b 100644 --- a/tests/analysis/test_eos.py +++ b/tests/analysis/test_eos.py @@ -5,10 +5,11 @@ from pytest import approx from pymatgen.analysis.eos import EOS, NumericalEOS +from pymatgen.util.testing import PymatgenTest -class TestEOS: - def setup_method(self): +class TestEOS(PymatgenTest): + def setUp(self): # Si data from Cormac self.volumes = [ 25.987454833, diff --git a/tests/analysis/test_ewald.py b/tests/analysis/test_ewald.py index 6e5ea7e5a0b..285152bb8fd 100644 --- a/tests/analysis/test_ewald.py +++ b/tests/analysis/test_ewald.py @@ -1,5 +1,7 @@ from __future__ import annotations +from unittest import TestCase + import numpy as np import pytest from pytest import approx @@ -9,8 +11,8 @@ from pymatgen.util.testing import VASP_IN_DIR -class TestEwaldSummation: - def setup_method(self): +class TestEwaldSummation(TestCase): + def setUp(self): filepath = f"{VASP_IN_DIR}/POSCAR" self.original_struct = Structure.from_file(filepath) self.struct = self.original_struct.copy() @@ -78,7 +80,7 @@ def test_as_dict(self): assert ham.as_dict() == EwaldSummation.from_dict(dct).as_dict() -class TestEwaldMinimizer: +class TestEwaldMinimizer(TestCase): def test_init(self): matrix = np.array( [ diff --git a/tests/analysis/test_fragmenter.py b/tests/analysis/test_fragmenter.py index d038babfc6d..211d7e3b7d1 100644 --- a/tests/analysis/test_fragmenter.py +++ b/tests/analysis/test_fragmenter.py @@ -8,7 +8,7 @@ from pymatgen.analysis.graphs import MoleculeGraph from pymatgen.analysis.local_env import OpenBabelNN from pymatgen.core.structure import Molecule -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest __author__ = "Samuel Blau" __email__ = "samblau1@gmail.com" @@ -17,9 +17,9 @@ TEST_DIR = f"{TEST_FILES_DIR}/analysis/local_env/fragmenter_files" -class TestFragmentMolecule: +class TestFragmentMolecule(PymatgenTest): @classmethod - def setup_class(cls): + def setUpClass(cls): cls.pc = Molecule.from_file(f"{TEST_DIR}/PC.xyz") cls.ec = Molecule.from_file(f"{TEST_DIR}/EC.xyz") cls.pos_pc = Molecule.from_file(f"{TEST_DIR}/PC.xyz") diff --git a/tests/analysis/test_functional_groups.py b/tests/analysis/test_functional_groups.py index 5b04e8290c2..a5fcb316e38 100644 --- a/tests/analysis/test_functional_groups.py +++ b/tests/analysis/test_functional_groups.py @@ -1,6 +1,7 @@ from __future__ import annotations import platform +from unittest import TestCase import pytest @@ -24,8 +25,8 @@ __credit__ = "Peiyuan Yu" -class TestFunctionalGroupExtractor: - def setup_method(self): +class TestFunctionalGroupExtractor(TestCase): + def setUp(self): self.file = f"{TEST_DIR}/func_group_test.mol" self.mol = Molecule.from_file(self.file) self.strategy = OpenBabelNN() diff --git a/tests/analysis/test_graphs.py b/tests/analysis/test_graphs.py index 476db66968b..ad42533435c 100644 --- a/tests/analysis/test_graphs.py +++ b/tests/analysis/test_graphs.py @@ -4,6 +4,7 @@ import re from glob import glob from shutil import which +from unittest import TestCase import networkx as nx import networkx.algorithms.isomorphism as iso @@ -23,7 +24,7 @@ from pymatgen.command_line.critic2_caller import Critic2Analysis from pymatgen.core import Lattice, Molecule, Site, Structure from pymatgen.core.structure import FunctionalGroups -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest try: from openbabel import openbabel @@ -45,8 +46,8 @@ TEST_DIR = f"{TEST_FILES_DIR}/analysis/graphs" -class TestStructureGraph: - def setup_method(self): +class TestStructureGraph(PymatgenTest): + def setUp(self): # trivial example, simple square lattice for testing structure = Structure(Lattice.tetragonal(5, 50), ["H"], [[0, 0, 0]]) self.square_sg = StructureGraph.from_empty_graph(structure, edge_weight_name="", edge_weight_units="") @@ -503,8 +504,8 @@ def test_sort(self): assert list(sg.graph.edges)[-2:] == [(1, 3, 0), (1, 2, 0)] -class TestMoleculeGraph: - def setup_method(self): +class TestMoleculeGraph(TestCase): + def setUp(self): cyclohexene_xyz = f"{TEST_DIR}/cyclohexene.xyz" cyclohexene = Molecule.from_file(cyclohexene_xyz) self.cyclohexene = MoleculeGraph.from_empty_graph( diff --git a/tests/analysis/test_interface_reactions.py b/tests/analysis/test_interface_reactions.py index 3f9e5939da2..a402fd34420 100644 --- a/tests/analysis/test_interface_reactions.py +++ b/tests/analysis/test_interface_reactions.py @@ -1,5 +1,7 @@ from __future__ import annotations +from unittest import TestCase + import numpy as np import pytest from matplotlib.figure import Figure as MplFigure @@ -15,8 +17,8 @@ from pymatgen.entries.computed_entries import ComputedEntry -class TestInterfaceReaction: - def setup_method(self): +class TestInterfaceReaction(TestCase): + def setUp(self): self.entries = [ ComputedEntry(Composition("Li"), 0), ComputedEntry(Composition("Mn"), 0), diff --git a/tests/analysis/test_local_env.py b/tests/analysis/test_local_env.py index 925f7da98cc..ac2ab8b099d 100644 --- a/tests/analysis/test_local_env.py +++ b/tests/analysis/test_local_env.py @@ -40,7 +40,7 @@ solid_angle, ) from pymatgen.core import Element, Lattice, Molecule, Structure -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest TEST_DIR = f"{TEST_FILES_DIR}/analysis/local_env/fragmenter_files" @@ -54,8 +54,8 @@ def test_opt_params(): assert cn_opt_params == CN_OPT_PARAMS -class TestValenceIonicRadiusEvaluator: - def setup_method(self): +class TestValenceIonicRadiusEvaluator(PymatgenTest): + def setUp(self): """Setup MgO rocksalt structure for testing Vacancy.""" mgo_latt = np.eye(3) * 4.212 mgo_specie = ["Mg"] * 4 + ["O"] * 4 @@ -89,8 +89,8 @@ def test_radii_ionic_structure(self): assert rad in {0.86, 1.26} -class TestVoronoiNN: - def setup_method(self): +class TestVoronoiNN(PymatgenTest): + def setUp(self): self.struct = self.get_structure("LiFePO4") self.nn = VoronoiNN(targets=[Element("O")]) self.s_sic = self.get_structure("Si") @@ -260,8 +260,8 @@ def test_filtered(self): assert [len(x) for x in all_nns] == [8] * 16 -class TestJmolNN: - def setup_method(self): +class TestJmolNN(PymatgenTest): + def setUp(self): self.jmol = JmolNN() self.jmol_update = JmolNN(el_radius_updates={"Li": 1}) @@ -290,7 +290,7 @@ def test_get_nn(self): assert len(self.jmol_update.get_nn(struct, 0)) == 2 -class TestIsayevNN: +class TestIsayevNN(PymatgenTest): def test_get_nn(self): inn = IsayevNN() struct = self.get_structure("LiFePO4") @@ -301,8 +301,8 @@ def test_get_nn(self): assert len(inn.get_nn(struct, 0)) == 2 -class TestOpenBabelNN: - def setup_method(self): +class TestOpenBabelNN(PymatgenTest): + def setUp(self): pytest.importorskip("openbabel") self.benzene = Molecule.from_file(f"{TEST_DIR}/../benzene.xyz") self.acetylene = Molecule.from_file(f"{TEST_FILES_DIR}/io/xyz/acetylene.xyz") @@ -333,8 +333,8 @@ def test_nn_length(self): assert strategy.get_nn_info(self.acetylene, 0)[0]["weight"] == approx(1.19, abs=1e-2) -class TestCovalentBondNN: - def setup_method(self): +class TestCovalentBondNN(PymatgenTest): + def setUp(self): self.benzene = Molecule.from_file(f"{TEST_DIR}/../benzene.xyz") self.acetylene = Molecule.from_file(f"{TEST_FILES_DIR}/io/xyz/acetylene.xyz") @@ -372,8 +372,8 @@ def test_bonded_structure(self): assert len(acetylene.graph.nodes) == 4 -class TestMiniDistNN: - def setup_method(self): +class TestMiniDistNN(PymatgenTest): + def setUp(self): self.diamond = Structure( Lattice([[2.189, 0, 1.264], [0.73, 2.064, 1.264], [0, 0, 2.528]]), ["C0+", "C0+"], @@ -485,8 +485,8 @@ def test_get_local_order_params(self): assert ops["octahedral"] == approx(0.9999995266669) -class TestMotifIdentification: - def setup_method(self): +class TestMotifIdentification(PymatgenTest): + def setUp(self): self.silicon = Structure( Lattice.cubic(5.47), ["Si", "Si", "Si", "Si", "Si", "Si", "Si", "Si"], @@ -583,8 +583,8 @@ def test_get_neighbors_of_site_with_index(self): assert len(get_neighbors_of_site_with_index(self.diamond, 0, approach="min_VIRE")) == 4 -class TestNearNeighbor: - def setup_method(self): +class TestNearNeighbor(PymatgenTest): + def setUp(self): self.diamond = Structure( Lattice([[2.189, 0, 1.264], [0.73, 2.064, 1.264], [0, 0, 2.528]]), ["C0+", "C0+"], @@ -617,8 +617,8 @@ def test_on_disorder_options(self): ) -class TestLocalStructOrderParams: - def setup_method(self): +class TestLocalStructOrderParams(PymatgenTest): + def setUp(self): self.single_bond = Structure( Lattice.cubic(10), ["H", "H", "H"], @@ -1182,8 +1182,8 @@ def test_get_order_parameters(self): ops_101.get_order_parameters(self.bcc, 0, indices_neighs=[2]) -class TestCrystalNN: - def setup_method(self): +class TestCrystalNN(PymatgenTest): + def setUp(self): self.lifepo4 = self.get_structure("LiFePO4") self.lifepo4.add_oxidation_state_by_guess() self.he_bcc = self.get_structure("He_BCC") @@ -1329,8 +1329,8 @@ def test_get_bonded_structure(self): cnn.get_bonded_structure(self.disordered_struct, 0, on_disorder="error") -class TestCutOffDictNN: - def setup_method(self): +class TestCutOffDictNN(PymatgenTest): + def setUp(self): self.diamond = Structure( Lattice([[2.189, 0, 1.264], [0.73, 2.064, 1.264], [0, 0, 2.528]]), ["C", "C"], @@ -1355,8 +1355,8 @@ def test_from_preset(self): @pytest.mark.skipif(not which("critic2"), reason="critic2 executable not present") -class TestCritic2NN: - def setup_method(self): +class TestCritic2NN(PymatgenTest): + def setUp(self): self.diamond = Structure( Lattice([[2.189, 0, 1.264], [0.73, 2.064, 1.264], [0, 0, 2.528]]), ["C", "C"], @@ -1369,8 +1369,8 @@ def test_cn(self): # assert nn.get_cn(self.diamond, 0) == 4 -class TestMetalEdgeExtender: - def setup_method(self): +class TestMetalEdgeExtender(PymatgenTest): + def setUp(self): self.LiEC = Molecule.from_file(f"{TEST_DIR}/LiEC.xyz") self.phsh = Molecule.from_file(f"{TEST_DIR}/phsh.xyz") self.phsh_graph = MoleculeGraph.from_edges( diff --git a/tests/analysis/test_molecule_matcher.py b/tests/analysis/test_molecule_matcher.py index aaffbe0a7b3..36a5db2c4c0 100644 --- a/tests/analysis/test_molecule_matcher.py +++ b/tests/analysis/test_molecule_matcher.py @@ -558,7 +558,7 @@ def test_fit(self): class TestKabschMatcherSi(TestCase): @classmethod - def setup_class(cls): + def setUpClass(cls): cls.mol1 = Molecule.from_file(f"{TEST_DIR}/Si_cluster.xyz") cls.mol_matcher = KabschMatcher(cls.mol1) @@ -595,7 +595,7 @@ def test_permuted_atoms_order(self): class TestBruteForceOrderMatcherSi(TestCase): @classmethod - def setup_class(cls): + def setUpClass(cls): cls.mol1 = Molecule.from_file(f"{TEST_DIR}/Si_cluster.xyz") cls.mol_matcher = BruteForceOrderMatcher(cls.mol1) @@ -616,7 +616,7 @@ def test_random_match(self): class TestHungarianOrderMatcherSi(TestCase): @classmethod - def setup_class(cls): + def setUpClass(cls): cls.mol1 = Molecule.from_file(f"{TEST_DIR}/Si_cluster.xyz") cls.mol_matcher = HungarianOrderMatcher(cls.mol1) @@ -655,7 +655,7 @@ def test_random_match(self): class TestGeneticOrderMatcherSi(TestCase): @classmethod - def setup_class(cls): + def setUpClass(cls): cls.mol1 = Molecule.from_file(f"{TEST_DIR}/Si_cluster.xyz") cls.mol_matcher = GeneticOrderMatcher(cls.mol1, threshold=0.3) @@ -692,7 +692,7 @@ def test_random_match(self): class TestKabschMatcherSi2O(TestCase): @classmethod - def setup_class(cls): + def setUpClass(cls): cls.mol1 = Molecule.from_file(f"{TEST_DIR}/Si2O_cluster.xyz") cls.mol_matcher = KabschMatcher(cls.mol1) @@ -727,7 +727,7 @@ def test_permuted_atoms_order(self): class TestBruteForceOrderMatcherSi2O(TestCase): @classmethod - def setup_class(cls): + def setUpClass(cls): cls.mol1 = Molecule.from_file(f"{TEST_DIR}/Si2O_cluster.xyz") cls.mol_matcher = BruteForceOrderMatcher(cls.mol1) @@ -759,7 +759,7 @@ def test_random_match(self): class TestHungarianOrderMatcherSi2O(TestCase): @classmethod - def setup_class(cls): + def setUpClass(cls): cls.mol1 = Molecule.from_file(f"{TEST_DIR}/Si2O_cluster.xyz") cls.mol_matcher = HungarianOrderMatcher(cls.mol1) @@ -791,7 +791,7 @@ def test_random_match(self): class TestGeneticOrderMatcherSi2O(TestCase): @classmethod - def setup_class(cls): + def setUpClass(cls): cls.mol1 = Molecule.from_file(f"{TEST_DIR}/Si2O_cluster.xyz") cls.mol_matcher = GeneticOrderMatcher(cls.mol1, threshold=0.3) diff --git a/tests/analysis/test_nmr.py b/tests/analysis/test_nmr.py index e90dfddc6ca..14490ec7a0c 100644 --- a/tests/analysis/test_nmr.py +++ b/tests/analysis/test_nmr.py @@ -5,9 +5,10 @@ from pytest import approx from pymatgen.analysis.nmr import ChemicalShielding, ElectricFieldGradient +from pymatgen.util.testing import PymatgenTest -class TestChemicalShieldingNotation: +class TestChemicalShieldingNotation(PymatgenTest): def test_construction(self): cs = ChemicalShielding(np.arange(9).reshape((3, 3))) assert cs.shape == (3, 3) @@ -45,7 +46,7 @@ def test_notations(self): assert mary1.kappa == approx(0.8337, abs=1e-5) -class TestElectricFieldGradient: +class TestElectricFieldGradient(PymatgenTest): def test_construction(self): efg = ElectricFieldGradient(np.arange(9).reshape((3, 3))) assert efg.shape == (3, 3) diff --git a/tests/analysis/test_phase_diagram.py b/tests/analysis/test_phase_diagram.py index f7162862aaf..934ba59fa9d 100644 --- a/tests/analysis/test_phase_diagram.py +++ b/tests/analysis/test_phase_diagram.py @@ -32,13 +32,13 @@ from pymatgen.core import Composition, DummySpecies, Element from pymatgen.entries.computed_entries import ComputedEntry from pymatgen.entries.entry_tools import EntrySet -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest TEST_DIR = f"{TEST_FILES_DIR}/analysis" class TestPDEntry(TestCase): - def setup_method(self): + def setUp(self): comp = Composition("LiFeO2") self.entry = PDEntry(comp, 53, name="mp-757614") self.gp_entry = GrandPotPDEntry(self.entry, {Element("O"): 1.5}) @@ -114,7 +114,7 @@ def test_read_csv(self): class TestTransformedPDEntry(TestCase): - def setup_method(self): + def setUp(self): comp = Composition("LiFeO2") entry = PDEntry(comp, 53) @@ -179,8 +179,8 @@ def test_normalize(self): assert norm_entry.composition == expected_comp -class TestPhaseDiagram: - def setup_method(self): +class TestPhaseDiagram(PymatgenTest): + def setUp(self): self.entries = EntrySet.from_csv(f"{TEST_DIR}/pd_entries_test.csv") self.pd = PhaseDiagram(self.entries) @@ -668,7 +668,7 @@ def test_val_err_on_no_entries(self): class TestGrandPotentialPhaseDiagram(TestCase): - def setup_method(self): + def setUp(self): self.entries = EntrySet.from_csv(f"{TEST_DIR}/pd_entries_test.csv") self.pd = GrandPotentialPhaseDiagram(self.entries, {Element("O"): -5}) self.pd6 = GrandPotentialPhaseDiagram(self.entries, {Element("O"): -6}) @@ -704,7 +704,7 @@ def test_str(self): class TestCompoundPhaseDiagram(TestCase): - def setup_method(self): + def setUp(self): self.entries = EntrySet.from_csv(f"{TEST_DIR}/pd_entries_test.csv") self.pd = CompoundPhaseDiagram(self.entries, [Composition("Li2O"), Composition("Fe2O3")]) @@ -742,7 +742,7 @@ def test_num2str(self): class TestPatchedPhaseDiagram(TestCase): - def setup_method(self): + def setUp(self): self.entries = EntrySet.from_csv(f"{TEST_DIR}/phase_diagram/reaction_entries_test.csv") # NOTE add He to test for correct behavior despite no patches involving He self.no_patch_entry = he_entry = PDEntry("He", -1.23) @@ -892,7 +892,7 @@ def test_remove_redundant_spaces(self): class TestReactionDiagram(TestCase): - def setup_method(self): + def setUp(self): self.entries = list(EntrySet.from_csv(f"{TEST_DIR}/phase_diagram/reaction_entries_test.csv").entries) for entry in self.entries: if entry.reduced_formula == "VPO5": @@ -932,7 +932,7 @@ def test_formula(self): class TestPDPlotter(TestCase): - def setup_method(self): + def setUp(self): entries = list(EntrySet.from_csv(f"{TEST_DIR}/pd_entries_test.csv")) elemental_entries = [entry for entry in entries if entry.elements == [Element("Li")]] diff --git a/tests/analysis/test_piezo.py b/tests/analysis/test_piezo.py index c03dd3f3f49..bf3eb7534c2 100644 --- a/tests/analysis/test_piezo.py +++ b/tests/analysis/test_piezo.py @@ -7,6 +7,7 @@ from numpy.testing import assert_allclose, assert_array_equal from pymatgen.analysis.piezo import PiezoTensor +from pymatgen.util.testing import PymatgenTest __author__ = "Shyam Dwaraknath" __version__ = "0.1" @@ -16,8 +17,8 @@ __date__ = "4/1/16" -class TestPiezo: - def setup_method(self): +class TestPiezo(PymatgenTest): + def setUp(self): self.piezo_struct = self.get_structure("BaNiO3") self.voigt_matrix = np.array( [ diff --git a/tests/analysis/test_piezo_sensitivity.py b/tests/analysis/test_piezo_sensitivity.py index 7c9ced77fb6..757215a30e4 100644 --- a/tests/analysis/test_piezo_sensitivity.py +++ b/tests/analysis/test_piezo_sensitivity.py @@ -17,7 +17,7 @@ rand_piezo, ) from pymatgen.io.phonopy import get_phonopy_structure -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest try: from phonopy import Phonopy @@ -34,8 +34,8 @@ TEST_DIR = f"{TEST_FILES_DIR}/analysis/piezo_sensitivity" -class TestPiezoSensitivity: - def setup_method(self): +class TestPiezoSensitivity(PymatgenTest): + def setUp(self): self.piezo_struct = self.get_structure("Pb2TiZrO6") self.IST = np.load(f"{TEST_DIR}/pztist.npy", allow_pickle=True) self.BEC = np.load(f"{TEST_DIR}/pztborn.npy", allow_pickle=True) diff --git a/tests/analysis/test_pourbaix_diagram.py b/tests/analysis/test_pourbaix_diagram.py index 65ab81aa569..22066499257 100644 --- a/tests/analysis/test_pourbaix_diagram.py +++ b/tests/analysis/test_pourbaix_diagram.py @@ -12,15 +12,15 @@ from pymatgen.core.composition import Composition from pymatgen.core.ion import Ion from pymatgen.entries.computed_entries import ComputedEntry -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest TEST_DIR = f"{TEST_FILES_DIR}/analysis/pourbaix_diagram" -class TestPourbaixEntry: +class TestPourbaixEntry(PymatgenTest): """Test all functions using a fictitious entry""" - def setup_method(self): + def setUp(self): # comp = Composition("Mn2O3") self.sol_entry = ComputedEntry("Mn2O3", 49) ion = Ion.from_formula("MnO4-") @@ -99,7 +99,7 @@ def test_get_elt_fraction(self): class TestPourbaixDiagram(TestCase): @classmethod - def setup_class(cls): + def setUpClass(cls): cls.test_data = loadfn(f"{TEST_DIR}/pourbaix_test_data.json") cls.pbx = PourbaixDiagram(cls.test_data["Zn"], filter_solids=True) cls.pbx_no_filter = PourbaixDiagram(cls.test_data["Zn"], filter_solids=False) @@ -294,7 +294,7 @@ def test_serialization(self): class TestPourbaixPlotter(TestCase): - def setup_method(self): + def setUp(self): self.test_data = loadfn(f"{TEST_DIR}/pourbaix_test_data.json") self.pd = PourbaixDiagram(self.test_data["Zn"]) self.plotter = PourbaixPlotter(self.pd) diff --git a/tests/analysis/test_prototypes.py b/tests/analysis/test_prototypes.py index 49f42675ea5..d2a16258d03 100644 --- a/tests/analysis/test_prototypes.py +++ b/tests/analysis/test_prototypes.py @@ -1,9 +1,10 @@ from __future__ import annotations from pymatgen.analysis.prototypes import AflowPrototypeMatcher +from pymatgen.util.testing import PymatgenTest -class TestAflowPrototypeMatcher: +class TestAflowPrototypeMatcher(PymatgenTest): def test_prototype_matching(self): af = AflowPrototypeMatcher() diff --git a/tests/analysis/test_quasi_harmonic_debye_approx.py b/tests/analysis/test_quasi_harmonic_debye_approx.py index 52c4cfc7aba..6c0c5816d2d 100644 --- a/tests/analysis/test_quasi_harmonic_debye_approx.py +++ b/tests/analysis/test_quasi_harmonic_debye_approx.py @@ -13,7 +13,7 @@ class TestQuasiHarmonicDebyeApprox(TestCase): - def setup_method(self): + def setUp(self): struct = Structure.from_dict( { "lattice": { @@ -138,7 +138,7 @@ def test_vibrational_free_energy(self): class TestAnharmonicQuasiHarmonicDebyeApprox(TestCase): - def setup_method(self): + def setUp(self): struct = Structure.from_str( """FCC Al 1.0 diff --git a/tests/analysis/test_quasirrho.py b/tests/analysis/test_quasirrho.py index 110382f263a..63cd0015ad4 100644 --- a/tests/analysis/test_quasirrho.py +++ b/tests/analysis/test_quasirrho.py @@ -15,7 +15,7 @@ class TestQuasiRRHO(TestCase): """Test class for QuasiRRHO""" - def setup_method(self): + def setUp(self): self.gout = GaussianOutput(f"{TEST_DIR}/quasirrho_gaufreq.log") self.linear_gout = GaussianOutput(f"{TEST_DIR}/co2.log.gz") self.qout = QCOutput(f"{TEST_DIR}/Frequency_no_equal.qout") diff --git a/tests/analysis/test_reaction_calculator.py b/tests/analysis/test_reaction_calculator.py index b4f6e4ceb1c..82fc1e03bea 100644 --- a/tests/analysis/test_reaction_calculator.py +++ b/tests/analysis/test_reaction_calculator.py @@ -288,7 +288,7 @@ def test_underdetermined_reactants(self): class TestBalancedReaction(TestCase): - def setup_method(self) -> None: + def setUp(self) -> None: rct = {"K2SO4": 3, "Na2S": 1, "Li": 24} prod = {"KNaS": 2, "K2S": 2, "Li2O": 12} self.rxn = BalancedReaction(rct, prod) @@ -335,7 +335,7 @@ def test_hash(self): class TestComputedReaction(TestCase): - def setup_method(self): + def setUp(self): dct = [ { "correction": 0, diff --git a/tests/analysis/test_structure_analyzer.py b/tests/analysis/test_structure_analyzer.py index 79c9846b1f3..a7da910eff0 100644 --- a/tests/analysis/test_structure_analyzer.py +++ b/tests/analysis/test_structure_analyzer.py @@ -18,11 +18,11 @@ ) from pymatgen.core import Element, Lattice, Structure from pymatgen.io.vasp.outputs import Xdatcar -from pymatgen.util.testing import VASP_IN_DIR, VASP_OUT_DIR +from pymatgen.util.testing import VASP_IN_DIR, VASP_OUT_DIR, PymatgenTest -class TestVoronoiAnalyzer: - def setup_method(self): +class TestVoronoiAnalyzer(PymatgenTest): + def setUp(self): self.structs = Xdatcar(f"{VASP_OUT_DIR}/XDATCAR.MD").structures self.struct = self.structs[1] self.va = VoronoiAnalyzer(cutoff=4) @@ -41,7 +41,7 @@ def test_analyze(self): class TestRelaxationAnalyzer(TestCase): - def setup_method(self): + def setUp(self): s1 = Structure.from_file(f"{VASP_IN_DIR}/POSCAR_Li2O") s2 = Structure.from_file(f"{VASP_OUT_DIR}/CONTCAR_Li2O") self.analyzer = RelaxationAnalyzer(s1, s2) @@ -62,7 +62,7 @@ def test_get_percentage_bond_dist_changes(self): assert approx(v2) == -0.009204092115527862 -class TestVoronoiConnectivity: +class TestVoronoiConnectivity(PymatgenTest): def test_connectivity_array(self): vc = VoronoiConnectivity(self.get_structure("LiFePO4")) ca = vc.connectivity_array @@ -78,7 +78,7 @@ def test_connectivity_array(self): assert_allclose(site.frac_coords, expected) -class TestMiscFunction: +class TestMiscFunction(PymatgenTest): def test_average_coordination_number(self): xdatcar = Xdatcar(f"{VASP_OUT_DIR}/XDATCAR.MD") coordination_numbers = average_coordination_number(xdatcar.structures, freq=1) diff --git a/tests/analysis/test_structure_matcher.py b/tests/analysis/test_structure_matcher.py index f39e4808f6b..5a71019ebe2 100644 --- a/tests/analysis/test_structure_matcher.py +++ b/tests/analysis/test_structure_matcher.py @@ -17,13 +17,13 @@ ) from pymatgen.core import Element, Lattice, Structure, SymmOp from pymatgen.util.coord import find_in_coord_list_pbc -from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR +from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, PymatgenTest TEST_DIR = f"{TEST_FILES_DIR}/analysis/structure_matcher" -class TestStructureMatcher: - def setup_method(self): +class TestStructureMatcher(PymatgenTest): + def setUp(self): with open(f"{TEST_FILES_DIR}/entries/TiO2_entries.json") as file: entries = json.load(file, cls=MontyDecoder) self.struct_list = [ent.structure for ent in entries] diff --git a/tests/analysis/test_surface_analysis.py b/tests/analysis/test_surface_analysis.py index b4afe4d8295..5492d9aefa6 100644 --- a/tests/analysis/test_surface_analysis.py +++ b/tests/analysis/test_surface_analysis.py @@ -9,7 +9,7 @@ from pymatgen.analysis.surface_analysis import NanoscaleStability, SlabEntry, SurfaceEnergyPlotter, WorkFunctionAnalyzer from pymatgen.entries.computed_entries import ComputedStructureEntry -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest __author__ = "Richard Tran" __copyright__ = "Copyright 2012, The Materials Project" @@ -22,8 +22,8 @@ TEST_DIR = f"{TEST_FILES_DIR}/surfaces" -class TestSlabEntry: - def setup_method(self): +class TestSlabEntry(PymatgenTest): + def setUp(self): with open(f"{TEST_DIR}/ucell_entries.txt") as file: ucell_entries = json.loads(file.read()) self.ucell_entries = ucell_entries @@ -118,8 +118,8 @@ def test_cleaned_up_slab(self): assert slab_clean.composition.reduced_composition == clean.composition.reduced_composition -class TestSurfaceEnergyPlotter: - def setup_method(self): +class TestSurfaceEnergyPlotter(PymatgenTest): + def setUp(self): entry_dict = get_entry_dict(f"{TEST_DIR}/Cu_entries.txt") self.Cu_entry_dict = entry_dict with open(f"{TEST_DIR}/ucell_entries.txt") as file: @@ -292,8 +292,8 @@ def test_surface_chempot_range_map(self): analyzer.chempot_vs_gamma_facet(hkl) -class TestWorkFunctionAnalyzer: - def setup_method(self): +class TestWorkFunctionAnalyzer(PymatgenTest): + def setUp(self): self.kwargs = { "poscar_filename": f"{TEST_DIR}/CONTCAR.relax1.gz", "locpot_filename": f"{TEST_DIR}/LOCPOT.gz", @@ -309,8 +309,8 @@ def test_is_converged(self): assert self.wf_analyzer.is_converged() -class TestNanoscaleStability: - def setup_method(self): +class TestNanoscaleStability(PymatgenTest): + def setUp(self): # Load all entries La_hcp_entry_dict = get_entry_dict(f"{TEST_DIR}/La_hcp_entries.txt") La_fcc_entry_dict = get_entry_dict(f"{TEST_DIR}/La_fcc_entries.txt") diff --git a/tests/analysis/test_transition_state.py b/tests/analysis/test_transition_state.py index 4ca1cf08339..96841bc482a 100644 --- a/tests/analysis/test_transition_state.py +++ b/tests/analysis/test_transition_state.py @@ -6,7 +6,7 @@ from numpy.testing import assert_allclose from pymatgen.analysis.transition_state import NEBAnalysis, combine_neb_plots -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest """ TODO: Modify unittest doc. @@ -23,7 +23,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/io/vasp/fixtures/neb_analysis" -class TestNEBAnalysis: +class TestNEBAnalysis(PymatgenTest): def test_run(self): neb_analysis1 = NEBAnalysis.from_dir(f"{TEST_DIR}/neb1/neb") neb_analysis1_from_dict = NEBAnalysis.from_dict(neb_analysis1.as_dict()) diff --git a/tests/analysis/test_wulff.py b/tests/analysis/test_wulff.py index b08f0b4bc39..768d079e2da 100644 --- a/tests/analysis/test_wulff.py +++ b/tests/analysis/test_wulff.py @@ -9,7 +9,7 @@ from pymatgen.core.structure import Structure from pymatgen.symmetry.analyzer import SpacegroupAnalyzer from pymatgen.util.coord import in_coord_list -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest __author__ = "Zihan Xu, Richard Tran, Balachandran Radhakrishnan" __copyright__ = "Copyright 2013, The Materials Virtual Lab" @@ -21,8 +21,8 @@ TEST_DIR = f"{TEST_FILES_DIR}/analysis/wulff" -class TestWulffShape: - def setup_method(self): +class TestWulffShape(PymatgenTest): + def setUp(self): with open(f"{TEST_DIR}/surface_samples.json") as data_file: surface_properties = json.load(data_file) diff --git a/tests/analysis/test_xps.py b/tests/analysis/test_xps.py index f2260c82717..45b250e3100 100644 --- a/tests/analysis/test_xps.py +++ b/tests/analysis/test_xps.py @@ -2,10 +2,10 @@ from pymatgen.analysis.xps import XPS from pymatgen.io.vasp import Vasprun -from pymatgen.util.testing import VASP_OUT_DIR +from pymatgen.util.testing import VASP_OUT_DIR, PymatgenTest -class TestXPS: +class TestXPS(PymatgenTest): def test_from_dos(self): vasp_run = Vasprun(f"{VASP_OUT_DIR}/vasprun.LiF.xml.gz") dos = vasp_run.complete_dos diff --git a/tests/analysis/topological/test_spillage.py b/tests/analysis/topological/test_spillage.py index 254b6002dc3..39224cdfc52 100644 --- a/tests/analysis/topological/test_spillage.py +++ b/tests/analysis/topological/test_spillage.py @@ -3,12 +3,12 @@ from pytest import approx from pymatgen.analysis.topological.spillage import SOCSpillage -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest TEST_DIR = f"{TEST_FILES_DIR}/analysis/topological" -class TestSolar: +class TestSolar(PymatgenTest): def test_spillage_from_vasprun(self): wf_noso = f"{TEST_DIR}/WAVECAR-NonSOC" wf_so = f"{TEST_DIR}/WAVECAR-SOC" diff --git a/tests/analysis/xas/test_spectrum.py b/tests/analysis/xas/test_spectrum.py index bcc0c1d4933..92a04879dc3 100644 --- a/tests/analysis/xas/test_spectrum.py +++ b/tests/analysis/xas/test_spectrum.py @@ -10,7 +10,7 @@ from pymatgen.analysis.xas.spectrum import XAS, site_weighted_spectrum from pymatgen.core import Element -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest TEST_DIR = f"{TEST_FILES_DIR}/analysis/spectrum_test" @@ -28,8 +28,8 @@ site2_xanes_dict = json.load(file, cls=MontyDecoder) -class TestXAS: - def setup_method(self): +class TestXAS(PymatgenTest): + def setUp(self): self.k_xanes = XAS.from_dict(k_xanes_dict) self.k_exafs = XAS.from_dict(k_exafs_dict) self.l2_xanes = XAS.from_dict(l2_xanes_dict) diff --git a/tests/apps/battery/test_analyzer.py b/tests/apps/battery/test_analyzer.py index 2fc5a1375d5..eea99df2ecb 100644 --- a/tests/apps/battery/test_analyzer.py +++ b/tests/apps/battery/test_analyzer.py @@ -5,10 +5,10 @@ from pymatgen.apps.battery.analyzer import BatteryAnalyzer from pymatgen.core.structure import Structure -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest -class TestBatteryAnalyzer: +class TestBatteryAnalyzer(PymatgenTest): def load_from_cif(self, filename, oxidations, working_ion="Li"): struct = Structure.from_file(f"{TEST_FILES_DIR}/cif/{filename}") struct.add_oxidation_state_by_element(oxidations) @@ -19,7 +19,7 @@ def load_from_internal(self, name, oxidations, working_ion="Li"): struct.add_oxidation_state_by_element(oxidations) return BatteryAnalyzer(struct, working_ion) - def setup_method(self): + def setUp(self): self.li_fe_p_o4 = self.load_from_internal("LiFePO4", {"Li": 1, "Fe": 2, "P": 5, "O": -2}) self.na_fe_p_o4 = self.load_from_internal("NaFePO4", {"Na": 1, "Fe": 2, "P": 5, "O": -2}, working_ion="Na") self.la2coo4f = self.load_from_internal("La2CoO4F", {"La": 3, "Co": 3, "O": -2, "F": -1}, working_ion="F") diff --git a/tests/apps/battery/test_conversion_battery.py b/tests/apps/battery/test_conversion_battery.py index 2fc7efb10c9..d2d1b817ff8 100644 --- a/tests/apps/battery/test_conversion_battery.py +++ b/tests/apps/battery/test_conversion_battery.py @@ -14,7 +14,7 @@ class TestConversionElectrode(TestCase): - def setup_method(self): + def setUp(self): self.formulas = ["LiCoO2", "FeF3", "MnO2"] self.conversion_electrodes = {} for formula in self.formulas: diff --git a/tests/apps/battery/test_insertion_battery.py b/tests/apps/battery/test_insertion_battery.py index d7028b835e9..4c6b9caa951 100644 --- a/tests/apps/battery/test_insertion_battery.py +++ b/tests/apps/battery/test_insertion_battery.py @@ -14,7 +14,7 @@ class TestInsertionElectrode(TestCase): - def setup_method(self): + def setUp(self): self.entry_Li = ComputedEntry("Li", -1.90753119) self.entry_Ca = ComputedEntry("Ca", -1.99689568) diff --git a/tests/apps/battery/test_plotter.py b/tests/apps/battery/test_plotter.py index a0f3daad6a0..8b93b20f8bf 100644 --- a/tests/apps/battery/test_plotter.py +++ b/tests/apps/battery/test_plotter.py @@ -16,7 +16,7 @@ class TestVoltageProfilePlotter(TestCase): - def setup_method(self): + def setUp(self): entry_Li = ComputedEntry("Li", -1.90753119) with open(f"{TEST_DIR}/LiTiO2_batt.json") as file: diff --git a/tests/apps/borg/test_hive.py b/tests/apps/borg/test_hive.py index 3e47e6e8e33..6005eaf3f2c 100644 --- a/tests/apps/borg/test_hive.py +++ b/tests/apps/borg/test_hive.py @@ -21,7 +21,7 @@ class TestVaspToComputedEntryDrone(TestCase): - def setup_method(self): + def setUp(self): self.drone = VaspToComputedEntryDrone(data=["efermi"]) self.structure_drone = VaspToComputedEntryDrone(inc_structure=True) @@ -54,7 +54,7 @@ def test_as_from_dict(self): class TestSimpleVaspToComputedEntryDrone(TestCase): - def setup_method(self): + def setUp(self): self.drone = SimpleVaspToComputedEntryDrone() self.structure_drone = SimpleVaspToComputedEntryDrone(inc_structure=True) @@ -74,7 +74,7 @@ def test_as_from_dict(self): class TestGaussianToComputedEntryDrone(TestCase): - def setup_method(self): + def setUp(self): self.drone = GaussianToComputedEntryDrone(data=["corrections"]) self.structure_drone = GaussianToComputedEntryDrone(inc_structure=True) diff --git a/tests/command_line/test_bader_caller.py b/tests/command_line/test_bader_caller.py index 41c01270e0a..ad39f8c6b61 100644 --- a/tests/command_line/test_bader_caller.py +++ b/tests/command_line/test_bader_caller.py @@ -1,5 +1,6 @@ from __future__ import annotations +import warnings from shutil import which import numpy as np @@ -9,13 +10,16 @@ from pytest import approx from pymatgen.command_line.bader_caller import BaderAnalysis, bader_analysis_from_path -from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR, MatSciTest +from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR, PymatgenTest TEST_DIR = f"{TEST_FILES_DIR}/command_line/bader" @pytest.mark.skipif(not which("bader"), reason="bader executable not present") -class TestBaderAnalysis(MatSciTest): +class TestBaderAnalysis(PymatgenTest): + def setUp(self): + warnings.catch_warnings() + def test_init(self): # test with reference file analysis = BaderAnalysis( diff --git a/tests/command_line/test_critic2_caller.py b/tests/command_line/test_critic2_caller.py index 55346936b92..430b052d4bf 100644 --- a/tests/command_line/test_critic2_caller.py +++ b/tests/command_line/test_critic2_caller.py @@ -1,6 +1,7 @@ from __future__ import annotations from shutil import which +from unittest import TestCase import pytest from pytest import approx @@ -74,8 +75,8 @@ def test_from_structure(self): assert "ERROR : load int.CHGCAR id chg_int zpsp Mo 6 S 6" in c2c._input_script -class TestCritic2Analysis: - def setup_method(self): +class TestCritic2Analysis(TestCase): + def setUp(self): stdout_file = f"{TEST_DIR}/MoS2_critic2_stdout.txt" stdout_file_new_format = f"{TEST_DIR}/MoS2_critic2_stdout_new_format.txt" with open(stdout_file) as file: diff --git a/tests/command_line/test_enumlib_caller.py b/tests/command_line/test_enumlib_caller.py index 2e538207603..aa3cebff4a3 100644 --- a/tests/command_line/test_enumlib_caller.py +++ b/tests/command_line/test_enumlib_caller.py @@ -11,14 +11,14 @@ from pymatgen.symmetry.analyzer import SpacegroupAnalyzer from pymatgen.transformations.site_transformations import RemoveSitesTransformation from pymatgen.transformations.standard_transformations import SubstitutionTransformation -from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest ENUM_CMD = which("enum.x") or which("multienum.x") MAKESTR_CMD = which("makestr.x") or which("makeStr.x") or which("makeStr.py") @pytest.mark.skipif(not (ENUM_CMD and MAKESTR_CMD), reason="enumlib not present.") -class TestEnumlibAdaptor(MatSciTest): +class TestEnumlibAdaptor(PymatgenTest): def test_init(self): struct = self.get_structure("LiFePO4") sub_trans = SubstitutionTransformation({"Li": {"Li": 0.5}}) diff --git a/tests/command_line/test_gulp_caller.py b/tests/command_line/test_gulp_caller.py index 4dc27857afa..18c3f05c268 100644 --- a/tests/command_line/test_gulp_caller.py +++ b/tests/command_line/test_gulp_caller.py @@ -9,6 +9,7 @@ import os import sys from shutil import which +from unittest import TestCase import numpy as np import pytest @@ -105,8 +106,8 @@ def test_decimal(self): caller.run(buckingham_input) -class TestGulpIO: - def setup_method(self): +class TestGulpIO(TestCase): + def setUp(self): self.structure = Structure.from_file(f"{VASP_IN_DIR}/POSCAR_Al12O18") self.gio = GulpIO() @@ -275,8 +276,8 @@ def test_tersoff_input(self): self.gio.tersoff_input(self.structure) -class TestGlobalFunctions: - def setup_method(self): +class TestGlobalFunctions(TestCase): + def setUp(self): mgo_latt = np.eye(3) * 4.212 mgo_specie = ["Mg", "O"] * 4 mgo_frac_cord = [ @@ -326,8 +327,8 @@ def test_get_energy_relax_structure_buckingham(self): assert site_len == len(self.mgo_uc) -class TestBuckinghamPotentialLewis: - def setup_method(self): +class TestBuckinghamPotentialLewis(TestCase): + def setUp(self): self.bpl = BuckinghamPotential("lewis") def test_existing_element(self): @@ -353,8 +354,8 @@ def test_spring(self): assert self.bpl.spring_dict["O"] != "" -class TestBuckinghamPotentialBush: - def setup_method(self): +class TestBuckinghamPotentialBush(TestCase): + def setUp(self): self.bpb = BuckinghamPotential("bush") def test_existing_element(self): diff --git a/tests/command_line/test_mcsqs_caller.py b/tests/command_line/test_mcsqs_caller.py index 04cc9c7c042..ca9f8a018d6 100644 --- a/tests/command_line/test_mcsqs_caller.py +++ b/tests/command_line/test_mcsqs_caller.py @@ -7,7 +7,7 @@ from pymatgen.command_line.mcsqs_caller import run_mcsqs from pymatgen.core.structure import Structure -from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest __author__ = "Handong Ling, Rachel Woods-Robinson" __maintainer__ = "Handong Ling, Rachel Woods-Robinson" @@ -18,8 +18,8 @@ @pytest.mark.skipif(not (which("mcsqs") and which("str2cif")), reason="mcsqs executable not present") -class TestMcsqsCaller(MatSciTest): - def setup_method(self): +class TestMcsqsCaller(PymatgenTest): + def setUp(self): self.pzt_structs = loadfn(f"{TEST_DIR}/pzt-structs.json") self.pzt_structs2 = loadfn(f"{TEST_DIR}/pzt-structs-2.json") self.struct = self.get_structure("Pb2TiZrO6") @@ -103,5 +103,5 @@ def test_mcsqs_caller_runtime_error(self): struct.replace_species({"Ti": {"Ti": 0.5, "Zr": 0.5}, "Zr": {"Ti": 0.5, "Zr": 0.5}}) struct.replace_species({"Pb": {"Ti": 0.2, "Pb": 0.8}}) struct.replace_species({"O": {"F": 0.8, "O": 0.2}}) - with pytest.raises(RuntimeError, match="mcsqs did not generate output files"): + with pytest.raises(RuntimeError, match="mcsqs exited before timeout reached"): run_mcsqs(struct, {2: 6, 3: 4}, 10, 0.000001) diff --git a/tests/command_line/test_vampire_caller.py b/tests/command_line/test_vampire_caller.py index 6021f65a366..e2e55a18486 100644 --- a/tests/command_line/test_vampire_caller.py +++ b/tests/command_line/test_vampire_caller.py @@ -8,15 +8,15 @@ from pymatgen.command_line.vampire_caller import VampireCaller from pymatgen.core.structure import Structure -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest TEST_DIR = f"{TEST_FILES_DIR}/analysis/magnetic_orderings" @pytest.mark.skipif(not which("vampire-serial"), reason="vampire executable not present") -class TestVampireCaller: +class TestVampireCaller(PymatgenTest): @classmethod - def setup_class(cls): + def setUpClass(cls): cls.Mn3Al = pd.read_json(f"{TEST_DIR}/Mn3Al.json") cls.compounds = [cls.Mn3Al] diff --git a/tests/core/test_composition.py b/tests/core/test_composition.py index cf055a82706..9c00c7678fd 100644 --- a/tests/core/test_composition.py +++ b/tests/core/test_composition.py @@ -13,10 +13,11 @@ from pymatgen.core import Composition, DummySpecies, Element, Species from pymatgen.core.composition import ChemicalPotential +from pymatgen.util.testing import PymatgenTest -class TestComposition: - def setup_method(self): +class TestComposition(PymatgenTest): + def setUp(self): self.comps = [ Composition("Li3Fe2(PO4)3"), Composition("Li3Fe(PO4)O"), diff --git a/tests/core/test_interface.py b/tests/core/test_interface.py index 2cb1f2cff0e..c2563cd2a7a 100644 --- a/tests/core/test_interface.py +++ b/tests/core/test_interface.py @@ -8,13 +8,13 @@ from pymatgen.core.structure import Structure from pymatgen.core.surface import SlabGenerator from pymatgen.symmetry.analyzer import SpacegroupAnalyzer -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest TEST_DIR = f"{TEST_FILES_DIR}/core/grain_boundary" -class TestGrainBoundary: - def setup_method(self): +class TestGrainBoundary(PymatgenTest): + def setUp(self): self.Cu_conv = Structure.from_file(f"{TEST_DIR}/Cu_mp-30_conventional_standard.cif") GB_Cu_conv = GrainBoundaryGenerator(self.Cu_conv) self.Cu_GB1 = GB_Cu_conv.gb_from_parameters( @@ -104,9 +104,9 @@ def test_as_dict_and_from_dict(self): assert_allclose(Cu_GB2_new.lattice.matrix, self.Cu_GB2.lattice.matrix) -class TestGrainBoundaryGenerator: +class TestGrainBoundaryGenerator(PymatgenTest): @classmethod - def setup_class(cls): + def setUpClass(cls): cls.Cu_prim = Structure.from_file(f"{TEST_DIR}/Cu_mp-30_primitive.cif") cls.GB_Cu_prim = GrainBoundaryGenerator(cls.Cu_prim) cls.Cu_conv = Structure.from_file(f"{TEST_DIR}/Cu_mp-30_conventional_standard.cif") @@ -331,8 +331,8 @@ def test_get_rotation_angle_from_sigma(self): assert_allclose(close_angle, angle) -class TestInterface: - def setup_method(self): +class TestInterface(PymatgenTest): + def setUp(self): self.interface: Interface = self.get_structure("Si_SiO2_Interface") def test_basic_props(self): diff --git a/tests/core/test_ion.py b/tests/core/test_ion.py index 2d2291c6da9..a547bfe9005 100644 --- a/tests/core/test_ion.py +++ b/tests/core/test_ion.py @@ -10,7 +10,7 @@ class TestIon(TestCase): - def setup_method(self): + def setUp(self): self.comp = [] self.comp.append(Ion.from_formula("Li+")) self.comp.append(Ion.from_formula("MnO4-")) diff --git a/tests/core/test_lattice.py b/tests/core/test_lattice.py index a1c39a7fcdb..89a79e6330c 100644 --- a/tests/core/test_lattice.py +++ b/tests/core/test_lattice.py @@ -9,10 +9,11 @@ from pymatgen.core.lattice import Lattice, get_points_in_spheres from pymatgen.core.operations import SymmOp +from pymatgen.util.testing import PymatgenTest -class TestLattice: - def setup_method(self): +class TestLattice(PymatgenTest): + def setUp(self): self.lattice = Lattice.cubic(10.0) self.cubic = self.lattice self.tetragonal = Lattice.tetragonal(10, 20) diff --git a/tests/core/test_libxcfunc.py b/tests/core/test_libxcfunc.py index 56ab6335159..435b71c389e 100644 --- a/tests/core/test_libxcfunc.py +++ b/tests/core/test_libxcfunc.py @@ -1,9 +1,10 @@ from __future__ import annotations from pymatgen.core.libxcfunc import LibxcFunc +from pymatgen.util.testing import PymatgenTest -class TestLibxcFunc: +class TestLibxcFunc(PymatgenTest): def test_libxcfunc_api(self): """Testing libxcfunc_api.""" # LDA correlation: Hedin & Lundqvist diff --git a/tests/core/test_molecular_orbitals.py b/tests/core/test_molecular_orbitals.py index 5d193409c20..4476c856d17 100644 --- a/tests/core/test_molecular_orbitals.py +++ b/tests/core/test_molecular_orbitals.py @@ -3,11 +3,12 @@ import pytest from pymatgen.core.molecular_orbitals import MolecularOrbitals +from pymatgen.util.testing import PymatgenTest test_case = MolecularOrbitals("NaCl") -class TestMolecularOrbital: +class TestMolecularOrbital(PymatgenTest): def test_max_electronegativity(self): test_elec_neg = 2.23 assert test_elec_neg == test_case.max_electronegativity() diff --git a/tests/core/test_operations.py b/tests/core/test_operations.py index c0a6b74a2f2..1d775b09b92 100644 --- a/tests/core/test_operations.py +++ b/tests/core/test_operations.py @@ -5,10 +5,11 @@ from pymatgen.core.operations import MagSymmOp, SymmOp from pymatgen.electronic_structure.core import Magmom +from pymatgen.util.testing import PymatgenTest -class TestSymmOp: - def setup_method(self): +class TestSymmOp(PymatgenTest): + def setUp(self): self.op = SymmOp.from_axis_angle_and_translation([0, 0, 1], 30, translation_vec=[0, 0, 1]) def test_properties(self): @@ -235,7 +236,7 @@ def test_xyz(self): assert_allclose(symm_op.translation_vector, [0.5, 0.25, 0.75]) -class TestMagSymmOp: +class TestMagSymmOp(PymatgenTest): def test_xyzt_string(self): xyzt_strings = ["x, y, z, +1", "x, y, z, -1", "-y+1/2, x+1/2, x+1/2, +1"] diff --git a/tests/core/test_periodic_table.py b/tests/core/test_periodic_table.py index 62d7e32b446..a4a696a4f56 100644 --- a/tests/core/test_periodic_table.py +++ b/tests/core/test_periodic_table.py @@ -14,9 +14,10 @@ from pymatgen.core.periodic_table import ElementBase, ElementType from pymatgen.core.units import Ha_to_eV from pymatgen.io.core import ParseError +from pymatgen.util.testing import PymatgenTest -class TestElement: +class TestElement(PymatgenTest): def test_init(self): assert Element("Fe").symbol == "Fe" @@ -391,8 +392,8 @@ def test_isotope(self): ] -class TestSpecies: - def setup_method(self): +class TestSpecies(PymatgenTest): + def setUp(self): self.specie1 = Species.from_str("Fe2+") self.specie2 = Species("Fe", 3) self.specie3 = Species("Fe", 2) diff --git a/tests/core/test_sites.py b/tests/core/test_sites.py index c93552229da..28fb7b07e4c 100644 --- a/tests/core/test_sites.py +++ b/tests/core/test_sites.py @@ -9,10 +9,11 @@ from pymatgen.core import Composition, Element, Lattice, PeriodicSite, Site, Species from pymatgen.electronic_structure.core import Magmom +from pymatgen.util.testing import PymatgenTest -class TestSite: - def setup_method(self): +class TestSite(PymatgenTest): + def setUp(self): self.ordered_site = Site("Fe", [0.25, 0.35, 0.45]) self.disordered_site = Site({"Fe": 0.5, "Mn": 0.5}, [0.25, 0.35, 0.45]) self.propertied_site = Site("Fe2+", [0.25, 0.35, 0.45], {"magmom": 5.1, "charge": 4.2}) @@ -78,8 +79,8 @@ def test_setters(self): self.disordered_site.species = {"Cu": 0.5, "Gd": 0.6} -class TestPeriodicSite: - def setup_method(self): +class TestPeriodicSite(PymatgenTest): + def setUp(self): self.lattice = Lattice.cubic(10.0) self.si = Element("Si") self.site = PeriodicSite("Fe", [0.25, 0.35, 0.45], self.lattice) diff --git a/tests/core/test_spectrum.py b/tests/core/test_spectrum.py index e38883a7371..2f8f208c175 100644 --- a/tests/core/test_spectrum.py +++ b/tests/core/test_spectrum.py @@ -6,10 +6,11 @@ from scipy import stats from pymatgen.core.spectrum import Spectrum +from pymatgen.util.testing import PymatgenTest -class TestSpectrum: - def setup_method(self): +class TestSpectrum(PymatgenTest): + def setUp(self): rng = np.random.default_rng() self.spec1 = Spectrum(np.arange(0, 10, 0.1), rng.standard_normal(100)) self.spec2 = Spectrum(np.arange(0, 10, 0.1), rng.standard_normal(100)) diff --git a/tests/core/test_structure.py b/tests/core/test_structure.py index 83995882799..7cb4abcbaf3 100644 --- a/tests/core/test_structure.py +++ b/tests/core/test_structure.py @@ -44,7 +44,7 @@ mcsqs_cmd = which("mcsqs") -class TestNeighbor: +class TestNeighbor(PymatgenTest): def test_msonable(self): struct = PymatgenTest.get_structure("Li2O") nn = struct.get_neighbors(struct[0], r=3) @@ -63,8 +63,8 @@ def test_neighbor_labels(self): assert p_neighbor.label == label if label is not None else "C" -class TestIStructure: - def setup_method(self): +class TestIStructure(PymatgenTest): + def setUp(self): coords = [[0, 0, 0], [0.75, 0.5, 0.75]] self.lattice = Lattice( [ @@ -965,8 +965,8 @@ def test_sites_setter(self): assert struct.sites == new_sites -class TestStructure: - def setup_method(self): +class TestStructure(PymatgenTest): + def setUp(self): coords = [[0, 0, 0], [0.75, 0.5, 0.75]] lattice = Lattice( [ @@ -2032,8 +2032,8 @@ def test_struct_with_isotope(self): assert "Deuterium" not in [el.long_name for el in struct.composition.elements] -class TestIMolecule: - def setup_method(self): +class TestIMolecule(PymatgenTest): + def setUp(self): coords = [ [0, 0, 0], [0, 0, 1.089], @@ -2327,8 +2327,8 @@ def test_to_file_alias(self): assert os.path.isfile(out_path) -class TestMolecule: - def setup_method(self): +class TestMolecule(PymatgenTest): + def setUp(self): coords = [ [0, 0, 0], [0, 0, 1.089000], diff --git a/tests/core/test_surface.py b/tests/core/test_surface.py index bc540df589e..0527fc671b0 100644 --- a/tests/core/test_surface.py +++ b/tests/core/test_surface.py @@ -24,13 +24,13 @@ ) from pymatgen.symmetry.analyzer import SpacegroupAnalyzer from pymatgen.symmetry.groups import SpaceGroup -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest PMG_CORE_DIR = os.path.dirname(pymatgen.core.__file__) -class TestSlab: - def setup_method(self): +class TestSlab(PymatgenTest): + def setUp(self): zno1 = Structure.from_file(f"{TEST_FILES_DIR}/surfaces/ZnO-wz.cif", primitive=False) zno55 = SlabGenerator(zno1, [1, 0, 0], 5, 5, lll_reduce=False, center_slab=False).get_slab() @@ -346,8 +346,8 @@ def test_as_dict(self): assert slab == Slab.from_dict(d) -class TestSlabGenerator: - def setup_method(self): +class TestSlabGenerator(PymatgenTest): + def setUp(self): lattice = Lattice.cubic(3.010) frac_coords = [ [0.00000, 0.00000, 0.00000], @@ -634,8 +634,8 @@ def test_bonds_broken(self): assert slabs[1].energy, 6.0 -class ReconstructionGeneratorTests: - def setup_method(self): +class ReconstructionGeneratorTests(PymatgenTest): + def setUp(self): lattice = Lattice.cubic(3.51) species = ["Ni"] coords = [[0, 0, 0]] @@ -723,8 +723,8 @@ def test_previous_reconstructions(self): assert any(len(match.group_structures([struct, slab])) == 1 for slab in slabs) -class TestMillerIndexFinder: - def setup_method(self): +class TestMillerIndexFinder(PymatgenTest): + def setUp(self): self.cscl = Structure.from_spacegroup("Pm-3m", Lattice.cubic(4.2), ["Cs", "Cl"], [[0, 0, 0], [0.5, 0.5, 0.5]]) self.Fe = Structure.from_spacegroup("Im-3m", Lattice.cubic(2.82), ["Fe"], [[0, 0, 0]]) mg_lattice = Lattice.from_parameters(3.2, 3.2, 5.13, 90, 90, 120) diff --git a/tests/core/test_tensors.py b/tests/core/test_tensors.py index b5aab2feef8..1c840dcfa2b 100644 --- a/tests/core/test_tensors.py +++ b/tests/core/test_tensors.py @@ -11,11 +11,11 @@ from pymatgen.core.operations import SymmOp from pymatgen.core.tensors import SquareTensor, Tensor, TensorCollection, TensorMapping, itertools, symmetry_reduce from pymatgen.symmetry.analyzer import SpacegroupAnalyzer -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest -class TestTensor: - def setup_method(self): +class TestTensor(PymatgenTest): + def setUp(self): rng = np.random.default_rng() self.vec = Tensor([1.0, 0.0, 0.0]) @@ -379,8 +379,8 @@ def test_round(self): assert isinstance(rounded, Tensor) -class TestTensorCollection: - def setup_method(self): +class TestTensorCollection(PymatgenTest): + def setUp(self): self.seq_tc = list(np.arange(4 * 3**3).reshape((4, 3, 3, 3))) self.seq_tc = TensorCollection(self.seq_tc) self.rand_tc = TensorCollection(list(np.random.default_rng().random((4, 3, 3)))) @@ -472,8 +472,8 @@ def test_serialization(self): assert_allclose(t, t_new) -class TestSquareTensor: - def setup_method(self): +class TestSquareTensor(PymatgenTest): + def setUp(self): self.rand_sqtensor = SquareTensor(np.random.default_rng().standard_normal((3, 3))) self.symm_sqtensor = SquareTensor([[0.1, 0.3, 0.4], [0.3, 0.5, 0.2], [0.4, 0.2, 0.6]]) self.non_invertible = SquareTensor([[0.1, 0, 0], [0.2, 0, 0], [0, 0, 0]]) diff --git a/tests/core/test_trajectory.py b/tests/core/test_trajectory.py index 7d26af7236e..cac745a8a75 100644 --- a/tests/core/test_trajectory.py +++ b/tests/core/test_trajectory.py @@ -12,13 +12,13 @@ from pymatgen.core.trajectory import Trajectory from pymatgen.io.qchem.outputs import QCOutput from pymatgen.io.vasp.outputs import Xdatcar -from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR +from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR, PymatgenTest TEST_DIR = f"{TEST_FILES_DIR}/core/trajectory" -class TestTrajectory: - def setup_method(self): +class TestTrajectory(PymatgenTest): + def setUp(self): xdatcar = Xdatcar(f"{VASP_OUT_DIR}/XDATCAR_traj") self.traj = Trajectory.from_file(f"{VASP_OUT_DIR}/XDATCAR_traj") self.structures = xdatcar.structures diff --git a/tests/core/test_units.py b/tests/core/test_units.py index 1f3c7f2ac5b..88e06d92517 100644 --- a/tests/core/test_units.py +++ b/tests/core/test_units.py @@ -26,6 +26,7 @@ eV_to_Ha, unitized, ) +from pymatgen.util.testing import PymatgenTest def test_unit_conversions(): @@ -36,7 +37,7 @@ def test_unit_conversions(): assert amu_to_kg == approx(1.66053906660e-27) -class TestUnit: +class TestUnit(PymatgenTest): def test_init(self): u1 = Unit((("m", 1), ("s", -1))) assert str(u1) == "m s^-1" @@ -52,7 +53,7 @@ def test_init(self): assert str(newton * Unit("m")) == "N m" -class TestFloatWithUnit: +class TestFloatWithUnit(PymatgenTest): def test_energy(self): a = Energy(1.1, "eV") b = a.to("Ha") @@ -184,7 +185,7 @@ def test_neg(self): assert FloatWithUnit(-5, "MPa") == -x -class TestArrayWithUnit: +class TestArrayWithUnit(PymatgenTest): def test_energy(self): """Similar to TestFloatWithUnit.test_energy. Check whether EnergyArray and FloatWithUnit have same behavior. @@ -292,7 +293,7 @@ def test_as_base_units(self): assert_array_equal(ArrayWithUnit([5000000, 10000000], "Pa"), pressure_arr.as_base_units) -class TestDataPersistence: +class TestDataPersistence(PymatgenTest): def test_pickle(self): """Test whether FloatWithUnit and ArrayWithUnit support pickle.""" for cls in [FloatWithUnit, ArrayWithUnit]: diff --git a/tests/core/test_xcfunc.py b/tests/core/test_xcfunc.py index 3ce0314049c..94627874bab 100644 --- a/tests/core/test_xcfunc.py +++ b/tests/core/test_xcfunc.py @@ -3,10 +3,11 @@ import pytest from pymatgen.core.xcfunc import XcFunc +from pymatgen.util.testing import PymatgenTest -class TestLibxcFunc: - def setup_method(self) -> None: +class TestLibxcFunc(PymatgenTest): + def setUp(self) -> None: self.ixc_11 = XcFunc.from_abinit_ixc(11) def test_aliases(self): diff --git a/tests/electronic_structure/test_bandstructure.py b/tests/electronic_structure/test_bandstructure.py index cb1cdb0f338..c5de50385ce 100644 --- a/tests/electronic_structure/test_bandstructure.py +++ b/tests/electronic_structure/test_bandstructure.py @@ -20,13 +20,13 @@ from pymatgen.electronic_structure.core import Orbital, Spin from pymatgen.electronic_structure.plotter import BSPlotterProjected from pymatgen.io.vasp import BSVasprun -from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR +from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR, PymatgenTest TEST_DIR = f"{TEST_FILES_DIR}/electronic_structure/bandstructure" class TestKpoint(TestCase): - def setup_method(self): + def setUp(self): self.lattice = Lattice.cubic(10.0) self.kpoint = Kpoint([0.1, 0.4, -0.5], self.lattice, label="X") @@ -68,8 +68,8 @@ def test_from_dict(self): assert kpoint.label == "X" -class TestBandStructureSymmLine: - def setup_method(self): +class TestBandStructureSymmLine(PymatgenTest): + def setUp(self): self.bs: BandStructureSymmLine = loadfn(f"{TEST_DIR}/Cu2O_361_bandstructure.json") self.bs2: BandStructureSymmLine = loadfn(f"{TEST_DIR}/CaO_2605_bandstructure.json") self.bs_spin: BandStructureSymmLine = loadfn(f"{TEST_DIR}/NiO_19009_bandstructure.json") @@ -258,8 +258,8 @@ def test_apply_scissor_spin_polarized(self): assert bs_scissored.efermi != approx(orig_efermi) -class TestReconstructBandStructure: - def setup_method(self): +class TestReconstructBandStructure(PymatgenTest): + def setUp(self): self.bs_cu: BandStructureSymmLine = loadfn(f"{TEST_DIR}/Cu_30_bandstructure.json") self.bs_cu2: BandStructureSymmLine = loadfn(f"{TEST_DIR}/Cu_30_bandstructure.json") @@ -277,8 +277,8 @@ def test_vasprun_bs(self): bs.get_projection_on_elements() -class TestLobsterBandStructureSymmLine: - def setup_method(self): +class TestLobsterBandStructureSymmLine(PymatgenTest): + def setUp(self): with open( f"{TEST_FILES_DIR}/electronic_structure/cohp/Fatband_SiO2/Test_p/lobster_band_structure_spin.json", ) as file: diff --git a/tests/electronic_structure/test_boltztrap.py b/tests/electronic_structure/test_boltztrap.py index dbc28997df1..a5983320da9 100644 --- a/tests/electronic_structure/test_boltztrap.py +++ b/tests/electronic_structure/test_boltztrap.py @@ -26,7 +26,7 @@ @pytest.mark.skipif(not which("x_trans"), reason="No x_trans.") class TestBoltztrapAnalyzer(TestCase): @classmethod - def setup_class(cls): + def setUpClass(cls): cls.bz = BoltztrapAnalyzer.from_files(f"{TEST_DIR}/transp/") cls.bz_bands = BoltztrapAnalyzer.from_files(f"{TEST_DIR}/bands/") cls.bz_up = BoltztrapAnalyzer.from_files(f"{TEST_DIR}/dos_up/", dos_spin=1) diff --git a/tests/electronic_structure/test_boltztrap2.py b/tests/electronic_structure/test_boltztrap2.py index 0fb225b0379..cdb75a24532 100644 --- a/tests/electronic_structure/test_boltztrap2.py +++ b/tests/electronic_structure/test_boltztrap2.py @@ -42,7 +42,7 @@ class TestVasprunBSLoader(TestCase): - def setup_method(self): + def setUp(self): self.loader = VasprunBSLoader(VASP_RUN) assert self.loader is not None self.loader = VasprunBSLoader(BAND_STRUCT, VASP_RUN.final_structure) @@ -81,7 +81,7 @@ def test_get_volume(self): class TestBandstructureLoader(TestCase): - def setup_method(self): + def setUp(self): self.loader = BandstructureLoader(BAND_STRUCT, VASP_RUN.structures[-1]) assert self.loader is not None @@ -108,7 +108,7 @@ def test_set_upper_lower_bands(self): class TestVasprunLoader(TestCase): - def setup_method(self): + def setUp(self): self.loader = VasprunLoader(VASP_RUN) assert self.loader.proj.shape == (120, 20, 2, 9) assert self.loader is not None @@ -127,7 +127,7 @@ def test_from_file(self): class TestBztInterpolator(TestCase): - def setup_method(self): + def setUp(self): with ScratchDir("."): shutil.copy(BZT_INTERP_FN, ".") @@ -206,7 +206,7 @@ def test_tot_proj_dos(self): class TestBztTransportProperties(TestCase): - def setup_method(self): + def setUp(self): with ScratchDir("."): shutil.copy(BZT_TRANSP_FN, ".") diff --git a/tests/electronic_structure/test_cohp.py b/tests/electronic_structure/test_cohp.py index 270abd76692..16f0ce2ca34 100644 --- a/tests/electronic_structure/test_cohp.py +++ b/tests/electronic_structure/test_cohp.py @@ -15,13 +15,13 @@ get_integrated_cohp_in_energy_range, ) from pymatgen.electronic_structure.core import Orbital, Spin -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest TEST_DIR = f"{TEST_FILES_DIR}/electronic_structure/cohp" class TestCohp(TestCase): - def setup_method(self): + def setUp(self): with open(f"{TEST_DIR}/cohp.json") as file: self.cohp = Cohp.from_dict(json.load(file)) self.cohp_only = Cohp(self.cohp.efermi, self.cohp.energies, self.cohp.cohp) @@ -91,7 +91,7 @@ def test_antibnd_states_below_efermi(self): class TestIcohpValue(TestCase): - def setup_method(self): + def setUp(self): # without spin polarization label = "1" atom1 = "K1" @@ -169,7 +169,7 @@ def test_str(self): class TestCombinedIcohp(TestCase): - def setup_method(self): + def setUp(self): # without spin polarization: are_coops = are_cobis = is_spin_polarized = False list_atom2 = ["K2", "K2", "K2", "K2", "K2", "K2"] @@ -797,8 +797,8 @@ def test_extremum_icohpvalue(self): assert self.icoopcollection_Fe.extremum_icohpvalue(summed_spin_channels=False, spin=Spin.down) == -0.05756 -class TestCompleteCohp: - def setup_method(self): +class TestCompleteCohp(PymatgenTest): + def setUp(self): filepath = f"{TEST_DIR}/complete_cohp_lobster.json" with open(filepath) as file: self.cohp_lobster_dict = CompleteCohp.from_dict(json.load(file)) @@ -1263,7 +1263,7 @@ def test_orbital_resolved_cohp_summed_spin_channels(self): class TestMethod(TestCase): - def setup_method(self): + def setUp(self): filepath = f"{TEST_DIR}/COHPCAR.lobster.gz" structure = f"{TEST_DIR}/POSCAR" self.cohp_lobster = CompleteCohp.from_file("lobster", filename=filepath, structure_file=structure) diff --git a/tests/electronic_structure/test_dos.py b/tests/electronic_structure/test_dos.py index 31c0f4edf6d..a7c8dec41b1 100644 --- a/tests/electronic_structure/test_dos.py +++ b/tests/electronic_structure/test_dos.py @@ -14,13 +14,13 @@ from pymatgen.core import Element, Structure from pymatgen.electronic_structure.core import Orbital, OrbitalType, Spin from pymatgen.electronic_structure.dos import DOS, CompleteDos, FermiDos, LobsterCompleteDos -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest TEST_DIR = f"{TEST_FILES_DIR}/electronic_structure/dos" class TestDos(TestCase): - def setup_method(self): + def setUp(self): with open(f"{TEST_DIR}/complete_dos.json") as file: self.dos = CompleteDos.from_dict(json.load(file)) @@ -58,7 +58,7 @@ def test_as_dict(self): class TestFermiDos(TestCase): - def setup_method(self): + def setUp(self): with open(f"{TEST_DIR}/complete_dos.json") as file: self.dos = CompleteDos.from_dict(json.load(file)) self.dos = FermiDos(self.dos) @@ -105,7 +105,7 @@ def test_as_dict(self): class TestCompleteDos(TestCase): - def setup_method(self): + def setUp(self): with open(f"{TEST_DIR}/complete_dos.json") as file: self.dos = CompleteDos.from_dict(json.load(file)) with zopen(f"{TEST_DIR}/pdag3_complete_dos.json.gz") as file: @@ -323,8 +323,8 @@ def test_dos_fp_exceptions(self): self.dos.get_dos_fp_similarity(dos_fp, dos_fp2, col=1, metric=metric, normalize=False) -class TestDOS: - def setup_method(self): +class TestDOS(PymatgenTest): + def setUp(self): with open(f"{TEST_DIR}/complete_dos.json") as file: dct = json.load(file) ys = list(zip(dct["densities"]["1"], dct["densities"]["-1"], strict=True)) @@ -359,7 +359,7 @@ def test_spin_polarization(self): class TestLobsterCompleteDos(TestCase): - def setup_method(self): + def setUp(self): with open(f"{TEST_DIR}/LobsterCompleteDos_spin.json") as file: data_spin = json.load(file) self.LobsterCompleteDOS_spin = LobsterCompleteDos.from_dict(data_spin) diff --git a/tests/electronic_structure/test_plotter.py b/tests/electronic_structure/test_plotter.py index 8c87e20ec67..59763e9ea59 100644 --- a/tests/electronic_structure/test_plotter.py +++ b/tests/electronic_structure/test_plotter.py @@ -30,15 +30,15 @@ plot_ellipsoid, ) from pymatgen.io.vasp import Vasprun -from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR +from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR, PymatgenTest BAND_TEST_DIR = f"{TEST_FILES_DIR}/electronic_structure/bandstructure" rc("text", usetex=False) # Disabling latex is needed for this test to work. -class TestDosPlotter: - def setup_method(self): +class TestDosPlotter(PymatgenTest): + def setUp(self): with open(f"{BAND_TEST_DIR}/../dos/complete_dos.json") as file: self.dos = CompleteDos.from_dict(json.load(file)) self.plotter = DosPlotter(sigma=0.2, stack=True) @@ -91,8 +91,8 @@ def get_plot_attributes(ax: plt.Axes): } -class TestBSPlotter: - def setup_method(self): +class TestBSPlotter(PymatgenTest): + def setUp(self): with open(f"{BAND_TEST_DIR}/CaO_2605_bandstructure.json") as file: dct = json.loads(file.read()) self.bs = BandStructureSymmLine.from_dict(dct) @@ -185,7 +185,7 @@ def test_get_plot(self): class TestBSPlotterProjected(TestCase): - def setup_method(self): + def setUp(self): with open(f"{BAND_TEST_DIR}/Cu2O_361_bandstructure.json") as file: self.bs_Cu2O = BandStructureSymmLine.from_dict(json.load(file)) self.plotter_Cu2O = BSPlotterProjected(self.bs_Cu2O) @@ -258,7 +258,7 @@ def test_methods(self): class TestPlotBZ(TestCase): - def setup_method(self): + def setUp(self): self.rec_latt = Structure.from_file(f"{TEST_FILES_DIR}/io/cssr/Si.cssr").lattice.reciprocal_lattice self.kpath = [[[0.0, 0.0, 0.0], [0.5, 0.0, 0.5], [0.5, 0.25, 0.75], [0.375, 0.375, 0.75]]] self.labels = { @@ -304,7 +304,7 @@ def test_fold_point(self): @pytest.mark.skip("TODO: need someone to fix this") @pytest.mark.skipif(not which("x_trans"), reason="No x_trans executable found") class TestBoltztrapPlotter(TestCase): - def setup_method(self): + def setUp(self): bz = BoltztrapAnalyzer.from_files(f"{TEST_FILES_DIR}/boltztrap/transp/") self.plotter = BoltztrapPlotter(bz) @@ -444,8 +444,8 @@ def test_plot_zt_temp(self): plt.close() -class TestCohpPlotter: - def setup_method(self): +class TestCohpPlotter(PymatgenTest): + def setUp(self): path = f"{TEST_FILES_DIR}/electronic_structure/cohp/complete_cohp_lobster.json" with open(path) as file: self.cohp = CompleteCohp.from_dict(json.load(file)) diff --git a/tests/entries/test_compatibility.py b/tests/entries/test_compatibility.py index 45d031e6caa..2aaa4cb02ce 100644 --- a/tests/entries/test_compatibility.py +++ b/tests/entries/test_compatibility.py @@ -46,7 +46,7 @@ class TestCorrectionSpecificity(TestCase): """Make sure corrections are only applied to GGA or GGA+U entries.""" - def setup_method(self): + def setUp(self): self.entry1 = ComputedEntry( "Fe2O3", -1, @@ -205,7 +205,7 @@ def test_overlapping_adjustments(): @pytest.mark.filterwarnings("ignore:MaterialsProjectCompatibility is deprecated") class TestMaterialsProjectCompatibility(TestCase): - def setup_method(self): + def setUp(self): self.entry1 = ComputedEntry( "Fe2O3", -1, @@ -622,7 +622,7 @@ def test_msonable(self): class TestMaterialsProjectCompatibility2020(TestCase): - def setup_method(self): + def setUp(self): self.entry1 = ComputedEntry( "Fe2O3", -1, @@ -1316,7 +1316,7 @@ def test_many_anions(self): class TestMITCompatibility(TestCase): - def setup_method(self): + def setUp(self): self.compat = MITCompatibility(check_potcar_hash=True) self.gga_compat = MITCompatibility("GGA", check_potcar_hash=True) self.entry_O = ComputedEntry( @@ -1656,7 +1656,7 @@ def test_msonable(self): class TestOxideTypeCorrection(TestCase): - def setup_method(self): + def setUp(self): self.compat = MITCompatibility(check_potcar_hash=True) def test_no_struct_compat(self): @@ -1827,7 +1827,7 @@ def test_process_entry_oxide(self): class TestSulfideTypeCorrection2020(TestCase): - def setup_method(self): + def setUp(self): self.compat = MaterialsProject2020Compatibility(check_potcar_hash=False) def test_struct_no_struct(self): @@ -1987,7 +1987,7 @@ def test_struct_no_struct(self): class TestOxideTypeCorrectionNoPeroxideCorr(TestCase): - def setup_method(self): + def setUp(self): self.compat = MITCompatibility(correct_peroxide=False) def test_oxide_energy_corr(self): @@ -2255,7 +2255,7 @@ def test_parallel_process_entries(self): class TestAqueousCorrection(TestCase): - def setup_method(self): + def setUp(self): fp = f"{PMG_ENTRIES_DIR}/MITCompatibility.yaml" self.corr = AqueousCorrection(fp) @@ -2282,7 +2282,7 @@ def test_compound_energy(self): class TestMITAqueousCompatibility(TestCase): - def setup_method(self): + def setUp(self): self.compat = MITCompatibility(check_potcar_hash=True) self.aqcompat = MITAqueousCompatibility(check_potcar_hash=True) fp = f"{PMG_ENTRIES_DIR}/MITCompatibility.yaml" @@ -2393,7 +2393,7 @@ def test_dont_error_on_weird_elements(self): class TestCorrectionErrors2020Compatibility(TestCase): - def setup_method(self): + def setUp(self): self.compat = MaterialsProject2020Compatibility() params = { diff --git a/tests/entries/test_computed_entries.py b/tests/entries/test_computed_entries.py index 63ce5c21d8f..9cf63caca6f 100644 --- a/tests/entries/test_computed_entries.py +++ b/tests/entries/test_computed_entries.py @@ -96,7 +96,7 @@ def test_temp_energy_adjustment(): class TestComputedEntry(TestCase): - def setup_method(self): + def setUp(self): self.entry = ComputedEntry( vasp_run.final_structure.composition, vasp_run.final_energy, @@ -257,7 +257,7 @@ def test_from_dict_null_fields(self): class TestComputedStructureEntry(TestCase): - def setup_method(self): + def setUp(self): self.entry = ComputedStructureEntry(vasp_run.final_structure, vasp_run.final_energy, parameters=vasp_run.incar) def test_energy(self): @@ -454,7 +454,7 @@ def test_eq(self): class TestGibbsComputedStructureEntry(TestCase): - def setup_method(self): + def setUp(self): self.temps = [300, 600, 900, 1200, 1500, 1800] self.struct = vasp_run.final_structure self.num_atoms = self.struct.composition.num_atoms diff --git a/tests/entries/test_correction_calculator.py b/tests/entries/test_correction_calculator.py index 66718efe212..209f781be41 100644 --- a/tests/entries/test_correction_calculator.py +++ b/tests/entries/test_correction_calculator.py @@ -11,7 +11,7 @@ class TestCorrectionCalculator(TestCase): - def setup_method(self): + def setUp(self): self.exclude_polyanions = [ "SO4", "CO3", diff --git a/tests/entries/test_entry_tools.py b/tests/entries/test_entry_tools.py index 6dec5a42b78..73d2d721d7b 100644 --- a/tests/entries/test_entry_tools.py +++ b/tests/entries/test_entry_tools.py @@ -9,12 +9,12 @@ from pymatgen.core import Element from pymatgen.entries.computed_entries import ComputedEntry from pymatgen.entries.entry_tools import EntrySet, group_entries_by_composition, group_entries_by_structure -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest TEST_DIR = f"{TEST_FILES_DIR}/entries" -class TestFunc: +class TestFunc(PymatgenTest): def test_group_entries_by_structure(self): entries = loadfn(f"{TEST_DIR}/TiO2_entries.json") groups = group_entries_by_structure(entries) @@ -49,8 +49,8 @@ def test_group_entries_by_composition(self): assert group == sorted(group, key=lambda e: e.energy_per_atom) -class TestEntrySet: - def setup_method(self): +class TestEntrySet(PymatgenTest): + def setUp(self): entries = loadfn(f"{TEST_DIR}/Li-Fe-P-O_entries.json") self.entry_set = EntrySet(entries) diff --git a/tests/entries/test_exp_entries.py b/tests/entries/test_exp_entries.py index b9752eae71f..b73be4ad8a4 100644 --- a/tests/entries/test_exp_entries.py +++ b/tests/entries/test_exp_entries.py @@ -11,7 +11,7 @@ class TestExpEntry(TestCase): - def setup_method(self): + def setUp(self): with open(f"{TEST_FILES_DIR}/entries/Fe2O3_exp.json") as file: thermo_data = json.load(file, cls=MontyDecoder) self.entry = ExpEntry("Fe2O3", thermo_data) diff --git a/tests/ext/test_matproj.py b/tests/ext/test_matproj.py index 0551919b6f3..18558a41525 100644 --- a/tests/ext/test_matproj.py +++ b/tests/ext/test_matproj.py @@ -23,7 +23,7 @@ from pymatgen.ext.matproj_legacy import MPRestError, TaskType, _MPResterLegacy from pymatgen.phonon.bandstructure import PhononBandStructureSymmLine from pymatgen.phonon.dos import CompletePhononDos -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest PMG_MAPI_KEY = SETTINGS.get("PMG_MAPI_KEY", "") if (10 < len(PMG_MAPI_KEY) <= 20) and "PMG_MAPI_KEY" in SETTINGS: @@ -48,8 +48,8 @@ not 10 < len(PMG_MAPI_KEY) <= 20, reason="Legacy PMG_MAPI_KEY environment variable not set.", ) -class TestMPResterOld: - def setup_method(self): +class TestMPResterOld(PymatgenTest): + def setUp(self): self.rester = _MPResterLegacy() def test_get_all_materials_ids_doc(self): @@ -528,8 +528,8 @@ def test_api_key_is_none(self): not len(PMG_MAPI_KEY) > 20, reason="PMG_MAPI_KEY environment variable not set.", ) -class TestMPResterNewBasic: - def setup_method(self): +class TestMPResterNewBasic(PymatgenTest): + def setUp(self): self.rester = _MPResterBasic() def test_get_summary(self): @@ -903,10 +903,10 @@ def test_pourbaix_mpr_pipeline(self): def test_parity_with_mp_api(self): try: - from mp_api.client import MPRester + from mp_api.client import MPRester as MpApi except Exception: pytest.skip("mp_api.client.MPRester cannot be imported for this test.") - mpr_mp_api = MPRester(PMG_MAPI_KEY) + mpr_mp_api = MpApi(PMG_MAPI_KEY) # Test summary mp_data = mpr_mp_api.summary.search(formula="Al2O3") pmg_data = self.rester.get_summary({"formula": "Al2O3"}) diff --git a/tests/ext/test_optimade.py b/tests/ext/test_optimade.py index 4a81116c5ce..e2710ddeaff 100644 --- a/tests/ext/test_optimade.py +++ b/tests/ext/test_optimade.py @@ -4,6 +4,7 @@ import requests from pymatgen.ext.optimade import OptimadeRester +from pymatgen.util.testing import PymatgenTest try: # 403 is returned when server detects bot-like behavior @@ -35,7 +36,7 @@ mc2d_down = True -class TestOptimade: +class TestOptimade(PymatgenTest): @pytest.mark.skipif(mp_website_down, reason="MP OPTIMADE is down.") def test_get_structures_mp(self): with OptimadeRester("mp") as optimade: diff --git a/tests/io/abinit/test_abiobjects.py b/tests/io/abinit/test_abiobjects.py index 03b90aefe4b..ad38c49dafe 100644 --- a/tests/io/abinit/test_abiobjects.py +++ b/tests/io/abinit/test_abiobjects.py @@ -19,10 +19,10 @@ species_by_znucl, structure_to_abivars, ) -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest -class TestLatticeFromAbivars: +class TestLatticeFromAbivars(PymatgenTest): def test_rprim_acell(self): l1 = lattice_from_abivars(acell=3 * [10], rprim=np.eye(3)) assert l1.volume == approx(bohr_to_ang**3 * 1000) @@ -108,7 +108,7 @@ def test_znucl_typat(self): structure_to_abivars(gan, enforce_znucl=enforce_znucl, enforce_typat=None) -class TestSpinMode: +class TestSpinMode(PymatgenTest): def test_base(self): polarized = SpinMode.as_spinmode("polarized") other_polarized = SpinMode.as_spinmode("polarized") @@ -128,7 +128,7 @@ def test_base(self): self.assert_msonable(unpolarized) -class TestSmearing: +class TestSmearing(PymatgenTest): def test_base(self): fd1ev = Smearing.as_smearing("fermi_dirac:1 eV") fd1ev.to_abivars() @@ -156,7 +156,7 @@ def test_base(self): self.assert_msonable(fd1ev) -class TestElectronsAlgorithm: +class TestElectronsAlgorithm(PymatgenTest): def test_base(self): algo = ElectronsAlgorithm(nstep=70) _ = algo.to_abivars() @@ -168,7 +168,7 @@ def test_base(self): self.assert_msonable(algo) -class TestElectrons: +class TestElectrons(PymatgenTest): def test_base(self): default_electrons = Electrons() assert default_electrons.nsppol == 2 @@ -195,7 +195,7 @@ def test_base(self): self.assert_msonable(custom_electrons) -class TestKSampling: +class TestKSampling(PymatgenTest): def test_base(self): monkhorst = KSampling.monkhorst((3, 3, 3), (0.5, 0.5, 0.5), 0, use_symmetries=False, use_time_reversal=False) gamma_centered = KSampling.gamma_centered((3, 3, 3), use_symmetries=False, use_time_reversal=False) @@ -207,7 +207,7 @@ def test_base(self): self.assert_msonable(gamma_centered) -class TestRelaxation: +class TestRelaxation(PymatgenTest): def test_base(self): atoms_and_cell = RelaxationMethod.atoms_and_cell() atoms_only = RelaxationMethod.atoms_only() @@ -227,7 +227,7 @@ def test_base(self): self.assert_msonable(atoms_only) -class TestPPModel: +class TestPPModel(PymatgenTest): def test_base(self): godby = PPModel.as_ppmodel("godby:12 eV") godby.to_abivars() diff --git a/tests/io/abinit/test_inputs.py b/tests/io/abinit/test_inputs.py index 0b83f596e80..762ea2acad8 100644 --- a/tests/io/abinit/test_inputs.py +++ b/tests/io/abinit/test_inputs.py @@ -18,7 +18,7 @@ ion_ioncell_relax_input, num_valence_electrons, ) -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest TEST_DIR = f"{TEST_FILES_DIR}/io/abinit" @@ -33,7 +33,7 @@ def abiref_files(*filenames): return [f"{TEST_DIR}/{file}" for file in filenames] -class TestAbinitInput: +class TestAbinitInput(PymatgenTest): """Unit tests for BasicAbinitInput.""" def test_api(self): @@ -168,7 +168,7 @@ def test_helper_functions(self): assert len(inp["kptbounds"]) == 12 -class TestMultiDataset: +class TestMultiDataset(PymatgenTest): """Unit tests for BasicMultiDataset.""" def test_api(self): @@ -251,7 +251,7 @@ def test_api(self): self.serialize_with_pickle(multi, test_eq=False) -class TestShiftMode: +class TestShiftMode(PymatgenTest): def test_shiftmode(self): gamma = ShiftMode.GammaCentered assert ShiftMode.from_object("G") == gamma @@ -260,8 +260,8 @@ def test_shiftmode(self): ShiftMode.from_object({}) -class TestFactory: - def setup_method(self): +class TestFactory(PymatgenTest): + def setUp(self): # Si ebands self.si_structure = Structure.from_file(abiref_file("si.cif")) self.si_pseudo = abiref_file("14si.pspnc") diff --git a/tests/io/abinit/test_netcdf.py b/tests/io/abinit/test_netcdf.py index 2e32d6bcc50..b4b2ffa68c1 100644 --- a/tests/io/abinit/test_netcdf.py +++ b/tests/io/abinit/test_netcdf.py @@ -11,7 +11,7 @@ from pymatgen.core.structure import Structure from pymatgen.io.abinit import EtsfReader from pymatgen.io.abinit.netcdf import AbinitHeader -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest try: import netCDF4 @@ -21,8 +21,8 @@ TEST_DIR = f"{TEST_FILES_DIR}/io/abinit" -class TestEtsfReader: - def setup_method(self): +class TestEtsfReader(PymatgenTest): + def setUp(self): formulas = ["Si2"] self.GSR_paths = dct = {} for formula in formulas: @@ -117,7 +117,7 @@ def test_read_fe(self): assert structure.site_properties["magmom"] == ref_magmom_noncollinear -class TestAbinitHeader: +class TestAbinitHeader(PymatgenTest): def test_api(self): head = AbinitHeader(foo=1, bar=2) assert head.foo == 1 diff --git a/tests/io/abinit/test_pseudos.py b/tests/io/abinit/test_pseudos.py index bdd92728d81..8cd9bace814 100644 --- a/tests/io/abinit/test_pseudos.py +++ b/tests/io/abinit/test_pseudos.py @@ -9,13 +9,13 @@ from pytest import approx from pymatgen.io.abinit.pseudos import Pseudo, PseudoTable -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest TEST_DIR = f"{TEST_FILES_DIR}/io/abinit" -class TestPseudo: - def setup_method(self): +class TestPseudo(PymatgenTest): + def setUp(self): nc_pseudo_fnames = defaultdict(list) nc_pseudo_fnames["Si"] = [f"{TEST_DIR}/{file}" for file in ("14si.pspnc", "14si.4.hgh", "14-Si.LDA.fhi")] @@ -198,7 +198,7 @@ def test_oncvpsp_pseudo_fr(self): assert pb.supports_soc -class TestPseudoTable: +class TestPseudoTable(PymatgenTest): def test_methods(self): """Test PseudoTable methods.""" table = PseudoTable([f"{TEST_DIR}/{file}" for file in ("14si.pspnc", "14si.4.hgh", "14-Si.LDA.fhi")]) diff --git a/tests/io/cp2k/test_inputs.py b/tests/io/cp2k/test_inputs.py index 10eedefb468..ec0b772c617 100644 --- a/tests/io/cp2k/test_inputs.py +++ b/tests/io/cp2k/test_inputs.py @@ -22,7 +22,7 @@ Section, SectionList, ) -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest TEST_DIR = f"{TEST_FILES_DIR}/io/cp2k" @@ -41,7 +41,7 @@ """ -class TestBasis: +class TestBasis(PymatgenTest): def test_basis_info(self): # Ensure basis metadata can be read from string basis_info = BasisInfo.from_str("cc-pc-DZVP-MOLOPT-q1-SCAN") @@ -92,7 +92,7 @@ def test_basis(self): mol_opt.info.admm = False -class TestPotential: +class TestPotential(PymatgenTest): all_hydrogen_str = """ H ALLELECTRON ALL 1 0 0 @@ -144,7 +144,7 @@ def test_potentials(self): assert kw.values[0] == "ALL" -class TestCp2kInput: +class TestCp2kInput(PymatgenTest): si_struct = Structure( lattice=[ [0, 2.734364, 2.734364], @@ -170,7 +170,7 @@ class TestCp2kInput: &END """ - def setup_method(self): + def setUp(self): self.ci = Cp2kInput.from_file(f"{TEST_DIR}/cp2k.inp") def test_basic_sections(self): @@ -268,7 +268,7 @@ def test_mongo(self): assert cp2k_input.check("global/subsec2") -class TestDataFile: +class TestDataFile(PymatgenTest): def test_data_file(self): # make temp file with BASIS_FILE_STR data_file = self.tmp_path / "data-file" diff --git a/tests/io/cp2k/test_outputs.py b/tests/io/cp2k/test_outputs.py index 19762d1bfb2..84c3fab0e18 100644 --- a/tests/io/cp2k/test_outputs.py +++ b/tests/io/cp2k/test_outputs.py @@ -13,7 +13,7 @@ class TestCp2kOutput(TestCase): - def setup_method(self): + def setUp(self): self.out = Cp2kOutput(f"{TEST_DIR}/cp2k.out", auto_load=True) def test_files(self): diff --git a/tests/io/cp2k/test_sets.py b/tests/io/cp2k/test_sets.py index 943facb4b87..e2c74bc31a6 100644 --- a/tests/io/cp2k/test_sets.py +++ b/tests/io/cp2k/test_sets.py @@ -6,7 +6,7 @@ from pymatgen.core.structure import Molecule, Structure from pymatgen.io.cp2k.sets import SETTINGS, Cp2kValidationError, DftSet, GaussianTypeOrbitalBasisSet, GthPotential -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest CP2K_TEST_DIR = f"{TEST_FILES_DIR}/io/cp2k" @@ -46,7 +46,7 @@ } -class TestDftSet: +class TestDftSet(PymatgenTest): def test_dft_set(self) -> None: """Test various DFT set configurations.""" SETTINGS["PMG_CP2K_DATA_DIR"] = CP2K_TEST_DIR diff --git a/tests/io/exciting/test_inputs.py b/tests/io/exciting/test_inputs.py index e3b134f8429..ccbac253944 100644 --- a/tests/io/exciting/test_inputs.py +++ b/tests/io/exciting/test_inputs.py @@ -6,7 +6,7 @@ from pymatgen.core import Lattice, Structure from pymatgen.io.exciting import ExcitingInput -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest __author__ = "Christian Vorwerk" __copyright__ = "Copyright 2016" @@ -19,7 +19,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/io/exciting" -class TestExcitingInput: +class TestExcitingInput(PymatgenTest): def test_fromfile(self): # Test for the import of a structure directly from an exciting # input file diff --git a/tests/io/feff/test_inputs.py b/tests/io/feff/test_inputs.py index ea95c1b25e6..0128bb60fed 100644 --- a/tests/io/feff/test_inputs.py +++ b/tests/io/feff/test_inputs.py @@ -58,7 +58,7 @@ def test_as_dict_and_from_dict(self): class TestFeffAtoms(TestCase): @classmethod - def setup_class(cls): + def setUpClass(cls): cls.structure = Structure.from_file(f"{TEST_FILES_DIR}/cif/CoO19128.cif") cls.atoms = Atoms(cls.structure, "O", 12.0) @@ -246,7 +246,7 @@ def test_as_dict_and_from_dict(self): class TestPaths(TestCase): - def setup_method(self): + def setUp(self): feo = Structure.from_dict( { "lattice": { diff --git a/tests/io/feff/test_sets.py b/tests/io/feff/test_sets.py index 5e47de2ca40..e57e560996c 100644 --- a/tests/io/feff/test_sets.py +++ b/tests/io/feff/test_sets.py @@ -9,14 +9,14 @@ from pymatgen.core.structure import Lattice, Molecule, Structure from pymatgen.io.feff.inputs import Atoms, Header, Potential, Tags from pymatgen.io.feff.sets import FEFFDictSet, MPELNESSet, MPEXAFSSet, MPXANESSet -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest FEFF_TEST_DIR = f"{TEST_FILES_DIR}/io/feff" -class TestFeffInputSet: +class TestFeffInputSet(PymatgenTest): @classmethod - def setup_class(cls): + def setUpClass(cls): cls.header_string = """* This FEFF.inp file generated by pymatgen TITLE comment: From cif file TITLE Source: CoO19128.cif diff --git a/tests/io/lammps/test_data.py b/tests/io/lammps/test_data.py index 3fbf53aa4f4..3be78db967c 100644 --- a/tests/io/lammps/test_data.py +++ b/tests/io/lammps/test_data.py @@ -14,14 +14,14 @@ from pymatgen.core import Element, Lattice, Molecule, Structure from pymatgen.io.lammps.data import CombinedData, ForceField, LammpsBox, LammpsData, Topology, lattice_2_lmpbox -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest TEST_DIR = f"{TEST_FILES_DIR}/io/lammps" -class TestLammpsBox: +class TestLammpsBox(PymatgenTest): @classmethod - def setup_class(cls): + def setUpClass(cls): cls.peptide = LammpsBox( bounds=[ [36.840194, 64.211560], @@ -73,9 +73,9 @@ def test_to_lattice(self): ) -class TestLammpsData: +class TestLammpsData(PymatgenTest): @classmethod - def setup_class(cls): + def setUpClass(cls): cls.peptide = LammpsData.from_file(filename=f"{TEST_DIR}/data.peptide") cls.ethane = LammpsData.from_file(filename=f"{TEST_DIR}/ethane.data") cls.quartz = LammpsData.from_file(filename=f"{TEST_DIR}/data.quartz", atom_style="atomic") @@ -665,9 +665,9 @@ def test_from_bonding(self): assert "Dihedrals" not in topo_etoh2.topologies -class TestForceField: +class TestForceField(PymatgenTest): @classmethod - def setup_class(cls): + def setUpClass(cls): mass_info = [ ("A", "H"), ("B", Element("C")), @@ -820,7 +820,7 @@ def test_lattice_2_lmpbox(self): class TestCombinedData(TestCase): @classmethod - def setup_class(cls): + def setUpClass(cls): cls.ec = LammpsData.from_file(filename=f"{TEST_DIR}/ec.data.gz") cls.fec = LammpsData.from_file(filename=f"{TEST_DIR}/fec.data.gz") cls.li = LammpsData.from_file(filename=f"{TEST_DIR}/li.data") diff --git a/tests/io/lammps/test_generators.py b/tests/io/lammps/test_generators.py index 41be716ae11..d19eddbf8df 100644 --- a/tests/io/lammps/test_generators.py +++ b/tests/io/lammps/test_generators.py @@ -3,14 +3,14 @@ from pymatgen.core.structure import Structure from pymatgen.io.lammps.data import LammpsData from pymatgen.io.lammps.generators import LammpsMinimization -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest TEST_DIR = f"{TEST_FILES_DIR}/io/lammps" -class TestLammpsMinimization: +class TestLammpsMinimization(PymatgenTest): @classmethod - def setup_class(cls): + def setUpClass(cls): cls.filename = f"{TEST_DIR}/lgps.in" cls.cif = f"{TEST_DIR}/lgps.cif" cls.structure = Structure.from_file(cls.cif) diff --git a/tests/io/lammps/test_inputs.py b/tests/io/lammps/test_inputs.py index 485a2177fe3..15f8ef3fac4 100644 --- a/tests/io/lammps/test_inputs.py +++ b/tests/io/lammps/test_inputs.py @@ -11,14 +11,14 @@ from pymatgen.core.structure import Structure from pymatgen.io.lammps.data import LammpsData from pymatgen.io.lammps.inputs import LammpsInputFile, LammpsRun, LammpsTemplateGen, write_lammps_inputs -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest TEST_DIR = f"{TEST_FILES_DIR}/io/lammps" -class TestLammpsInputFile: +class TestLammpsInputFile(PymatgenTest): @classmethod - def setup_class(cls): + def setUpClass(cls): cls.filename = f"{TEST_DIR}/lgps.in" def test_from_file(self): @@ -640,7 +640,7 @@ def test_add_comment(self): ] -class TestLammpsRun: +class TestLammpsRun(PymatgenTest): def test_md(self): struct = Structure.from_spacegroup(225, Lattice.cubic(3.62126), ["Cu"], [[0, 0, 0]]) ld = LammpsData.from_structure(struct, atom_style="atomic") @@ -690,7 +690,7 @@ def test_md(self): assert os.path.isfile(f"{self.tmp_path}/md/md.data") -class TestFunc: +class TestFunc(PymatgenTest): @pytest.mark.filterwarnings("ignore:write_lammps_inputs is deprecated") def test_write_lammps_inputs(self): # script template @@ -727,7 +727,7 @@ def test_write_lammps_inputs(self): pd.testing.assert_frame_equal(obj_read.atoms, obj.atoms) -class TestLammpsTemplateGen: +class TestLammpsTemplateGen(PymatgenTest): def test_write_inputs(self): # simple script without data file lis = LammpsTemplateGen().get_input_set( diff --git a/tests/io/lammps/test_outputs.py b/tests/io/lammps/test_outputs.py index 15b482c3d7c..6d5e83c3089 100644 --- a/tests/io/lammps/test_outputs.py +++ b/tests/io/lammps/test_outputs.py @@ -16,7 +16,7 @@ class TestLammpsDump(TestCase): @classmethod - def setup_class(cls): + def setUpClass(cls): with open(f"{TEST_DIR}/dump.rdx_wc.100") as file: rdx_str = file.read() cls.rdx = LammpsDump.from_str(string=rdx_str) diff --git a/tests/io/lammps/test_utils.py b/tests/io/lammps/test_utils.py index ed3f6790580..4a116c021a6 100644 --- a/tests/io/lammps/test_utils.py +++ b/tests/io/lammps/test_utils.py @@ -12,7 +12,7 @@ class TestPolymer(TestCase): @classmethod - def setup_class(cls): + def setUpClass(cls): # head molecule cls.peo_head = Molecule.from_file(f"{TEST_DIR}/peo_head.xyz") charges = [-0.1187, 0.0861, 0.0861, 0.0861, -0.2792, -0.0326, 0.0861, 0.0861] @@ -84,7 +84,7 @@ def test_polymer_chain_topologies(self): class TestPackmolOutput(TestCase): @classmethod - def setup_class(cls): + def setUpClass(cls): ethanol_coords = [ [0.00720, -0.56870, 0.00000], [-1.28540, 0.24990, 0.00000], diff --git a/tests/io/lobster/test_inputs.py b/tests/io/lobster/test_inputs.py index 98720a0d5d6..59960d5970f 100644 --- a/tests/io/lobster/test_inputs.py +++ b/tests/io/lobster/test_inputs.py @@ -8,7 +8,7 @@ from pymatgen.io.lobster import Lobsterin from pymatgen.io.lobster.inputs import get_all_possible_basis_combinations from pymatgen.io.vasp.inputs import Incar, Kpoints, Potcar -from pymatgen.util.testing import FAKE_POTCAR_DIR, TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR +from pymatgen.util.testing import FAKE_POTCAR_DIR, TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR, PymatgenTest TEST_DIR = f"{TEST_FILES_DIR}/electronic_structure/cohp" @@ -19,8 +19,8 @@ __date__ = "Dec 10, 2017" -class TestLobsterin: - def setup_method(self): +class TestLobsterin(PymatgenTest): + def setUp(self): self.Lobsterin = Lobsterin.from_file(f"{TEST_DIR}/lobsterin.1") self.Lobsterin2 = Lobsterin.from_file(f"{TEST_DIR}/lobsterin.2") self.Lobsterin3 = Lobsterin.from_file(f"{TEST_DIR}/lobsterin.3") @@ -579,7 +579,7 @@ def test_as_from_dict(self): new_lobsterin.to_json() -class TestUtils: +class TestUtils(PymatgenTest): def test_get_all_possible_basis_combinations(self): # this basis is just for testing (not correct) min_basis = ["Li 1s 2s ", "Na 1s 2s", "Si 1s 2s"] diff --git a/tests/io/lobster/test_lobsterenv.py b/tests/io/lobster/test_lobsterenv.py index 52505d4670e..4f9cc9959b8 100644 --- a/tests/io/lobster/test_lobsterenv.py +++ b/tests/io/lobster/test_lobsterenv.py @@ -25,7 +25,7 @@ class TestLobsterNeighbors(TestCase): - def setup_method(self): + def setUp(self): # test additional conditions first # only consider cation anion bonds diff --git a/tests/io/lobster/test_outputs.py b/tests/io/lobster/test_outputs.py index 2119f05b413..4dac8c4a01b 100644 --- a/tests/io/lobster/test_outputs.py +++ b/tests/io/lobster/test_outputs.py @@ -31,7 +31,7 @@ Wavefunction, ) from pymatgen.io.vasp import Vasprun -from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR +from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR, PymatgenTest TEST_DIR = f"{TEST_FILES_DIR}/electronic_structure/cohp" @@ -42,8 +42,8 @@ __date__ = "Dec 10, 2017" -class TestBwdf: - def setup_method(self): +class TestBwdf(PymatgenTest): + def setUp(self): self.bwdf_coop = Bwdf(filename=f"{TEST_DIR}/BWDF.lobster.AlN.gz") self.bwdf_cohp = Bwdf(filename=f"{TEST_DIR}/BWDFCOHP.lobster.NaCl.gz") @@ -57,8 +57,8 @@ def test_attributes(self): assert self.bwdf_cohp.bwdf[Spin.up][103] == approx(-0.01392, abs=1e-4) -class TestCohpcar: - def setup_method(self): +class TestCohpcar(PymatgenTest): + def setUp(self): self.cohp_bise = Cohpcar(filename=f"{TEST_DIR}/COHPCAR.lobster.BiSe.gz") self.coop_bise = Cohpcar( filename=f"{TEST_DIR}/COOPCAR.lobster.BiSe.gz", @@ -399,7 +399,7 @@ def test_orbital_resolved_cohp(self): class TestDoscar(TestCase): - def setup_method(self): + def setUp(self): # first for spin polarized version doscar = f"{VASP_OUT_DIR}/DOSCAR.lobster.spin" poscar = f"{VASP_IN_DIR}/POSCAR.lobster.spin_DOS" @@ -637,8 +637,8 @@ def test_is_spin_polarized(self): assert not self.DOSCAR_nonspin_pol.is_spin_polarized -class TestCharge: - def setup_method(self): +class TestCharge(PymatgenTest): + def setUp(self): self.charge2 = Charge(filename=f"{TEST_DIR}/CHARGE.lobster.MnO") # gzipped file self.charge = Charge(filename=f"{TEST_DIR}/CHARGE.lobster.MnO2.gz") @@ -716,8 +716,8 @@ def test_msonable(self): assert getattr(charge_from_dict, attr_name) == attr_value -class TestLobsterout: - def setup_method(self): +class TestLobsterout(PymatgenTest): + def setUp(self): self.lobsterout_normal = Lobsterout(filename=f"{TEST_DIR}/lobsterout.normal") # make sure .gz files are also read correctly self.lobsterout_normal = Lobsterout(filename=f"{TEST_DIR}/lobsterout.normal2.gz") @@ -1245,8 +1245,8 @@ def test_msonable(self): Lobsterout(filename=None, invalid="val") -class TestFatband: - def setup_method(self): +class TestFatband(PymatgenTest): + def setUp(self): self.structure = Vasprun( filename=f"{TEST_DIR}/Fatband_SiO2/Test_p_x/vasprun.xml", ionic_step_skip=None, @@ -1481,7 +1481,7 @@ def test_get_bandstructure(self): class TestBandoverlaps(TestCase): - def setup_method(self): + def setUp(self): # test spin-polarized calc and non spin-polarized calc self.band_overlaps1 = Bandoverlaps(f"{TEST_DIR}/bandOverlaps.lobster.1") @@ -1714,7 +1714,7 @@ def test_keys(self): class TestGrosspop(TestCase): - def setup_method(self): + def setUp(self): self.grosspop1 = Grosspop(f"{TEST_DIR}/GROSSPOP.lobster") self.grosspop_511_sp = Grosspop(f"{TEST_DIR}/GROSSPOP_511_sp.lobster.AlN.gz") self.grosspop_511_nsp = Grosspop(f"{TEST_DIR}/GROSSPOP_511_nsp.lobster.NaCl.gz") @@ -1864,7 +1864,7 @@ def test_msonable(self): class TestIcohplist(TestCase): - def setup_method(self): + def setUp(self): self.icohp_bise = Icohplist(filename=f"{TEST_DIR}/ICOHPLIST.lobster.BiSe") self.icoop_bise = Icohplist( filename=f"{TEST_DIR}/ICOOPLIST.lobster.BiSe", @@ -2169,7 +2169,7 @@ def test_msonable(self): class TestNciCobiList(TestCase): - def setup_method(self): + def setUp(self): self.ncicobi = NciCobiList(filename=f"{TEST_DIR}/NcICOBILIST.lobster") self.ncicobi_gz = NciCobiList(filename=f"{TEST_DIR}/NcICOBILIST.lobster.gz") self.ncicobi_no_spin = NciCobiList(filename=f"{TEST_DIR}/NcICOBILIST.lobster.nospin") @@ -2204,7 +2204,7 @@ def test_ncicobilist(self): ) -class TestWavefunction: +class TestWavefunction(PymatgenTest): def test_parse_file(self): grid, points, real, imaginary, distance = Wavefunction._parse_file( f"{TEST_DIR}/LCAOWaveFunctionAfterLSO1PlotOfSpin1Kpoint1band1.gz" @@ -2272,8 +2272,8 @@ def test_write_file(self): assert os.path.isfile(density_wavecar_path) -class TestSitePotentials: - def setup_method(self) -> None: +class TestSitePotentials(PymatgenTest): + def setUp(self) -> None: self.sitepotential = SitePotential(filename=f"{TEST_DIR}/SitePotentials.lobster.perovskite") def test_attributes(self): @@ -2323,8 +2323,8 @@ def test_msonable(self): assert getattr(sitepotential_from_dict, attr_name) == attr_value -class TestMadelungEnergies: - def setup_method(self) -> None: +class TestMadelungEnergies(PymatgenTest): + def setUp(self) -> None: self.madelungenergies = MadelungEnergies(filename=f"{TEST_DIR}/MadelungEnergies.lobster.perovskite") def test_attributes(self): @@ -2340,8 +2340,8 @@ def test_msonable(self): assert getattr(madelung_from_dict, attr_name) == attr_value -class TestLobsterMatrices: - def setup_method(self) -> None: +class TestLobsterMatrices(PymatgenTest): + def setUp(self) -> None: self.hamilton_matrices = LobsterMatrices( filename=f"{TEST_DIR}/Na_hamiltonMatrices.lobster.gz", e_fermi=-2.79650354 ) @@ -2490,8 +2490,8 @@ def test_raises(self): self.hamilton_matrices = LobsterMatrices(filename=f"{TEST_DIR}/hamiltonMatrices.lobster") -class TestPolarization: - def setup_method(self) -> None: +class TestPolarization(PymatgenTest): + def setUp(self) -> None: self.polarization = Polarization(filename=f"{TEST_DIR}/POLARIZATION.lobster.AlN.gz") def test_attributes(self): diff --git a/tests/io/pwmat/test_inputs.py b/tests/io/pwmat/test_inputs.py index 8e21dc0428f..7618e7ecdf6 100644 --- a/tests/io/pwmat/test_inputs.py +++ b/tests/io/pwmat/test_inputs.py @@ -18,7 +18,7 @@ LineLocator, ListLocator, ) -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest TEST_DIR = f"{TEST_FILES_DIR}/io/pwmat" @@ -43,7 +43,7 @@ def test_list_locator(exclusion: str, expected_idx: int): assert aim_idx == expected_idx -class TestACstrExtractor: +class TestACstrExtractor(PymatgenTest): def test_extract(self): filepath = f"{TEST_DIR}/atom.config" ac_extractor = ACExtractor(file_path=filepath) @@ -60,7 +60,7 @@ def test_extract(self): assert ac_extractor.magmoms[idx] == ac_str_extractor.get_magmoms()[idx] -class TestAtomConfig: +class TestAtomConfig(PymatgenTest): def test_init(self): filepath = f"{TEST_DIR}/atom.config" structure = Structure.from_file(filepath) @@ -82,7 +82,7 @@ def test_write_file(self): assert_allclose(atom_config.structure.lattice.abc, tmp_atom_config.structure.lattice.abc, 5) -class TestGenKpt: +class TestGenKpt(PymatgenTest): def test_from_structure(self): pytest.importorskip("seekpath") filepath = f"{TEST_DIR}/atom.config" @@ -107,7 +107,7 @@ def test_write_file(self): assert gen_kpt.get_str() == tmp_gen_kpt_str -class TestHighSymmetryPoint: +class TestHighSymmetryPoint(PymatgenTest): def test_from_structure(self): pytest.importorskip("seekpath") filepath = f"{TEST_DIR}/atom.config" diff --git a/tests/io/pwmat/test_outputs.py b/tests/io/pwmat/test_outputs.py index ea7d0150122..b2a97f891fe 100644 --- a/tests/io/pwmat/test_outputs.py +++ b/tests/io/pwmat/test_outputs.py @@ -1,12 +1,12 @@ from __future__ import annotations from pymatgen.io.pwmat.outputs import DosSpin, Movement, OutFermi, Report -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest TEST_DIR = f"{TEST_FILES_DIR}/io/pwmat" -class TestMovement: +class TestMovement(PymatgenTest): def test_init_and_properties(self): filepath = f"{TEST_DIR}/MOVEMENT.lzma" movement = Movement(filepath) @@ -26,14 +26,14 @@ def test_init_and_properties(self): assert movement.ionic_steps[0]["e_tot"] == -357677.2281 -class TestOutFermi: +class TestOutFermi(PymatgenTest): def test_init_and_properties(self): filepath = f"{TEST_DIR}/OUT.FERMI.lzma" out_fermi = OutFermi(filepath) assert out_fermi.e_fermi == -2.359 -class TestReport: +class TestReport(PymatgenTest): def test_init_and_properties(self): filepath = f"{TEST_DIR}/REPORT" report = Report(filepath) @@ -46,7 +46,7 @@ def test_init_and_properties(self): assert report.hsps == {} -class TestDosSpin: +class TestDosSpin(PymatgenTest): def test_init_and_properties(self): filepath = f"{TEST_DIR}/DOS.spinup_projected" dos_spin = DosSpin(filepath) diff --git a/tests/io/qchem/test_inputs.py b/tests/io/qchem/test_inputs.py index 49737711af7..fe87a29a095 100644 --- a/tests/io/qchem/test_inputs.py +++ b/tests/io/qchem/test_inputs.py @@ -8,7 +8,7 @@ from pymatgen.core.structure import Molecule from pymatgen.io.qchem.inputs import QCInput from pymatgen.io.qchem.sets import OptSet -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest TEST_DIR = f"{TEST_FILES_DIR}/io/qchem" @@ -20,7 +20,7 @@ __credits__ = "Xiaohui Qu" -class TestQCInput: +class TestQCInput(PymatgenTest): def test_molecule_template(self): species = ["C", "O"] coords = [ diff --git a/tests/io/qchem/test_outputs.py b/tests/io/qchem/test_outputs.py index 0c727a1bdce..22f681f8918 100644 --- a/tests/io/qchem/test_outputs.py +++ b/tests/io/qchem/test_outputs.py @@ -17,7 +17,7 @@ hessian_parser, orbital_coeffs_parser, ) -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest try: from openbabel import openbabel @@ -260,7 +260,7 @@ } -class TestQCOutput: +class TestQCOutput(PymatgenTest): @staticmethod def generate_single_job_dict(): """Used to generate test dictionary for single jobs.""" diff --git a/tests/io/qchem/test_sets.py b/tests/io/qchem/test_sets.py index f969e5a1c78..9a677b02ab8 100644 --- a/tests/io/qchem/test_sets.py +++ b/tests/io/qchem/test_sets.py @@ -14,7 +14,7 @@ SinglePointSet, TransitionStateSet, ) -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest __author__ = "Samuel Blau, Brandon Wood, Shyam Dwaraknath, Evan Spotte-Smith, Ryan Kingsbury" __copyright__ = "Copyright 2018-2022, The Materials Project" @@ -26,7 +26,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/io/qchem/new_qchem_files" -class TestQChemDictSet: +class TestQChemDictSet(PymatgenTest): def test_init(self): test_molecule = QCInput.from_file(f"{TEST_DIR}/pcm.qin").molecule test_dict_set = QChemDictSet( @@ -469,7 +469,7 @@ def test_solvation_warnings(self): ) -class TestSinglePointSet: +class TestSinglePointSet(PymatgenTest): def test_init(self): test_molecule = QCInput.from_file(f"{TEST_DIR}/pcm.qin").molecule test_sp_set = SinglePointSet(molecule=test_molecule) @@ -671,7 +671,7 @@ def test_plots_init(self): assert test_sp_set.molecule == test_molecule -class TestOptSet: +class TestOptSet(PymatgenTest): def test_init(self): test_molecule = QCInput.from_file(f"{TEST_DIR}/pcm.qin").molecule test_opt_set = OptSet(molecule=test_molecule) @@ -846,7 +846,7 @@ def test_v5_vs_v6(self): assert v6_opt_set_modified.geom_opt == ref_dict -class TestTransitionStateSet: +class TestTransitionStateSet(PymatgenTest): def test_init(self): test_molecule = QCInput.from_file(f"{TEST_DIR}/pcm.qin").molecule test_ts_set = TransitionStateSet(molecule=test_molecule) @@ -927,7 +927,7 @@ def test_smd_init(self): assert test_ts_set.molecule == test_molecule -class TestForceSet: +class TestForceSet(PymatgenTest): def test_init(self): test_molecule = QCInput.from_file(f"{TEST_DIR}/pcm.qin").molecule test_forceset = ForceSet(molecule=test_molecule) @@ -1004,7 +1004,7 @@ def test_smd_init(self): assert test_forceset.molecule == test_molecule -class TestPESScanSet: +class TestPESScanSet(PymatgenTest): def test_init(self): test_molecule = QCInput.from_file(f"{TEST_DIR}/pes_scan.qin").molecule @@ -1097,7 +1097,7 @@ def test_smd_init(self): assert test_pes_scan.molecule == test_molecule -class TestFreqSet: +class TestFreqSet(PymatgenTest): def test_init(self): test_molecule = QCInput.from_file(f"{TEST_DIR}/pcm.qin").molecule test_freq_set = FreqSet(molecule=test_molecule) diff --git a/tests/io/qchem/test_utils.py b/tests/io/qchem/test_utils.py index c12dc788063..4ad091b8242 100644 --- a/tests/io/qchem/test_utils.py +++ b/tests/io/qchem/test_utils.py @@ -6,7 +6,7 @@ from monty.io import zopen from pymatgen.io.qchem.utils import lower_and_check_unique, process_parsed_hess -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest __author__ = "Ryan Kingsbury, Samuel Blau" __copyright__ = "Copyright 2018-2022, The Materials Project" @@ -15,7 +15,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/io/qchem/new_qchem_files" -class TestUtil: +class TestUtil(PymatgenTest): """test utils.""" def test_lower_and_check_unique(self): diff --git a/tests/io/test_adf.py b/tests/io/test_adf.py index 43d210e8a3e..d3b6785320f 100644 --- a/tests/io/test_adf.py +++ b/tests/io/test_adf.py @@ -4,7 +4,7 @@ from pymatgen.core.structure import Molecule from pymatgen.io.adf import AdfInput, AdfKey, AdfOutput, AdfTask -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest __author__ = "Xin Chen, chenxin13@mails.tsinghua.edu.cn" @@ -242,7 +242,7 @@ def test_serialization(self): } -class TestAdfInput: +class TestAdfInput(PymatgenTest): def test_main(self): tmp_file = f"{self.tmp_path}/adf.temp" mol = Molecule.from_str(rhb18_xyz, "xyz") diff --git a/tests/io/test_atat.py b/tests/io/test_atat.py index 23c9ca9472e..a9562f92511 100644 --- a/tests/io/test_atat.py +++ b/tests/io/test_atat.py @@ -5,12 +5,12 @@ from pymatgen.core.structure import Structure from pymatgen.io.atat import Mcsqs -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest TEST_DIR = f"{TEST_FILES_DIR}/io/atat/mcsqs" -class TestAtat: +class TestAtat(PymatgenTest): def test_mcsqs_import(self): test_str = """1.000000 0.000000 0.000000 0.000000 1.000000 0.000000 diff --git a/tests/io/test_babel.py b/tests/io/test_babel.py index 32087bd3ac4..6a130dd8914 100644 --- a/tests/io/test_babel.py +++ b/tests/io/test_babel.py @@ -18,7 +18,7 @@ class TestBabelMolAdaptor(TestCase): - def setup_method(self): + def setUp(self): coords = [ [0.000000, 0.000000, 0.000000], [0.000000, 0.000000, 1.089000], diff --git a/tests/io/test_cif.py b/tests/io/test_cif.py index b9d448e01a5..690c67c302d 100644 --- a/tests/io/test_cif.py +++ b/tests/io/test_cif.py @@ -9,7 +9,7 @@ from pymatgen.electronic_structure.core import Magmom from pymatgen.io.cif import CifBlock, CifParser, CifWriter from pymatgen.symmetry.structure import SymmetrizedStructure -from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR +from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, PymatgenTest try: import pybtex @@ -20,7 +20,7 @@ MCIF_TEST_DIR = f"{TEST_FILES_DIR}/io/cif/mcif" -class TestCifBlock: +class TestCifBlock(PymatgenTest): def test_to_str(self): with open(f"{TEST_FILES_DIR}/cif/Graphite.cif") as file: cif_str = file.read() @@ -164,7 +164,7 @@ def test_long_loop(self): assert str(CifBlock(data, loops, "test")) == cif_str -class TestCifIO: +class TestCifIO(PymatgenTest): def test_cif_parser(self): parser = CifParser(f"{TEST_FILES_DIR}/cif/LiFePO4.cif") for struct in parser.parse_structures(): @@ -999,8 +999,8 @@ def test_cif_writer_site_properties(self): assert "O O23 1 0.95662769 0.25000000 0.29286233 1 -1.0" in cif_str -class TestMagCif: - def setup_method(self): +class TestMagCif(PymatgenTest): + def setUp(self): self.mcif = CifParser(f"{MCIF_TEST_DIR}/magnetic.example.NiO.mcif") self.mcif_ncl = CifParser(f"{MCIF_TEST_DIR}/magnetic.ncl.example.GdB4.mcif") self.mcif_incommensurate = CifParser(f"{MCIF_TEST_DIR}/magnetic.incommensurate.example.Cr.mcif") diff --git a/tests/io/test_core.py b/tests/io/test_core.py index 24fb290dc15..bd4ad9ea7fa 100644 --- a/tests/io/test_core.py +++ b/tests/io/test_core.py @@ -10,7 +10,7 @@ from pymatgen.core.structure import Structure from pymatgen.io.cif import CifParser, CifWriter from pymatgen.io.core import InputFile, InputSet -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest if TYPE_CHECKING: from typing_extensions import Self @@ -44,7 +44,7 @@ def __str__(self): return f"{self.a}\n{self.b}" -class TestInputFile: +class TestInputFile(PymatgenTest): def test_file_io(self): with pytest.raises(FileNotFoundError, match="No such file or directory: 'fakepath.cif'"): StructInputFile.from_file("fakepath.cif") @@ -64,9 +64,9 @@ def test_msonable(self): assert sif.structure == temp_sif.structure -class TestInputSet: +class TestInputSet(PymatgenTest): @classmethod - def setup_class(cls): + def setUpClass(cls): cls.sif1 = StructInputFile.from_file(f"{TEST_FILES_DIR}/cif/Li.cif") cls.sif2 = StructInputFile.from_file(f"{TEST_FILES_DIR}/cif/LiFePO4.cif") cls.sif3 = StructInputFile.from_file(f"{TEST_FILES_DIR}/cif/Li2O.cif") diff --git a/tests/io/test_cssr.py b/tests/io/test_cssr.py index 951dab817e8..467be18ae3e 100644 --- a/tests/io/test_cssr.py +++ b/tests/io/test_cssr.py @@ -19,7 +19,7 @@ class TestCssr(TestCase): - def setup_method(self): + def setUp(self): filepath = f"{VASP_IN_DIR}/POSCAR" self.cssr = Cssr(Structure.from_file(filepath)) diff --git a/tests/io/test_fiesta.py b/tests/io/test_fiesta.py index d5bce31b5ba..bcc6904a076 100644 --- a/tests/io/test_fiesta.py +++ b/tests/io/test_fiesta.py @@ -10,7 +10,7 @@ class TestFiestaInput(TestCase): - def setup_method(self): + def setUp(self): coords = [ [0.000000, 0.000000, 0.000000], [0.000000, 0.000000, 1.089000], @@ -72,7 +72,7 @@ def test_str_and_from_str(self): class TestFiestaOutput(TestCase): - def setup_method(self): + def setUp(self): self.log_fiesta = FiestaOutput(f"{TEST_DIR}/log_fiesta") def test_props(self): diff --git a/tests/io/test_gaussian.py b/tests/io/test_gaussian.py index 9a5ec7ad0e1..b44db9f2c32 100644 --- a/tests/io/test_gaussian.py +++ b/tests/io/test_gaussian.py @@ -14,7 +14,7 @@ class TestGaussianInput(TestCase): - def setup_method(self): + def setUp(self): coords = [ [0, 0, 0], [0, 0, 1.089], @@ -281,7 +281,7 @@ def test_no_molecule_func_bset_charge_mult(self): class TestGaussianOutput(TestCase): # TODO: Add unittest for PCM type output. - def setup_method(self): + def setUp(self): self.gau_out = GaussianOutput(f"{TEST_DIR}/methane.log") def test_resume(self): diff --git a/tests/io/test_lmto.py b/tests/io/test_lmto.py index 5903fa9daec..1ddc8c2abcf 100644 --- a/tests/io/test_lmto.py +++ b/tests/io/test_lmto.py @@ -10,7 +10,7 @@ from pymatgen.electronic_structure.core import Spin from pymatgen.io.lmto import LMTOCopl, LMTOCtrl from pymatgen.util.num import round_to_sigfigs -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest __author__ = "Marco Esters" __copyright__ = "Copyright 2017, The Materials Project" @@ -23,13 +23,13 @@ MODULE_DIR = os.path.dirname(os.path.abspath(__file__)) -class TestCtrl: - def setup_method(self): +class TestCtrl(PymatgenTest): + def setUp(self): os.chdir(TEST_DIR) self.ref_bise = LMTOCtrl.from_file(filename="CTRL.BiSe") self.ref_fe = LMTOCtrl.from_file() - def teardown_method(self): + def tearDown(self): os.chdir(MODULE_DIR) def test_dict(self): @@ -47,14 +47,14 @@ def test_read_write(self): assert self.ref_bise.structure.matches(ctrl_file.structure) -class TestCopl: - def setup_method(self): +class TestCopl(PymatgenTest): + def setUp(self): os.chdir(TEST_DIR) self.copl_bise = LMTOCopl("COPL.BiSe") self.copl_bise_eV = LMTOCopl(filename="COPL.BiSe", to_eV=True) self.copl_fe = LMTOCopl() - def teardown_method(self): + def tearDown(self): os.chdir(MODULE_DIR) def test_attributes(self): diff --git a/tests/io/test_nwchem.py b/tests/io/test_nwchem.py index beb3e40366a..7304ec4a10e 100644 --- a/tests/io/test_nwchem.py +++ b/tests/io/test_nwchem.py @@ -23,7 +23,7 @@ class TestNwTask(TestCase): - def setup_method(self): + def setUp(self): self.task = NwTask( 0, 1, @@ -137,7 +137,7 @@ def test_esp_task(self): class TestNwInput(TestCase): - def setup_method(self): + def setUp(self): tasks = [ NwTask.dft_task(mol, operation="optimize", xc="b3lyp", basis_set="6-31++G*"), NwTask.dft_task(mol, operation="freq", xc="b3lyp", basis_set="6-31++G*"), diff --git a/tests/io/test_packmol.py b/tests/io/test_packmol.py index 5c709436d83..c6d25953dcd 100644 --- a/tests/io/test_packmol.py +++ b/tests/io/test_packmol.py @@ -10,7 +10,7 @@ from pymatgen.analysis.molecule_matcher import MoleculeMatcher from pymatgen.core import Molecule from pymatgen.io.packmol import PackmolBoxGen -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest TEST_DIR = f"{TEST_FILES_DIR}/io/packmol" # error message is different in CI for unknown reasons (as of 2024-04-12) @@ -48,7 +48,7 @@ water = Molecule(water_atoms, water_coords) -class TestPackmolSet: +class TestPackmolSet(PymatgenTest): def test_packmol_with_molecule(self): """Test coords input as Molecule.""" pw = PackmolBoxGen().get_input_set( diff --git a/tests/io/test_phonopy.py b/tests/io/test_phonopy.py index 4c3000097d1..802e43049e2 100644 --- a/tests/io/test_phonopy.py +++ b/tests/io/test_phonopy.py @@ -42,7 +42,7 @@ PHONON_DIR = f"{TEST_FILES_DIR}/phonon" -class TestPhonopyParser: +class TestPhonopyParser(PymatgenTest): def test_get_ph_bs(self): ph_bs = get_ph_bs_symm_line(f"{TEST_DIR}/NaCl_band.yaml", has_nac=True) @@ -98,7 +98,7 @@ def test_get_complete_dos(self): @pytest.mark.skipif(Phonopy is None, reason="Phonopy not present") -class TestStructureConversion: +class TestStructureConversion(PymatgenTest): def test_structure_conversion(self): struct_pmg = PymatgenTest.get_structure("LiFePO4") # add magmoms to site_properties @@ -126,7 +126,7 @@ def test_structure_conversion(self): @pytest.mark.skipif(Phonopy is None, reason="Phonopy not present") -class TestGetDisplacedStructures: +class TestGetDisplacedStructures(PymatgenTest): def test_get_displaced_structures(self): pmg_s = Structure.from_file(f"{TEST_DIR}/POSCAR-unitcell", primitive=False) supercell_matrix = np.diag((2, 1, 2)) @@ -163,7 +163,7 @@ def test_get_displaced_structures(self): reason="See https://github.com/conda-forge/phonopy-feedstock/pull/158#issuecomment-2227506701", ) class TestPhonopyFromForceConstants(TestCase): - def setup_method(self) -> None: + def setUp(self) -> None: test_path = Path(TEST_DIR) structure_file = test_path / "POSCAR-NaCl" fc_file = test_path / "FORCE_CONSTANTS" @@ -246,7 +246,7 @@ def test_gruneisen_parameter(self): @pytest.mark.skipif(Phonopy is None, reason="Phonopy not present") -class TestThermalDisplacementMatrices: +class TestThermalDisplacementMatrices(PymatgenTest): def test_get_thermal_displacement_matrix(self): list_matrices = get_thermal_displacement_matrices( f"{PHONON_DIR}/thermal_displacement_matrices/thermal_displacement_matrices.yaml", diff --git a/tests/io/test_pwscf.py b/tests/io/test_pwscf.py index 8cde518b0c5..6e39c8b4019 100644 --- a/tests/io/test_pwscf.py +++ b/tests/io/test_pwscf.py @@ -6,12 +6,12 @@ from pytest import approx from pymatgen.io.pwscf import PWInput, PWInputError, PWOutput -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest TEST_DIR = f"{TEST_FILES_DIR}/io/pwscf" -class TestPWInput: +class TestPWInput(PymatgenTest): def test_init(self): struct = self.get_structure("Li2O") with pytest.raises(PWInputError, match="Missing O2- in pseudo specification"): @@ -542,8 +542,8 @@ def test_custom_decimal_precision_write_and_read_str(self): assert pw_str.strip() == str(PWInput.from_str(pw_str)).strip() -class TestPWOutput: - def setup_method(self): +class TestPWOutput(PymatgenTest): + def setUp(self): self.pw_out = PWOutput(f"{TEST_DIR}/Si.pwscf.out") def test_properties(self): diff --git a/tests/io/test_shengbte.py b/tests/io/test_shengbte.py index e3419d93c8d..303c9d094aa 100644 --- a/tests/io/test_shengbte.py +++ b/tests/io/test_shengbte.py @@ -4,14 +4,14 @@ from numpy.testing import assert_array_equal from pymatgen.io.shengbte import Control -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest f90nml = pytest.importorskip("f90nml") TEST_DIR = f"{TEST_FILES_DIR}/io/shengbte" -class TestShengBTE: - def setup_method(self): +class TestShengBTE(PymatgenTest): + def setUp(self): self.filename = f"{TEST_DIR}/CONTROL-CSLD_Si" self.test_dict = { "nelements": 1, diff --git a/tests/io/test_template_input.py b/tests/io/test_template_input.py index f6ea6e84cf6..3be8ae45374 100644 --- a/tests/io/test_template_input.py +++ b/tests/io/test_template_input.py @@ -5,12 +5,12 @@ import pytest from pymatgen.io.template import TemplateInputGen -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest TEST_DIR = f"{TEST_FILES_DIR}/io" -class TestTemplateInputGen: +class TestTemplateInputGen(PymatgenTest): def test_write_inputs(self): input_set = TemplateInputGen().get_input_set( template=f"{TEST_DIR}/template_input_file.txt", diff --git a/tests/io/test_wannier90.py b/tests/io/test_wannier90.py index 6459e3b9c98..93ac0e256e7 100644 --- a/tests/io/test_wannier90.py +++ b/tests/io/test_wannier90.py @@ -8,13 +8,13 @@ from pytest import approx from pymatgen.io.wannier90 import Unk -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest TEST_DIR = f"{TEST_FILES_DIR}/io/wannier90" -class TestUnk: - def setup_method(self): +class TestUnk(PymatgenTest): + def setUp(self): rng = np.random.default_rng() self.data_std = rng.random((10, 5, 5, 5)) self.unk_std = Unk(1, self.data_std) diff --git a/tests/io/test_xcrysden.py b/tests/io/test_xcrysden.py index 35a82e2d59a..3a13a2cf7b5 100644 --- a/tests/io/test_xcrysden.py +++ b/tests/io/test_xcrysden.py @@ -4,10 +4,11 @@ from pymatgen.core.structure import Structure from pymatgen.io.xcrysden import XSF +from pymatgen.util.testing import PymatgenTest -class TestXSF: - def setup_method(self): +class TestXSF(PymatgenTest): + def setUp(self): self.coords = [[0, 0, 0], [0.75, 0.5, 0.75]] self.lattice = [ [3.8401979337, 0.00, 0.00], diff --git a/tests/io/test_xr.py b/tests/io/test_xr.py index 8321c2340af..05cfa8bfc8e 100644 --- a/tests/io/test_xr.py +++ b/tests/io/test_xr.py @@ -15,7 +15,7 @@ class TestXr(TestCase): - def setup_method(self): + def setUp(self): struct = Structure.from_file(f"{VASP_IN_DIR}/POSCAR") self.xr = Xr(struct) diff --git a/tests/io/test_xyz.py b/tests/io/test_xyz.py index e0ad2ea6f1a..ad57feca5af 100644 --- a/tests/io/test_xyz.py +++ b/tests/io/test_xyz.py @@ -13,7 +13,7 @@ class TestXYZ(TestCase): - def setup_method(self): + def setUp(self): coords = [ [0, 0, 0], [0, 0, 1.089000], diff --git a/tests/io/test_zeopp.py b/tests/io/test_zeopp.py index f049ffccc97..28bc18aad8c 100644 --- a/tests/io/test_zeopp.py +++ b/tests/io/test_zeopp.py @@ -29,7 +29,7 @@ class TestZeoCssr(TestCase): - def setup_method(self): + def setUp(self): filepath = f"{VASP_IN_DIR}/POSCAR" self.zeo_cssr = ZeoCssr(Structure.from_file(filepath)) @@ -71,7 +71,7 @@ def test_from_file(self): class TestZeoCssrOxi(TestCase): - def setup_method(self): + def setUp(self): filepath = f"{VASP_IN_DIR}/POSCAR" structure = BVAnalyzer().get_oxi_state_decorated_structure(Structure.from_file(filepath)) self.zeo_cssr = ZeoCssr(structure) @@ -114,7 +114,7 @@ def test_from_file(self): class TestZeoVoronoiXYZ(TestCase): - def setup_method(self): + def setUp(self): coords = [ [0.000000, 0.000000, 0.000000], [0.000000, 0.000000, 1.089000], @@ -144,7 +144,7 @@ def test_from_file(self): class TestGetVoronoiNodes(TestCase): - def setup_method(self): + def setUp(self): filepath = f"{VASP_IN_DIR}/POSCAR" self.structure = Structure.from_file(filepath) bv = BVAnalyzer() @@ -168,7 +168,7 @@ def test_get_voronoi_nodes(self): @pytest.mark.skip("TODO: file free_sph.cif not present") class TestGetFreeSphereParams(TestCase): - def setup_method(self): + def setUp(self): filepath = f"{TEST_FILES_DIR}/cif/free_sph.cif" self.structure = Structure.from_file(filepath) self.rad_dict = { @@ -189,7 +189,7 @@ def test_get_free_sphere_params(self): class TestGetHighAccuracyVoronoiNodes(TestCase): - def setup_method(self): + def setUp(self): filepath = f"{VASP_IN_DIR}/POSCAR" self.structure = Structure.from_file(filepath) bv = BVAnalyzer() @@ -208,7 +208,7 @@ def test_get_voronoi_nodes(self): class TestGetVoronoiNodesMultiOxi(TestCase): - def setup_method(self): + def setUp(self): filepath = f"{VASP_IN_DIR}/POSCAR" self.structure = Structure.from_file(filepath) bv = BVAnalyzer() diff --git a/tests/io/vasp/test_inputs.py b/tests/io/vasp/test_inputs.py index 11f1bff0de1..1616ff4e5e7 100644 --- a/tests/io/vasp/test_inputs.py +++ b/tests/io/vasp/test_inputs.py @@ -38,7 +38,7 @@ VaspInput, _gen_potcar_summary_stats, ) -from pymatgen.util.testing import FAKE_POTCAR_DIR, TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR +from pymatgen.util.testing import FAKE_POTCAR_DIR, TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR, PymatgenTest # Filter some expected warnings warnings.filterwarnings( @@ -72,7 +72,7 @@ def _mock_complete_potcar_summary_stats(monkeypatch: pytest.MonkeyPatch) -> None @pytest.mark.filterwarnings( "ignore:POTCAR data with symbol .* is not known to pymatgen:pymatgen.io.vasp.inputs.UnknownPotcarWarning" ) -class TestPoscar: +class TestPoscar(PymatgenTest): def test_init(self): comp = Structure.from_file(f"{VASP_IN_DIR}/POSCAR").composition assert comp == Composition("Fe4P4O16") @@ -649,8 +649,8 @@ def test_vasp_6_4_2_format(self): assert poscar.structure.formula == "Li4 Fe4 P4 O16" -class TestIncar: - def setup_method(self): +class TestIncar(PymatgenTest): + def setUp(self): self.incar = Incar.from_file(f"{VASP_IN_DIR}/INCAR") def test_init(self): @@ -1298,7 +1298,7 @@ def test_automatic_monkhorst_vs_gamma_style_selection(self): "ignore:POTCAR data with symbol .* is not known to pymatgen:pymatgen.io.vasp.inputs.UnknownPotcarWarning" ) class TestPotcarSingle(TestCase): - def setup_method(self): + def setUp(self): self.psingle_Mn_pv = PotcarSingle.from_file(f"{FAKE_POTCAR_DIR}/POT_GGA_PAW_PBE/POTCAR.Mn_pv.gz") self.psingle_Fe = PotcarSingle.from_file(f"{FAKE_POTCAR_DIR}/POT_GGA_PAW_PBE/POTCAR.Fe.gz") self.psingle_Fe_54 = PotcarSingle.from_file(f"{FAKE_POTCAR_DIR}/POT_GGA_PAW_PBE_54/POTCAR.Fe.gz") @@ -1537,8 +1537,8 @@ def test_copy(self): @pytest.mark.filterwarnings( "ignore:POTCAR data with symbol .* is not known to pymatgen:pymatgen.io.vasp.inputs.UnknownPotcarWarning" ) -class TestPotcar: - def setup_method(self): +class TestPotcar(PymatgenTest): + def setUp(self): SETTINGS.setdefault("PMG_VASP_PSP_DIR", str(TEST_FILES_DIR)) self.filepath = f"{FAKE_POTCAR_DIR}/POTCAR.gz" self.potcar = Potcar.from_file(self.filepath) @@ -1616,8 +1616,8 @@ def test_pickle(self): @pytest.mark.filterwarnings( "ignore:POTCAR data with symbol .* is not known to pymatgen:pymatgen.io.vasp.inputs.UnknownPotcarWarning" ) -class TestVaspInput: - def setup_method(self): +class TestVaspInput(PymatgenTest): + def setUp(self): filepath = f"{VASP_IN_DIR}/INCAR" incar = Incar.from_file(filepath) filepath = f"{VASP_IN_DIR}/POSCAR" diff --git a/tests/io/vasp/test_optics.py b/tests/io/vasp/test_optics.py index a898c5fb7eb..3a2caf7a94a 100644 --- a/tests/io/vasp/test_optics.py +++ b/tests/io/vasp/test_optics.py @@ -7,7 +7,7 @@ from pymatgen.io.vasp.optics import DielectricFunctionCalculator, delta_func, delta_methfessel_paxton, step_func from pymatgen.io.vasp.outputs import Vasprun -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest __author__ = "Jimmy-Xuan Shen" __copyright__ = "Copyright 2022, The Materials Project" @@ -16,7 +16,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/io/vasp" -class TestVasprun: +class TestVasprun(PymatgenTest): def test_optics(self): eps_data_path = f"{TEST_DIR}/fixtures/reproduce_eps" vrun = Vasprun(f"{eps_data_path}/vasprun.xml") diff --git a/tests/io/vasp/test_outputs.py b/tests/io/vasp/test_outputs.py index 11ebfec2b80..e02b9ac027a 100644 --- a/tests/io/vasp/test_outputs.py +++ b/tests/io/vasp/test_outputs.py @@ -41,7 +41,7 @@ Xdatcar, ) from pymatgen.io.wannier90 import Unk -from pymatgen.util.testing import FAKE_POTCAR_DIR, TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR +from pymatgen.util.testing import FAKE_POTCAR_DIR, TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR, PymatgenTest try: import h5py @@ -53,7 +53,7 @@ kpts_opt_vrun_path = f"{TEST_DIR}/fixtures/kpoints_opt/vasprun.xml.gz" -class TestVasprun: +class TestVasprun(PymatgenTest): def test_vasprun_ml(self): # Test for ML MD simulation # The trajectory data is stored in md_data @@ -832,7 +832,7 @@ def test_parse_potcar_cwd_relative(self): assert vrun.potcar_spec[ipot]["summary_stats"] == potcar[ipot]._summary_stats -class TestOutcar: +class TestOutcar(PymatgenTest): def test_init(self): outcar = Outcar(f"{VASP_OUT_DIR}/OUTCAR.gz") expected_mag = ( @@ -1423,7 +1423,7 @@ def test_read_table_pattern(self): ) -class TestBSVasprun: +class TestBSVasprun(PymatgenTest): def test_get_band_structure(self): filepath = f"{VASP_OUT_DIR}/vasprun_Si_bands.xml.gz" vasprun = BSVasprun(filepath, parse_potcar_file=False) @@ -1477,7 +1477,7 @@ def test_kpoints_opt(self): assert {*vrun_dct["output"]} >= {"eigenvalues", "eigenvalues_kpoints_opt"} -class TestOszicar: +class TestOszicar(PymatgenTest): def test_init(self): fpath = f"{VASP_OUT_DIR}/OSZICAR" oszicar = Oszicar(fpath) @@ -1493,7 +1493,7 @@ def test_static(self): assert set(oszicar.ionic_steps[-1]) == set({"F", "E0", "dE", "mag"}) -class TestLocpot: +class TestLocpot(PymatgenTest): def test_init(self): filepath = f"{VASP_OUT_DIR}/LOCPOT.gz" locpot = Locpot.from_file(filepath) @@ -1514,9 +1514,9 @@ def test_vasp_6x_style(self): assert {str(ele) for ele in locpot.structure.composition} == {"Mg", "Si"} -class TestChgcar: +class TestChgcar(PymatgenTest): @classmethod - def setup_class(cls): + def setUpClass(cls): filepath = f"{VASP_OUT_DIR}/CHGCAR.nospin.gz" cls.chgcar_no_spin = Chgcar.from_file(filepath) @@ -1638,7 +1638,7 @@ def test_as_dict_and_from_dict(self): ) -class TestAeccars: +class TestAeccars(PymatgenTest): # https://github.com/materialsproject/pymatgen/pull/3343 def test_read_write_file(self): aeccar0_test = Chgcar.from_file(f"{TEST_FILES_DIR}/command_line/bader/AECCAR0.gz") @@ -1654,7 +1654,7 @@ def test_read_write_file(self): assert_allclose(aeccar2.data["total"], aeccar2_read.data["total"]) -class TestElfcar: +class TestElfcar(PymatgenTest): def test_init(self): elfcar = Elfcar.from_file(f"{VASP_OUT_DIR}/ELFCAR.gz") assert approx(np.mean(elfcar.data["total"])) == 0.19076207645194002 @@ -1674,7 +1674,7 @@ def test_interpolation(self): assert len(elfcar.linear_slice([0.0, 0.0, 0.0], [1.0, 1.0, 1.0])) == 100 -class TestProcar: +class TestProcar(PymatgenTest): def test_init(self): filepath = f"{VASP_OUT_DIR}/PROCAR.simple" procar = Procar(filepath) @@ -1817,8 +1817,8 @@ def test_init(self): # TODO: test get_phonon_frequencies once cross-checked -class TestWavecar: - def setup_method(self): +class TestWavecar(PymatgenTest): + def setUp(self): latt_mat = np.array(np.eye(3) * 10, dtype=float) # lattice vectors self.vol = np.dot(latt_mat[0, :], np.cross(latt_mat[1, :], latt_mat[2, :])) # unit cell volume # reciprocal lattice vectors @@ -2095,7 +2095,7 @@ def test_write_unks(self): assert unk == unk_ncl -class TestEigenval: +class TestEigenval(PymatgenTest): def test_init(self): eig = Eigenval(f"{VASP_OUT_DIR}/EIGENVAL.gz") assert eig.ispin == 1 @@ -2135,8 +2135,8 @@ def test_eigenvalue_band_properties_separate_spins(self): assert props[3][1] -class TestWaveder: - def setup_method(self): +class TestWaveder(PymatgenTest): + def setUp(self): wder = Waveder.from_binary(f"{VASP_OUT_DIR}/WAVEDER", "float64") assert wder.nbands == 36 assert wder.nkpoints == 56 @@ -2168,8 +2168,8 @@ def _check(wder): _check(wderf) -class TestWSWQ: - def setup_method(self): +class TestWSWQ(PymatgenTest): + def setUp(self): self.wswq = WSWQ.from_file(f"{VASP_OUT_DIR}/WSWQ.gz") def test_consistency(self): diff --git a/tests/io/vasp/test_sets.py b/tests/io/vasp/test_sets.py index 65334e7059c..6b4f9ceebdb 100644 --- a/tests/io/vasp/test_sets.py +++ b/tests/io/vasp/test_sets.py @@ -91,7 +91,7 @@ def test_yb_2_warning(input_set: VaspInputSet) -> None: assert expected in str(record[0].message) -class TestSetChangeCheck: +class TestSetChangeCheck(PymatgenTest): def test_sets_changed(self): msg = ( "WARNING! These tests will fail when you change an input set. They are included " @@ -128,9 +128,9 @@ def test_sets_changed(self): assert hash_str == known_hashes[input_set], f"{input_set=}\n{msg}" -class TestVaspInputSet: +class TestVaspInputSet(PymatgenTest): @classmethod - def setup_class(cls): + def setUpClass(cls): filepath = f"{VASP_IN_DIR}/POSCAR" cls.structure = Structure.from_file(filepath) @@ -165,9 +165,9 @@ def test_as_dict(self): assert dict_set.potcar_functional == dict_set.user_potcar_functional -class TestMITMPRelaxSet: +class TestMITMPRelaxSet(PymatgenTest): @classmethod - def setup_class(cls): + def setUpClass(cls): cls.set = MITRelaxSet cls.mp_set = MPRelaxSet @@ -718,8 +718,8 @@ def test_get_nedos(self): assert vis._get_nedos(0.1) == pytest.approx(741, abs=1) -class TestMPStaticSet: - def setup_method(self): +class TestMPStaticSet(PymatgenTest): + def setUp(self): self.set = MPStaticSet def test_init(self): @@ -870,8 +870,8 @@ def test_grid_size_from_struct(self): ) -class TestMatPESStaticSet: - def setup_method(self): +class TestMatPESStaticSet(PymatgenTest): + def setUp(self): self.struct = Structure.from_file(f"{VASP_IN_DIR}/POSCAR") self.prev_incar = Incar.from_file(f"{VASP_IN_DIR}/INCAR") @@ -987,8 +987,8 @@ def test_from_prev_calc(self): assert vis.kpoints is None -class TestMPNonSCFSet: - def setup_method(self): +class TestMPNonSCFSet(PymatgenTest): + def setUp(self): self.set = MPNonSCFSet @skip_if_no_psp_dir @@ -1153,7 +1153,7 @@ def test_user_kpoint_override(self): assert vis.kpoints.style == Kpoints.supported_modes.Gamma -class TestMagmomLdau: +class TestMagmomLdau(PymatgenTest): def test_structure_from_prev_run(self): vrun = Vasprun(f"{VASP_OUT_DIR}/vasprun.magmom_ldau.xml.gz") structure = vrun.final_structure @@ -1188,8 +1188,8 @@ def test_ln_magmom(self): assert vis.incar["MAGMOM"] == magmom_ans -class TestMITMDSet: - def setup_method(self): +class TestMITMDSet(PymatgenTest): + def setUp(self): self.set = MITMDSet filepath = f"{VASP_IN_DIR}/POSCAR" self.struct = Structure.from_file(filepath) @@ -1230,8 +1230,8 @@ def test_user_heat_speed(self): @skip_if_no_psp_dir -class TestMVLNPTMDSet: - def setup_method(self): +class TestMVLNPTMDSet(PymatgenTest): + def setUp(self): file_path = f"{VASP_IN_DIR}/POSCAR" self.struct = Structure.from_file(file_path) self.mvl_npt_set = MVLNPTMDSet(self.struct, start_temp=0, end_temp=300, nsteps=1000) @@ -1266,8 +1266,8 @@ def test_as_from_dict(self): assert input_set.incar["NSW"] == 1000 -class TestMPMDSet: - def setup_method(self): +class TestMPMDSet(PymatgenTest): + def setUp(self): filepath = f"{VASP_IN_DIR}/POSCAR" self.struct = Structure.from_file(filepath) self.struct_with_H = Structure.from_file(f"{VASP_IN_DIR}/POSCAR_hcp") @@ -1308,8 +1308,8 @@ def test_as_from_dict(self): assert v.incar["NSW"] == 1000 -class TestMITNEBSet: - def setup_method(self): +class TestMITNEBSet(PymatgenTest): + def setUp(self): c1 = [[0.5] * 3, [0.9] * 3] c2 = [[0.5] * 3, [0.9, 0.1, 0.1]] s1 = Structure(Lattice.cubic(5), ["Si", "Si"], c1) @@ -1356,8 +1356,8 @@ def test_write_input(self): assert not os.path.isfile("04/POSCAR") -class TestMPSOCSet: - def setup_method(self): +class TestMPSOCSet(PymatgenTest): + def setUp(self): self.set = MPSOCSet def test_from_prev_calc(self): @@ -1393,7 +1393,7 @@ def test_override_from_prev_calc(self): assert vis.incar["SIGMA"] == 0.025 -class TestMPNMRSet: +class TestMPNMRSet(PymatgenTest): def test_incar(self): filepath = f"{TEST_FILES_DIR}/cif/Li.cif" structure = Structure.from_file(filepath) @@ -1415,8 +1415,8 @@ def test_incar(self): @skip_if_no_psp_dir -class TestMVLSlabSet: - def setup_method(self): +class TestMVLSlabSet(PymatgenTest): + def setUp(self): self.set = MVLSlabSet struct = self.get_structure("Li2O") gen = SlabGenerator(struct, (1, 0, 0), 10, 10) @@ -1487,7 +1487,7 @@ def test_as_from_dict(self): assert "structure" not in self.vis.as_dict(verbosity=1) -class TestMVLElasticSet: +class TestMVLElasticSet(PymatgenTest): def test_incar(self): mvlparam = MVLElasticSet(self.get_structure("Graphite")) incar = mvlparam.incar @@ -1498,8 +1498,8 @@ def test_incar(self): @skip_if_no_psp_dir -class TestMVLGWSet: - def setup_method(self): +class TestMVLGWSet(PymatgenTest): + def setUp(self): self.set = MVLGWSet self.struct = PymatgenTest.get_structure("Li2O") @@ -1576,8 +1576,8 @@ def test_bse(self): assert mvlgwgbse1.incar["ALGO"] == "Bse" -class TestMPHSERelaxSet: - def setup_method(self): +class TestMPHSERelaxSet(PymatgenTest): + def setUp(self): self.structure = dummy_structure self.set = MPHSERelaxSet @@ -1643,8 +1643,8 @@ def test_override_from_prev_calc(self): assert "VDW_S8" in vis_bj.incar -class TestMPHSEBS: - def setup_method(self): +class TestMPHSEBS(PymatgenTest): + def setUp(self): self.set = MPHSEBSSet def test_init(self): @@ -1699,8 +1699,8 @@ def test_override_from_prev_calc(self): assert len(vis.kpoints.kpts) == 180 -class TestMVLScanRelaxSet: - def setup_method(self): +class TestMVLScanRelaxSet(PymatgenTest): + def setUp(self): self.set = MVLScanRelaxSet file_path = f"{VASP_IN_DIR}/POSCAR" self.struct = Structure.from_file(file_path) @@ -1777,8 +1777,8 @@ def test_as_from_dict(self): assert v.user_incar_settings["NSW"] == 500 -class TestMPScanRelaxSet: - def setup_method(self): +class TestMPScanRelaxSet(PymatgenTest): + def setUp(self): file_path = f"{VASP_IN_DIR}/POSCAR" self.struct = Structure.from_file(file_path) self.mp_scan_set = MPScanRelaxSet( @@ -1898,8 +1898,8 @@ def test_write_input(self): assert os.path.isfile(f"{self.tmp_path}/POSCAR") -class TestMPScanStaticSet: - def setup_method(self): +class TestMPScanStaticSet(PymatgenTest): + def setUp(self): self.set = MPScanStaticSet self.prev_run = f"{TEST_DIR}/fixtures/scan_relaxation" # test inheriting from a previous SCAN relaxation @@ -1988,7 +1988,7 @@ def test_override_from_prev_calc(self): assert lepsilon_vis.incar.get("NPAR") is None -class TestFunc: +class TestFunc(PymatgenTest): @skip_if_no_psp_dir def test_batch_write_input(self): structs = list(map(PymatgenTest.get_structure, ("Li2O", "LiFePO4"))) @@ -2000,8 +2000,8 @@ def test_batch_write_input(self): @skip_if_no_psp_dir -class TestMVLGBSet: - def setup_method(self): +class TestMVLGBSet(PymatgenTest): + def setUp(self): filepath = f"{TEST_FILES_DIR}/cif/Li.cif" self.struct = Structure.from_file(filepath) @@ -2026,8 +2026,8 @@ def test_kpoints(self): assert kpoints.kpts == [(k_a, k_b, 1)] -class TestMVLRelax52Set: - def setup_method(self): +class TestMVLRelax52Set(PymatgenTest): + def setUp(self): self.set = MVLRelax52Set file_path = f"{VASP_IN_DIR}/POSCAR" self.struct = Structure.from_file(file_path) @@ -2064,8 +2064,8 @@ def test_as_from_dict(self): assert vasp_input.incar["NSW"] == 500 -class TestLobsterSet: - def setup_method(self): +class TestLobsterSet(PymatgenTest): + def setUp(self): self.set = LobsterSet file_path = f"{VASP_IN_DIR}/POSCAR" file_path2 = f"{VASP_IN_DIR}/POSCAR.lobster.spin_DOS" @@ -2163,8 +2163,8 @@ def test_as_from_dict(self): @skip_if_no_psp_dir -class TestMPAbsorptionSet: - def setup_method(self): +class TestMPAbsorptionSet(PymatgenTest): + def setUp(self): file_path = f"{TEST_DIR}/fixtures/absorption/static/POSCAR" self.structure = Structure.from_file(file_path) self.set = MPAbsorptionSet diff --git a/tests/io/xtb/test_inputs.py b/tests/io/xtb/test_inputs.py index 16d5be8e0fe..546386c6391 100644 --- a/tests/io/xtb/test_inputs.py +++ b/tests/io/xtb/test_inputs.py @@ -2,7 +2,7 @@ from pymatgen.core.structure import Molecule from pymatgen.io.xtb.inputs import CRESTInput -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest __author__ = "Alex Epstein" __copyright__ = "Copyright 2020, The Materials Project" @@ -12,7 +12,7 @@ EXPECTED_DIR = f"{TEST_FILES_DIR}/io/xtb/expected_output" -class TestCRESTInput: +class TestCRESTInput(PymatgenTest): """ Checks that all attributes of CRESTInput match the expected values for sample inputs. diff --git a/tests/io/xtb/test_outputs.py b/tests/io/xtb/test_outputs.py index e617996b8f1..c4d3fe69777 100644 --- a/tests/io/xtb/test_outputs.py +++ b/tests/io/xtb/test_outputs.py @@ -7,7 +7,7 @@ from pymatgen.core.structure import Molecule from pymatgen.io.qchem.outputs import check_for_structure_changes from pymatgen.io.xtb.outputs import CRESTOutput -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest try: from openbabel import openbabel @@ -23,7 +23,7 @@ EXPECTED_DIR = f"{TEST_FILES_DIR}/io/xtb/expected_output" -class TestCRESTOutput: +class TestCRESTOutput(PymatgenTest): """ Checks that all attributes of CRESTOutput match the expected values for a sample CREST output directory. diff --git a/tests/optimization/test_linear_assignment.py b/tests/optimization/test_linear_assignment.py index ce0f7dfdc4d..961a5032b6d 100644 --- a/tests/optimization/test_linear_assignment.py +++ b/tests/optimization/test_linear_assignment.py @@ -1,5 +1,7 @@ from __future__ import annotations +from unittest import TestCase + import numpy as np import pytest from pytest import approx @@ -7,8 +9,8 @@ from pymatgen.optimization.linear_assignment import LinearAssignment -class TestLinearAssignment: - def test_case_one(self): +class TestLinearAssignment(TestCase): + def test(self): w0 = np.array( [ [19, 95, 9, 43, 62, 90, 10, 77, 71, 27], @@ -100,7 +102,7 @@ def test_rectangular(self): with pytest.raises(ValueError, match="cost matrix must have at least as many columns as rows"): LinearAssignment(w0.T) - def test_case_two(self): + def another_test_case(self): w1 = np.array( [ [ diff --git a/tests/optimization/test_neighbors.py b/tests/optimization/test_neighbors.py index 7f84787bb16..3542acd20ff 100644 --- a/tests/optimization/test_neighbors.py +++ b/tests/optimization/test_neighbors.py @@ -4,10 +4,11 @@ from pymatgen.core.lattice import Lattice from pymatgen.optimization.neighbors import find_points_in_spheres +from pymatgen.util.testing import PymatgenTest -class TestNeighbors: - def setup_method(self): +class TestNeighbors(PymatgenTest): + def setUp(self): self.lattice = Lattice.cubic(10.0) self.cubic = self.lattice self.tetragonal = Lattice.tetragonal(10, 20) diff --git a/tests/phonon/test_bandstructure.py b/tests/phonon/test_bandstructure.py index ccebf1ec8af..7f449792544 100644 --- a/tests/phonon/test_bandstructure.py +++ b/tests/phonon/test_bandstructure.py @@ -8,13 +8,13 @@ from pymatgen.electronic_structure.bandstructure import Kpoint from pymatgen.phonon.bandstructure import PhononBandStructureSymmLine -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest TEST_DIR = f"{TEST_FILES_DIR}/electronic_structure/bandstructure" -class TestPhononBandStructureSymmLine: - def setup_method(self): +class TestPhononBandStructureSymmLine(PymatgenTest): + def setUp(self): with open(f"{TEST_DIR}/NaCl_phonon_bandstructure.json") as file: dct = json.load(file) self.bs = PhononBandStructureSymmLine.from_dict(dct) diff --git a/tests/phonon/test_dos.py b/tests/phonon/test_dos.py index 9875eca9fff..e586604d81e 100644 --- a/tests/phonon/test_dos.py +++ b/tests/phonon/test_dos.py @@ -9,13 +9,13 @@ from pymatgen.core import Element from pymatgen.phonon.dos import CompletePhononDos, PhononDos -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest TEST_DIR = f"{TEST_FILES_DIR}/phonon/dos" -class TestPhononDos: - def setup_method(self): +class TestPhononDos(PymatgenTest): + def setUp(self): with open(f"{TEST_DIR}/NaCl_ph_dos.json") as file: self.dos = PhononDos.from_dict(json.load(file)) with open(f"{TEST_DIR}/NaCl_complete_ph_dos.json") as file: @@ -182,8 +182,8 @@ def test_dos_fp_exceptions(self): self.dos.get_dos_fp_similarity(dos_fp, dos_fp2, col=1, metric=metric, normalize=False) -class TestCompletePhononDos: - def setup_method(self): +class TestCompletePhononDos(PymatgenTest): + def setUp(self): with open(f"{TEST_DIR}/NaCl_complete_ph_dos.json") as file: self.cdos = CompletePhononDos.from_dict(json.load(file)) diff --git a/tests/phonon/test_gruneisen.py b/tests/phonon/test_gruneisen.py index 18446f81d5e..748fd68c8c2 100644 --- a/tests/phonon/test_gruneisen.py +++ b/tests/phonon/test_gruneisen.py @@ -9,7 +9,7 @@ from pymatgen.io.phonopy import get_gruneisen_ph_bs_symm_line, get_gruneisenparameter from pymatgen.phonon.gruneisen import GruneisenParameter from pymatgen.phonon.plotter import GruneisenPhononBandStructureSymmLine, GruneisenPhononBSPlotter, GruneisenPlotter -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest try: import phonopy @@ -21,8 +21,8 @@ TEST_DIR = f"{TEST_FILES_DIR}/phonon/gruneisen" -class TestGruneisenPhononBandStructureSymmLine: - def setup_method(self) -> None: +class TestGruneisenPhononBandStructureSymmLine(PymatgenTest): + def setUp(self) -> None: self.bs_symm_line = get_gruneisen_ph_bs_symm_line( gruneisen_path=f"{TEST_DIR}/gruneisen_eq_plus_minus_InP.yaml", structure_path=f"{TEST_DIR}/eq/POSCAR_InP", @@ -76,8 +76,8 @@ def test_as_dict_from_dict(self): @pytest.mark.skipif(TotalDos is None, reason="Phonopy not present") -class TestGruneisenParameter: - def setup_method(self) -> None: +class TestGruneisenParameter(PymatgenTest): + def setUp(self) -> None: self.gruneisen_obj = get_gruneisenparameter( f"{TEST_DIR}/gruneisen_mesh_InP.yaml", structure_path=f"{TEST_DIR}/eq/POSCAR_InP", diff --git a/tests/phonon/test_ir_spectra.py b/tests/phonon/test_ir_spectra.py index 86c909432e4..7a7eb40f4ce 100644 --- a/tests/phonon/test_ir_spectra.py +++ b/tests/phonon/test_ir_spectra.py @@ -2,11 +2,11 @@ from monty.serialization import loadfn -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest -class TestIRDielectricTensor: - def setup_method(self): +class TestIRDielectricTensor(PymatgenTest): + def setUp(self): self.ir_spectra = loadfn(f"{TEST_FILES_DIR}/phonon/dos/ir_spectra_mp-991652_DDB.json") def test_basic(self): diff --git a/tests/phonon/test_plotter.py b/tests/phonon/test_plotter.py index 49e32b1c326..1afdd7c62bd 100644 --- a/tests/phonon/test_plotter.py +++ b/tests/phonon/test_plotter.py @@ -17,7 +17,7 @@ class TestPhononDosPlotter(TestCase): - def setup_method(self): + def setUp(self): with open(f"{TEST_DIR}/NaCl_complete_ph_dos.json") as file: self.dos = CompletePhononDos.from_dict(json.load(file)) self.plotter = PhononDosPlotter(sigma=0.2, stack=True) @@ -55,7 +55,7 @@ def test_plot(self): class TestPhononBSPlotter(TestCase): - def setup_method(self): + def setUp(self): with open(f"{TEST_FILES_DIR}/electronic_structure/bandstructure/NaCl_phonon_bandstructure.json") as file: dct = json.loads(file.read()) self.bs = PhononBandStructureSymmLine.from_dict(dct) @@ -114,7 +114,7 @@ def test_plot_compare(self): class TestThermoPlotter(TestCase): - def setup_method(self): + def setUp(self): with open(f"{TEST_DIR}/NaCl_complete_ph_dos.json") as file: self.dos = CompletePhononDos.from_dict(json.load(file)) self.plotter = ThermoPlotter(self.dos, self.dos.structure) diff --git a/tests/phonon/test_thermal_displacements.py b/tests/phonon/test_thermal_displacements.py index 7d4b4fb2f15..aeb26a4dffc 100644 --- a/tests/phonon/test_thermal_displacements.py +++ b/tests/phonon/test_thermal_displacements.py @@ -6,15 +6,15 @@ from pymatgen.core.structure import Structure from pymatgen.phonon.thermal_displacements import ThermalDisplacementMatrices -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest TEST_DIR = f"{TEST_FILES_DIR}/phonon/thermal_displacement_matrices" -class TestThermalDisplacement: +class TestThermalDisplacement(PymatgenTest): """Test data from J. George's matlab code https://github.com/JaGeo/MolecularToolbox.""" - def setup_method(self) -> None: + def setUp(self) -> None: self.thermal = ThermalDisplacementMatrices( thermal_displacement_matrix_cart=[ [5.16e-03, 6.13e-03, 4.15e-03, -1.10e-04, -1.58e-03, -8.10e-04], diff --git a/tests/symmetry/test_analyzer.py b/tests/symmetry/test_analyzer.py index 964ef209dab..7966c815ce9 100644 --- a/tests/symmetry/test_analyzer.py +++ b/tests/symmetry/test_analyzer.py @@ -24,8 +24,8 @@ TEST_DIR = f"{TEST_FILES_DIR}/symmetry/analyzer" -class TestSpacegroupAnalyzer: - def setup_method(self): +class TestSpacegroupAnalyzer(PymatgenTest): + def setUp(self): self.structure = Structure.from_file(f"{VASP_IN_DIR}/POSCAR") self.sg = SpacegroupAnalyzer(self.structure, 0.001) self.disordered_structure = self.get_structure("Li10GeP2S12") @@ -445,7 +445,7 @@ def test_bad_structure(self): class TestSpacegroup(TestCase): - def setup_method(self): + def setUp(self): self.structure = Structure.from_file(f"{VASP_IN_DIR}/POSCAR") self.sg1 = SpacegroupAnalyzer(self.structure, 0.001).get_space_group_operations() @@ -537,7 +537,7 @@ def test_are_symmetrically_equivalent(self): ) -class TestPointGroupAnalyzer: +class TestPointGroupAnalyzer(PymatgenTest): def test_spherical(self): pg_analyzer = PointGroupAnalyzer(CH4) assert pg_analyzer.sch_symbol == "Td" diff --git a/tests/symmetry/test_kpath_hin.py b/tests/symmetry/test_kpath_hin.py index 1cadbc40f7e..2a7cce41712 100644 --- a/tests/symmetry/test_kpath_hin.py +++ b/tests/symmetry/test_kpath_hin.py @@ -6,11 +6,12 @@ from pymatgen.core.lattice import Lattice from pymatgen.core.structure import Structure from pymatgen.symmetry.kpath import KPathSeek +from pymatgen.util.testing import PymatgenTest pytest.importorskip("seekpath", reason="seekpath not installed") -class TestKPathSeek: +class TestKPathSeek(PymatgenTest): def test_kpath_generation(self): triclinic = [1, 2] monoclinic = range(3, 16) diff --git a/tests/symmetry/test_kpath_lm.py b/tests/symmetry/test_kpath_lm.py index b203ddcae72..479ffecb65d 100644 --- a/tests/symmetry/test_kpath_lm.py +++ b/tests/symmetry/test_kpath_lm.py @@ -8,10 +8,10 @@ from pymatgen.core.structure import Structure from pymatgen.symmetry.analyzer import SpacegroupAnalyzer from pymatgen.symmetry.kpath import KPathLatimerMunro -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest -class TestKPathLatimerMunro: +class TestKPathLatimerMunro(PymatgenTest): def test_kpath_generation(self): triclinic = [1, 2] monoclinic = range(3, 16) diff --git a/tests/symmetry/test_kpath_sc.py b/tests/symmetry/test_kpath_sc.py index 72b1b4eb716..d88c97f79dd 100644 --- a/tests/symmetry/test_kpath_sc.py +++ b/tests/symmetry/test_kpath_sc.py @@ -6,12 +6,12 @@ from pymatgen.core.lattice import Lattice from pymatgen.core.structure import Structure from pymatgen.symmetry.kpath import KPathSetyawanCurtarolo -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest TEST_DIR = f"{TEST_FILES_DIR}/symmetry/space_group_structs" -class TestBandStructureSC: +class TestBandStructureSC(PymatgenTest): def test_kpath_generation(self): triclinic = [1, 2] monoclinic = range(3, 16) diff --git a/tests/symmetry/test_kpaths.py b/tests/symmetry/test_kpaths.py index 46a0f51671b..87c8bd16480 100644 --- a/tests/symmetry/test_kpaths.py +++ b/tests/symmetry/test_kpaths.py @@ -7,7 +7,7 @@ from pymatgen.core.lattice import Lattice from pymatgen.core.structure import Structure from pymatgen.symmetry.bandstructure import HighSymmKpath -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest try: from seekpath import get_path @@ -17,7 +17,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/electronic_structure/bandstructure" -class TestHighSymmKpath: +class TestHighSymmKpath(PymatgenTest): @pytest.mark.skipif(get_path is None, reason="No seek path present.") def test_kpath_generation(self): triclinic = [1, 2] diff --git a/tests/symmetry/test_maggroups.py b/tests/symmetry/test_maggroups.py index c868f5d62fa..72f184d553f 100644 --- a/tests/symmetry/test_maggroups.py +++ b/tests/symmetry/test_maggroups.py @@ -6,6 +6,7 @@ from pymatgen.core.lattice import Lattice from pymatgen.symmetry.groups import SpaceGroup from pymatgen.symmetry.maggroups import MagneticSpaceGroup +from pymatgen.util.testing import PymatgenTest __author__ = "Matthew Horton" __copyright__ = "Copyright 2017, The Materials Project" @@ -16,8 +17,8 @@ __date__ = "Feb 2017" -class TestMagneticSpaceGroup: - def setup_method(self): +class TestMagneticSpaceGroup(PymatgenTest): + def setUp(self): self.msg_1 = MagneticSpaceGroup([70, 530]) self.msg_2 = MagneticSpaceGroup([62, 448]) self.msg_3 = MagneticSpaceGroup([20, 37]) diff --git a/tests/symmetry/test_settings.py b/tests/symmetry/test_settings.py index be51dfbb1df..79a6b56c138 100644 --- a/tests/symmetry/test_settings.py +++ b/tests/symmetry/test_settings.py @@ -17,7 +17,7 @@ class TestJonesFaithfulTransformation(TestCase): - def setup_method(self): + def setUp(self): self.test_strings = [ "a,b,c;0,0,0", # identity "a-b,a+b,2c;0,0,1/2", diff --git a/tests/symmetry/test_site_symmetries.py b/tests/symmetry/test_site_symmetries.py index 455f45ba512..1b33f3a11f0 100644 --- a/tests/symmetry/test_site_symmetries.py +++ b/tests/symmetry/test_site_symmetries.py @@ -6,7 +6,7 @@ from monty.json import MontyDecoder from pymatgen.symmetry import site_symmetries as ss -from pymatgen.util.testing import TEST_FILES_DIR +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest __author__ = "Handong Ling" __version__ = "0.1" @@ -18,8 +18,8 @@ TEST_DIR = f"{TEST_FILES_DIR}/symmetry/site_symmetries" -class TestSiteSymmetries: - def setup_method(self): +class TestSiteSymmetries(PymatgenTest): + def setUp(self): with gzip.open(f"{TEST_DIR}/point_ops.json.gz", mode="rt") as file: self.point_ops = MontyDecoder().process_decoded(json.load(file)) diff --git a/tests/transformations/test_advanced_transformations.py b/tests/transformations/test_advanced_transformations.py index 96222afdadb..2f73ace7cd3 100644 --- a/tests/transformations/test_advanced_transformations.py +++ b/tests/transformations/test_advanced_transformations.py @@ -276,8 +276,8 @@ def test_as_dict(self): @pytest.mark.skipif(not enumlib_present, reason="enum_lib not present.") -class TestMagOrderingTransformation: - def setup_method(self): +class TestMagOrderingTransformation(PymatgenTest): + def setUp(self): lattice = Lattice.cubic(4.17) species = ["Ni", "O"] coords = [[0, 0, 0], [0.5, 0.5, 0.5]] @@ -488,7 +488,7 @@ def test_advanced_usage(self): @pytest.mark.skipif(not enumlib_present, reason="enum_lib not present.") -class TestDopingTransformation: +class TestDopingTransformation(PymatgenTest): def test_apply_transformation(self): structure = PymatgenTest.get_structure("LiFePO4") spga = SpacegroupAnalyzer(structure, 0.1) @@ -551,7 +551,7 @@ def test_find_codopant(self): assert find_codopant(Species("Fe", 2), 3) == Species("In", 3) -class TestSlabTransformation: +class TestSlabTransformation(PymatgenTest): def test_apply_transformation(self): struct = self.get_structure("LiFePO4") trans = SlabTransformation([0, 0, 1], 10, 10, shift=0.25) @@ -570,7 +570,7 @@ def test_apply_transformation(self): assert_allclose(slab_from_gen.cart_coords, slab_from_trans.cart_coords) -class TestGrainBoundaryTransformation: +class TestGrainBoundaryTransformation(PymatgenTest): def test_apply_transformation(self): Al_bulk = Structure.from_spacegroup("Fm-3m", Lattice.cubic(2.8575585), ["Al"], [[0, 0, 0]]) gb_gen_params_s5 = { @@ -590,7 +590,7 @@ def test_apply_transformation(self): assert_allclose(gb_from_generator.cart_coords, gb_from_trans.cart_coords) -class TestDisorderedOrderedTransformation: +class TestDisorderedOrderedTransformation(PymatgenTest): def test_apply_transformation(self): # nonsensical example just for testing purposes struct = self.get_structure("BaNiO3") @@ -603,7 +603,7 @@ def test_apply_transformation(self): @pytest.mark.skipif(not mcsqs_cmd, reason="mcsqs not present.") -class TestSQSTransformation: +class TestSQSTransformation(PymatgenTest): def test_apply_transformation(self): pzt_structs = loadfn(f"{TEST_FILES_DIR}/io/atat/mcsqs/pzt-structs.json") trans = SQSTransformation(scaling=[2, 1, 1], search_time=0.01, instances=1, wd=0) @@ -649,7 +649,7 @@ def test_spin(self): @pytest.mark.skipif(ClusterSpace is None, reason="icet not installed.") -class TestSQSTransformationIcet: +class TestSQSTransformationIcet(PymatgenTest): stored_run: dict = loadfn(f"{TEST_FILES_DIR}/transformations/icet-sqs-fcc-Mg_75-Al_25-scaling_8.json.gz") scaling: int = 8 @@ -699,7 +699,7 @@ def test_monte_carlo(self): assert isinstance(sqs_output[0][key], val) -class TestCubicSupercellTransformation: +class TestCubicSupercellTransformation(PymatgenTest): def test_apply_transformation_cubic_supercell(self): structure = self.get_structure("TlBiSe2") min_atoms = 100 @@ -848,7 +848,7 @@ def test_apply_transformation_orthorhombic_supercell(self): assert transformed_cubic.lattice.angles == transformed_orthorhombic.lattice.angles -class TestAddAdsorbateTransformation: +class TestAddAdsorbateTransformation(PymatgenTest): def test_apply_transformation(self): co = Molecule(["C", "O"], [[0, 0, 0], [0, 0, 1.23]]) trans = AddAdsorbateTransformation(co) @@ -859,7 +859,7 @@ def test_apply_transformation(self): assert out.reduced_formula == "Pt4CO" -class TestSubstituteSurfaceSiteTransformation: +class TestSubstituteSurfaceSiteTransformation(PymatgenTest): def test_apply_transformation(self): trans = SubstituteSurfaceSiteTransformation("Au") pt = Structure(Lattice.cubic(5), ["Pt"], [[0, 0, 0]]) # fictitious @@ -870,7 +870,7 @@ def test_apply_transformation(self): @pytest.mark.skipif(not hiphive, reason="hiphive not present") -class TestMonteCarloRattleTransformation: +class TestMonteCarloRattleTransformation(PymatgenTest): def test_apply_transformation(self): struct = self.get_structure("Si") mcrt = MonteCarloRattleTransformation(0.01, 2, seed=1) diff --git a/tests/transformations/test_site_transformations.py b/tests/transformations/test_site_transformations.py index 1baef5b7297..0e97aceabc0 100644 --- a/tests/transformations/test_site_transformations.py +++ b/tests/transformations/test_site_transformations.py @@ -1,6 +1,7 @@ from __future__ import annotations from shutil import which +from unittest import TestCase import numpy as np import pytest @@ -16,14 +17,15 @@ ReplaceSiteSpeciesTransformation, TranslateSitesTransformation, ) +from pymatgen.util.testing import PymatgenTest enum_cmd = which("enum.x") or which("multienum.x") makestr_cmd = which("makestr.x") or which("makeStr.x") or which("makeStr.py") enumlib_present = enum_cmd and makestr_cmd -class TestTranslateSitesTransformation: - def setup_method(self): +class TestTranslateSitesTransformation(PymatgenTest): + def setUp(self): coords = [ [0, 0, 0], [0.375, 0.375, 0.375], @@ -76,8 +78,8 @@ def test_as_from_dict(self): str(t2) -class TestReplaceSiteSpeciesTransformation: - def setup_method(self): +class TestReplaceSiteSpeciesTransformation(TestCase): + def setUp(self): coords = [ [0, 0, 0], [0.375, 0.375, 0.375], @@ -108,8 +110,8 @@ def test_as_from_dict(self): assert struct.formula == "Na1 Li3 O4" -class TestRemoveSitesTransformation: - def setup_method(self): +class TestRemoveSitesTransformation(TestCase): + def setUp(self): coords = [ [0, 0, 0], [0.375, 0.375, 0.375], @@ -140,8 +142,8 @@ def test_as_from_dict(self): assert struct.formula == "Li2 O4" -class TestInsertSitesTransformation: - def setup_method(self): +class TestInsertSitesTransformation(TestCase): + def setUp(self): coords = [ [0, 0, 0], [0.375, 0.375, 0.375], @@ -177,8 +179,8 @@ def test_as_from_dict(self): assert struct.formula == "Li4 Mn1 Fe1 O4" -class TestPartialRemoveSitesTransformation: - def setup_method(self): +class TestPartialRemoveSitesTransformation(TestCase): + def setUp(self): coords = [ [0, 0, 0], [0.375, 0.375, 0.375], @@ -262,7 +264,7 @@ def test_str(self): ) -class TestAddSitePropertyTransformation: +class TestAddSitePropertyTransformation(PymatgenTest): def test_apply_transformation(self): struct = self.get_structure("Li2O2") sd = [[True, True, True] for _ in struct] @@ -277,8 +279,8 @@ def test_apply_transformation(self): assert_allclose(trans_set.site_properties[prop], manually_set.site_properties[prop]) -class TestRadialSiteDistortionTransformation: - def setup_method(self): +class TestRadialSiteDistortionTransformation(PymatgenTest): + def setUp(self): self.molecule = Molecule( species=["C", "H", "H", "H", "H", "H", "H", "H", "H", "H", "H", "H", "H"], coords=[ diff --git a/tests/transformations/test_standard_transformations.py b/tests/transformations/test_standard_transformations.py index 653d58ae7ec..0074eece962 100644 --- a/tests/transformations/test_standard_transformations.py +++ b/tests/transformations/test_standard_transformations.py @@ -41,8 +41,8 @@ enumlib_present = which("enum.x") and which("makestr.x") -class TestRotationTransformations: - def setup_method(self): +class TestRotationTransformations(TestCase): + def setUp(self): coords = [[0, 0, 0], [0.75, 0.5, 0.75]] lattice = [ [3.8401979337, 0, 0], @@ -109,7 +109,7 @@ def test_fractional_substitution(self): class TestSupercellTransformation(TestCase): - def setup_method(self): + def setUp(self): coords = [[0, 0, 0], [0.75, 0.75, 0.75], [0.5, 0.5, 0.5], [0.25, 0.25, 0.25]] lattice = [ [3.8401979337, 0, 0], diff --git a/tests/util/test_coord.py b/tests/util/test_coord.py index b8c9b08aaba..c97914e6319 100644 --- a/tests/util/test_coord.py +++ b/tests/util/test_coord.py @@ -1,5 +1,7 @@ from __future__ import annotations +from unittest import TestCase + import numpy as np import pytest from numpy.testing import assert_allclose, assert_array_equal @@ -248,8 +250,8 @@ def test_get_angle(self): assert coord.get_angle(v1, v2, units="radians") == approx(0.9553166181245092) -class TestSimplex: - def setup_method(self): +class TestSimplex(TestCase): + def setUp(self): coords = [[0, 0, 0], [0, 1, 0], [0, 0, 1], [1, 0, 0]] self.simplex = coord.Simplex(coords) diff --git a/tests/util/test_io.py b/tests/util/test_io.py index 1c810ab98a3..09458240656 100644 --- a/tests/util/test_io.py +++ b/tests/util/test_io.py @@ -1,10 +1,10 @@ from __future__ import annotations from pymatgen.util.io_utils import micro_pyawk -from pymatgen.util.testing import VASP_OUT_DIR +from pymatgen.util.testing import VASP_OUT_DIR, PymatgenTest -class TestFunc: +class TestFunc(PymatgenTest): def test_micro_pyawk(self): data = [] diff --git a/tests/util/test_plotting.py b/tests/util/test_plotting.py index e9771589e06..ec68c960d88 100644 --- a/tests/util/test_plotting.py +++ b/tests/util/test_plotting.py @@ -3,6 +3,7 @@ import matplotlib.pyplot as plt from pymatgen.util.plotting import periodic_table_heatmap, van_arkel_triangle +from pymatgen.util.testing import PymatgenTest try: import pymatviz @@ -11,7 +12,7 @@ pymatviz = None -class TestFunc: +class TestFunc(PymatgenTest): def test_plot_periodic_heatmap(self): random_data = {"Te": 0.11083, "Au": 0.75756, "Th": 1.24758, "Ni": -2.0354} fig = periodic_table_heatmap(random_data) diff --git a/tests/util/test_provenance.py b/tests/util/test_provenance.py index c6c2d59bd72..7a276f8eeb8 100644 --- a/tests/util/test_provenance.py +++ b/tests/util/test_provenance.py @@ -3,6 +3,7 @@ from __future__ import annotations from datetime import datetime, timedelta, timezone +from unittest import TestCase import numpy as np import pytest @@ -19,8 +20,8 @@ __date__ = "2/14/13" -class TestStructureNL: - def setup_method(self): +class TestStructureNL(TestCase): + def setUp(self): # set up a Structure self.struct = Structure(np.eye(3, 3) * 3, ["Fe"], [[0, 0, 0]]) self.s2 = Structure(np.eye(3, 3) * 3, ["Al"], [[0, 0, 0]]) diff --git a/tests/vis/test_plotters.py b/tests/vis/test_plotters.py index 9789d4ba4e5..87311cc4d66 100644 --- a/tests/vis/test_plotters.py +++ b/tests/vis/test_plotters.py @@ -8,15 +8,15 @@ from monty.json import MontyDecoder from pymatgen.analysis.xas.spectrum import XAS -from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest +from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest from pymatgen.vis.plotters import SpectrumPlotter -with open(f"{TEST_FILES_DIR}/analysis/spectrum_test/LiCoO2_k_xanes.json", encoding="utf-8") as file: +with open(f"{TEST_FILES_DIR}/analysis/spectrum_test/LiCoO2_k_xanes.json") as file: spect_data_dict = json.load(file, cls=MontyDecoder) -class TestSpectrumPlotter(MatSciTest): - def setup_method(self): +class TestSpectrumPlotter(PymatgenTest): + def setUp(self): self.xanes = XAS.from_dict(spect_data_dict) def test_get_plot(self): From 9d33460b8c31db9fd092b79fccc75f45f8f9681c Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Wed, 4 Dec 2024 22:47:21 +0800 Subject: [PATCH 12/31] deprecate pymatgen with matscitest --- src/pymatgen/util/testing/__init__.py | 127 +++++++++++++++++++++++++- 1 file changed, 125 insertions(+), 2 deletions(-) diff --git a/src/pymatgen/util/testing/__init__.py b/src/pymatgen/util/testing/__init__.py index acf83e32c93..af6b0c61667 100644 --- a/src/pymatgen/util/testing/__init__.py +++ b/src/pymatgen/util/testing/__init__.py @@ -35,8 +35,15 @@ FAKE_POTCAR_DIR = f"{VASP_IN_DIR}/fake_potcars" -class PymatgenTest(TestCase): - """Extends unittest.TestCase with several assert methods for array and str comparison.""" +class MatSciTest: + """TODO: name might need discussion. + + TODO: finish docstring + + TODO: reduce code duplicate + + TODO: add deprecation warning + """ # dict of lazily-loaded test structures (initialized to None) TEST_STRUCTURES: ClassVar[dict[str | Path, Structure | None]] = dict.fromkeys(STRUCTURES_DIR.glob("*")) @@ -149,3 +156,119 @@ def assert_msonable(self, obj: MSONable, test_is_subclass: bool = True) -> str: if not issubclass(type(round_trip), type(obj)): raise TypeError(f"{type(round_trip)} != {type(obj)}") return json_str + + +class PymatgenTest(TestCase): + """Extends unittest.TestCase with several assert methods for array and str comparison. + + Deprecated: please use `MatSciTest` instead (migrate from `unittest` to `pytest`). + """ + + # dict of lazily-loaded test structures (initialized to None) + TEST_STRUCTURES: ClassVar[dict[str | Path, Structure | None]] = dict.fromkeys(STRUCTURES_DIR.glob("*")) + + @pytest.fixture(autouse=True) # make all tests run a in a temporary directory accessible via self.tmp_path + def _tmp_dir(self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None: + # https://pytest.org/en/latest/how-to/unittest.html#using-autouse-fixtures-and-accessing-other-fixtures + monkeypatch.chdir(tmp_path) # change to pytest-provided temporary directory + self.tmp_path = tmp_path + + @classmethod + def get_structure(cls, name: str) -> Structure: + """ + Lazily load a structure from pymatgen/util/structures. + + Args: + name (str): Name of structure file. + + Returns: + Structure + """ + return MatSciTest.get_structure(name) + + @staticmethod + def assert_str_content_equal(actual, expected): + """Test if two strings are equal, ignoring things like trailing spaces, etc.""" + MatSciTest.assert_str_content_equal(actual, expected) + + def serialize_with_pickle(self, objects: Any, protocols: Sequence[int] | None = None, test_eq: bool = True): + """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. + + Args: + 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. + """ + # Build a list even when we receive a single object. + got_single_object = False + if not isinstance(objects, list | tuple): + got_single_object = True + objects = [objects] + + protocols = protocols or [pickle.HIGHEST_PROTOCOL] + + # This list will contain the objects deserialized with the different protocols. + objects_by_protocol, errors = [], [] + + for protocol in protocols: + # Serialize and deserialize the object. + tmpfile = self.tmp_path / f"tempfile_{protocol}.pkl" + + try: + with open(tmpfile, "wb") as file: + pickle.dump(objects, file, protocol=protocol) + except Exception as exc: + errors.append(f"pickle.dump with {protocol=} raised:\n{exc}") + continue + + try: + with open(tmpfile, "rb") as file: + unpickled_objs = pickle.load(file) # noqa: S301 + except Exception as exc: + errors.append(f"pickle.load with {protocol=} raised:\n{exc}") + continue + + # Test for equality + if test_eq: + for orig, unpickled in zip(objects, unpickled_objs, strict=True): + if orig != unpickled: + raise ValueError( + f"Unpickled and original objects are unequal for {protocol=}\n{orig=}\n{unpickled=}" + ) + + # Save the deserialized objects and test for equality. + objects_by_protocol.append(unpickled_objs) + + if errors: + raise ValueError("\n".join(errors)) + + # Return nested list so that client code can perform additional tests. + if got_single_object: + return [o[0] for o in objects_by_protocol] + return objects_by_protocol + + def assert_msonable(self, obj: MSONable, test_is_subclass: bool = True) -> str: + """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. + """ + if test_is_subclass and not isinstance(obj, MSONable): + raise TypeError("obj is not MSONable") + if obj.as_dict() != type(obj).from_dict(obj.as_dict()).as_dict(): + raise ValueError("obj could not be reconstructed accurately from its dict representation.") + json_str = json.dumps(obj.as_dict(), cls=MontyEncoder) + round_trip = json.loads(json_str, cls=MontyDecoder) + if not issubclass(type(round_trip), type(obj)): + raise TypeError(f"{type(round_trip)} != {type(obj)}") + return json_str From be187d0e902c5ebf8b8d043e0c2ad91ef564db70 Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Wed, 4 Dec 2024 23:21:15 +0800 Subject: [PATCH 13/31] global replace setUp with setup_method --- tests/alchemy/test_filters.py | 4 +- tests/alchemy/test_materials.py | 2 +- .../test_coordination_geometry_finder.py | 2 +- .../utils/test_coordination_geometry_utils.py | 2 +- tests/analysis/elasticity/test_elastic.py | 8 ++-- tests/analysis/elasticity/test_strain.py | 6 +-- tests/analysis/elasticity/test_stress.py | 2 +- .../ferroelectricity/test_polarization.py | 6 +-- .../interfaces/test_coherent_interface.py | 2 +- tests/analysis/interfaces/test_zsl.py | 2 +- tests/analysis/magnetism/test_analyzer.py | 2 +- tests/analysis/magnetism/test_jahnteller.py | 2 +- .../test_dopant_predictor.py | 2 +- .../structure_prediction/test_substitutor.py | 2 +- tests/analysis/test_adsorption.py | 2 +- tests/analysis/test_bond_dissociation.py | 2 +- tests/analysis/test_bond_valence.py | 2 +- tests/analysis/test_chempot_diagram.py | 2 +- tests/analysis/test_cost.py | 2 +- tests/analysis/test_dimensionality.py | 2 +- tests/analysis/test_eos.py | 2 +- tests/analysis/test_ewald.py | 2 +- tests/analysis/test_functional_groups.py | 2 +- tests/analysis/test_graphs.py | 4 +- tests/analysis/test_interface_reactions.py | 2 +- tests/analysis/test_local_env.py | 26 ++++++------- tests/analysis/test_phase_diagram.py | 16 ++++---- tests/analysis/test_piezo.py | 2 +- tests/analysis/test_piezo_sensitivity.py | 2 +- tests/analysis/test_pourbaix_diagram.py | 4 +- .../test_quasi_harmonic_debye_approx.py | 4 +- tests/analysis/test_quasirrho.py | 2 +- tests/analysis/test_reaction_calculator.py | 4 +- tests/analysis/test_structure_analyzer.py | 4 +- tests/analysis/test_structure_matcher.py | 2 +- tests/analysis/test_surface_analysis.py | 8 ++-- tests/analysis/test_wulff.py | 2 +- tests/analysis/xas/test_spectrum.py | 2 +- tests/apps/battery/test_analyzer.py | 2 +- tests/apps/battery/test_conversion_battery.py | 2 +- tests/apps/battery/test_insertion_battery.py | 2 +- tests/apps/battery/test_plotter.py | 2 +- tests/apps/borg/test_hive.py | 6 +-- tests/command_line/test_bader_caller.py | 2 +- tests/command_line/test_critic2_caller.py | 2 +- tests/command_line/test_gulp_caller.py | 8 ++-- tests/command_line/test_mcsqs_caller.py | 2 +- tests/core/test_composition.py | 2 +- tests/core/test_interface.py | 4 +- tests/core/test_ion.py | 2 +- tests/core/test_lattice.py | 2 +- tests/core/test_operations.py | 2 +- tests/core/test_periodic_table.py | 2 +- tests/core/test_sites.py | 4 +- tests/core/test_spectrum.py | 2 +- tests/core/test_structure.py | 8 ++-- tests/core/test_surface.py | 8 ++-- tests/core/test_tensors.py | 6 +-- tests/core/test_trajectory.py | 2 +- tests/core/test_xcfunc.py | 2 +- .../test_bandstructure.py | 8 ++-- tests/electronic_structure/test_boltztrap2.py | 10 ++--- tests/electronic_structure/test_cohp.py | 10 ++--- tests/electronic_structure/test_dos.py | 10 ++--- tests/electronic_structure/test_plotter.py | 12 +++--- tests/entries/test_compatibility.py | 20 +++++----- tests/entries/test_computed_entries.py | 6 +-- tests/entries/test_correction_calculator.py | 2 +- tests/entries/test_entry_tools.py | 2 +- tests/entries/test_exp_entries.py | 2 +- tests/ext/test_matproj.py | 4 +- tests/io/abinit/test_inputs.py | 2 +- tests/io/abinit/test_netcdf.py | 2 +- tests/io/abinit/test_pseudos.py | 2 +- tests/io/cp2k/test_inputs.py | 2 +- tests/io/cp2k/test_outputs.py | 2 +- tests/io/feff/test_inputs.py | 2 +- tests/io/lobster/test_inputs.py | 2 +- tests/io/lobster/test_lobsterenv.py | 2 +- tests/io/lobster/test_outputs.py | 28 +++++++------- tests/io/test_babel.py | 2 +- tests/io/test_cif.py | 2 +- tests/io/test_cssr.py | 2 +- tests/io/test_fiesta.py | 4 +- tests/io/test_gaussian.py | 4 +- tests/io/test_lmto.py | 4 +- tests/io/test_nwchem.py | 4 +- tests/io/test_phonopy.py | 2 +- tests/io/test_pwscf.py | 2 +- tests/io/test_shengbte.py | 2 +- tests/io/test_wannier90.py | 2 +- tests/io/test_xcrysden.py | 2 +- tests/io/test_xr.py | 2 +- tests/io/test_xyz.py | 2 +- tests/io/test_zeopp.py | 14 +++---- tests/io/vasp/test_inputs.py | 8 ++-- tests/io/vasp/test_outputs.py | 6 +-- tests/io/vasp/test_sets.py | 38 +++++++++---------- tests/optimization/test_neighbors.py | 2 +- tests/phonon/test_bandstructure.py | 2 +- tests/phonon/test_dos.py | 4 +- tests/phonon/test_gruneisen.py | 4 +- tests/phonon/test_ir_spectra.py | 2 +- tests/phonon/test_plotter.py | 6 +-- tests/phonon/test_thermal_displacements.py | 2 +- tests/symmetry/test_analyzer.py | 4 +- tests/symmetry/test_maggroups.py | 2 +- tests/symmetry/test_settings.py | 2 +- tests/symmetry/test_site_symmetries.py | 2 +- .../test_advanced_transformations.py | 2 +- .../test_site_transformations.py | 12 +++--- .../test_standard_transformations.py | 4 +- tests/util/test_coord.py | 2 +- tests/util/test_provenance.py | 2 +- tests/vis/test_plotters.py | 2 +- 115 files changed, 254 insertions(+), 254 deletions(-) diff --git a/tests/alchemy/test_filters.py b/tests/alchemy/test_filters.py index 16737ae67fa..dbaf1a19588 100644 --- a/tests/alchemy/test_filters.py +++ b/tests/alchemy/test_filters.py @@ -71,7 +71,7 @@ def test_as_from_dict(self): class TestRemoveDuplicatesFilter(TestCase): - def setUp(self): + def setup_method(self): with open(f"{TEST_FILES_DIR}/entries/TiO2_entries.json") as file: entries = json.load(file, cls=MontyDecoder) self._struct_list = [entry.structure for entry in entries] @@ -90,7 +90,7 @@ def test_as_from_dict(self): class TestRemoveExistingFilter(TestCase): - def setUp(self): + def setup_method(self): with open(f"{TEST_FILES_DIR}/entries/TiO2_entries.json") as file: entries = json.load(file, cls=MontyDecoder) self._struct_list = [entry.structure for entry in entries] diff --git a/tests/alchemy/test_materials.py b/tests/alchemy/test_materials.py index 25b8cc74ad2..1e946163473 100644 --- a/tests/alchemy/test_materials.py +++ b/tests/alchemy/test_materials.py @@ -22,7 +22,7 @@ class TestTransformedStructure(PymatgenTest): - def setUp(self): + def setup_method(self): structure = PymatgenTest.get_structure("LiFePO4") self.structure = structure trafos = [SubstitutionTransformation({"Li": "Na"})] diff --git a/tests/analysis/chemenv/coordination_environments/test_coordination_geometry_finder.py b/tests/analysis/chemenv/coordination_environments/test_coordination_geometry_finder.py index 01aedf2d245..74120fa0d94 100644 --- a/tests/analysis/chemenv/coordination_environments/test_coordination_geometry_finder.py +++ b/tests/analysis/chemenv/coordination_environments/test_coordination_geometry_finder.py @@ -27,7 +27,7 @@ class TestCoordinationGeometryFinder(PymatgenTest): - def setUp(self): + def setup_method(self): self.lgf = LocalGeometryFinder() self.lgf.setup_parameters( centering_type="standard", diff --git a/tests/analysis/chemenv/utils/test_coordination_geometry_utils.py b/tests/analysis/chemenv/utils/test_coordination_geometry_utils.py index d7cbc5b7f19..60801c5a0b6 100644 --- a/tests/analysis/chemenv/utils/test_coordination_geometry_utils.py +++ b/tests/analysis/chemenv/utils/test_coordination_geometry_utils.py @@ -13,7 +13,7 @@ class TestPlanesUtils(PymatgenTest): - def setUp(self): + def setup_method(self): # Test of plane 4x + 2y - 4z + 3 = 0 (used in most test cases) self.expected_coefficients = np.array([4, 2, -4, 3], float) self.p1 = np.array([0, 0, 0.75]) diff --git a/tests/analysis/elasticity/test_elastic.py b/tests/analysis/elasticity/test_elastic.py index 699f97d4061..97917144d2e 100644 --- a/tests/analysis/elasticity/test_elastic.py +++ b/tests/analysis/elasticity/test_elastic.py @@ -33,7 +33,7 @@ class TestElasticTensor(PymatgenTest): - def setUp(self): + def setup_method(self): self.voigt_1 = [ [59.33, 28.08, 28.08, 0, 0, 0], [28.08, 59.31, 28.07, 0, 0, 0], @@ -264,7 +264,7 @@ def test_energy_density(self): class TestElasticTensorExpansion(PymatgenTest): - def setUp(self): + def setup_method(self): with open(f"{TEST_DIR}/test_toec_data.json") as file: self.data_dict = json.load(file) self.strains = [Strain(sm) for sm in self.data_dict["strains"]] @@ -365,7 +365,7 @@ def test_get_yield_stress(self): class TestNthOrderElasticTensor(PymatgenTest): - def setUp(self): + def setup_method(self): with open(f"{TEST_DIR}/test_toec_data.json") as file: self.data_dict = json.load(file) self.strains = [Strain(sm) for sm in self.data_dict["strains"]] @@ -404,7 +404,7 @@ def test_energy_density(self): class TestDiffFit(PymatgenTest): """Test various functions related to diff fitting.""" - def setUp(self): + def setup_method(self): with open(f"{TEST_DIR}/test_toec_data.json") as file: self.data_dict = json.load(file) self.strains = [Strain(sm) for sm in self.data_dict["strains"]] diff --git a/tests/analysis/elasticity/test_strain.py b/tests/analysis/elasticity/test_strain.py index 9679fb367cd..9b2daee68fb 100644 --- a/tests/analysis/elasticity/test_strain.py +++ b/tests/analysis/elasticity/test_strain.py @@ -11,7 +11,7 @@ class TestDeformation(PymatgenTest): - def setUp(self): + def setup_method(self): self.norm_defo = Deformation.from_index_amount((0, 0), 0.02) self.ind_defo = Deformation.from_index_amount((0, 1), 0.02) self.non_ind_defo = Deformation([[1, 0.02, 0.02], [0, 1, 0], [0, 0, 1]]) @@ -82,7 +82,7 @@ def test_apply_to_structure(self): class TestStrain(PymatgenTest): - def setUp(self): + def setup_method(self): self.norm_str = Strain.from_deformation([[1.02, 0, 0], [0, 1, 0], [0, 0, 1]]) self.ind_str = Strain.from_deformation([[1, 0.02, 0], [0, 1, 0], [0, 0, 1]]) @@ -143,7 +143,7 @@ def test_convert_strain_to_deformation(self): class TestDeformedStructureSet(PymatgenTest): - def setUp(self): + def setup_method(self): self.structure = self.get_structure("Sn") self.default_dss = DeformedStructureSet(self.structure) diff --git a/tests/analysis/elasticity/test_stress.py b/tests/analysis/elasticity/test_stress.py index 9d1dc98ad33..303c7d0f87c 100644 --- a/tests/analysis/elasticity/test_stress.py +++ b/tests/analysis/elasticity/test_stress.py @@ -11,7 +11,7 @@ class TestStress(PymatgenTest): - def setUp(self): + def setup_method(self): self.rand_stress = Stress(np.random.default_rng().standard_normal((3, 3))) self.symm_stress = Stress([[0.51, 2.29, 2.42], [2.29, 5.14, 5.07], [2.42, 5.07, 5.33]]) self.non_symm = Stress([[0.1, 0.2, 0.3], [0.4, 0.5, 0.6], [0.2, 0.5, 0.5]]) diff --git a/tests/analysis/ferroelectricity/test_polarization.py b/tests/analysis/ferroelectricity/test_polarization.py index 57236ff98c4..f6fca157600 100644 --- a/tests/analysis/ferroelectricity/test_polarization.py +++ b/tests/analysis/ferroelectricity/test_polarization.py @@ -39,7 +39,7 @@ class TestUtils(PymatgenTest): - def setUp(self): + def setup_method(self): self.potcar = Potcar.from_file(f"{TEST_DIR}/POTCAR") self.zval_dict = {"Ba": 10, "Ti": 10, "O": 6} self.ions = ions @@ -55,7 +55,7 @@ def test_get_total_ionic_dipole(self): class TestPolarization(PymatgenTest): - def setUp(self): + def setup_method(self): self.p_ions = ions self.p_ions_outcar = np.array( [ @@ -259,7 +259,7 @@ def test_smoothness(self): class TestEnergyTrend(PymatgenTest): - def setUp(self): + def setup_method(self): self.energies = [ -7.97738049, -7.988621176, diff --git a/tests/analysis/interfaces/test_coherent_interface.py b/tests/analysis/interfaces/test_coherent_interface.py index e2a19a73915..1be08782139 100644 --- a/tests/analysis/interfaces/test_coherent_interface.py +++ b/tests/analysis/interfaces/test_coherent_interface.py @@ -52,7 +52,7 @@ def test_coherent_interface_builder(self): class TestCoherentInterfaceBuilder(unittest.TestCase): - def setUp(self): + def setup_method(self): # build substrate & film structure basis = [[0, 0, 0], [0.25, 0.25, 0.25]] self.substrate = Structure(Lattice.cubic(a=5.431), ["Si", "Si"], basis) diff --git a/tests/analysis/interfaces/test_zsl.py b/tests/analysis/interfaces/test_zsl.py index 25ab77950e1..3030a3d3074 100644 --- a/tests/analysis/interfaces/test_zsl.py +++ b/tests/analysis/interfaces/test_zsl.py @@ -24,7 +24,7 @@ class TestZSLGen(PymatgenTest): - def setUp(self): + def setup_method(self): # Film VO2 self.film = SpacegroupAnalyzer(self.get_structure("VO2"), symprec=0.1).get_conventional_standard_structure() diff --git a/tests/analysis/magnetism/test_analyzer.py b/tests/analysis/magnetism/test_analyzer.py index 3286409d05f..e71dfadaa6d 100644 --- a/tests/analysis/magnetism/test_analyzer.py +++ b/tests/analysis/magnetism/test_analyzer.py @@ -25,7 +25,7 @@ class TestCollinearMagneticStructureAnalyzer(TestCase): - def setUp(self): + def setup_method(self): self.Fe = Structure.from_file(f"{TEST_FILES_DIR}/cif/Fe.cif", primitive=True) self.LiFePO4 = Structure.from_file(f"{TEST_FILES_DIR}/cif/LiFePO4.cif", primitive=True) diff --git a/tests/analysis/magnetism/test_jahnteller.py b/tests/analysis/magnetism/test_jahnteller.py index ac3555cce47..f1938dbafe5 100644 --- a/tests/analysis/magnetism/test_jahnteller.py +++ b/tests/analysis/magnetism/test_jahnteller.py @@ -11,7 +11,7 @@ class TestJahnTeller(TestCase): - def setUp(self): + def setup_method(self): self.jt = JahnTellerAnalyzer() def test_jahn_teller_species_analysis(self): diff --git a/tests/analysis/structure_prediction/test_dopant_predictor.py b/tests/analysis/structure_prediction/test_dopant_predictor.py index f19d032624d..a88e424a9c6 100644 --- a/tests/analysis/structure_prediction/test_dopant_predictor.py +++ b/tests/analysis/structure_prediction/test_dopant_predictor.py @@ -13,7 +13,7 @@ class TestDopantPrediction(TestCase): - def setUp(self): + def setup_method(self): self.tin_dioxide = Structure( [3.24, 0, 0, 0, 4.83, 0, 0, 0, 4.84], ["O", "O", "O", "O", "Sn", "Sn"], diff --git a/tests/analysis/structure_prediction/test_substitutor.py b/tests/analysis/structure_prediction/test_substitutor.py index 6965408afcc..87ba7b2e787 100644 --- a/tests/analysis/structure_prediction/test_substitutor.py +++ b/tests/analysis/structure_prediction/test_substitutor.py @@ -21,7 +21,7 @@ def get_table(): class TestSubstitutor(PymatgenTest): - def setUp(self): + def setup_method(self): self.substitutor = Substitutor(threshold=1e-3, lambda_table=get_table(), alpha=-5.0) def test_substitutor(self): diff --git a/tests/analysis/test_adsorption.py b/tests/analysis/test_adsorption.py index ced3948a366..1b90989c410 100644 --- a/tests/analysis/test_adsorption.py +++ b/tests/analysis/test_adsorption.py @@ -12,7 +12,7 @@ class TestAdsorbateSiteFinder(PymatgenTest): - def setUp(self): + def setup_method(self): self.structure = Structure.from_spacegroup("Fm-3m", Lattice.cubic(3.5), ["Ni"], [[0, 0, 0]]) lattice = Lattice.cubic(3.010) frac_coords = [ diff --git a/tests/analysis/test_bond_dissociation.py b/tests/analysis/test_bond_dissociation.py index 01cb71aaea6..3366b2fae8d 100644 --- a/tests/analysis/test_bond_dissociation.py +++ b/tests/analysis/test_bond_dissociation.py @@ -13,7 +13,7 @@ class TestBondDissociation(TestCase): - def setUp(self): + def setup_method(self): pytest.importorskip("openbabel") self.PC_65_principle = loadfn(f"{TEST_DIR}/PC_65_principle.json") self.PC_65_principle["initial_molecule"] = self.PC_65_principle["initial_molecule"].as_dict() diff --git a/tests/analysis/test_bond_valence.py b/tests/analysis/test_bond_valence.py index a2e0db2ce0c..17c94ad404d 100644 --- a/tests/analysis/test_bond_valence.py +++ b/tests/analysis/test_bond_valence.py @@ -11,7 +11,7 @@ class TestBVAnalyzer(PymatgenTest): - def setUp(self): + def setup_method(self): self.analyzer = BVAnalyzer() def test_get_valences(self): diff --git a/tests/analysis/test_chempot_diagram.py b/tests/analysis/test_chempot_diagram.py index 43dfd957b0d..3c4a87b6262 100644 --- a/tests/analysis/test_chempot_diagram.py +++ b/tests/analysis/test_chempot_diagram.py @@ -18,7 +18,7 @@ class TestChemicalPotentialDiagram(PymatgenTest): - def setUp(self): + def setup_method(self): self.entries = EntrySet.from_csv(f"{TEST_DIR}/pd_entries_test.csv") self.cpd_ternary, self.cpd_ternary_formal = ( ChemicalPotentialDiagram(entries=self.entries, default_min_limit=-25, formal_chempots=formal) diff --git a/tests/analysis/test_cost.py b/tests/analysis/test_cost.py index c20bed2fd54..39475af303f 100644 --- a/tests/analysis/test_cost.py +++ b/tests/analysis/test_cost.py @@ -11,7 +11,7 @@ class TestCostAnalyzer(TestCase): - def setUp(self): + def setup_method(self): self.ca1 = CostAnalyzer(CostDBCSV(f"{TEST_DIR}/costdb_1.csv")) self.ca2 = CostAnalyzer(CostDBCSV(f"{TEST_DIR}/costdb_2.csv")) diff --git a/tests/analysis/test_dimensionality.py b/tests/analysis/test_dimensionality.py index 8b99c6fd5e2..49482280d61 100644 --- a/tests/analysis/test_dimensionality.py +++ b/tests/analysis/test_dimensionality.py @@ -19,7 +19,7 @@ class TestLarsenDimensionality(PymatgenTest): - def setUp(self): + def setup_method(self): cnn = CrystalNN() self.lifepo = cnn.get_bonded_structure(self.get_structure("LiFePO4")) self.graphite = cnn.get_bonded_structure(self.get_structure("Graphite")) diff --git a/tests/analysis/test_eos.py b/tests/analysis/test_eos.py index 9a839f8279b..9138fe905ab 100644 --- a/tests/analysis/test_eos.py +++ b/tests/analysis/test_eos.py @@ -9,7 +9,7 @@ class TestEOS(PymatgenTest): - def setUp(self): + def setup_method(self): # Si data from Cormac self.volumes = [ 25.987454833, diff --git a/tests/analysis/test_ewald.py b/tests/analysis/test_ewald.py index 285152bb8fd..3edc515038b 100644 --- a/tests/analysis/test_ewald.py +++ b/tests/analysis/test_ewald.py @@ -12,7 +12,7 @@ class TestEwaldSummation(TestCase): - def setUp(self): + def setup_method(self): filepath = f"{VASP_IN_DIR}/POSCAR" self.original_struct = Structure.from_file(filepath) self.struct = self.original_struct.copy() diff --git a/tests/analysis/test_functional_groups.py b/tests/analysis/test_functional_groups.py index a5fcb316e38..a19a12b997b 100644 --- a/tests/analysis/test_functional_groups.py +++ b/tests/analysis/test_functional_groups.py @@ -26,7 +26,7 @@ class TestFunctionalGroupExtractor(TestCase): - def setUp(self): + def setup_method(self): self.file = f"{TEST_DIR}/func_group_test.mol" self.mol = Molecule.from_file(self.file) self.strategy = OpenBabelNN() diff --git a/tests/analysis/test_graphs.py b/tests/analysis/test_graphs.py index ad42533435c..899f7e564e6 100644 --- a/tests/analysis/test_graphs.py +++ b/tests/analysis/test_graphs.py @@ -47,7 +47,7 @@ class TestStructureGraph(PymatgenTest): - def setUp(self): + def setup_method(self): # trivial example, simple square lattice for testing structure = Structure(Lattice.tetragonal(5, 50), ["H"], [[0, 0, 0]]) self.square_sg = StructureGraph.from_empty_graph(structure, edge_weight_name="", edge_weight_units="") @@ -505,7 +505,7 @@ def test_sort(self): class TestMoleculeGraph(TestCase): - def setUp(self): + def setup_method(self): cyclohexene_xyz = f"{TEST_DIR}/cyclohexene.xyz" cyclohexene = Molecule.from_file(cyclohexene_xyz) self.cyclohexene = MoleculeGraph.from_empty_graph( diff --git a/tests/analysis/test_interface_reactions.py b/tests/analysis/test_interface_reactions.py index a402fd34420..372049e1447 100644 --- a/tests/analysis/test_interface_reactions.py +++ b/tests/analysis/test_interface_reactions.py @@ -18,7 +18,7 @@ class TestInterfaceReaction(TestCase): - def setUp(self): + def setup_method(self): self.entries = [ ComputedEntry(Composition("Li"), 0), ComputedEntry(Composition("Mn"), 0), diff --git a/tests/analysis/test_local_env.py b/tests/analysis/test_local_env.py index ac2ab8b099d..039282e2cc3 100644 --- a/tests/analysis/test_local_env.py +++ b/tests/analysis/test_local_env.py @@ -55,7 +55,7 @@ def test_opt_params(): class TestValenceIonicRadiusEvaluator(PymatgenTest): - def setUp(self): + def setup_method(self): """Setup MgO rocksalt structure for testing Vacancy.""" mgo_latt = np.eye(3) * 4.212 mgo_specie = ["Mg"] * 4 + ["O"] * 4 @@ -90,7 +90,7 @@ def test_radii_ionic_structure(self): class TestVoronoiNN(PymatgenTest): - def setUp(self): + def setup_method(self): self.struct = self.get_structure("LiFePO4") self.nn = VoronoiNN(targets=[Element("O")]) self.s_sic = self.get_structure("Si") @@ -261,7 +261,7 @@ def test_filtered(self): class TestJmolNN(PymatgenTest): - def setUp(self): + def setup_method(self): self.jmol = JmolNN() self.jmol_update = JmolNN(el_radius_updates={"Li": 1}) @@ -302,7 +302,7 @@ def test_get_nn(self): class TestOpenBabelNN(PymatgenTest): - def setUp(self): + def setup_method(self): pytest.importorskip("openbabel") self.benzene = Molecule.from_file(f"{TEST_DIR}/../benzene.xyz") self.acetylene = Molecule.from_file(f"{TEST_FILES_DIR}/io/xyz/acetylene.xyz") @@ -334,7 +334,7 @@ def test_nn_length(self): class TestCovalentBondNN(PymatgenTest): - def setUp(self): + def setup_method(self): self.benzene = Molecule.from_file(f"{TEST_DIR}/../benzene.xyz") self.acetylene = Molecule.from_file(f"{TEST_FILES_DIR}/io/xyz/acetylene.xyz") @@ -373,7 +373,7 @@ def test_bonded_structure(self): class TestMiniDistNN(PymatgenTest): - def setUp(self): + def setup_method(self): self.diamond = Structure( Lattice([[2.189, 0, 1.264], [0.73, 2.064, 1.264], [0, 0, 2.528]]), ["C0+", "C0+"], @@ -486,7 +486,7 @@ def test_get_local_order_params(self): class TestMotifIdentification(PymatgenTest): - def setUp(self): + def setup_method(self): self.silicon = Structure( Lattice.cubic(5.47), ["Si", "Si", "Si", "Si", "Si", "Si", "Si", "Si"], @@ -584,7 +584,7 @@ def test_get_neighbors_of_site_with_index(self): class TestNearNeighbor(PymatgenTest): - def setUp(self): + def setup_method(self): self.diamond = Structure( Lattice([[2.189, 0, 1.264], [0.73, 2.064, 1.264], [0, 0, 2.528]]), ["C0+", "C0+"], @@ -618,7 +618,7 @@ def test_on_disorder_options(self): class TestLocalStructOrderParams(PymatgenTest): - def setUp(self): + def setup_method(self): self.single_bond = Structure( Lattice.cubic(10), ["H", "H", "H"], @@ -1183,7 +1183,7 @@ def test_get_order_parameters(self): class TestCrystalNN(PymatgenTest): - def setUp(self): + def setup_method(self): self.lifepo4 = self.get_structure("LiFePO4") self.lifepo4.add_oxidation_state_by_guess() self.he_bcc = self.get_structure("He_BCC") @@ -1330,7 +1330,7 @@ def test_get_bonded_structure(self): class TestCutOffDictNN(PymatgenTest): - def setUp(self): + def setup_method(self): self.diamond = Structure( Lattice([[2.189, 0, 1.264], [0.73, 2.064, 1.264], [0, 0, 2.528]]), ["C", "C"], @@ -1356,7 +1356,7 @@ def test_from_preset(self): @pytest.mark.skipif(not which("critic2"), reason="critic2 executable not present") class TestCritic2NN(PymatgenTest): - def setUp(self): + def setup_method(self): self.diamond = Structure( Lattice([[2.189, 0, 1.264], [0.73, 2.064, 1.264], [0, 0, 2.528]]), ["C", "C"], @@ -1370,7 +1370,7 @@ def test_cn(self): class TestMetalEdgeExtender(PymatgenTest): - def setUp(self): + def setup_method(self): self.LiEC = Molecule.from_file(f"{TEST_DIR}/LiEC.xyz") self.phsh = Molecule.from_file(f"{TEST_DIR}/phsh.xyz") self.phsh_graph = MoleculeGraph.from_edges( diff --git a/tests/analysis/test_phase_diagram.py b/tests/analysis/test_phase_diagram.py index 934ba59fa9d..a84a95beae3 100644 --- a/tests/analysis/test_phase_diagram.py +++ b/tests/analysis/test_phase_diagram.py @@ -38,7 +38,7 @@ class TestPDEntry(TestCase): - def setUp(self): + def setup_method(self): comp = Composition("LiFeO2") self.entry = PDEntry(comp, 53, name="mp-757614") self.gp_entry = GrandPotPDEntry(self.entry, {Element("O"): 1.5}) @@ -114,7 +114,7 @@ def test_read_csv(self): class TestTransformedPDEntry(TestCase): - def setUp(self): + def setup_method(self): comp = Composition("LiFeO2") entry = PDEntry(comp, 53) @@ -180,7 +180,7 @@ def test_normalize(self): class TestPhaseDiagram(PymatgenTest): - def setUp(self): + def setup_method(self): self.entries = EntrySet.from_csv(f"{TEST_DIR}/pd_entries_test.csv") self.pd = PhaseDiagram(self.entries) @@ -668,7 +668,7 @@ def test_val_err_on_no_entries(self): class TestGrandPotentialPhaseDiagram(TestCase): - def setUp(self): + def setup_method(self): self.entries = EntrySet.from_csv(f"{TEST_DIR}/pd_entries_test.csv") self.pd = GrandPotentialPhaseDiagram(self.entries, {Element("O"): -5}) self.pd6 = GrandPotentialPhaseDiagram(self.entries, {Element("O"): -6}) @@ -704,7 +704,7 @@ def test_str(self): class TestCompoundPhaseDiagram(TestCase): - def setUp(self): + def setup_method(self): self.entries = EntrySet.from_csv(f"{TEST_DIR}/pd_entries_test.csv") self.pd = CompoundPhaseDiagram(self.entries, [Composition("Li2O"), Composition("Fe2O3")]) @@ -742,7 +742,7 @@ def test_num2str(self): class TestPatchedPhaseDiagram(TestCase): - def setUp(self): + def setup_method(self): self.entries = EntrySet.from_csv(f"{TEST_DIR}/phase_diagram/reaction_entries_test.csv") # NOTE add He to test for correct behavior despite no patches involving He self.no_patch_entry = he_entry = PDEntry("He", -1.23) @@ -892,7 +892,7 @@ def test_remove_redundant_spaces(self): class TestReactionDiagram(TestCase): - def setUp(self): + def setup_method(self): self.entries = list(EntrySet.from_csv(f"{TEST_DIR}/phase_diagram/reaction_entries_test.csv").entries) for entry in self.entries: if entry.reduced_formula == "VPO5": @@ -932,7 +932,7 @@ def test_formula(self): class TestPDPlotter(TestCase): - def setUp(self): + def setup_method(self): entries = list(EntrySet.from_csv(f"{TEST_DIR}/pd_entries_test.csv")) elemental_entries = [entry for entry in entries if entry.elements == [Element("Li")]] diff --git a/tests/analysis/test_piezo.py b/tests/analysis/test_piezo.py index bf3eb7534c2..59eb96e5996 100644 --- a/tests/analysis/test_piezo.py +++ b/tests/analysis/test_piezo.py @@ -18,7 +18,7 @@ class TestPiezo(PymatgenTest): - def setUp(self): + def setup_method(self): self.piezo_struct = self.get_structure("BaNiO3") self.voigt_matrix = np.array( [ diff --git a/tests/analysis/test_piezo_sensitivity.py b/tests/analysis/test_piezo_sensitivity.py index 757215a30e4..454f1caed77 100644 --- a/tests/analysis/test_piezo_sensitivity.py +++ b/tests/analysis/test_piezo_sensitivity.py @@ -35,7 +35,7 @@ class TestPiezoSensitivity(PymatgenTest): - def setUp(self): + def setup_method(self): self.piezo_struct = self.get_structure("Pb2TiZrO6") self.IST = np.load(f"{TEST_DIR}/pztist.npy", allow_pickle=True) self.BEC = np.load(f"{TEST_DIR}/pztborn.npy", allow_pickle=True) diff --git a/tests/analysis/test_pourbaix_diagram.py b/tests/analysis/test_pourbaix_diagram.py index 22066499257..04720d1c747 100644 --- a/tests/analysis/test_pourbaix_diagram.py +++ b/tests/analysis/test_pourbaix_diagram.py @@ -20,7 +20,7 @@ class TestPourbaixEntry(PymatgenTest): """Test all functions using a fictitious entry""" - def setUp(self): + def setup_method(self): # comp = Composition("Mn2O3") self.sol_entry = ComputedEntry("Mn2O3", 49) ion = Ion.from_formula("MnO4-") @@ -294,7 +294,7 @@ def test_serialization(self): class TestPourbaixPlotter(TestCase): - def setUp(self): + def setup_method(self): self.test_data = loadfn(f"{TEST_DIR}/pourbaix_test_data.json") self.pd = PourbaixDiagram(self.test_data["Zn"]) self.plotter = PourbaixPlotter(self.pd) diff --git a/tests/analysis/test_quasi_harmonic_debye_approx.py b/tests/analysis/test_quasi_harmonic_debye_approx.py index 6c0c5816d2d..52c4cfc7aba 100644 --- a/tests/analysis/test_quasi_harmonic_debye_approx.py +++ b/tests/analysis/test_quasi_harmonic_debye_approx.py @@ -13,7 +13,7 @@ class TestQuasiHarmonicDebyeApprox(TestCase): - def setUp(self): + def setup_method(self): struct = Structure.from_dict( { "lattice": { @@ -138,7 +138,7 @@ def test_vibrational_free_energy(self): class TestAnharmonicQuasiHarmonicDebyeApprox(TestCase): - def setUp(self): + def setup_method(self): struct = Structure.from_str( """FCC Al 1.0 diff --git a/tests/analysis/test_quasirrho.py b/tests/analysis/test_quasirrho.py index 63cd0015ad4..110382f263a 100644 --- a/tests/analysis/test_quasirrho.py +++ b/tests/analysis/test_quasirrho.py @@ -15,7 +15,7 @@ class TestQuasiRRHO(TestCase): """Test class for QuasiRRHO""" - def setUp(self): + def setup_method(self): self.gout = GaussianOutput(f"{TEST_DIR}/quasirrho_gaufreq.log") self.linear_gout = GaussianOutput(f"{TEST_DIR}/co2.log.gz") self.qout = QCOutput(f"{TEST_DIR}/Frequency_no_equal.qout") diff --git a/tests/analysis/test_reaction_calculator.py b/tests/analysis/test_reaction_calculator.py index 82fc1e03bea..b4f6e4ceb1c 100644 --- a/tests/analysis/test_reaction_calculator.py +++ b/tests/analysis/test_reaction_calculator.py @@ -288,7 +288,7 @@ def test_underdetermined_reactants(self): class TestBalancedReaction(TestCase): - def setUp(self) -> None: + def setup_method(self) -> None: rct = {"K2SO4": 3, "Na2S": 1, "Li": 24} prod = {"KNaS": 2, "K2S": 2, "Li2O": 12} self.rxn = BalancedReaction(rct, prod) @@ -335,7 +335,7 @@ def test_hash(self): class TestComputedReaction(TestCase): - def setUp(self): + def setup_method(self): dct = [ { "correction": 0, diff --git a/tests/analysis/test_structure_analyzer.py b/tests/analysis/test_structure_analyzer.py index a7da910eff0..066a6890af8 100644 --- a/tests/analysis/test_structure_analyzer.py +++ b/tests/analysis/test_structure_analyzer.py @@ -22,7 +22,7 @@ class TestVoronoiAnalyzer(PymatgenTest): - def setUp(self): + def setup_method(self): self.structs = Xdatcar(f"{VASP_OUT_DIR}/XDATCAR.MD").structures self.struct = self.structs[1] self.va = VoronoiAnalyzer(cutoff=4) @@ -41,7 +41,7 @@ def test_analyze(self): class TestRelaxationAnalyzer(TestCase): - def setUp(self): + def setup_method(self): s1 = Structure.from_file(f"{VASP_IN_DIR}/POSCAR_Li2O") s2 = Structure.from_file(f"{VASP_OUT_DIR}/CONTCAR_Li2O") self.analyzer = RelaxationAnalyzer(s1, s2) diff --git a/tests/analysis/test_structure_matcher.py b/tests/analysis/test_structure_matcher.py index 5a71019ebe2..5106f19a527 100644 --- a/tests/analysis/test_structure_matcher.py +++ b/tests/analysis/test_structure_matcher.py @@ -23,7 +23,7 @@ class TestStructureMatcher(PymatgenTest): - def setUp(self): + def setup_method(self): with open(f"{TEST_FILES_DIR}/entries/TiO2_entries.json") as file: entries = json.load(file, cls=MontyDecoder) self.struct_list = [ent.structure for ent in entries] diff --git a/tests/analysis/test_surface_analysis.py b/tests/analysis/test_surface_analysis.py index 5492d9aefa6..2f95ad7edbb 100644 --- a/tests/analysis/test_surface_analysis.py +++ b/tests/analysis/test_surface_analysis.py @@ -23,7 +23,7 @@ class TestSlabEntry(PymatgenTest): - def setUp(self): + def setup_method(self): with open(f"{TEST_DIR}/ucell_entries.txt") as file: ucell_entries = json.loads(file.read()) self.ucell_entries = ucell_entries @@ -119,7 +119,7 @@ def test_cleaned_up_slab(self): class TestSurfaceEnergyPlotter(PymatgenTest): - def setUp(self): + def setup_method(self): entry_dict = get_entry_dict(f"{TEST_DIR}/Cu_entries.txt") self.Cu_entry_dict = entry_dict with open(f"{TEST_DIR}/ucell_entries.txt") as file: @@ -293,7 +293,7 @@ def test_surface_chempot_range_map(self): class TestWorkFunctionAnalyzer(PymatgenTest): - def setUp(self): + def setup_method(self): self.kwargs = { "poscar_filename": f"{TEST_DIR}/CONTCAR.relax1.gz", "locpot_filename": f"{TEST_DIR}/LOCPOT.gz", @@ -310,7 +310,7 @@ def test_is_converged(self): class TestNanoscaleStability(PymatgenTest): - def setUp(self): + def setup_method(self): # Load all entries La_hcp_entry_dict = get_entry_dict(f"{TEST_DIR}/La_hcp_entries.txt") La_fcc_entry_dict = get_entry_dict(f"{TEST_DIR}/La_fcc_entries.txt") diff --git a/tests/analysis/test_wulff.py b/tests/analysis/test_wulff.py index 768d079e2da..8ecba2e2e41 100644 --- a/tests/analysis/test_wulff.py +++ b/tests/analysis/test_wulff.py @@ -22,7 +22,7 @@ class TestWulffShape(PymatgenTest): - def setUp(self): + def setup_method(self): with open(f"{TEST_DIR}/surface_samples.json") as data_file: surface_properties = json.load(data_file) diff --git a/tests/analysis/xas/test_spectrum.py b/tests/analysis/xas/test_spectrum.py index 92a04879dc3..54dd93760a7 100644 --- a/tests/analysis/xas/test_spectrum.py +++ b/tests/analysis/xas/test_spectrum.py @@ -29,7 +29,7 @@ class TestXAS(PymatgenTest): - def setUp(self): + def setup_method(self): self.k_xanes = XAS.from_dict(k_xanes_dict) self.k_exafs = XAS.from_dict(k_exafs_dict) self.l2_xanes = XAS.from_dict(l2_xanes_dict) diff --git a/tests/apps/battery/test_analyzer.py b/tests/apps/battery/test_analyzer.py index eea99df2ecb..52e59c5680d 100644 --- a/tests/apps/battery/test_analyzer.py +++ b/tests/apps/battery/test_analyzer.py @@ -19,7 +19,7 @@ def load_from_internal(self, name, oxidations, working_ion="Li"): struct.add_oxidation_state_by_element(oxidations) return BatteryAnalyzer(struct, working_ion) - def setUp(self): + def setup_method(self): self.li_fe_p_o4 = self.load_from_internal("LiFePO4", {"Li": 1, "Fe": 2, "P": 5, "O": -2}) self.na_fe_p_o4 = self.load_from_internal("NaFePO4", {"Na": 1, "Fe": 2, "P": 5, "O": -2}, working_ion="Na") self.la2coo4f = self.load_from_internal("La2CoO4F", {"La": 3, "Co": 3, "O": -2, "F": -1}, working_ion="F") diff --git a/tests/apps/battery/test_conversion_battery.py b/tests/apps/battery/test_conversion_battery.py index d2d1b817ff8..2fc7efb10c9 100644 --- a/tests/apps/battery/test_conversion_battery.py +++ b/tests/apps/battery/test_conversion_battery.py @@ -14,7 +14,7 @@ class TestConversionElectrode(TestCase): - def setUp(self): + def setup_method(self): self.formulas = ["LiCoO2", "FeF3", "MnO2"] self.conversion_electrodes = {} for formula in self.formulas: diff --git a/tests/apps/battery/test_insertion_battery.py b/tests/apps/battery/test_insertion_battery.py index 4c6b9caa951..d7028b835e9 100644 --- a/tests/apps/battery/test_insertion_battery.py +++ b/tests/apps/battery/test_insertion_battery.py @@ -14,7 +14,7 @@ class TestInsertionElectrode(TestCase): - def setUp(self): + def setup_method(self): self.entry_Li = ComputedEntry("Li", -1.90753119) self.entry_Ca = ComputedEntry("Ca", -1.99689568) diff --git a/tests/apps/battery/test_plotter.py b/tests/apps/battery/test_plotter.py index 8b93b20f8bf..a0f3daad6a0 100644 --- a/tests/apps/battery/test_plotter.py +++ b/tests/apps/battery/test_plotter.py @@ -16,7 +16,7 @@ class TestVoltageProfilePlotter(TestCase): - def setUp(self): + def setup_method(self): entry_Li = ComputedEntry("Li", -1.90753119) with open(f"{TEST_DIR}/LiTiO2_batt.json") as file: diff --git a/tests/apps/borg/test_hive.py b/tests/apps/borg/test_hive.py index 6005eaf3f2c..3e47e6e8e33 100644 --- a/tests/apps/borg/test_hive.py +++ b/tests/apps/borg/test_hive.py @@ -21,7 +21,7 @@ class TestVaspToComputedEntryDrone(TestCase): - def setUp(self): + def setup_method(self): self.drone = VaspToComputedEntryDrone(data=["efermi"]) self.structure_drone = VaspToComputedEntryDrone(inc_structure=True) @@ -54,7 +54,7 @@ def test_as_from_dict(self): class TestSimpleVaspToComputedEntryDrone(TestCase): - def setUp(self): + def setup_method(self): self.drone = SimpleVaspToComputedEntryDrone() self.structure_drone = SimpleVaspToComputedEntryDrone(inc_structure=True) @@ -74,7 +74,7 @@ def test_as_from_dict(self): class TestGaussianToComputedEntryDrone(TestCase): - def setUp(self): + def setup_method(self): self.drone = GaussianToComputedEntryDrone(data=["corrections"]) self.structure_drone = GaussianToComputedEntryDrone(inc_structure=True) diff --git a/tests/command_line/test_bader_caller.py b/tests/command_line/test_bader_caller.py index ad39f8c6b61..6b63ce9aa9a 100644 --- a/tests/command_line/test_bader_caller.py +++ b/tests/command_line/test_bader_caller.py @@ -17,7 +17,7 @@ @pytest.mark.skipif(not which("bader"), reason="bader executable not present") class TestBaderAnalysis(PymatgenTest): - def setUp(self): + def setup_method(self): warnings.catch_warnings() def test_init(self): diff --git a/tests/command_line/test_critic2_caller.py b/tests/command_line/test_critic2_caller.py index 430b052d4bf..303269f3d42 100644 --- a/tests/command_line/test_critic2_caller.py +++ b/tests/command_line/test_critic2_caller.py @@ -76,7 +76,7 @@ def test_from_structure(self): class TestCritic2Analysis(TestCase): - def setUp(self): + def setup_method(self): stdout_file = f"{TEST_DIR}/MoS2_critic2_stdout.txt" stdout_file_new_format = f"{TEST_DIR}/MoS2_critic2_stdout_new_format.txt" with open(stdout_file) as file: diff --git a/tests/command_line/test_gulp_caller.py b/tests/command_line/test_gulp_caller.py index 18c3f05c268..09bea1d8044 100644 --- a/tests/command_line/test_gulp_caller.py +++ b/tests/command_line/test_gulp_caller.py @@ -107,7 +107,7 @@ def test_decimal(self): class TestGulpIO(TestCase): - def setUp(self): + def setup_method(self): self.structure = Structure.from_file(f"{VASP_IN_DIR}/POSCAR_Al12O18") self.gio = GulpIO() @@ -277,7 +277,7 @@ def test_tersoff_input(self): class TestGlobalFunctions(TestCase): - def setUp(self): + def setup_method(self): mgo_latt = np.eye(3) * 4.212 mgo_specie = ["Mg", "O"] * 4 mgo_frac_cord = [ @@ -328,7 +328,7 @@ def test_get_energy_relax_structure_buckingham(self): class TestBuckinghamPotentialLewis(TestCase): - def setUp(self): + def setup_method(self): self.bpl = BuckinghamPotential("lewis") def test_existing_element(self): @@ -355,7 +355,7 @@ def test_spring(self): class TestBuckinghamPotentialBush(TestCase): - def setUp(self): + def setup_method(self): self.bpb = BuckinghamPotential("bush") def test_existing_element(self): diff --git a/tests/command_line/test_mcsqs_caller.py b/tests/command_line/test_mcsqs_caller.py index ca9f8a018d6..aa749e1bab8 100644 --- a/tests/command_line/test_mcsqs_caller.py +++ b/tests/command_line/test_mcsqs_caller.py @@ -19,7 +19,7 @@ @pytest.mark.skipif(not (which("mcsqs") and which("str2cif")), reason="mcsqs executable not present") class TestMcsqsCaller(PymatgenTest): - def setUp(self): + def setup_method(self): self.pzt_structs = loadfn(f"{TEST_DIR}/pzt-structs.json") self.pzt_structs2 = loadfn(f"{TEST_DIR}/pzt-structs-2.json") self.struct = self.get_structure("Pb2TiZrO6") diff --git a/tests/core/test_composition.py b/tests/core/test_composition.py index 9c00c7678fd..52d38e0079c 100644 --- a/tests/core/test_composition.py +++ b/tests/core/test_composition.py @@ -17,7 +17,7 @@ class TestComposition(PymatgenTest): - def setUp(self): + def setup_method(self): self.comps = [ Composition("Li3Fe2(PO4)3"), Composition("Li3Fe(PO4)O"), diff --git a/tests/core/test_interface.py b/tests/core/test_interface.py index c2563cd2a7a..c40c7ba9631 100644 --- a/tests/core/test_interface.py +++ b/tests/core/test_interface.py @@ -14,7 +14,7 @@ class TestGrainBoundary(PymatgenTest): - def setUp(self): + def setup_method(self): self.Cu_conv = Structure.from_file(f"{TEST_DIR}/Cu_mp-30_conventional_standard.cif") GB_Cu_conv = GrainBoundaryGenerator(self.Cu_conv) self.Cu_GB1 = GB_Cu_conv.gb_from_parameters( @@ -332,7 +332,7 @@ def test_get_rotation_angle_from_sigma(self): class TestInterface(PymatgenTest): - def setUp(self): + def setup_method(self): self.interface: Interface = self.get_structure("Si_SiO2_Interface") def test_basic_props(self): diff --git a/tests/core/test_ion.py b/tests/core/test_ion.py index a547bfe9005..2d2291c6da9 100644 --- a/tests/core/test_ion.py +++ b/tests/core/test_ion.py @@ -10,7 +10,7 @@ class TestIon(TestCase): - def setUp(self): + def setup_method(self): self.comp = [] self.comp.append(Ion.from_formula("Li+")) self.comp.append(Ion.from_formula("MnO4-")) diff --git a/tests/core/test_lattice.py b/tests/core/test_lattice.py index 89a79e6330c..1bbe8f4b865 100644 --- a/tests/core/test_lattice.py +++ b/tests/core/test_lattice.py @@ -13,7 +13,7 @@ class TestLattice(PymatgenTest): - def setUp(self): + def setup_method(self): self.lattice = Lattice.cubic(10.0) self.cubic = self.lattice self.tetragonal = Lattice.tetragonal(10, 20) diff --git a/tests/core/test_operations.py b/tests/core/test_operations.py index 1d775b09b92..63efb6317c3 100644 --- a/tests/core/test_operations.py +++ b/tests/core/test_operations.py @@ -9,7 +9,7 @@ class TestSymmOp(PymatgenTest): - def setUp(self): + def setup_method(self): self.op = SymmOp.from_axis_angle_and_translation([0, 0, 1], 30, translation_vec=[0, 0, 1]) def test_properties(self): diff --git a/tests/core/test_periodic_table.py b/tests/core/test_periodic_table.py index a4a696a4f56..1a1c2fa68fe 100644 --- a/tests/core/test_periodic_table.py +++ b/tests/core/test_periodic_table.py @@ -393,7 +393,7 @@ def test_isotope(self): class TestSpecies(PymatgenTest): - def setUp(self): + def setup_method(self): self.specie1 = Species.from_str("Fe2+") self.specie2 = Species("Fe", 3) self.specie3 = Species("Fe", 2) diff --git a/tests/core/test_sites.py b/tests/core/test_sites.py index 28fb7b07e4c..c8d53ca6f19 100644 --- a/tests/core/test_sites.py +++ b/tests/core/test_sites.py @@ -13,7 +13,7 @@ class TestSite(PymatgenTest): - def setUp(self): + def setup_method(self): self.ordered_site = Site("Fe", [0.25, 0.35, 0.45]) self.disordered_site = Site({"Fe": 0.5, "Mn": 0.5}, [0.25, 0.35, 0.45]) self.propertied_site = Site("Fe2+", [0.25, 0.35, 0.45], {"magmom": 5.1, "charge": 4.2}) @@ -80,7 +80,7 @@ def test_setters(self): class TestPeriodicSite(PymatgenTest): - def setUp(self): + def setup_method(self): self.lattice = Lattice.cubic(10.0) self.si = Element("Si") self.site = PeriodicSite("Fe", [0.25, 0.35, 0.45], self.lattice) diff --git a/tests/core/test_spectrum.py b/tests/core/test_spectrum.py index 2f8f208c175..4d317e016ad 100644 --- a/tests/core/test_spectrum.py +++ b/tests/core/test_spectrum.py @@ -10,7 +10,7 @@ class TestSpectrum(PymatgenTest): - def setUp(self): + def setup_method(self): rng = np.random.default_rng() self.spec1 = Spectrum(np.arange(0, 10, 0.1), rng.standard_normal(100)) self.spec2 = Spectrum(np.arange(0, 10, 0.1), rng.standard_normal(100)) diff --git a/tests/core/test_structure.py b/tests/core/test_structure.py index 7cb4abcbaf3..365cdfbab6d 100644 --- a/tests/core/test_structure.py +++ b/tests/core/test_structure.py @@ -64,7 +64,7 @@ def test_neighbor_labels(self): class TestIStructure(PymatgenTest): - def setUp(self): + def setup_method(self): coords = [[0, 0, 0], [0.75, 0.5, 0.75]] self.lattice = Lattice( [ @@ -966,7 +966,7 @@ def test_sites_setter(self): class TestStructure(PymatgenTest): - def setUp(self): + def setup_method(self): coords = [[0, 0, 0], [0.75, 0.5, 0.75]] lattice = Lattice( [ @@ -2033,7 +2033,7 @@ def test_struct_with_isotope(self): class TestIMolecule(PymatgenTest): - def setUp(self): + def setup_method(self): coords = [ [0, 0, 0], [0, 0, 1.089], @@ -2328,7 +2328,7 @@ def test_to_file_alias(self): class TestMolecule(PymatgenTest): - def setUp(self): + def setup_method(self): coords = [ [0, 0, 0], [0, 0, 1.089000], diff --git a/tests/core/test_surface.py b/tests/core/test_surface.py index 0527fc671b0..e57f7a3edb6 100644 --- a/tests/core/test_surface.py +++ b/tests/core/test_surface.py @@ -30,7 +30,7 @@ class TestSlab(PymatgenTest): - def setUp(self): + def setup_method(self): zno1 = Structure.from_file(f"{TEST_FILES_DIR}/surfaces/ZnO-wz.cif", primitive=False) zno55 = SlabGenerator(zno1, [1, 0, 0], 5, 5, lll_reduce=False, center_slab=False).get_slab() @@ -347,7 +347,7 @@ def test_as_dict(self): class TestSlabGenerator(PymatgenTest): - def setUp(self): + def setup_method(self): lattice = Lattice.cubic(3.010) frac_coords = [ [0.00000, 0.00000, 0.00000], @@ -635,7 +635,7 @@ def test_bonds_broken(self): class ReconstructionGeneratorTests(PymatgenTest): - def setUp(self): + def setup_method(self): lattice = Lattice.cubic(3.51) species = ["Ni"] coords = [[0, 0, 0]] @@ -724,7 +724,7 @@ def test_previous_reconstructions(self): class TestMillerIndexFinder(PymatgenTest): - def setUp(self): + def setup_method(self): self.cscl = Structure.from_spacegroup("Pm-3m", Lattice.cubic(4.2), ["Cs", "Cl"], [[0, 0, 0], [0.5, 0.5, 0.5]]) self.Fe = Structure.from_spacegroup("Im-3m", Lattice.cubic(2.82), ["Fe"], [[0, 0, 0]]) mg_lattice = Lattice.from_parameters(3.2, 3.2, 5.13, 90, 90, 120) diff --git a/tests/core/test_tensors.py b/tests/core/test_tensors.py index 1c840dcfa2b..94c3a24d395 100644 --- a/tests/core/test_tensors.py +++ b/tests/core/test_tensors.py @@ -15,7 +15,7 @@ class TestTensor(PymatgenTest): - def setUp(self): + def setup_method(self): rng = np.random.default_rng() self.vec = Tensor([1.0, 0.0, 0.0]) @@ -380,7 +380,7 @@ def test_round(self): class TestTensorCollection(PymatgenTest): - def setUp(self): + def setup_method(self): self.seq_tc = list(np.arange(4 * 3**3).reshape((4, 3, 3, 3))) self.seq_tc = TensorCollection(self.seq_tc) self.rand_tc = TensorCollection(list(np.random.default_rng().random((4, 3, 3)))) @@ -473,7 +473,7 @@ def test_serialization(self): class TestSquareTensor(PymatgenTest): - def setUp(self): + def setup_method(self): self.rand_sqtensor = SquareTensor(np.random.default_rng().standard_normal((3, 3))) self.symm_sqtensor = SquareTensor([[0.1, 0.3, 0.4], [0.3, 0.5, 0.2], [0.4, 0.2, 0.6]]) self.non_invertible = SquareTensor([[0.1, 0, 0], [0.2, 0, 0], [0, 0, 0]]) diff --git a/tests/core/test_trajectory.py b/tests/core/test_trajectory.py index cac745a8a75..9259b5f1b44 100644 --- a/tests/core/test_trajectory.py +++ b/tests/core/test_trajectory.py @@ -18,7 +18,7 @@ class TestTrajectory(PymatgenTest): - def setUp(self): + def setup_method(self): xdatcar = Xdatcar(f"{VASP_OUT_DIR}/XDATCAR_traj") self.traj = Trajectory.from_file(f"{VASP_OUT_DIR}/XDATCAR_traj") self.structures = xdatcar.structures diff --git a/tests/core/test_xcfunc.py b/tests/core/test_xcfunc.py index 94627874bab..793fb9f7cad 100644 --- a/tests/core/test_xcfunc.py +++ b/tests/core/test_xcfunc.py @@ -7,7 +7,7 @@ class TestLibxcFunc(PymatgenTest): - def setUp(self) -> None: + def setup_method(self) -> None: self.ixc_11 = XcFunc.from_abinit_ixc(11) def test_aliases(self): diff --git a/tests/electronic_structure/test_bandstructure.py b/tests/electronic_structure/test_bandstructure.py index c5de50385ce..79c4ff99f53 100644 --- a/tests/electronic_structure/test_bandstructure.py +++ b/tests/electronic_structure/test_bandstructure.py @@ -26,7 +26,7 @@ class TestKpoint(TestCase): - def setUp(self): + def setup_method(self): self.lattice = Lattice.cubic(10.0) self.kpoint = Kpoint([0.1, 0.4, -0.5], self.lattice, label="X") @@ -69,7 +69,7 @@ def test_from_dict(self): class TestBandStructureSymmLine(PymatgenTest): - def setUp(self): + def setup_method(self): self.bs: BandStructureSymmLine = loadfn(f"{TEST_DIR}/Cu2O_361_bandstructure.json") self.bs2: BandStructureSymmLine = loadfn(f"{TEST_DIR}/CaO_2605_bandstructure.json") self.bs_spin: BandStructureSymmLine = loadfn(f"{TEST_DIR}/NiO_19009_bandstructure.json") @@ -259,7 +259,7 @@ def test_apply_scissor_spin_polarized(self): class TestReconstructBandStructure(PymatgenTest): - def setUp(self): + def setup_method(self): self.bs_cu: BandStructureSymmLine = loadfn(f"{TEST_DIR}/Cu_30_bandstructure.json") self.bs_cu2: BandStructureSymmLine = loadfn(f"{TEST_DIR}/Cu_30_bandstructure.json") @@ -278,7 +278,7 @@ def test_vasprun_bs(self): class TestLobsterBandStructureSymmLine(PymatgenTest): - def setUp(self): + def setup_method(self): with open( f"{TEST_FILES_DIR}/electronic_structure/cohp/Fatband_SiO2/Test_p/lobster_band_structure_spin.json", ) as file: diff --git a/tests/electronic_structure/test_boltztrap2.py b/tests/electronic_structure/test_boltztrap2.py index cdb75a24532..0fb225b0379 100644 --- a/tests/electronic_structure/test_boltztrap2.py +++ b/tests/electronic_structure/test_boltztrap2.py @@ -42,7 +42,7 @@ class TestVasprunBSLoader(TestCase): - def setUp(self): + def setup_method(self): self.loader = VasprunBSLoader(VASP_RUN) assert self.loader is not None self.loader = VasprunBSLoader(BAND_STRUCT, VASP_RUN.final_structure) @@ -81,7 +81,7 @@ def test_get_volume(self): class TestBandstructureLoader(TestCase): - def setUp(self): + def setup_method(self): self.loader = BandstructureLoader(BAND_STRUCT, VASP_RUN.structures[-1]) assert self.loader is not None @@ -108,7 +108,7 @@ def test_set_upper_lower_bands(self): class TestVasprunLoader(TestCase): - def setUp(self): + def setup_method(self): self.loader = VasprunLoader(VASP_RUN) assert self.loader.proj.shape == (120, 20, 2, 9) assert self.loader is not None @@ -127,7 +127,7 @@ def test_from_file(self): class TestBztInterpolator(TestCase): - def setUp(self): + def setup_method(self): with ScratchDir("."): shutil.copy(BZT_INTERP_FN, ".") @@ -206,7 +206,7 @@ def test_tot_proj_dos(self): class TestBztTransportProperties(TestCase): - def setUp(self): + def setup_method(self): with ScratchDir("."): shutil.copy(BZT_TRANSP_FN, ".") diff --git a/tests/electronic_structure/test_cohp.py b/tests/electronic_structure/test_cohp.py index 16f0ce2ca34..ed362e37103 100644 --- a/tests/electronic_structure/test_cohp.py +++ b/tests/electronic_structure/test_cohp.py @@ -21,7 +21,7 @@ class TestCohp(TestCase): - def setUp(self): + def setup_method(self): with open(f"{TEST_DIR}/cohp.json") as file: self.cohp = Cohp.from_dict(json.load(file)) self.cohp_only = Cohp(self.cohp.efermi, self.cohp.energies, self.cohp.cohp) @@ -91,7 +91,7 @@ def test_antibnd_states_below_efermi(self): class TestIcohpValue(TestCase): - def setUp(self): + def setup_method(self): # without spin polarization label = "1" atom1 = "K1" @@ -169,7 +169,7 @@ def test_str(self): class TestCombinedIcohp(TestCase): - def setUp(self): + def setup_method(self): # without spin polarization: are_coops = are_cobis = is_spin_polarized = False list_atom2 = ["K2", "K2", "K2", "K2", "K2", "K2"] @@ -798,7 +798,7 @@ def test_extremum_icohpvalue(self): class TestCompleteCohp(PymatgenTest): - def setUp(self): + def setup_method(self): filepath = f"{TEST_DIR}/complete_cohp_lobster.json" with open(filepath) as file: self.cohp_lobster_dict = CompleteCohp.from_dict(json.load(file)) @@ -1263,7 +1263,7 @@ def test_orbital_resolved_cohp_summed_spin_channels(self): class TestMethod(TestCase): - def setUp(self): + def setup_method(self): filepath = f"{TEST_DIR}/COHPCAR.lobster.gz" structure = f"{TEST_DIR}/POSCAR" self.cohp_lobster = CompleteCohp.from_file("lobster", filename=filepath, structure_file=structure) diff --git a/tests/electronic_structure/test_dos.py b/tests/electronic_structure/test_dos.py index a7c8dec41b1..9a10cc1ed74 100644 --- a/tests/electronic_structure/test_dos.py +++ b/tests/electronic_structure/test_dos.py @@ -20,7 +20,7 @@ class TestDos(TestCase): - def setUp(self): + def setup_method(self): with open(f"{TEST_DIR}/complete_dos.json") as file: self.dos = CompleteDos.from_dict(json.load(file)) @@ -58,7 +58,7 @@ def test_as_dict(self): class TestFermiDos(TestCase): - def setUp(self): + def setup_method(self): with open(f"{TEST_DIR}/complete_dos.json") as file: self.dos = CompleteDos.from_dict(json.load(file)) self.dos = FermiDos(self.dos) @@ -105,7 +105,7 @@ def test_as_dict(self): class TestCompleteDos(TestCase): - def setUp(self): + def setup_method(self): with open(f"{TEST_DIR}/complete_dos.json") as file: self.dos = CompleteDos.from_dict(json.load(file)) with zopen(f"{TEST_DIR}/pdag3_complete_dos.json.gz") as file: @@ -324,7 +324,7 @@ def test_dos_fp_exceptions(self): class TestDOS(PymatgenTest): - def setUp(self): + def setup_method(self): with open(f"{TEST_DIR}/complete_dos.json") as file: dct = json.load(file) ys = list(zip(dct["densities"]["1"], dct["densities"]["-1"], strict=True)) @@ -359,7 +359,7 @@ def test_spin_polarization(self): class TestLobsterCompleteDos(TestCase): - def setUp(self): + def setup_method(self): with open(f"{TEST_DIR}/LobsterCompleteDos_spin.json") as file: data_spin = json.load(file) self.LobsterCompleteDOS_spin = LobsterCompleteDos.from_dict(data_spin) diff --git a/tests/electronic_structure/test_plotter.py b/tests/electronic_structure/test_plotter.py index 59763e9ea59..8dc211a0d40 100644 --- a/tests/electronic_structure/test_plotter.py +++ b/tests/electronic_structure/test_plotter.py @@ -38,7 +38,7 @@ class TestDosPlotter(PymatgenTest): - def setUp(self): + def setup_method(self): with open(f"{BAND_TEST_DIR}/../dos/complete_dos.json") as file: self.dos = CompleteDos.from_dict(json.load(file)) self.plotter = DosPlotter(sigma=0.2, stack=True) @@ -92,7 +92,7 @@ def get_plot_attributes(ax: plt.Axes): class TestBSPlotter(PymatgenTest): - def setUp(self): + def setup_method(self): with open(f"{BAND_TEST_DIR}/CaO_2605_bandstructure.json") as file: dct = json.loads(file.read()) self.bs = BandStructureSymmLine.from_dict(dct) @@ -185,7 +185,7 @@ def test_get_plot(self): class TestBSPlotterProjected(TestCase): - def setUp(self): + def setup_method(self): with open(f"{BAND_TEST_DIR}/Cu2O_361_bandstructure.json") as file: self.bs_Cu2O = BandStructureSymmLine.from_dict(json.load(file)) self.plotter_Cu2O = BSPlotterProjected(self.bs_Cu2O) @@ -258,7 +258,7 @@ def test_methods(self): class TestPlotBZ(TestCase): - def setUp(self): + def setup_method(self): self.rec_latt = Structure.from_file(f"{TEST_FILES_DIR}/io/cssr/Si.cssr").lattice.reciprocal_lattice self.kpath = [[[0.0, 0.0, 0.0], [0.5, 0.0, 0.5], [0.5, 0.25, 0.75], [0.375, 0.375, 0.75]]] self.labels = { @@ -304,7 +304,7 @@ def test_fold_point(self): @pytest.mark.skip("TODO: need someone to fix this") @pytest.mark.skipif(not which("x_trans"), reason="No x_trans executable found") class TestBoltztrapPlotter(TestCase): - def setUp(self): + def setup_method(self): bz = BoltztrapAnalyzer.from_files(f"{TEST_FILES_DIR}/boltztrap/transp/") self.plotter = BoltztrapPlotter(bz) @@ -445,7 +445,7 @@ def test_plot_zt_temp(self): class TestCohpPlotter(PymatgenTest): - def setUp(self): + def setup_method(self): path = f"{TEST_FILES_DIR}/electronic_structure/cohp/complete_cohp_lobster.json" with open(path) as file: self.cohp = CompleteCohp.from_dict(json.load(file)) diff --git a/tests/entries/test_compatibility.py b/tests/entries/test_compatibility.py index 2aaa4cb02ce..45d031e6caa 100644 --- a/tests/entries/test_compatibility.py +++ b/tests/entries/test_compatibility.py @@ -46,7 +46,7 @@ class TestCorrectionSpecificity(TestCase): """Make sure corrections are only applied to GGA or GGA+U entries.""" - def setUp(self): + def setup_method(self): self.entry1 = ComputedEntry( "Fe2O3", -1, @@ -205,7 +205,7 @@ def test_overlapping_adjustments(): @pytest.mark.filterwarnings("ignore:MaterialsProjectCompatibility is deprecated") class TestMaterialsProjectCompatibility(TestCase): - def setUp(self): + def setup_method(self): self.entry1 = ComputedEntry( "Fe2O3", -1, @@ -622,7 +622,7 @@ def test_msonable(self): class TestMaterialsProjectCompatibility2020(TestCase): - def setUp(self): + def setup_method(self): self.entry1 = ComputedEntry( "Fe2O3", -1, @@ -1316,7 +1316,7 @@ def test_many_anions(self): class TestMITCompatibility(TestCase): - def setUp(self): + def setup_method(self): self.compat = MITCompatibility(check_potcar_hash=True) self.gga_compat = MITCompatibility("GGA", check_potcar_hash=True) self.entry_O = ComputedEntry( @@ -1656,7 +1656,7 @@ def test_msonable(self): class TestOxideTypeCorrection(TestCase): - def setUp(self): + def setup_method(self): self.compat = MITCompatibility(check_potcar_hash=True) def test_no_struct_compat(self): @@ -1827,7 +1827,7 @@ def test_process_entry_oxide(self): class TestSulfideTypeCorrection2020(TestCase): - def setUp(self): + def setup_method(self): self.compat = MaterialsProject2020Compatibility(check_potcar_hash=False) def test_struct_no_struct(self): @@ -1987,7 +1987,7 @@ def test_struct_no_struct(self): class TestOxideTypeCorrectionNoPeroxideCorr(TestCase): - def setUp(self): + def setup_method(self): self.compat = MITCompatibility(correct_peroxide=False) def test_oxide_energy_corr(self): @@ -2255,7 +2255,7 @@ def test_parallel_process_entries(self): class TestAqueousCorrection(TestCase): - def setUp(self): + def setup_method(self): fp = f"{PMG_ENTRIES_DIR}/MITCompatibility.yaml" self.corr = AqueousCorrection(fp) @@ -2282,7 +2282,7 @@ def test_compound_energy(self): class TestMITAqueousCompatibility(TestCase): - def setUp(self): + def setup_method(self): self.compat = MITCompatibility(check_potcar_hash=True) self.aqcompat = MITAqueousCompatibility(check_potcar_hash=True) fp = f"{PMG_ENTRIES_DIR}/MITCompatibility.yaml" @@ -2393,7 +2393,7 @@ def test_dont_error_on_weird_elements(self): class TestCorrectionErrors2020Compatibility(TestCase): - def setUp(self): + def setup_method(self): self.compat = MaterialsProject2020Compatibility() params = { diff --git a/tests/entries/test_computed_entries.py b/tests/entries/test_computed_entries.py index 9cf63caca6f..63ce5c21d8f 100644 --- a/tests/entries/test_computed_entries.py +++ b/tests/entries/test_computed_entries.py @@ -96,7 +96,7 @@ def test_temp_energy_adjustment(): class TestComputedEntry(TestCase): - def setUp(self): + def setup_method(self): self.entry = ComputedEntry( vasp_run.final_structure.composition, vasp_run.final_energy, @@ -257,7 +257,7 @@ def test_from_dict_null_fields(self): class TestComputedStructureEntry(TestCase): - def setUp(self): + def setup_method(self): self.entry = ComputedStructureEntry(vasp_run.final_structure, vasp_run.final_energy, parameters=vasp_run.incar) def test_energy(self): @@ -454,7 +454,7 @@ def test_eq(self): class TestGibbsComputedStructureEntry(TestCase): - def setUp(self): + def setup_method(self): self.temps = [300, 600, 900, 1200, 1500, 1800] self.struct = vasp_run.final_structure self.num_atoms = self.struct.composition.num_atoms diff --git a/tests/entries/test_correction_calculator.py b/tests/entries/test_correction_calculator.py index 209f781be41..66718efe212 100644 --- a/tests/entries/test_correction_calculator.py +++ b/tests/entries/test_correction_calculator.py @@ -11,7 +11,7 @@ class TestCorrectionCalculator(TestCase): - def setUp(self): + def setup_method(self): self.exclude_polyanions = [ "SO4", "CO3", diff --git a/tests/entries/test_entry_tools.py b/tests/entries/test_entry_tools.py index 73d2d721d7b..a3c559239ed 100644 --- a/tests/entries/test_entry_tools.py +++ b/tests/entries/test_entry_tools.py @@ -50,7 +50,7 @@ def test_group_entries_by_composition(self): class TestEntrySet(PymatgenTest): - def setUp(self): + def setup_method(self): entries = loadfn(f"{TEST_DIR}/Li-Fe-P-O_entries.json") self.entry_set = EntrySet(entries) diff --git a/tests/entries/test_exp_entries.py b/tests/entries/test_exp_entries.py index b73be4ad8a4..b9752eae71f 100644 --- a/tests/entries/test_exp_entries.py +++ b/tests/entries/test_exp_entries.py @@ -11,7 +11,7 @@ class TestExpEntry(TestCase): - def setUp(self): + def setup_method(self): with open(f"{TEST_FILES_DIR}/entries/Fe2O3_exp.json") as file: thermo_data = json.load(file, cls=MontyDecoder) self.entry = ExpEntry("Fe2O3", thermo_data) diff --git a/tests/ext/test_matproj.py b/tests/ext/test_matproj.py index 18558a41525..7f4093d8d84 100644 --- a/tests/ext/test_matproj.py +++ b/tests/ext/test_matproj.py @@ -49,7 +49,7 @@ reason="Legacy PMG_MAPI_KEY environment variable not set.", ) class TestMPResterOld(PymatgenTest): - def setUp(self): + def setup_method(self): self.rester = _MPResterLegacy() def test_get_all_materials_ids_doc(self): @@ -529,7 +529,7 @@ def test_api_key_is_none(self): reason="PMG_MAPI_KEY environment variable not set.", ) class TestMPResterNewBasic(PymatgenTest): - def setUp(self): + def setup_method(self): self.rester = _MPResterBasic() def test_get_summary(self): diff --git a/tests/io/abinit/test_inputs.py b/tests/io/abinit/test_inputs.py index 762ea2acad8..4bc0229b0f3 100644 --- a/tests/io/abinit/test_inputs.py +++ b/tests/io/abinit/test_inputs.py @@ -261,7 +261,7 @@ def test_shiftmode(self): class TestFactory(PymatgenTest): - def setUp(self): + def setup_method(self): # Si ebands self.si_structure = Structure.from_file(abiref_file("si.cif")) self.si_pseudo = abiref_file("14si.pspnc") diff --git a/tests/io/abinit/test_netcdf.py b/tests/io/abinit/test_netcdf.py index b4b2ffa68c1..16c0babe320 100644 --- a/tests/io/abinit/test_netcdf.py +++ b/tests/io/abinit/test_netcdf.py @@ -22,7 +22,7 @@ class TestEtsfReader(PymatgenTest): - def setUp(self): + def setup_method(self): formulas = ["Si2"] self.GSR_paths = dct = {} for formula in formulas: diff --git a/tests/io/abinit/test_pseudos.py b/tests/io/abinit/test_pseudos.py index 8cd9bace814..518036ce6ed 100644 --- a/tests/io/abinit/test_pseudos.py +++ b/tests/io/abinit/test_pseudos.py @@ -15,7 +15,7 @@ class TestPseudo(PymatgenTest): - def setUp(self): + def setup_method(self): nc_pseudo_fnames = defaultdict(list) nc_pseudo_fnames["Si"] = [f"{TEST_DIR}/{file}" for file in ("14si.pspnc", "14si.4.hgh", "14-Si.LDA.fhi")] diff --git a/tests/io/cp2k/test_inputs.py b/tests/io/cp2k/test_inputs.py index ec0b772c617..d55100773fe 100644 --- a/tests/io/cp2k/test_inputs.py +++ b/tests/io/cp2k/test_inputs.py @@ -170,7 +170,7 @@ class TestCp2kInput(PymatgenTest): &END """ - def setUp(self): + def setup_method(self): self.ci = Cp2kInput.from_file(f"{TEST_DIR}/cp2k.inp") def test_basic_sections(self): diff --git a/tests/io/cp2k/test_outputs.py b/tests/io/cp2k/test_outputs.py index 84c3fab0e18..19762d1bfb2 100644 --- a/tests/io/cp2k/test_outputs.py +++ b/tests/io/cp2k/test_outputs.py @@ -13,7 +13,7 @@ class TestCp2kOutput(TestCase): - def setUp(self): + def setup_method(self): self.out = Cp2kOutput(f"{TEST_DIR}/cp2k.out", auto_load=True) def test_files(self): diff --git a/tests/io/feff/test_inputs.py b/tests/io/feff/test_inputs.py index 0128bb60fed..564c2e114a1 100644 --- a/tests/io/feff/test_inputs.py +++ b/tests/io/feff/test_inputs.py @@ -246,7 +246,7 @@ def test_as_dict_and_from_dict(self): class TestPaths(TestCase): - def setUp(self): + def setup_method(self): feo = Structure.from_dict( { "lattice": { diff --git a/tests/io/lobster/test_inputs.py b/tests/io/lobster/test_inputs.py index 59960d5970f..9e7dbe2b97e 100644 --- a/tests/io/lobster/test_inputs.py +++ b/tests/io/lobster/test_inputs.py @@ -20,7 +20,7 @@ class TestLobsterin(PymatgenTest): - def setUp(self): + def setup_method(self): self.Lobsterin = Lobsterin.from_file(f"{TEST_DIR}/lobsterin.1") self.Lobsterin2 = Lobsterin.from_file(f"{TEST_DIR}/lobsterin.2") self.Lobsterin3 = Lobsterin.from_file(f"{TEST_DIR}/lobsterin.3") diff --git a/tests/io/lobster/test_lobsterenv.py b/tests/io/lobster/test_lobsterenv.py index 4f9cc9959b8..52505d4670e 100644 --- a/tests/io/lobster/test_lobsterenv.py +++ b/tests/io/lobster/test_lobsterenv.py @@ -25,7 +25,7 @@ class TestLobsterNeighbors(TestCase): - def setUp(self): + def setup_method(self): # test additional conditions first # only consider cation anion bonds diff --git a/tests/io/lobster/test_outputs.py b/tests/io/lobster/test_outputs.py index 4dac8c4a01b..91a1a20bd49 100644 --- a/tests/io/lobster/test_outputs.py +++ b/tests/io/lobster/test_outputs.py @@ -43,7 +43,7 @@ class TestBwdf(PymatgenTest): - def setUp(self): + def setup_method(self): self.bwdf_coop = Bwdf(filename=f"{TEST_DIR}/BWDF.lobster.AlN.gz") self.bwdf_cohp = Bwdf(filename=f"{TEST_DIR}/BWDFCOHP.lobster.NaCl.gz") @@ -58,7 +58,7 @@ def test_attributes(self): class TestCohpcar(PymatgenTest): - def setUp(self): + def setup_method(self): self.cohp_bise = Cohpcar(filename=f"{TEST_DIR}/COHPCAR.lobster.BiSe.gz") self.coop_bise = Cohpcar( filename=f"{TEST_DIR}/COOPCAR.lobster.BiSe.gz", @@ -399,7 +399,7 @@ def test_orbital_resolved_cohp(self): class TestDoscar(TestCase): - def setUp(self): + def setup_method(self): # first for spin polarized version doscar = f"{VASP_OUT_DIR}/DOSCAR.lobster.spin" poscar = f"{VASP_IN_DIR}/POSCAR.lobster.spin_DOS" @@ -638,7 +638,7 @@ def test_is_spin_polarized(self): class TestCharge(PymatgenTest): - def setUp(self): + def setup_method(self): self.charge2 = Charge(filename=f"{TEST_DIR}/CHARGE.lobster.MnO") # gzipped file self.charge = Charge(filename=f"{TEST_DIR}/CHARGE.lobster.MnO2.gz") @@ -717,7 +717,7 @@ def test_msonable(self): class TestLobsterout(PymatgenTest): - def setUp(self): + def setup_method(self): self.lobsterout_normal = Lobsterout(filename=f"{TEST_DIR}/lobsterout.normal") # make sure .gz files are also read correctly self.lobsterout_normal = Lobsterout(filename=f"{TEST_DIR}/lobsterout.normal2.gz") @@ -1246,7 +1246,7 @@ def test_msonable(self): class TestFatband(PymatgenTest): - def setUp(self): + def setup_method(self): self.structure = Vasprun( filename=f"{TEST_DIR}/Fatband_SiO2/Test_p_x/vasprun.xml", ionic_step_skip=None, @@ -1481,7 +1481,7 @@ def test_get_bandstructure(self): class TestBandoverlaps(TestCase): - def setUp(self): + def setup_method(self): # test spin-polarized calc and non spin-polarized calc self.band_overlaps1 = Bandoverlaps(f"{TEST_DIR}/bandOverlaps.lobster.1") @@ -1714,7 +1714,7 @@ def test_keys(self): class TestGrosspop(TestCase): - def setUp(self): + def setup_method(self): self.grosspop1 = Grosspop(f"{TEST_DIR}/GROSSPOP.lobster") self.grosspop_511_sp = Grosspop(f"{TEST_DIR}/GROSSPOP_511_sp.lobster.AlN.gz") self.grosspop_511_nsp = Grosspop(f"{TEST_DIR}/GROSSPOP_511_nsp.lobster.NaCl.gz") @@ -1864,7 +1864,7 @@ def test_msonable(self): class TestIcohplist(TestCase): - def setUp(self): + def setup_method(self): self.icohp_bise = Icohplist(filename=f"{TEST_DIR}/ICOHPLIST.lobster.BiSe") self.icoop_bise = Icohplist( filename=f"{TEST_DIR}/ICOOPLIST.lobster.BiSe", @@ -2169,7 +2169,7 @@ def test_msonable(self): class TestNciCobiList(TestCase): - def setUp(self): + def setup_method(self): self.ncicobi = NciCobiList(filename=f"{TEST_DIR}/NcICOBILIST.lobster") self.ncicobi_gz = NciCobiList(filename=f"{TEST_DIR}/NcICOBILIST.lobster.gz") self.ncicobi_no_spin = NciCobiList(filename=f"{TEST_DIR}/NcICOBILIST.lobster.nospin") @@ -2273,7 +2273,7 @@ def test_write_file(self): class TestSitePotentials(PymatgenTest): - def setUp(self) -> None: + def setup_method(self) -> None: self.sitepotential = SitePotential(filename=f"{TEST_DIR}/SitePotentials.lobster.perovskite") def test_attributes(self): @@ -2324,7 +2324,7 @@ def test_msonable(self): class TestMadelungEnergies(PymatgenTest): - def setUp(self) -> None: + def setup_method(self) -> None: self.madelungenergies = MadelungEnergies(filename=f"{TEST_DIR}/MadelungEnergies.lobster.perovskite") def test_attributes(self): @@ -2341,7 +2341,7 @@ def test_msonable(self): class TestLobsterMatrices(PymatgenTest): - def setUp(self) -> None: + def setup_method(self) -> None: self.hamilton_matrices = LobsterMatrices( filename=f"{TEST_DIR}/Na_hamiltonMatrices.lobster.gz", e_fermi=-2.79650354 ) @@ -2491,7 +2491,7 @@ def test_raises(self): class TestPolarization(PymatgenTest): - def setUp(self) -> None: + def setup_method(self) -> None: self.polarization = Polarization(filename=f"{TEST_DIR}/POLARIZATION.lobster.AlN.gz") def test_attributes(self): diff --git a/tests/io/test_babel.py b/tests/io/test_babel.py index 6a130dd8914..32087bd3ac4 100644 --- a/tests/io/test_babel.py +++ b/tests/io/test_babel.py @@ -18,7 +18,7 @@ class TestBabelMolAdaptor(TestCase): - def setUp(self): + def setup_method(self): coords = [ [0.000000, 0.000000, 0.000000], [0.000000, 0.000000, 1.089000], diff --git a/tests/io/test_cif.py b/tests/io/test_cif.py index 690c67c302d..eecb2261e84 100644 --- a/tests/io/test_cif.py +++ b/tests/io/test_cif.py @@ -1000,7 +1000,7 @@ def test_cif_writer_site_properties(self): class TestMagCif(PymatgenTest): - def setUp(self): + def setup_method(self): self.mcif = CifParser(f"{MCIF_TEST_DIR}/magnetic.example.NiO.mcif") self.mcif_ncl = CifParser(f"{MCIF_TEST_DIR}/magnetic.ncl.example.GdB4.mcif") self.mcif_incommensurate = CifParser(f"{MCIF_TEST_DIR}/magnetic.incommensurate.example.Cr.mcif") diff --git a/tests/io/test_cssr.py b/tests/io/test_cssr.py index 467be18ae3e..951dab817e8 100644 --- a/tests/io/test_cssr.py +++ b/tests/io/test_cssr.py @@ -19,7 +19,7 @@ class TestCssr(TestCase): - def setUp(self): + def setup_method(self): filepath = f"{VASP_IN_DIR}/POSCAR" self.cssr = Cssr(Structure.from_file(filepath)) diff --git a/tests/io/test_fiesta.py b/tests/io/test_fiesta.py index bcc6904a076..d5bce31b5ba 100644 --- a/tests/io/test_fiesta.py +++ b/tests/io/test_fiesta.py @@ -10,7 +10,7 @@ class TestFiestaInput(TestCase): - def setUp(self): + def setup_method(self): coords = [ [0.000000, 0.000000, 0.000000], [0.000000, 0.000000, 1.089000], @@ -72,7 +72,7 @@ def test_str_and_from_str(self): class TestFiestaOutput(TestCase): - def setUp(self): + def setup_method(self): self.log_fiesta = FiestaOutput(f"{TEST_DIR}/log_fiesta") def test_props(self): diff --git a/tests/io/test_gaussian.py b/tests/io/test_gaussian.py index b44db9f2c32..9a5ec7ad0e1 100644 --- a/tests/io/test_gaussian.py +++ b/tests/io/test_gaussian.py @@ -14,7 +14,7 @@ class TestGaussianInput(TestCase): - def setUp(self): + def setup_method(self): coords = [ [0, 0, 0], [0, 0, 1.089], @@ -281,7 +281,7 @@ def test_no_molecule_func_bset_charge_mult(self): class TestGaussianOutput(TestCase): # TODO: Add unittest for PCM type output. - def setUp(self): + def setup_method(self): self.gau_out = GaussianOutput(f"{TEST_DIR}/methane.log") def test_resume(self): diff --git a/tests/io/test_lmto.py b/tests/io/test_lmto.py index 1ddc8c2abcf..d7798e17fa9 100644 --- a/tests/io/test_lmto.py +++ b/tests/io/test_lmto.py @@ -24,7 +24,7 @@ class TestCtrl(PymatgenTest): - def setUp(self): + def setup_method(self): os.chdir(TEST_DIR) self.ref_bise = LMTOCtrl.from_file(filename="CTRL.BiSe") self.ref_fe = LMTOCtrl.from_file() @@ -48,7 +48,7 @@ def test_read_write(self): class TestCopl(PymatgenTest): - def setUp(self): + def setup_method(self): os.chdir(TEST_DIR) self.copl_bise = LMTOCopl("COPL.BiSe") self.copl_bise_eV = LMTOCopl(filename="COPL.BiSe", to_eV=True) diff --git a/tests/io/test_nwchem.py b/tests/io/test_nwchem.py index 7304ec4a10e..beb3e40366a 100644 --- a/tests/io/test_nwchem.py +++ b/tests/io/test_nwchem.py @@ -23,7 +23,7 @@ class TestNwTask(TestCase): - def setUp(self): + def setup_method(self): self.task = NwTask( 0, 1, @@ -137,7 +137,7 @@ def test_esp_task(self): class TestNwInput(TestCase): - def setUp(self): + def setup_method(self): tasks = [ NwTask.dft_task(mol, operation="optimize", xc="b3lyp", basis_set="6-31++G*"), NwTask.dft_task(mol, operation="freq", xc="b3lyp", basis_set="6-31++G*"), diff --git a/tests/io/test_phonopy.py b/tests/io/test_phonopy.py index 802e43049e2..b9ff2ccaf9a 100644 --- a/tests/io/test_phonopy.py +++ b/tests/io/test_phonopy.py @@ -163,7 +163,7 @@ def test_get_displaced_structures(self): reason="See https://github.com/conda-forge/phonopy-feedstock/pull/158#issuecomment-2227506701", ) class TestPhonopyFromForceConstants(TestCase): - def setUp(self) -> None: + def setup_method(self) -> None: test_path = Path(TEST_DIR) structure_file = test_path / "POSCAR-NaCl" fc_file = test_path / "FORCE_CONSTANTS" diff --git a/tests/io/test_pwscf.py b/tests/io/test_pwscf.py index 6e39c8b4019..5954e02cfd4 100644 --- a/tests/io/test_pwscf.py +++ b/tests/io/test_pwscf.py @@ -543,7 +543,7 @@ def test_custom_decimal_precision_write_and_read_str(self): class TestPWOutput(PymatgenTest): - def setUp(self): + def setup_method(self): self.pw_out = PWOutput(f"{TEST_DIR}/Si.pwscf.out") def test_properties(self): diff --git a/tests/io/test_shengbte.py b/tests/io/test_shengbte.py index 303c9d094aa..2c733a10a9c 100644 --- a/tests/io/test_shengbte.py +++ b/tests/io/test_shengbte.py @@ -11,7 +11,7 @@ class TestShengBTE(PymatgenTest): - def setUp(self): + def setup_method(self): self.filename = f"{TEST_DIR}/CONTROL-CSLD_Si" self.test_dict = { "nelements": 1, diff --git a/tests/io/test_wannier90.py b/tests/io/test_wannier90.py index 93ac0e256e7..b72e00acc27 100644 --- a/tests/io/test_wannier90.py +++ b/tests/io/test_wannier90.py @@ -14,7 +14,7 @@ class TestUnk(PymatgenTest): - def setUp(self): + def setup_method(self): rng = np.random.default_rng() self.data_std = rng.random((10, 5, 5, 5)) self.unk_std = Unk(1, self.data_std) diff --git a/tests/io/test_xcrysden.py b/tests/io/test_xcrysden.py index 3a13a2cf7b5..d742f9ed4b4 100644 --- a/tests/io/test_xcrysden.py +++ b/tests/io/test_xcrysden.py @@ -8,7 +8,7 @@ class TestXSF(PymatgenTest): - def setUp(self): + def setup_method(self): self.coords = [[0, 0, 0], [0.75, 0.5, 0.75]] self.lattice = [ [3.8401979337, 0.00, 0.00], diff --git a/tests/io/test_xr.py b/tests/io/test_xr.py index 05cfa8bfc8e..8321c2340af 100644 --- a/tests/io/test_xr.py +++ b/tests/io/test_xr.py @@ -15,7 +15,7 @@ class TestXr(TestCase): - def setUp(self): + def setup_method(self): struct = Structure.from_file(f"{VASP_IN_DIR}/POSCAR") self.xr = Xr(struct) diff --git a/tests/io/test_xyz.py b/tests/io/test_xyz.py index ad57feca5af..e0ad2ea6f1a 100644 --- a/tests/io/test_xyz.py +++ b/tests/io/test_xyz.py @@ -13,7 +13,7 @@ class TestXYZ(TestCase): - def setUp(self): + def setup_method(self): coords = [ [0, 0, 0], [0, 0, 1.089000], diff --git a/tests/io/test_zeopp.py b/tests/io/test_zeopp.py index 28bc18aad8c..f049ffccc97 100644 --- a/tests/io/test_zeopp.py +++ b/tests/io/test_zeopp.py @@ -29,7 +29,7 @@ class TestZeoCssr(TestCase): - def setUp(self): + def setup_method(self): filepath = f"{VASP_IN_DIR}/POSCAR" self.zeo_cssr = ZeoCssr(Structure.from_file(filepath)) @@ -71,7 +71,7 @@ def test_from_file(self): class TestZeoCssrOxi(TestCase): - def setUp(self): + def setup_method(self): filepath = f"{VASP_IN_DIR}/POSCAR" structure = BVAnalyzer().get_oxi_state_decorated_structure(Structure.from_file(filepath)) self.zeo_cssr = ZeoCssr(structure) @@ -114,7 +114,7 @@ def test_from_file(self): class TestZeoVoronoiXYZ(TestCase): - def setUp(self): + def setup_method(self): coords = [ [0.000000, 0.000000, 0.000000], [0.000000, 0.000000, 1.089000], @@ -144,7 +144,7 @@ def test_from_file(self): class TestGetVoronoiNodes(TestCase): - def setUp(self): + def setup_method(self): filepath = f"{VASP_IN_DIR}/POSCAR" self.structure = Structure.from_file(filepath) bv = BVAnalyzer() @@ -168,7 +168,7 @@ def test_get_voronoi_nodes(self): @pytest.mark.skip("TODO: file free_sph.cif not present") class TestGetFreeSphereParams(TestCase): - def setUp(self): + def setup_method(self): filepath = f"{TEST_FILES_DIR}/cif/free_sph.cif" self.structure = Structure.from_file(filepath) self.rad_dict = { @@ -189,7 +189,7 @@ def test_get_free_sphere_params(self): class TestGetHighAccuracyVoronoiNodes(TestCase): - def setUp(self): + def setup_method(self): filepath = f"{VASP_IN_DIR}/POSCAR" self.structure = Structure.from_file(filepath) bv = BVAnalyzer() @@ -208,7 +208,7 @@ def test_get_voronoi_nodes(self): class TestGetVoronoiNodesMultiOxi(TestCase): - def setUp(self): + def setup_method(self): filepath = f"{VASP_IN_DIR}/POSCAR" self.structure = Structure.from_file(filepath) bv = BVAnalyzer() diff --git a/tests/io/vasp/test_inputs.py b/tests/io/vasp/test_inputs.py index 1616ff4e5e7..decccb7a344 100644 --- a/tests/io/vasp/test_inputs.py +++ b/tests/io/vasp/test_inputs.py @@ -650,7 +650,7 @@ def test_vasp_6_4_2_format(self): class TestIncar(PymatgenTest): - def setUp(self): + def setup_method(self): self.incar = Incar.from_file(f"{VASP_IN_DIR}/INCAR") def test_init(self): @@ -1298,7 +1298,7 @@ def test_automatic_monkhorst_vs_gamma_style_selection(self): "ignore:POTCAR data with symbol .* is not known to pymatgen:pymatgen.io.vasp.inputs.UnknownPotcarWarning" ) class TestPotcarSingle(TestCase): - def setUp(self): + def setup_method(self): self.psingle_Mn_pv = PotcarSingle.from_file(f"{FAKE_POTCAR_DIR}/POT_GGA_PAW_PBE/POTCAR.Mn_pv.gz") self.psingle_Fe = PotcarSingle.from_file(f"{FAKE_POTCAR_DIR}/POT_GGA_PAW_PBE/POTCAR.Fe.gz") self.psingle_Fe_54 = PotcarSingle.from_file(f"{FAKE_POTCAR_DIR}/POT_GGA_PAW_PBE_54/POTCAR.Fe.gz") @@ -1538,7 +1538,7 @@ def test_copy(self): "ignore:POTCAR data with symbol .* is not known to pymatgen:pymatgen.io.vasp.inputs.UnknownPotcarWarning" ) class TestPotcar(PymatgenTest): - def setUp(self): + def setup_method(self): SETTINGS.setdefault("PMG_VASP_PSP_DIR", str(TEST_FILES_DIR)) self.filepath = f"{FAKE_POTCAR_DIR}/POTCAR.gz" self.potcar = Potcar.from_file(self.filepath) @@ -1617,7 +1617,7 @@ def test_pickle(self): "ignore:POTCAR data with symbol .* is not known to pymatgen:pymatgen.io.vasp.inputs.UnknownPotcarWarning" ) class TestVaspInput(PymatgenTest): - def setUp(self): + def setup_method(self): filepath = f"{VASP_IN_DIR}/INCAR" incar = Incar.from_file(filepath) filepath = f"{VASP_IN_DIR}/POSCAR" diff --git a/tests/io/vasp/test_outputs.py b/tests/io/vasp/test_outputs.py index e02b9ac027a..99d05597987 100644 --- a/tests/io/vasp/test_outputs.py +++ b/tests/io/vasp/test_outputs.py @@ -1818,7 +1818,7 @@ def test_init(self): class TestWavecar(PymatgenTest): - def setUp(self): + def setup_method(self): latt_mat = np.array(np.eye(3) * 10, dtype=float) # lattice vectors self.vol = np.dot(latt_mat[0, :], np.cross(latt_mat[1, :], latt_mat[2, :])) # unit cell volume # reciprocal lattice vectors @@ -2136,7 +2136,7 @@ def test_eigenvalue_band_properties_separate_spins(self): class TestWaveder(PymatgenTest): - def setUp(self): + def setup_method(self): wder = Waveder.from_binary(f"{VASP_OUT_DIR}/WAVEDER", "float64") assert wder.nbands == 36 assert wder.nkpoints == 56 @@ -2169,7 +2169,7 @@ def _check(wder): class TestWSWQ(PymatgenTest): - def setUp(self): + def setup_method(self): self.wswq = WSWQ.from_file(f"{VASP_OUT_DIR}/WSWQ.gz") def test_consistency(self): diff --git a/tests/io/vasp/test_sets.py b/tests/io/vasp/test_sets.py index 6b4f9ceebdb..836478a6e93 100644 --- a/tests/io/vasp/test_sets.py +++ b/tests/io/vasp/test_sets.py @@ -719,7 +719,7 @@ def test_get_nedos(self): class TestMPStaticSet(PymatgenTest): - def setUp(self): + def setup_method(self): self.set = MPStaticSet def test_init(self): @@ -871,7 +871,7 @@ def test_grid_size_from_struct(self): class TestMatPESStaticSet(PymatgenTest): - def setUp(self): + def setup_method(self): self.struct = Structure.from_file(f"{VASP_IN_DIR}/POSCAR") self.prev_incar = Incar.from_file(f"{VASP_IN_DIR}/INCAR") @@ -988,7 +988,7 @@ def test_from_prev_calc(self): class TestMPNonSCFSet(PymatgenTest): - def setUp(self): + def setup_method(self): self.set = MPNonSCFSet @skip_if_no_psp_dir @@ -1189,7 +1189,7 @@ def test_ln_magmom(self): class TestMITMDSet(PymatgenTest): - def setUp(self): + def setup_method(self): self.set = MITMDSet filepath = f"{VASP_IN_DIR}/POSCAR" self.struct = Structure.from_file(filepath) @@ -1231,7 +1231,7 @@ def test_user_heat_speed(self): @skip_if_no_psp_dir class TestMVLNPTMDSet(PymatgenTest): - def setUp(self): + def setup_method(self): file_path = f"{VASP_IN_DIR}/POSCAR" self.struct = Structure.from_file(file_path) self.mvl_npt_set = MVLNPTMDSet(self.struct, start_temp=0, end_temp=300, nsteps=1000) @@ -1267,7 +1267,7 @@ def test_as_from_dict(self): class TestMPMDSet(PymatgenTest): - def setUp(self): + def setup_method(self): filepath = f"{VASP_IN_DIR}/POSCAR" self.struct = Structure.from_file(filepath) self.struct_with_H = Structure.from_file(f"{VASP_IN_DIR}/POSCAR_hcp") @@ -1309,7 +1309,7 @@ def test_as_from_dict(self): class TestMITNEBSet(PymatgenTest): - def setUp(self): + def setup_method(self): c1 = [[0.5] * 3, [0.9] * 3] c2 = [[0.5] * 3, [0.9, 0.1, 0.1]] s1 = Structure(Lattice.cubic(5), ["Si", "Si"], c1) @@ -1357,7 +1357,7 @@ def test_write_input(self): class TestMPSOCSet(PymatgenTest): - def setUp(self): + def setup_method(self): self.set = MPSOCSet def test_from_prev_calc(self): @@ -1416,7 +1416,7 @@ def test_incar(self): @skip_if_no_psp_dir class TestMVLSlabSet(PymatgenTest): - def setUp(self): + def setup_method(self): self.set = MVLSlabSet struct = self.get_structure("Li2O") gen = SlabGenerator(struct, (1, 0, 0), 10, 10) @@ -1499,7 +1499,7 @@ def test_incar(self): @skip_if_no_psp_dir class TestMVLGWSet(PymatgenTest): - def setUp(self): + def setup_method(self): self.set = MVLGWSet self.struct = PymatgenTest.get_structure("Li2O") @@ -1577,7 +1577,7 @@ def test_bse(self): class TestMPHSERelaxSet(PymatgenTest): - def setUp(self): + def setup_method(self): self.structure = dummy_structure self.set = MPHSERelaxSet @@ -1644,7 +1644,7 @@ def test_override_from_prev_calc(self): class TestMPHSEBS(PymatgenTest): - def setUp(self): + def setup_method(self): self.set = MPHSEBSSet def test_init(self): @@ -1700,7 +1700,7 @@ def test_override_from_prev_calc(self): class TestMVLScanRelaxSet(PymatgenTest): - def setUp(self): + def setup_method(self): self.set = MVLScanRelaxSet file_path = f"{VASP_IN_DIR}/POSCAR" self.struct = Structure.from_file(file_path) @@ -1778,7 +1778,7 @@ def test_as_from_dict(self): class TestMPScanRelaxSet(PymatgenTest): - def setUp(self): + def setup_method(self): file_path = f"{VASP_IN_DIR}/POSCAR" self.struct = Structure.from_file(file_path) self.mp_scan_set = MPScanRelaxSet( @@ -1899,7 +1899,7 @@ def test_write_input(self): class TestMPScanStaticSet(PymatgenTest): - def setUp(self): + def setup_method(self): self.set = MPScanStaticSet self.prev_run = f"{TEST_DIR}/fixtures/scan_relaxation" # test inheriting from a previous SCAN relaxation @@ -2001,7 +2001,7 @@ def test_batch_write_input(self): @skip_if_no_psp_dir class TestMVLGBSet(PymatgenTest): - def setUp(self): + def setup_method(self): filepath = f"{TEST_FILES_DIR}/cif/Li.cif" self.struct = Structure.from_file(filepath) @@ -2027,7 +2027,7 @@ def test_kpoints(self): class TestMVLRelax52Set(PymatgenTest): - def setUp(self): + def setup_method(self): self.set = MVLRelax52Set file_path = f"{VASP_IN_DIR}/POSCAR" self.struct = Structure.from_file(file_path) @@ -2065,7 +2065,7 @@ def test_as_from_dict(self): class TestLobsterSet(PymatgenTest): - def setUp(self): + def setup_method(self): self.set = LobsterSet file_path = f"{VASP_IN_DIR}/POSCAR" file_path2 = f"{VASP_IN_DIR}/POSCAR.lobster.spin_DOS" @@ -2164,7 +2164,7 @@ def test_as_from_dict(self): @skip_if_no_psp_dir class TestMPAbsorptionSet(PymatgenTest): - def setUp(self): + def setup_method(self): file_path = f"{TEST_DIR}/fixtures/absorption/static/POSCAR" self.structure = Structure.from_file(file_path) self.set = MPAbsorptionSet diff --git a/tests/optimization/test_neighbors.py b/tests/optimization/test_neighbors.py index 3542acd20ff..cd022d34dde 100644 --- a/tests/optimization/test_neighbors.py +++ b/tests/optimization/test_neighbors.py @@ -8,7 +8,7 @@ class TestNeighbors(PymatgenTest): - def setUp(self): + def setup_method(self): self.lattice = Lattice.cubic(10.0) self.cubic = self.lattice self.tetragonal = Lattice.tetragonal(10, 20) diff --git a/tests/phonon/test_bandstructure.py b/tests/phonon/test_bandstructure.py index 7f449792544..ac6727628cf 100644 --- a/tests/phonon/test_bandstructure.py +++ b/tests/phonon/test_bandstructure.py @@ -14,7 +14,7 @@ class TestPhononBandStructureSymmLine(PymatgenTest): - def setUp(self): + def setup_method(self): with open(f"{TEST_DIR}/NaCl_phonon_bandstructure.json") as file: dct = json.load(file) self.bs = PhononBandStructureSymmLine.from_dict(dct) diff --git a/tests/phonon/test_dos.py b/tests/phonon/test_dos.py index e586604d81e..a1c14cd00b2 100644 --- a/tests/phonon/test_dos.py +++ b/tests/phonon/test_dos.py @@ -15,7 +15,7 @@ class TestPhononDos(PymatgenTest): - def setUp(self): + def setup_method(self): with open(f"{TEST_DIR}/NaCl_ph_dos.json") as file: self.dos = PhononDos.from_dict(json.load(file)) with open(f"{TEST_DIR}/NaCl_complete_ph_dos.json") as file: @@ -183,7 +183,7 @@ def test_dos_fp_exceptions(self): class TestCompletePhononDos(PymatgenTest): - def setUp(self): + def setup_method(self): with open(f"{TEST_DIR}/NaCl_complete_ph_dos.json") as file: self.cdos = CompletePhononDos.from_dict(json.load(file)) diff --git a/tests/phonon/test_gruneisen.py b/tests/phonon/test_gruneisen.py index 748fd68c8c2..fac97aaebab 100644 --- a/tests/phonon/test_gruneisen.py +++ b/tests/phonon/test_gruneisen.py @@ -22,7 +22,7 @@ class TestGruneisenPhononBandStructureSymmLine(PymatgenTest): - def setUp(self) -> None: + def setup_method(self) -> None: self.bs_symm_line = get_gruneisen_ph_bs_symm_line( gruneisen_path=f"{TEST_DIR}/gruneisen_eq_plus_minus_InP.yaml", structure_path=f"{TEST_DIR}/eq/POSCAR_InP", @@ -77,7 +77,7 @@ def test_as_dict_from_dict(self): @pytest.mark.skipif(TotalDos is None, reason="Phonopy not present") class TestGruneisenParameter(PymatgenTest): - def setUp(self) -> None: + def setup_method(self) -> None: self.gruneisen_obj = get_gruneisenparameter( f"{TEST_DIR}/gruneisen_mesh_InP.yaml", structure_path=f"{TEST_DIR}/eq/POSCAR_InP", diff --git a/tests/phonon/test_ir_spectra.py b/tests/phonon/test_ir_spectra.py index 7a7eb40f4ce..07fa82e678b 100644 --- a/tests/phonon/test_ir_spectra.py +++ b/tests/phonon/test_ir_spectra.py @@ -6,7 +6,7 @@ class TestIRDielectricTensor(PymatgenTest): - def setUp(self): + def setup_method(self): self.ir_spectra = loadfn(f"{TEST_FILES_DIR}/phonon/dos/ir_spectra_mp-991652_DDB.json") def test_basic(self): diff --git a/tests/phonon/test_plotter.py b/tests/phonon/test_plotter.py index 1afdd7c62bd..49e32b1c326 100644 --- a/tests/phonon/test_plotter.py +++ b/tests/phonon/test_plotter.py @@ -17,7 +17,7 @@ class TestPhononDosPlotter(TestCase): - def setUp(self): + def setup_method(self): with open(f"{TEST_DIR}/NaCl_complete_ph_dos.json") as file: self.dos = CompletePhononDos.from_dict(json.load(file)) self.plotter = PhononDosPlotter(sigma=0.2, stack=True) @@ -55,7 +55,7 @@ def test_plot(self): class TestPhononBSPlotter(TestCase): - def setUp(self): + def setup_method(self): with open(f"{TEST_FILES_DIR}/electronic_structure/bandstructure/NaCl_phonon_bandstructure.json") as file: dct = json.loads(file.read()) self.bs = PhononBandStructureSymmLine.from_dict(dct) @@ -114,7 +114,7 @@ def test_plot_compare(self): class TestThermoPlotter(TestCase): - def setUp(self): + def setup_method(self): with open(f"{TEST_DIR}/NaCl_complete_ph_dos.json") as file: self.dos = CompletePhononDos.from_dict(json.load(file)) self.plotter = ThermoPlotter(self.dos, self.dos.structure) diff --git a/tests/phonon/test_thermal_displacements.py b/tests/phonon/test_thermal_displacements.py index aeb26a4dffc..23afe16e670 100644 --- a/tests/phonon/test_thermal_displacements.py +++ b/tests/phonon/test_thermal_displacements.py @@ -14,7 +14,7 @@ class TestThermalDisplacement(PymatgenTest): """Test data from J. George's matlab code https://github.com/JaGeo/MolecularToolbox.""" - def setUp(self) -> None: + def setup_method(self) -> None: self.thermal = ThermalDisplacementMatrices( thermal_displacement_matrix_cart=[ [5.16e-03, 6.13e-03, 4.15e-03, -1.10e-04, -1.58e-03, -8.10e-04], diff --git a/tests/symmetry/test_analyzer.py b/tests/symmetry/test_analyzer.py index 7966c815ce9..a4faa165678 100644 --- a/tests/symmetry/test_analyzer.py +++ b/tests/symmetry/test_analyzer.py @@ -25,7 +25,7 @@ class TestSpacegroupAnalyzer(PymatgenTest): - def setUp(self): + def setup_method(self): self.structure = Structure.from_file(f"{VASP_IN_DIR}/POSCAR") self.sg = SpacegroupAnalyzer(self.structure, 0.001) self.disordered_structure = self.get_structure("Li10GeP2S12") @@ -445,7 +445,7 @@ def test_bad_structure(self): class TestSpacegroup(TestCase): - def setUp(self): + def setup_method(self): self.structure = Structure.from_file(f"{VASP_IN_DIR}/POSCAR") self.sg1 = SpacegroupAnalyzer(self.structure, 0.001).get_space_group_operations() diff --git a/tests/symmetry/test_maggroups.py b/tests/symmetry/test_maggroups.py index 72f184d553f..21475b7a4c9 100644 --- a/tests/symmetry/test_maggroups.py +++ b/tests/symmetry/test_maggroups.py @@ -18,7 +18,7 @@ class TestMagneticSpaceGroup(PymatgenTest): - def setUp(self): + def setup_method(self): self.msg_1 = MagneticSpaceGroup([70, 530]) self.msg_2 = MagneticSpaceGroup([62, 448]) self.msg_3 = MagneticSpaceGroup([20, 37]) diff --git a/tests/symmetry/test_settings.py b/tests/symmetry/test_settings.py index 79a6b56c138..be51dfbb1df 100644 --- a/tests/symmetry/test_settings.py +++ b/tests/symmetry/test_settings.py @@ -17,7 +17,7 @@ class TestJonesFaithfulTransformation(TestCase): - def setUp(self): + def setup_method(self): self.test_strings = [ "a,b,c;0,0,0", # identity "a-b,a+b,2c;0,0,1/2", diff --git a/tests/symmetry/test_site_symmetries.py b/tests/symmetry/test_site_symmetries.py index 1b33f3a11f0..24bb53b22e8 100644 --- a/tests/symmetry/test_site_symmetries.py +++ b/tests/symmetry/test_site_symmetries.py @@ -19,7 +19,7 @@ class TestSiteSymmetries(PymatgenTest): - def setUp(self): + def setup_method(self): with gzip.open(f"{TEST_DIR}/point_ops.json.gz", mode="rt") as file: self.point_ops = MontyDecoder().process_decoded(json.load(file)) diff --git a/tests/transformations/test_advanced_transformations.py b/tests/transformations/test_advanced_transformations.py index 2f73ace7cd3..1bba0acb289 100644 --- a/tests/transformations/test_advanced_transformations.py +++ b/tests/transformations/test_advanced_transformations.py @@ -277,7 +277,7 @@ def test_as_dict(self): @pytest.mark.skipif(not enumlib_present, reason="enum_lib not present.") class TestMagOrderingTransformation(PymatgenTest): - def setUp(self): + def setup_method(self): lattice = Lattice.cubic(4.17) species = ["Ni", "O"] coords = [[0, 0, 0], [0.5, 0.5, 0.5]] diff --git a/tests/transformations/test_site_transformations.py b/tests/transformations/test_site_transformations.py index 0e97aceabc0..b63057c5f80 100644 --- a/tests/transformations/test_site_transformations.py +++ b/tests/transformations/test_site_transformations.py @@ -25,7 +25,7 @@ class TestTranslateSitesTransformation(PymatgenTest): - def setUp(self): + def setup_method(self): coords = [ [0, 0, 0], [0.375, 0.375, 0.375], @@ -79,7 +79,7 @@ def test_as_from_dict(self): class TestReplaceSiteSpeciesTransformation(TestCase): - def setUp(self): + def setup_method(self): coords = [ [0, 0, 0], [0.375, 0.375, 0.375], @@ -111,7 +111,7 @@ def test_as_from_dict(self): class TestRemoveSitesTransformation(TestCase): - def setUp(self): + def setup_method(self): coords = [ [0, 0, 0], [0.375, 0.375, 0.375], @@ -143,7 +143,7 @@ def test_as_from_dict(self): class TestInsertSitesTransformation(TestCase): - def setUp(self): + def setup_method(self): coords = [ [0, 0, 0], [0.375, 0.375, 0.375], @@ -180,7 +180,7 @@ def test_as_from_dict(self): class TestPartialRemoveSitesTransformation(TestCase): - def setUp(self): + def setup_method(self): coords = [ [0, 0, 0], [0.375, 0.375, 0.375], @@ -280,7 +280,7 @@ def test_apply_transformation(self): class TestRadialSiteDistortionTransformation(PymatgenTest): - def setUp(self): + def setup_method(self): self.molecule = Molecule( species=["C", "H", "H", "H", "H", "H", "H", "H", "H", "H", "H", "H", "H"], coords=[ diff --git a/tests/transformations/test_standard_transformations.py b/tests/transformations/test_standard_transformations.py index 0074eece962..741081e052a 100644 --- a/tests/transformations/test_standard_transformations.py +++ b/tests/transformations/test_standard_transformations.py @@ -42,7 +42,7 @@ class TestRotationTransformations(TestCase): - def setUp(self): + def setup_method(self): coords = [[0, 0, 0], [0.75, 0.5, 0.75]] lattice = [ [3.8401979337, 0, 0], @@ -109,7 +109,7 @@ def test_fractional_substitution(self): class TestSupercellTransformation(TestCase): - def setUp(self): + def setup_method(self): coords = [[0, 0, 0], [0.75, 0.75, 0.75], [0.5, 0.5, 0.5], [0.25, 0.25, 0.25]] lattice = [ [3.8401979337, 0, 0], diff --git a/tests/util/test_coord.py b/tests/util/test_coord.py index c97914e6319..985d4100804 100644 --- a/tests/util/test_coord.py +++ b/tests/util/test_coord.py @@ -251,7 +251,7 @@ def test_get_angle(self): class TestSimplex(TestCase): - def setUp(self): + def setup_method(self): coords = [[0, 0, 0], [0, 1, 0], [0, 0, 1], [1, 0, 0]] self.simplex = coord.Simplex(coords) diff --git a/tests/util/test_provenance.py b/tests/util/test_provenance.py index 7a276f8eeb8..41a1bea230e 100644 --- a/tests/util/test_provenance.py +++ b/tests/util/test_provenance.py @@ -21,7 +21,7 @@ class TestStructureNL(TestCase): - def setUp(self): + def setup_method(self): # set up a Structure self.struct = Structure(np.eye(3, 3) * 3, ["Fe"], [[0, 0, 0]]) self.s2 = Structure(np.eye(3, 3) * 3, ["Al"], [[0, 0, 0]]) diff --git a/tests/vis/test_plotters.py b/tests/vis/test_plotters.py index 87311cc4d66..d6f5d535117 100644 --- a/tests/vis/test_plotters.py +++ b/tests/vis/test_plotters.py @@ -16,7 +16,7 @@ class TestSpectrumPlotter(PymatgenTest): - def setUp(self): + def setup_method(self): self.xanes = XAS.from_dict(spect_data_dict) def test_get_plot(self): From 7366ec7a8af47f57390838b0138084c5324a33aa Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Wed, 4 Dec 2024 23:21:51 +0800 Subject: [PATCH 14/31] replace tearDown --- tests/io/test_lmto.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/io/test_lmto.py b/tests/io/test_lmto.py index d7798e17fa9..25e75d4daa8 100644 --- a/tests/io/test_lmto.py +++ b/tests/io/test_lmto.py @@ -29,7 +29,7 @@ def setup_method(self): self.ref_bise = LMTOCtrl.from_file(filename="CTRL.BiSe") self.ref_fe = LMTOCtrl.from_file() - def tearDown(self): + def teardown_method(self): os.chdir(MODULE_DIR) def test_dict(self): @@ -54,7 +54,7 @@ def setup_method(self): self.copl_bise_eV = LMTOCopl(filename="COPL.BiSe", to_eV=True) self.copl_fe = LMTOCopl() - def tearDown(self): + def teardown_method(self): os.chdir(MODULE_DIR) def test_attributes(self): From 3239fd5d99752cfdaa0b0ca0588d14357e54c406 Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Wed, 4 Dec 2024 23:22:25 +0800 Subject: [PATCH 15/31] replace setUpClass(cls) with setup_class(cls) --- .../coordination_environments/test_read_write.py | 2 +- .../interfaces/test_coherent_interface.py | 2 +- tests/analysis/magnetism/test_heisenberg.py | 2 +- tests/analysis/test_fragmenter.py | 2 +- tests/analysis/test_molecule_matcher.py | 16 ++++++++-------- tests/analysis/test_pourbaix_diagram.py | 2 +- tests/command_line/test_vampire_caller.py | 2 +- tests/core/test_interface.py | 2 +- tests/electronic_structure/test_boltztrap.py | 2 +- tests/io/feff/test_inputs.py | 2 +- tests/io/feff/test_sets.py | 2 +- tests/io/lammps/test_data.py | 8 ++++---- tests/io/lammps/test_generators.py | 2 +- tests/io/lammps/test_inputs.py | 2 +- tests/io/lammps/test_outputs.py | 2 +- tests/io/lammps/test_utils.py | 4 ++-- tests/io/test_core.py | 2 +- tests/io/vasp/test_outputs.py | 2 +- tests/io/vasp/test_sets.py | 4 ++-- 19 files changed, 31 insertions(+), 31 deletions(-) diff --git a/tests/analysis/chemenv/coordination_environments/test_read_write.py b/tests/analysis/chemenv/coordination_environments/test_read_write.py index 640770fccad..dba1f04b070 100644 --- a/tests/analysis/chemenv/coordination_environments/test_read_write.py +++ b/tests/analysis/chemenv/coordination_environments/test_read_write.py @@ -32,7 +32,7 @@ class TestReadWriteChemenv(PymatgenTest): @classmethod - def setUpClass(cls): + def setup_class(cls): cls.lgf = LocalGeometryFinder() cls.lgf.setup_parameters(centering_type="standard") diff --git a/tests/analysis/interfaces/test_coherent_interface.py b/tests/analysis/interfaces/test_coherent_interface.py index 1be08782139..2b19cafd1cb 100644 --- a/tests/analysis/interfaces/test_coherent_interface.py +++ b/tests/analysis/interfaces/test_coherent_interface.py @@ -19,7 +19,7 @@ class TestInterfaceBuilder(PymatgenTest): @classmethod - def setUpClass(cls): + def setup_class(cls): si_struct = cls.get_structure("Si") sio2_struct = cls.get_structure("SiO2") cls.si_conventional = SpacegroupAnalyzer(si_struct).get_conventional_standard_structure() diff --git a/tests/analysis/magnetism/test_heisenberg.py b/tests/analysis/magnetism/test_heisenberg.py index 248bb559227..fa46f8b91b6 100644 --- a/tests/analysis/magnetism/test_heisenberg.py +++ b/tests/analysis/magnetism/test_heisenberg.py @@ -13,7 +13,7 @@ class TestHeisenbergMapper(TestCase): @classmethod - def setUpClass(cls): + def setup_class(cls): cls.df = pd.read_json(f"{TEST_DIR}/mag_orderings_test_cases.json") # Good tests diff --git a/tests/analysis/test_fragmenter.py b/tests/analysis/test_fragmenter.py index 211d7e3b7d1..be951ed19f0 100644 --- a/tests/analysis/test_fragmenter.py +++ b/tests/analysis/test_fragmenter.py @@ -19,7 +19,7 @@ class TestFragmentMolecule(PymatgenTest): @classmethod - def setUpClass(cls): + def setup_class(cls): cls.pc = Molecule.from_file(f"{TEST_DIR}/PC.xyz") cls.ec = Molecule.from_file(f"{TEST_DIR}/EC.xyz") cls.pos_pc = Molecule.from_file(f"{TEST_DIR}/PC.xyz") diff --git a/tests/analysis/test_molecule_matcher.py b/tests/analysis/test_molecule_matcher.py index 36a5db2c4c0..aaffbe0a7b3 100644 --- a/tests/analysis/test_molecule_matcher.py +++ b/tests/analysis/test_molecule_matcher.py @@ -558,7 +558,7 @@ def test_fit(self): class TestKabschMatcherSi(TestCase): @classmethod - def setUpClass(cls): + def setup_class(cls): cls.mol1 = Molecule.from_file(f"{TEST_DIR}/Si_cluster.xyz") cls.mol_matcher = KabschMatcher(cls.mol1) @@ -595,7 +595,7 @@ def test_permuted_atoms_order(self): class TestBruteForceOrderMatcherSi(TestCase): @classmethod - def setUpClass(cls): + def setup_class(cls): cls.mol1 = Molecule.from_file(f"{TEST_DIR}/Si_cluster.xyz") cls.mol_matcher = BruteForceOrderMatcher(cls.mol1) @@ -616,7 +616,7 @@ def test_random_match(self): class TestHungarianOrderMatcherSi(TestCase): @classmethod - def setUpClass(cls): + def setup_class(cls): cls.mol1 = Molecule.from_file(f"{TEST_DIR}/Si_cluster.xyz") cls.mol_matcher = HungarianOrderMatcher(cls.mol1) @@ -655,7 +655,7 @@ def test_random_match(self): class TestGeneticOrderMatcherSi(TestCase): @classmethod - def setUpClass(cls): + def setup_class(cls): cls.mol1 = Molecule.from_file(f"{TEST_DIR}/Si_cluster.xyz") cls.mol_matcher = GeneticOrderMatcher(cls.mol1, threshold=0.3) @@ -692,7 +692,7 @@ def test_random_match(self): class TestKabschMatcherSi2O(TestCase): @classmethod - def setUpClass(cls): + def setup_class(cls): cls.mol1 = Molecule.from_file(f"{TEST_DIR}/Si2O_cluster.xyz") cls.mol_matcher = KabschMatcher(cls.mol1) @@ -727,7 +727,7 @@ def test_permuted_atoms_order(self): class TestBruteForceOrderMatcherSi2O(TestCase): @classmethod - def setUpClass(cls): + def setup_class(cls): cls.mol1 = Molecule.from_file(f"{TEST_DIR}/Si2O_cluster.xyz") cls.mol_matcher = BruteForceOrderMatcher(cls.mol1) @@ -759,7 +759,7 @@ def test_random_match(self): class TestHungarianOrderMatcherSi2O(TestCase): @classmethod - def setUpClass(cls): + def setup_class(cls): cls.mol1 = Molecule.from_file(f"{TEST_DIR}/Si2O_cluster.xyz") cls.mol_matcher = HungarianOrderMatcher(cls.mol1) @@ -791,7 +791,7 @@ def test_random_match(self): class TestGeneticOrderMatcherSi2O(TestCase): @classmethod - def setUpClass(cls): + def setup_class(cls): cls.mol1 = Molecule.from_file(f"{TEST_DIR}/Si2O_cluster.xyz") cls.mol_matcher = GeneticOrderMatcher(cls.mol1, threshold=0.3) diff --git a/tests/analysis/test_pourbaix_diagram.py b/tests/analysis/test_pourbaix_diagram.py index 04720d1c747..703c0ff3e9d 100644 --- a/tests/analysis/test_pourbaix_diagram.py +++ b/tests/analysis/test_pourbaix_diagram.py @@ -99,7 +99,7 @@ def test_get_elt_fraction(self): class TestPourbaixDiagram(TestCase): @classmethod - def setUpClass(cls): + def setup_class(cls): cls.test_data = loadfn(f"{TEST_DIR}/pourbaix_test_data.json") cls.pbx = PourbaixDiagram(cls.test_data["Zn"], filter_solids=True) cls.pbx_no_filter = PourbaixDiagram(cls.test_data["Zn"], filter_solids=False) diff --git a/tests/command_line/test_vampire_caller.py b/tests/command_line/test_vampire_caller.py index e2e55a18486..439c14344c4 100644 --- a/tests/command_line/test_vampire_caller.py +++ b/tests/command_line/test_vampire_caller.py @@ -16,7 +16,7 @@ @pytest.mark.skipif(not which("vampire-serial"), reason="vampire executable not present") class TestVampireCaller(PymatgenTest): @classmethod - def setUpClass(cls): + def setup_class(cls): cls.Mn3Al = pd.read_json(f"{TEST_DIR}/Mn3Al.json") cls.compounds = [cls.Mn3Al] diff --git a/tests/core/test_interface.py b/tests/core/test_interface.py index c40c7ba9631..ccaaa59dcf6 100644 --- a/tests/core/test_interface.py +++ b/tests/core/test_interface.py @@ -106,7 +106,7 @@ def test_as_dict_and_from_dict(self): class TestGrainBoundaryGenerator(PymatgenTest): @classmethod - def setUpClass(cls): + def setup_class(cls): cls.Cu_prim = Structure.from_file(f"{TEST_DIR}/Cu_mp-30_primitive.cif") cls.GB_Cu_prim = GrainBoundaryGenerator(cls.Cu_prim) cls.Cu_conv = Structure.from_file(f"{TEST_DIR}/Cu_mp-30_conventional_standard.cif") diff --git a/tests/electronic_structure/test_boltztrap.py b/tests/electronic_structure/test_boltztrap.py index a5983320da9..dbc28997df1 100644 --- a/tests/electronic_structure/test_boltztrap.py +++ b/tests/electronic_structure/test_boltztrap.py @@ -26,7 +26,7 @@ @pytest.mark.skipif(not which("x_trans"), reason="No x_trans.") class TestBoltztrapAnalyzer(TestCase): @classmethod - def setUpClass(cls): + def setup_class(cls): cls.bz = BoltztrapAnalyzer.from_files(f"{TEST_DIR}/transp/") cls.bz_bands = BoltztrapAnalyzer.from_files(f"{TEST_DIR}/bands/") cls.bz_up = BoltztrapAnalyzer.from_files(f"{TEST_DIR}/dos_up/", dos_spin=1) diff --git a/tests/io/feff/test_inputs.py b/tests/io/feff/test_inputs.py index 564c2e114a1..ea95c1b25e6 100644 --- a/tests/io/feff/test_inputs.py +++ b/tests/io/feff/test_inputs.py @@ -58,7 +58,7 @@ def test_as_dict_and_from_dict(self): class TestFeffAtoms(TestCase): @classmethod - def setUpClass(cls): + def setup_class(cls): cls.structure = Structure.from_file(f"{TEST_FILES_DIR}/cif/CoO19128.cif") cls.atoms = Atoms(cls.structure, "O", 12.0) diff --git a/tests/io/feff/test_sets.py b/tests/io/feff/test_sets.py index e57e560996c..faf3aa85b78 100644 --- a/tests/io/feff/test_sets.py +++ b/tests/io/feff/test_sets.py @@ -16,7 +16,7 @@ class TestFeffInputSet(PymatgenTest): @classmethod - def setUpClass(cls): + def setup_class(cls): cls.header_string = """* This FEFF.inp file generated by pymatgen TITLE comment: From cif file TITLE Source: CoO19128.cif diff --git a/tests/io/lammps/test_data.py b/tests/io/lammps/test_data.py index 3be78db967c..9da40c48b7c 100644 --- a/tests/io/lammps/test_data.py +++ b/tests/io/lammps/test_data.py @@ -21,7 +21,7 @@ class TestLammpsBox(PymatgenTest): @classmethod - def setUpClass(cls): + def setup_class(cls): cls.peptide = LammpsBox( bounds=[ [36.840194, 64.211560], @@ -75,7 +75,7 @@ def test_to_lattice(self): class TestLammpsData(PymatgenTest): @classmethod - def setUpClass(cls): + def setup_class(cls): cls.peptide = LammpsData.from_file(filename=f"{TEST_DIR}/data.peptide") cls.ethane = LammpsData.from_file(filename=f"{TEST_DIR}/ethane.data") cls.quartz = LammpsData.from_file(filename=f"{TEST_DIR}/data.quartz", atom_style="atomic") @@ -667,7 +667,7 @@ def test_from_bonding(self): class TestForceField(PymatgenTest): @classmethod - def setUpClass(cls): + def setup_class(cls): mass_info = [ ("A", "H"), ("B", Element("C")), @@ -820,7 +820,7 @@ def test_lattice_2_lmpbox(self): class TestCombinedData(TestCase): @classmethod - def setUpClass(cls): + def setup_class(cls): cls.ec = LammpsData.from_file(filename=f"{TEST_DIR}/ec.data.gz") cls.fec = LammpsData.from_file(filename=f"{TEST_DIR}/fec.data.gz") cls.li = LammpsData.from_file(filename=f"{TEST_DIR}/li.data") diff --git a/tests/io/lammps/test_generators.py b/tests/io/lammps/test_generators.py index d19eddbf8df..950542da6ff 100644 --- a/tests/io/lammps/test_generators.py +++ b/tests/io/lammps/test_generators.py @@ -10,7 +10,7 @@ class TestLammpsMinimization(PymatgenTest): @classmethod - def setUpClass(cls): + def setup_class(cls): cls.filename = f"{TEST_DIR}/lgps.in" cls.cif = f"{TEST_DIR}/lgps.cif" cls.structure = Structure.from_file(cls.cif) diff --git a/tests/io/lammps/test_inputs.py b/tests/io/lammps/test_inputs.py index 15f8ef3fac4..23e3df888fd 100644 --- a/tests/io/lammps/test_inputs.py +++ b/tests/io/lammps/test_inputs.py @@ -18,7 +18,7 @@ class TestLammpsInputFile(PymatgenTest): @classmethod - def setUpClass(cls): + def setup_class(cls): cls.filename = f"{TEST_DIR}/lgps.in" def test_from_file(self): diff --git a/tests/io/lammps/test_outputs.py b/tests/io/lammps/test_outputs.py index 6d5e83c3089..15b482c3d7c 100644 --- a/tests/io/lammps/test_outputs.py +++ b/tests/io/lammps/test_outputs.py @@ -16,7 +16,7 @@ class TestLammpsDump(TestCase): @classmethod - def setUpClass(cls): + def setup_class(cls): with open(f"{TEST_DIR}/dump.rdx_wc.100") as file: rdx_str = file.read() cls.rdx = LammpsDump.from_str(string=rdx_str) diff --git a/tests/io/lammps/test_utils.py b/tests/io/lammps/test_utils.py index 4a116c021a6..ed3f6790580 100644 --- a/tests/io/lammps/test_utils.py +++ b/tests/io/lammps/test_utils.py @@ -12,7 +12,7 @@ class TestPolymer(TestCase): @classmethod - def setUpClass(cls): + def setup_class(cls): # head molecule cls.peo_head = Molecule.from_file(f"{TEST_DIR}/peo_head.xyz") charges = [-0.1187, 0.0861, 0.0861, 0.0861, -0.2792, -0.0326, 0.0861, 0.0861] @@ -84,7 +84,7 @@ def test_polymer_chain_topologies(self): class TestPackmolOutput(TestCase): @classmethod - def setUpClass(cls): + def setup_class(cls): ethanol_coords = [ [0.00720, -0.56870, 0.00000], [-1.28540, 0.24990, 0.00000], diff --git a/tests/io/test_core.py b/tests/io/test_core.py index bd4ad9ea7fa..560bd35848b 100644 --- a/tests/io/test_core.py +++ b/tests/io/test_core.py @@ -66,7 +66,7 @@ def test_msonable(self): class TestInputSet(PymatgenTest): @classmethod - def setUpClass(cls): + def setup_class(cls): cls.sif1 = StructInputFile.from_file(f"{TEST_FILES_DIR}/cif/Li.cif") cls.sif2 = StructInputFile.from_file(f"{TEST_FILES_DIR}/cif/LiFePO4.cif") cls.sif3 = StructInputFile.from_file(f"{TEST_FILES_DIR}/cif/Li2O.cif") diff --git a/tests/io/vasp/test_outputs.py b/tests/io/vasp/test_outputs.py index 99d05597987..b14510f1778 100644 --- a/tests/io/vasp/test_outputs.py +++ b/tests/io/vasp/test_outputs.py @@ -1516,7 +1516,7 @@ def test_vasp_6x_style(self): class TestChgcar(PymatgenTest): @classmethod - def setUpClass(cls): + def setup_class(cls): filepath = f"{VASP_OUT_DIR}/CHGCAR.nospin.gz" cls.chgcar_no_spin = Chgcar.from_file(filepath) diff --git a/tests/io/vasp/test_sets.py b/tests/io/vasp/test_sets.py index 836478a6e93..726e8a199fc 100644 --- a/tests/io/vasp/test_sets.py +++ b/tests/io/vasp/test_sets.py @@ -130,7 +130,7 @@ def test_sets_changed(self): class TestVaspInputSet(PymatgenTest): @classmethod - def setUpClass(cls): + def setup_class(cls): filepath = f"{VASP_IN_DIR}/POSCAR" cls.structure = Structure.from_file(filepath) @@ -167,7 +167,7 @@ def test_as_dict(self): class TestMITMPRelaxSet(PymatgenTest): @classmethod - def setUpClass(cls): + def setup_class(cls): cls.set = MITRelaxSet cls.mp_set = MPRelaxSet From 4429546f59e655d53af14b6b1e0319120c2006c4 Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Wed, 4 Dec 2024 23:23:16 +0800 Subject: [PATCH 16/31] global remove inheritance from TestCase --- tests/alchemy/test_filters.py | 5 ++--- tests/analysis/magnetism/test_analyzer.py | 3 +-- tests/analysis/magnetism/test_heisenberg.py | 4 +--- tests/analysis/magnetism/test_jahnteller.py | 4 +--- .../test_dopant_predictor.py | 4 +--- .../test_substitution_probability.py | 5 ++--- tests/analysis/test_bond_dissociation.py | 3 +-- tests/analysis/test_cost.py | 6 ++---- tests/analysis/test_ewald.py | 6 ++---- tests/analysis/test_functional_groups.py | 3 +-- tests/analysis/test_graphs.py | 3 +-- tests/analysis/test_interface_reactions.py | 4 +--- tests/analysis/test_molecule_matcher.py | 17 +++++++-------- .../test_molecule_structure_comparator.py | 4 +--- tests/analysis/test_phase_diagram.py | 15 +++++++------ tests/analysis/test_pourbaix_diagram.py | 5 ++--- .../test_quasi_harmonic_debye_approx.py | 6 ++---- tests/analysis/test_quasirrho.py | 4 +--- tests/analysis/test_reaction_calculator.py | 5 ++--- tests/analysis/test_structure_analyzer.py | 4 +--- tests/apps/battery/test_conversion_battery.py | 3 +-- tests/apps/battery/test_insertion_battery.py | 3 +-- tests/apps/battery/test_plotter.py | 3 +-- tests/apps/borg/test_hive.py | 7 +++---- tests/command_line/test_critic2_caller.py | 3 +-- tests/command_line/test_gulp_caller.py | 9 ++++---- tests/core/test_ion.py | 4 +--- .../test_bandstructure.py | 3 +-- tests/electronic_structure/test_boltztrap.py | 3 +-- tests/electronic_structure/test_boltztrap2.py | 11 +++++----- tests/electronic_structure/test_cohp.py | 9 ++++---- tests/electronic_structure/test_dos.py | 11 +++++----- tests/electronic_structure/test_plotter.py | 7 +++---- tests/entries/test_compatibility.py | 21 +++++++++---------- tests/entries/test_computed_entries.py | 7 +++---- tests/entries/test_correction_calculator.py | 4 +--- tests/entries/test_exp_entries.py | 3 +-- tests/io/cp2k/test_outputs.py | 4 +--- tests/io/feff/test_inputs.py | 11 +++++----- tests/io/feff/test_outputs.py | 6 ++---- tests/io/lammps/test_data.py | 7 +++---- tests/io/lammps/test_outputs.py | 5 ++--- tests/io/lammps/test_utils.py | 6 ++---- tests/io/lobster/test_lobsterenv.py | 4 +--- tests/io/lobster/test_outputs.py | 11 +++++----- tests/io/test_babel.py | 3 +-- tests/io/test_cssr.py | 4 +--- tests/io/test_fiesta.py | 6 ++---- tests/io/test_gaussian.py | 6 ++---- tests/io/test_nwchem.py | 5 ++--- tests/io/test_phonopy.py | 3 +-- tests/io/test_xr.py | 4 +--- tests/io/test_xyz.py | 4 +--- tests/io/test_zeopp.py | 16 +++++++------- tests/io/vasp/test_inputs.py | 3 +-- tests/optimization/test_linear_assignment.py | 4 +--- tests/phonon/test_plotter.py | 7 +++---- tests/symmetry/test_analyzer.py | 5 ++--- tests/symmetry/test_settings.py | 4 +--- .../test_site_transformations.py | 9 ++++---- .../test_standard_transformations.py | 5 ++--- tests/util/test_coord.py | 4 +--- tests/util/test_provenance.py | 3 +-- 63 files changed, 141 insertions(+), 229 deletions(-) diff --git a/tests/alchemy/test_filters.py b/tests/alchemy/test_filters.py index dbaf1a19588..a5bcc72ea10 100644 --- a/tests/alchemy/test_filters.py +++ b/tests/alchemy/test_filters.py @@ -1,7 +1,6 @@ from __future__ import annotations import json -from unittest import TestCase from monty.json import MontyDecoder @@ -70,7 +69,7 @@ def test_as_from_dict(self): assert isinstance(SpecieProximityFilter.from_dict(dct), SpecieProximityFilter) -class TestRemoveDuplicatesFilter(TestCase): +class TestRemoveDuplicatesFilter: def setup_method(self): with open(f"{TEST_FILES_DIR}/entries/TiO2_entries.json") as file: entries = json.load(file, cls=MontyDecoder) @@ -89,7 +88,7 @@ def test_as_from_dict(self): assert isinstance(RemoveDuplicatesFilter().from_dict(dct), RemoveDuplicatesFilter) -class TestRemoveExistingFilter(TestCase): +class TestRemoveExistingFilter: def setup_method(self): with open(f"{TEST_FILES_DIR}/entries/TiO2_entries.json") as file: entries = json.load(file, cls=MontyDecoder) diff --git a/tests/analysis/magnetism/test_analyzer.py b/tests/analysis/magnetism/test_analyzer.py index e71dfadaa6d..dfbac279ef4 100644 --- a/tests/analysis/magnetism/test_analyzer.py +++ b/tests/analysis/magnetism/test_analyzer.py @@ -1,7 +1,6 @@ from __future__ import annotations from shutil import which -from unittest import TestCase import pytest from monty.serialization import loadfn @@ -24,7 +23,7 @@ enumlib_present = enum_cmd and makestr_cmd -class TestCollinearMagneticStructureAnalyzer(TestCase): +class TestCollinearMagneticStructureAnalyzer: def setup_method(self): self.Fe = Structure.from_file(f"{TEST_FILES_DIR}/cif/Fe.cif", primitive=True) diff --git a/tests/analysis/magnetism/test_heisenberg.py b/tests/analysis/magnetism/test_heisenberg.py index fa46f8b91b6..d6ce648ea87 100644 --- a/tests/analysis/magnetism/test_heisenberg.py +++ b/tests/analysis/magnetism/test_heisenberg.py @@ -1,7 +1,5 @@ from __future__ import annotations -from unittest import TestCase - import pandas as pd from pymatgen.analysis.magnetism.heisenberg import HeisenbergMapper @@ -11,7 +9,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/analysis/magnetic_orderings" -class TestHeisenbergMapper(TestCase): +class TestHeisenbergMapper: @classmethod def setup_class(cls): cls.df = pd.read_json(f"{TEST_DIR}/mag_orderings_test_cases.json") diff --git a/tests/analysis/magnetism/test_jahnteller.py b/tests/analysis/magnetism/test_jahnteller.py index f1938dbafe5..11f81b9686b 100644 --- a/tests/analysis/magnetism/test_jahnteller.py +++ b/tests/analysis/magnetism/test_jahnteller.py @@ -1,7 +1,5 @@ from __future__ import annotations -from unittest import TestCase - import numpy as np from pytest import approx @@ -10,7 +8,7 @@ from pymatgen.util.testing import TEST_FILES_DIR -class TestJahnTeller(TestCase): +class TestJahnTeller: def setup_method(self): self.jt = JahnTellerAnalyzer() diff --git a/tests/analysis/structure_prediction/test_dopant_predictor.py b/tests/analysis/structure_prediction/test_dopant_predictor.py index a88e424a9c6..7f4d8aaf6c5 100644 --- a/tests/analysis/structure_prediction/test_dopant_predictor.py +++ b/tests/analysis/structure_prediction/test_dopant_predictor.py @@ -1,7 +1,5 @@ from __future__ import annotations -from unittest import TestCase - from pytest import approx from pymatgen.analysis.local_env import CrystalNN @@ -12,7 +10,7 @@ from pymatgen.core import Species, Structure -class TestDopantPrediction(TestCase): +class TestDopantPrediction: def setup_method(self): self.tin_dioxide = Structure( [3.24, 0, 0, 0, 4.83, 0, 0, 0, 4.84], diff --git a/tests/analysis/structure_prediction/test_substitution_probability.py b/tests/analysis/structure_prediction/test_substitution_probability.py index e6c5f9786d0..137a5478bda 100644 --- a/tests/analysis/structure_prediction/test_substitution_probability.py +++ b/tests/analysis/structure_prediction/test_substitution_probability.py @@ -1,7 +1,6 @@ from __future__ import annotations import json -from unittest import TestCase from pytest import approx @@ -26,7 +25,7 @@ def get_table(): return json.load(file) -class TestSubstitutionProbability(TestCase): +class TestSubstitutionProbability: def test_full_lambda_table(self): """Check specific values in the data folder. If the JSON is updated, these tests will have to be as well. @@ -57,7 +56,7 @@ def test_mini_lambda_table(self): assert prob == approx(0.00102673915742, abs=1e-5), "probability isn't correct" -class TestSubstitutionPredictor(TestCase): +class TestSubstitutionPredictor: def test_prediction(self): sp = SubstitutionPredictor(threshold=8e-3) result = sp.list_prediction(["Na+", "Cl-"], to_this_composition=True)[5] diff --git a/tests/analysis/test_bond_dissociation.py b/tests/analysis/test_bond_dissociation.py index 3366b2fae8d..9ac3a059a8a 100644 --- a/tests/analysis/test_bond_dissociation.py +++ b/tests/analysis/test_bond_dissociation.py @@ -1,7 +1,6 @@ from __future__ import annotations import platform -from unittest import TestCase import pytest from monty.serialization import loadfn @@ -12,7 +11,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/analysis/bond_dissociation" -class TestBondDissociation(TestCase): +class TestBondDissociation: def setup_method(self): pytest.importorskip("openbabel") self.PC_65_principle = loadfn(f"{TEST_DIR}/PC_65_principle.json") diff --git a/tests/analysis/test_cost.py b/tests/analysis/test_cost.py index 39475af303f..074a98cd9c7 100644 --- a/tests/analysis/test_cost.py +++ b/tests/analysis/test_cost.py @@ -1,7 +1,5 @@ from __future__ import annotations -from unittest import TestCase - from pytest import approx from pymatgen.analysis.cost import CostAnalyzer, CostDBCSV, CostDBElements @@ -10,7 +8,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/analysis/cost" -class TestCostAnalyzer(TestCase): +class TestCostAnalyzer: def setup_method(self): self.ca1 = CostAnalyzer(CostDBCSV(f"{TEST_DIR}/costdb_1.csv")) self.ca2 = CostAnalyzer(CostDBCSV(f"{TEST_DIR}/costdb_2.csv")) @@ -31,7 +29,7 @@ def test_sanity(self): assert self.ca1.get_cost_per_kg("Ag") == self.ca2.get_cost_per_kg("Ag") -class TestCostDB(TestCase): +class TestCostDB: def test_sanity(self): ca = CostAnalyzer(CostDBElements()) assert ca.get_cost_per_kg("PtO") > ca.get_cost_per_kg("MgO") diff --git a/tests/analysis/test_ewald.py b/tests/analysis/test_ewald.py index 3edc515038b..6e5ea7e5a0b 100644 --- a/tests/analysis/test_ewald.py +++ b/tests/analysis/test_ewald.py @@ -1,7 +1,5 @@ from __future__ import annotations -from unittest import TestCase - import numpy as np import pytest from pytest import approx @@ -11,7 +9,7 @@ from pymatgen.util.testing import VASP_IN_DIR -class TestEwaldSummation(TestCase): +class TestEwaldSummation: def setup_method(self): filepath = f"{VASP_IN_DIR}/POSCAR" self.original_struct = Structure.from_file(filepath) @@ -80,7 +78,7 @@ def test_as_dict(self): assert ham.as_dict() == EwaldSummation.from_dict(dct).as_dict() -class TestEwaldMinimizer(TestCase): +class TestEwaldMinimizer: def test_init(self): matrix = np.array( [ diff --git a/tests/analysis/test_functional_groups.py b/tests/analysis/test_functional_groups.py index a19a12b997b..5b04e8290c2 100644 --- a/tests/analysis/test_functional_groups.py +++ b/tests/analysis/test_functional_groups.py @@ -1,7 +1,6 @@ from __future__ import annotations import platform -from unittest import TestCase import pytest @@ -25,7 +24,7 @@ __credit__ = "Peiyuan Yu" -class TestFunctionalGroupExtractor(TestCase): +class TestFunctionalGroupExtractor: def setup_method(self): self.file = f"{TEST_DIR}/func_group_test.mol" self.mol = Molecule.from_file(self.file) diff --git a/tests/analysis/test_graphs.py b/tests/analysis/test_graphs.py index 899f7e564e6..89e4c4d1281 100644 --- a/tests/analysis/test_graphs.py +++ b/tests/analysis/test_graphs.py @@ -4,7 +4,6 @@ import re from glob import glob from shutil import which -from unittest import TestCase import networkx as nx import networkx.algorithms.isomorphism as iso @@ -504,7 +503,7 @@ def test_sort(self): assert list(sg.graph.edges)[-2:] == [(1, 3, 0), (1, 2, 0)] -class TestMoleculeGraph(TestCase): +class TestMoleculeGraph: def setup_method(self): cyclohexene_xyz = f"{TEST_DIR}/cyclohexene.xyz" cyclohexene = Molecule.from_file(cyclohexene_xyz) diff --git a/tests/analysis/test_interface_reactions.py b/tests/analysis/test_interface_reactions.py index 372049e1447..3f9e5939da2 100644 --- a/tests/analysis/test_interface_reactions.py +++ b/tests/analysis/test_interface_reactions.py @@ -1,7 +1,5 @@ from __future__ import annotations -from unittest import TestCase - import numpy as np import pytest from matplotlib.figure import Figure as MplFigure @@ -17,7 +15,7 @@ from pymatgen.entries.computed_entries import ComputedEntry -class TestInterfaceReaction(TestCase): +class TestInterfaceReaction: def setup_method(self): self.entries = [ ComputedEntry(Composition("Li"), 0), diff --git a/tests/analysis/test_molecule_matcher.py b/tests/analysis/test_molecule_matcher.py index aaffbe0a7b3..56bcf0dd030 100644 --- a/tests/analysis/test_molecule_matcher.py +++ b/tests/analysis/test_molecule_matcher.py @@ -1,7 +1,6 @@ from __future__ import annotations import platform -from unittest import TestCase import numpy as np import pytest @@ -556,7 +555,7 @@ def test_fit(self): assert rmsd == approx(0, abs=6) -class TestKabschMatcherSi(TestCase): +class TestKabschMatcherSi: @classmethod def setup_class(cls): cls.mol1 = Molecule.from_file(f"{TEST_DIR}/Si_cluster.xyz") @@ -593,7 +592,7 @@ def test_permuted_atoms_order(self): assert rmsd == approx(2.7962454578966454, abs=1e-6) -class TestBruteForceOrderMatcherSi(TestCase): +class TestBruteForceOrderMatcherSi: @classmethod def setup_class(cls): cls.mol1 = Molecule.from_file(f"{TEST_DIR}/Si_cluster.xyz") @@ -614,7 +613,7 @@ def test_random_match(self): self.mol_matcher.fit(mol2) -class TestHungarianOrderMatcherSi(TestCase): +class TestHungarianOrderMatcherSi: @classmethod def setup_class(cls): cls.mol1 = Molecule.from_file(f"{TEST_DIR}/Si_cluster.xyz") @@ -653,7 +652,7 @@ def test_random_match(self): assert rmsd == approx(1.0177241485450828, abs=1e-6) -class TestGeneticOrderMatcherSi(TestCase): +class TestGeneticOrderMatcherSi: @classmethod def setup_class(cls): cls.mol1 = Molecule.from_file(f"{TEST_DIR}/Si_cluster.xyz") @@ -690,7 +689,7 @@ def test_random_match(self): assert res[0][-1] == approx(0.22163169511782, abs=1e-6) -class TestKabschMatcherSi2O(TestCase): +class TestKabschMatcherSi2O: @classmethod def setup_class(cls): cls.mol1 = Molecule.from_file(f"{TEST_DIR}/Si2O_cluster.xyz") @@ -725,7 +724,7 @@ def test_permuted_atoms_order(self): self.mol_matcher.fit(mol2) -class TestBruteForceOrderMatcherSi2O(TestCase): +class TestBruteForceOrderMatcherSi2O: @classmethod def setup_class(cls): cls.mol1 = Molecule.from_file(f"{TEST_DIR}/Si2O_cluster.xyz") @@ -757,7 +756,7 @@ def test_random_match(self): assert rmsd == approx(0.23051587697194997, abs=1e-6) -class TestHungarianOrderMatcherSi2O(TestCase): +class TestHungarianOrderMatcherSi2O: @classmethod def setup_class(cls): cls.mol1 = Molecule.from_file(f"{TEST_DIR}/Si2O_cluster.xyz") @@ -789,7 +788,7 @@ def test_random_match(self): assert rmsd == approx(0.23231038877573124, abs=1e-6) -class TestGeneticOrderMatcherSi2O(TestCase): +class TestGeneticOrderMatcherSi2O: @classmethod def setup_class(cls): cls.mol1 = Molecule.from_file(f"{TEST_DIR}/Si2O_cluster.xyz") diff --git a/tests/analysis/test_molecule_structure_comparator.py b/tests/analysis/test_molecule_structure_comparator.py index 3875ffb44ec..b212b593e17 100644 --- a/tests/analysis/test_molecule_structure_comparator.py +++ b/tests/analysis/test_molecule_structure_comparator.py @@ -1,7 +1,5 @@ from __future__ import annotations -from unittest import TestCase - import pytest from pymatgen.analysis.molecule_structure_comparator import MoleculeStructureComparator @@ -15,7 +13,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/analysis/structural_change" -class TestMoleculeStructureComparator(TestCase): +class TestMoleculeStructureComparator: def test_are_equal(self): msc1 = MoleculeStructureComparator() mol1 = Molecule.from_file(f"{TEST_DIR}/t1.xyz") diff --git a/tests/analysis/test_phase_diagram.py b/tests/analysis/test_phase_diagram.py index a84a95beae3..25b84f2f7ca 100644 --- a/tests/analysis/test_phase_diagram.py +++ b/tests/analysis/test_phase_diagram.py @@ -5,7 +5,6 @@ import unittest.mock from itertools import combinations from numbers import Number -from unittest import TestCase import matplotlib.pyplot as plt import numpy as np @@ -37,7 +36,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/analysis" -class TestPDEntry(TestCase): +class TestPDEntry: def setup_method(self): comp = Composition("LiFeO2") self.entry = PDEntry(comp, 53, name="mp-757614") @@ -113,7 +112,7 @@ def test_read_csv(self): assert len(entries) == 490, "Wrong number of entries!" -class TestTransformedPDEntry(TestCase): +class TestTransformedPDEntry: def setup_method(self): comp = Composition("LiFeO2") entry = PDEntry(comp, 53) @@ -667,7 +666,7 @@ def test_val_err_on_no_entries(self): PhaseDiagram(entries=entries) -class TestGrandPotentialPhaseDiagram(TestCase): +class TestGrandPotentialPhaseDiagram: def setup_method(self): self.entries = EntrySet.from_csv(f"{TEST_DIR}/pd_entries_test.csv") self.pd = GrandPotentialPhaseDiagram(self.entries, {Element("O"): -5}) @@ -703,7 +702,7 @@ def test_str(self): ) -class TestCompoundPhaseDiagram(TestCase): +class TestCompoundPhaseDiagram: def setup_method(self): self.entries = EntrySet.from_csv(f"{TEST_DIR}/pd_entries_test.csv") self.pd = CompoundPhaseDiagram(self.entries, [Composition("Li2O"), Composition("Fe2O3")]) @@ -741,7 +740,7 @@ def test_num2str(self): assert len(ret) == num -class TestPatchedPhaseDiagram(TestCase): +class TestPatchedPhaseDiagram: def setup_method(self): self.entries = EntrySet.from_csv(f"{TEST_DIR}/phase_diagram/reaction_entries_test.csv") # NOTE add He to test for correct behavior despite no patches involving He @@ -891,7 +890,7 @@ def test_remove_redundant_spaces(self): assert len(self.ppd.remove_redundant_spaces(test)) == 30 -class TestReactionDiagram(TestCase): +class TestReactionDiagram: def setup_method(self): self.entries = list(EntrySet.from_csv(f"{TEST_DIR}/phase_diagram/reaction_entries_test.csv").entries) for entry in self.entries: @@ -931,7 +930,7 @@ def test_formula(self): # assert formula in formed_formula, f"{formed_formula=} not in {expected_formula=}" -class TestPDPlotter(TestCase): +class TestPDPlotter: def setup_method(self): entries = list(EntrySet.from_csv(f"{TEST_DIR}/pd_entries_test.csv")) diff --git a/tests/analysis/test_pourbaix_diagram.py b/tests/analysis/test_pourbaix_diagram.py index 703c0ff3e9d..77f71721327 100644 --- a/tests/analysis/test_pourbaix_diagram.py +++ b/tests/analysis/test_pourbaix_diagram.py @@ -1,7 +1,6 @@ from __future__ import annotations import multiprocessing -from unittest import TestCase import matplotlib.pyplot as plt import numpy as np @@ -97,7 +96,7 @@ def test_get_elt_fraction(self): assert pb_entry.get_element_fraction("Mn") == approx(0.4) -class TestPourbaixDiagram(TestCase): +class TestPourbaixDiagram: @classmethod def setup_class(cls): cls.test_data = loadfn(f"{TEST_DIR}/pourbaix_test_data.json") @@ -293,7 +292,7 @@ def test_serialization(self): assert len(pd_binary.stable_entries) == len(new_binary.stable_entries) -class TestPourbaixPlotter(TestCase): +class TestPourbaixPlotter: def setup_method(self): self.test_data = loadfn(f"{TEST_DIR}/pourbaix_test_data.json") self.pd = PourbaixDiagram(self.test_data["Zn"]) diff --git a/tests/analysis/test_quasi_harmonic_debye_approx.py b/tests/analysis/test_quasi_harmonic_debye_approx.py index 52c4cfc7aba..c9481f73513 100644 --- a/tests/analysis/test_quasi_harmonic_debye_approx.py +++ b/tests/analysis/test_quasi_harmonic_debye_approx.py @@ -1,7 +1,5 @@ from __future__ import annotations -from unittest import TestCase - import numpy as np from numpy.testing import assert_allclose @@ -12,7 +10,7 @@ __author__ = "Kiran Mathew" -class TestQuasiHarmonicDebyeApprox(TestCase): +class TestQuasiHarmonicDebyeApprox: def setup_method(self): struct = Structure.from_dict( { @@ -137,7 +135,7 @@ def test_vibrational_free_energy(self): assert_allclose(A, 0.494687, atol=1e-3) -class TestAnharmonicQuasiHarmonicDebyeApprox(TestCase): +class TestAnharmonicQuasiHarmonicDebyeApprox: def setup_method(self): struct = Structure.from_str( """FCC Al diff --git a/tests/analysis/test_quasirrho.py b/tests/analysis/test_quasirrho.py index 110382f263a..61fbdf8c251 100644 --- a/tests/analysis/test_quasirrho.py +++ b/tests/analysis/test_quasirrho.py @@ -1,7 +1,5 @@ from __future__ import annotations -from unittest import TestCase - import pytest from pymatgen.analysis.quasirrho import QuasiRRHO, get_avg_mom_inertia @@ -12,7 +10,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/analysis/quasirrho" -class TestQuasiRRHO(TestCase): +class TestQuasiRRHO: """Test class for QuasiRRHO""" def setup_method(self): diff --git a/tests/analysis/test_reaction_calculator.py b/tests/analysis/test_reaction_calculator.py index b4f6e4ceb1c..cb6363a0114 100644 --- a/tests/analysis/test_reaction_calculator.py +++ b/tests/analysis/test_reaction_calculator.py @@ -2,7 +2,6 @@ import math from collections import defaultdict -from unittest import TestCase import numpy as np import pytest @@ -287,7 +286,7 @@ def test_underdetermined_reactants(self): assert str(rxn) == "LiMnCl3 + 3 LiCl + MnCl2 -> 2 Li2MnCl4" -class TestBalancedReaction(TestCase): +class TestBalancedReaction: def setup_method(self) -> None: rct = {"K2SO4": 3, "Na2S": 1, "Li": 24} prod = {"KNaS": 2, "K2S": 2, "Li2O": 12} @@ -334,7 +333,7 @@ def test_hash(self): assert hash(self.rxn) == 4774511606373046513 -class TestComputedReaction(TestCase): +class TestComputedReaction: def setup_method(self): dct = [ { diff --git a/tests/analysis/test_structure_analyzer.py b/tests/analysis/test_structure_analyzer.py index 066a6890af8..d92b954f79a 100644 --- a/tests/analysis/test_structure_analyzer.py +++ b/tests/analysis/test_structure_analyzer.py @@ -1,7 +1,5 @@ from __future__ import annotations -from unittest import TestCase - import numpy as np from numpy.testing import assert_allclose from pytest import approx @@ -40,7 +38,7 @@ def test_analyze(self): ) in ensemble, "Cannot find the right polyhedron in ensemble." -class TestRelaxationAnalyzer(TestCase): +class TestRelaxationAnalyzer: def setup_method(self): s1 = Structure.from_file(f"{VASP_IN_DIR}/POSCAR_Li2O") s2 = Structure.from_file(f"{VASP_OUT_DIR}/CONTCAR_Li2O") diff --git a/tests/apps/battery/test_conversion_battery.py b/tests/apps/battery/test_conversion_battery.py index 2fc7efb10c9..db9c58c2f55 100644 --- a/tests/apps/battery/test_conversion_battery.py +++ b/tests/apps/battery/test_conversion_battery.py @@ -1,7 +1,6 @@ from __future__ import annotations import json -from unittest import TestCase from monty.json import MontyDecoder from pytest import approx @@ -13,7 +12,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/apps/battery" -class TestConversionElectrode(TestCase): +class TestConversionElectrode: def setup_method(self): self.formulas = ["LiCoO2", "FeF3", "MnO2"] self.conversion_electrodes = {} diff --git a/tests/apps/battery/test_insertion_battery.py b/tests/apps/battery/test_insertion_battery.py index d7028b835e9..40a67a3b7dc 100644 --- a/tests/apps/battery/test_insertion_battery.py +++ b/tests/apps/battery/test_insertion_battery.py @@ -1,7 +1,6 @@ from __future__ import annotations import json -from unittest import TestCase from monty.json import MontyDecoder, MontyEncoder from pytest import approx @@ -13,7 +12,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/apps/battery" -class TestInsertionElectrode(TestCase): +class TestInsertionElectrode: def setup_method(self): self.entry_Li = ComputedEntry("Li", -1.90753119) self.entry_Ca = ComputedEntry("Ca", -1.99689568) diff --git a/tests/apps/battery/test_plotter.py b/tests/apps/battery/test_plotter.py index a0f3daad6a0..d59f5c2ba64 100644 --- a/tests/apps/battery/test_plotter.py +++ b/tests/apps/battery/test_plotter.py @@ -1,7 +1,6 @@ from __future__ import annotations import json -from unittest import TestCase from monty.json import MontyDecoder @@ -15,7 +14,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/apps/battery" -class TestVoltageProfilePlotter(TestCase): +class TestVoltageProfilePlotter: def setup_method(self): entry_Li = ComputedEntry("Li", -1.90753119) diff --git a/tests/apps/borg/test_hive.py b/tests/apps/borg/test_hive.py index 3e47e6e8e33..84a2782553c 100644 --- a/tests/apps/borg/test_hive.py +++ b/tests/apps/borg/test_hive.py @@ -1,7 +1,6 @@ from __future__ import annotations import os -from unittest import TestCase import pytest from monty.tempfile import ScratchDir @@ -20,7 +19,7 @@ MOL_TEST_DIR = f"{TEST_FILES_DIR}/io/gaussian" -class TestVaspToComputedEntryDrone(TestCase): +class TestVaspToComputedEntryDrone: def setup_method(self): self.drone = VaspToComputedEntryDrone(data=["efermi"]) self.structure_drone = VaspToComputedEntryDrone(inc_structure=True) @@ -53,7 +52,7 @@ def test_as_from_dict(self): assert isinstance(drone, VaspToComputedEntryDrone) -class TestSimpleVaspToComputedEntryDrone(TestCase): +class TestSimpleVaspToComputedEntryDrone: def setup_method(self): self.drone = SimpleVaspToComputedEntryDrone() self.structure_drone = SimpleVaspToComputedEntryDrone(inc_structure=True) @@ -73,7 +72,7 @@ def test_as_from_dict(self): assert isinstance(drone, SimpleVaspToComputedEntryDrone) -class TestGaussianToComputedEntryDrone(TestCase): +class TestGaussianToComputedEntryDrone: def setup_method(self): self.drone = GaussianToComputedEntryDrone(data=["corrections"]) self.structure_drone = GaussianToComputedEntryDrone(inc_structure=True) diff --git a/tests/command_line/test_critic2_caller.py b/tests/command_line/test_critic2_caller.py index 303269f3d42..55346936b92 100644 --- a/tests/command_line/test_critic2_caller.py +++ b/tests/command_line/test_critic2_caller.py @@ -1,7 +1,6 @@ from __future__ import annotations from shutil import which -from unittest import TestCase import pytest from pytest import approx @@ -75,7 +74,7 @@ def test_from_structure(self): assert "ERROR : load int.CHGCAR id chg_int zpsp Mo 6 S 6" in c2c._input_script -class TestCritic2Analysis(TestCase): +class TestCritic2Analysis: def setup_method(self): stdout_file = f"{TEST_DIR}/MoS2_critic2_stdout.txt" stdout_file_new_format = f"{TEST_DIR}/MoS2_critic2_stdout_new_format.txt" diff --git a/tests/command_line/test_gulp_caller.py b/tests/command_line/test_gulp_caller.py index 09bea1d8044..4dc27857afa 100644 --- a/tests/command_line/test_gulp_caller.py +++ b/tests/command_line/test_gulp_caller.py @@ -9,7 +9,6 @@ import os import sys from shutil import which -from unittest import TestCase import numpy as np import pytest @@ -106,7 +105,7 @@ def test_decimal(self): caller.run(buckingham_input) -class TestGulpIO(TestCase): +class TestGulpIO: def setup_method(self): self.structure = Structure.from_file(f"{VASP_IN_DIR}/POSCAR_Al12O18") self.gio = GulpIO() @@ -276,7 +275,7 @@ def test_tersoff_input(self): self.gio.tersoff_input(self.structure) -class TestGlobalFunctions(TestCase): +class TestGlobalFunctions: def setup_method(self): mgo_latt = np.eye(3) * 4.212 mgo_specie = ["Mg", "O"] * 4 @@ -327,7 +326,7 @@ def test_get_energy_relax_structure_buckingham(self): assert site_len == len(self.mgo_uc) -class TestBuckinghamPotentialLewis(TestCase): +class TestBuckinghamPotentialLewis: def setup_method(self): self.bpl = BuckinghamPotential("lewis") @@ -354,7 +353,7 @@ def test_spring(self): assert self.bpl.spring_dict["O"] != "" -class TestBuckinghamPotentialBush(TestCase): +class TestBuckinghamPotentialBush: def setup_method(self): self.bpb = BuckinghamPotential("bush") diff --git a/tests/core/test_ion.py b/tests/core/test_ion.py index 2d2291c6da9..601bb5eec8c 100644 --- a/tests/core/test_ion.py +++ b/tests/core/test_ion.py @@ -1,7 +1,5 @@ from __future__ import annotations -from unittest import TestCase - import numpy as np import pytest @@ -9,7 +7,7 @@ from pymatgen.core.ion import Ion -class TestIon(TestCase): +class TestIon: def setup_method(self): self.comp = [] self.comp.append(Ion.from_formula("Li+")) diff --git a/tests/electronic_structure/test_bandstructure.py b/tests/electronic_structure/test_bandstructure.py index 79c4ff99f53..a1e88e8ab0e 100644 --- a/tests/electronic_structure/test_bandstructure.py +++ b/tests/electronic_structure/test_bandstructure.py @@ -2,7 +2,6 @@ import copy import json -from unittest import TestCase import numpy as np import pytest @@ -25,7 +24,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/electronic_structure/bandstructure" -class TestKpoint(TestCase): +class TestKpoint: def setup_method(self): self.lattice = Lattice.cubic(10.0) self.kpoint = Kpoint([0.1, 0.4, -0.5], self.lattice, label="X") diff --git a/tests/electronic_structure/test_boltztrap.py b/tests/electronic_structure/test_boltztrap.py index dbc28997df1..e16fb934460 100644 --- a/tests/electronic_structure/test_boltztrap.py +++ b/tests/electronic_structure/test_boltztrap.py @@ -2,7 +2,6 @@ import json from shutil import which -from unittest import TestCase import pytest from monty.serialization import loadfn @@ -24,7 +23,7 @@ @pytest.mark.skipif(not which("x_trans"), reason="No x_trans.") -class TestBoltztrapAnalyzer(TestCase): +class TestBoltztrapAnalyzer: @classmethod def setup_class(cls): cls.bz = BoltztrapAnalyzer.from_files(f"{TEST_DIR}/transp/") diff --git a/tests/electronic_structure/test_boltztrap2.py b/tests/electronic_structure/test_boltztrap2.py index 0fb225b0379..4d8255d232a 100644 --- a/tests/electronic_structure/test_boltztrap2.py +++ b/tests/electronic_structure/test_boltztrap2.py @@ -1,7 +1,6 @@ from __future__ import annotations import shutil -from unittest import TestCase import numpy as np import pytest @@ -41,7 +40,7 @@ BZT_TRANSP_FN = f"{TEST_DIR}/bztTranspProps.json.gz" -class TestVasprunBSLoader(TestCase): +class TestVasprunBSLoader: def setup_method(self): self.loader = VasprunBSLoader(VASP_RUN) assert self.loader is not None @@ -80,7 +79,7 @@ def test_get_volume(self): assert self.loader.get_volume() == approx(477.6256714925874, abs=1e-5) -class TestBandstructureLoader(TestCase): +class TestBandstructureLoader: def setup_method(self): self.loader = BandstructureLoader(BAND_STRUCT, VASP_RUN.structures[-1]) assert self.loader is not None @@ -107,7 +106,7 @@ def test_set_upper_lower_bands(self): assert self.loader_sp_dn.ebands.shape == (14, 198) -class TestVasprunLoader(TestCase): +class TestVasprunLoader: def setup_method(self): self.loader = VasprunLoader(VASP_RUN) assert self.loader.proj.shape == (120, 20, 2, 9) @@ -126,7 +125,7 @@ def test_from_file(self): assert self.loader is not None -class TestBztInterpolator(TestCase): +class TestBztInterpolator: def setup_method(self): with ScratchDir("."): shutil.copy(BZT_INTERP_FN, ".") @@ -205,7 +204,7 @@ def test_tot_proj_dos(self): assert pdos == approx(272.194174, abs=1e-5) -class TestBztTransportProperties(TestCase): +class TestBztTransportProperties: def setup_method(self): with ScratchDir("."): shutil.copy(BZT_TRANSP_FN, ".") diff --git a/tests/electronic_structure/test_cohp.py b/tests/electronic_structure/test_cohp.py index ed362e37103..78f09623d09 100644 --- a/tests/electronic_structure/test_cohp.py +++ b/tests/electronic_structure/test_cohp.py @@ -1,7 +1,6 @@ from __future__ import annotations import json -from unittest import TestCase import pytest from numpy.testing import assert_allclose, assert_array_equal @@ -20,7 +19,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/electronic_structure/cohp" -class TestCohp(TestCase): +class TestCohp: def setup_method(self): with open(f"{TEST_DIR}/cohp.json") as file: self.cohp = Cohp.from_dict(json.load(file)) @@ -90,7 +89,7 @@ def test_antibnd_states_below_efermi(self): assert self.cohp.has_antibnd_states_below_efermi(spin=Spin.up, limit=0.5) == {Spin.up: False} -class TestIcohpValue(TestCase): +class TestIcohpValue: def setup_method(self): # without spin polarization label = "1" @@ -168,7 +167,7 @@ def test_str(self): assert str(self.icohpvalue_sp) == expected -class TestCombinedIcohp(TestCase): +class TestCombinedIcohp: def setup_method(self): # without spin polarization: are_coops = are_cobis = is_spin_polarized = False @@ -1262,7 +1261,7 @@ def test_orbital_resolved_cohp_summed_spin_channels(self): ).are_coops -class TestMethod(TestCase): +class TestMethod: def setup_method(self): filepath = f"{TEST_DIR}/COHPCAR.lobster.gz" structure = f"{TEST_DIR}/POSCAR" diff --git a/tests/electronic_structure/test_dos.py b/tests/electronic_structure/test_dos.py index 9a10cc1ed74..fa0f5b1ff91 100644 --- a/tests/electronic_structure/test_dos.py +++ b/tests/electronic_structure/test_dos.py @@ -2,7 +2,6 @@ import json import re -from unittest import TestCase import numpy as np import pytest @@ -19,7 +18,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/electronic_structure/dos" -class TestDos(TestCase): +class TestDos: def setup_method(self): with open(f"{TEST_DIR}/complete_dos.json") as file: self.dos = CompleteDos.from_dict(json.load(file)) @@ -57,7 +56,7 @@ def test_as_dict(self): assert not isinstance(dos_dict["densities"]["1"][0], np.float64) -class TestFermiDos(TestCase): +class TestFermiDos: def setup_method(self): with open(f"{TEST_DIR}/complete_dos.json") as file: self.dos = CompleteDos.from_dict(json.load(file)) @@ -104,7 +103,7 @@ def test_as_dict(self): assert not isinstance(dos_dict["densities"]["1"][0], np.float64) -class TestCompleteDos(TestCase): +class TestCompleteDos: def setup_method(self): with open(f"{TEST_DIR}/complete_dos.json") as file: self.dos = CompleteDos.from_dict(json.load(file)) @@ -351,14 +350,14 @@ def test_get_gap(self): assert_allclose(self.dos.get_cbm_vbm(spin=Spin.down), (4.645, 1.8140000000000001)) -class TestSpinPolarization(TestCase): +class TestSpinPolarization: def test_spin_polarization(self): dos_path = f"{TEST_DIR}/dos_spin_polarization_mp-865805.json" dos = loadfn(dos_path) assert dos.spin_polarization == approx(0.6460514663341762) -class TestLobsterCompleteDos(TestCase): +class TestLobsterCompleteDos: def setup_method(self): with open(f"{TEST_DIR}/LobsterCompleteDos_spin.json") as file: data_spin = json.load(file) diff --git a/tests/electronic_structure/test_plotter.py b/tests/electronic_structure/test_plotter.py index 8dc211a0d40..813dfa4a556 100644 --- a/tests/electronic_structure/test_plotter.py +++ b/tests/electronic_structure/test_plotter.py @@ -3,7 +3,6 @@ import json import os from shutil import which -from unittest import TestCase import matplotlib.pyplot as plt import numpy as np @@ -184,7 +183,7 @@ def test_get_plot(self): plt.close("all") -class TestBSPlotterProjected(TestCase): +class TestBSPlotterProjected: def setup_method(self): with open(f"{BAND_TEST_DIR}/Cu2O_361_bandstructure.json") as file: self.bs_Cu2O = BandStructureSymmLine.from_dict(json.load(file)) @@ -257,7 +256,7 @@ def test_methods(self): assert isinstance(ax, plt.Axes) -class TestPlotBZ(TestCase): +class TestPlotBZ: def setup_method(self): self.rec_latt = Structure.from_file(f"{TEST_FILES_DIR}/io/cssr/Si.cssr").lattice.reciprocal_lattice self.kpath = [[[0.0, 0.0, 0.0], [0.5, 0.0, 0.5], [0.5, 0.25, 0.75], [0.375, 0.375, 0.75]]] @@ -303,7 +302,7 @@ def test_fold_point(self): @pytest.mark.skip("TODO: need someone to fix this") @pytest.mark.skipif(not which("x_trans"), reason="No x_trans executable found") -class TestBoltztrapPlotter(TestCase): +class TestBoltztrapPlotter: def setup_method(self): bz = BoltztrapAnalyzer.from_files(f"{TEST_FILES_DIR}/boltztrap/transp/") self.plotter = BoltztrapPlotter(bz) diff --git a/tests/entries/test_compatibility.py b/tests/entries/test_compatibility.py index 45d031e6caa..4130c2d108c 100644 --- a/tests/entries/test_compatibility.py +++ b/tests/entries/test_compatibility.py @@ -7,7 +7,6 @@ from collections import defaultdict from pathlib import Path from typing import TYPE_CHECKING -from unittest import TestCase import pytest from monty.json import MontyDecoder @@ -43,7 +42,7 @@ @pytest.mark.filterwarnings("ignore:MaterialsProjectCompatibility is deprecated") -class TestCorrectionSpecificity(TestCase): +class TestCorrectionSpecificity: """Make sure corrections are only applied to GGA or GGA+U entries.""" def setup_method(self): @@ -204,7 +203,7 @@ def test_overlapping_adjustments(): @pytest.mark.filterwarnings("ignore:MaterialsProjectCompatibility is deprecated") -class TestMaterialsProjectCompatibility(TestCase): +class TestMaterialsProjectCompatibility: def setup_method(self): self.entry1 = ComputedEntry( "Fe2O3", @@ -621,7 +620,7 @@ def test_msonable(self): assert isinstance(temp_compat, MaterialsProjectCompatibility) -class TestMaterialsProjectCompatibility2020(TestCase): +class TestMaterialsProjectCompatibility2020: def setup_method(self): self.entry1 = ComputedEntry( "Fe2O3", @@ -1315,7 +1314,7 @@ def test_many_anions(self): assert processed_entry.energy == -1 -class TestMITCompatibility(TestCase): +class TestMITCompatibility: def setup_method(self): self.compat = MITCompatibility(check_potcar_hash=True) self.gga_compat = MITCompatibility("GGA", check_potcar_hash=True) @@ -1655,7 +1654,7 @@ def test_msonable(self): assert isinstance(temp_compat, MITCompatibility) -class TestOxideTypeCorrection(TestCase): +class TestOxideTypeCorrection: def setup_method(self): self.compat = MITCompatibility(check_potcar_hash=True) @@ -1826,7 +1825,7 @@ def test_process_entry_oxide(self): assert li2o_entry_corrected.energy == approx(-3.0 - 0.66975) -class TestSulfideTypeCorrection2020(TestCase): +class TestSulfideTypeCorrection2020: def setup_method(self): self.compat = MaterialsProject2020Compatibility(check_potcar_hash=False) @@ -1986,7 +1985,7 @@ def test_struct_no_struct(self): assert struct_corrected.correction == approx(nostruct_corrected.correction) -class TestOxideTypeCorrectionNoPeroxideCorr(TestCase): +class TestOxideTypeCorrectionNoPeroxideCorr: def setup_method(self): self.compat = MITCompatibility(correct_peroxide=False) @@ -2254,7 +2253,7 @@ def test_parallel_process_entries(self): assert len(entries) == 2 -class TestAqueousCorrection(TestCase): +class TestAqueousCorrection: def setup_method(self): fp = f"{PMG_ENTRIES_DIR}/MITCompatibility.yaml" self.corr = AqueousCorrection(fp) @@ -2281,7 +2280,7 @@ def test_compound_energy(self): assert entry.energy == approx(-24.344373) -class TestMITAqueousCompatibility(TestCase): +class TestMITAqueousCompatibility: def setup_method(self): self.compat = MITCompatibility(check_potcar_hash=True) self.aqcompat = MITAqueousCompatibility(check_potcar_hash=True) @@ -2392,7 +2391,7 @@ def test_dont_error_on_weird_elements(self): assert self.compat.process_entry(entry) is None -class TestCorrectionErrors2020Compatibility(TestCase): +class TestCorrectionErrors2020Compatibility: def setup_method(self): self.compat = MaterialsProject2020Compatibility() diff --git a/tests/entries/test_computed_entries.py b/tests/entries/test_computed_entries.py index 63ce5c21d8f..d7e6eb17cd0 100644 --- a/tests/entries/test_computed_entries.py +++ b/tests/entries/test_computed_entries.py @@ -3,7 +3,6 @@ import copy import json from collections import defaultdict -from unittest import TestCase import pytest from monty.json import MontyDecoder @@ -95,7 +94,7 @@ def test_temp_energy_adjustment(): assert str(ea_dct) == str(ea2.as_dict()) -class TestComputedEntry(TestCase): +class TestComputedEntry: def setup_method(self): self.entry = ComputedEntry( vasp_run.final_structure.composition, @@ -256,7 +255,7 @@ def test_from_dict_null_fields(self): assert getattr(new_ce, k, None) is not None -class TestComputedStructureEntry(TestCase): +class TestComputedStructureEntry: def setup_method(self): self.entry = ComputedStructureEntry(vasp_run.final_structure, vasp_run.final_energy, parameters=vasp_run.incar) @@ -453,7 +452,7 @@ def test_eq(self): assert copy3 != copy1 -class TestGibbsComputedStructureEntry(TestCase): +class TestGibbsComputedStructureEntry: def setup_method(self): self.temps = [300, 600, 900, 1200, 1500, 1800] self.struct = vasp_run.final_structure diff --git a/tests/entries/test_correction_calculator.py b/tests/entries/test_correction_calculator.py index 66718efe212..d0dfa81e039 100644 --- a/tests/entries/test_correction_calculator.py +++ b/tests/entries/test_correction_calculator.py @@ -1,7 +1,5 @@ from __future__ import annotations -from unittest import TestCase - import pytest from pymatgen.entries.correction_calculator import CorrectionCalculator @@ -10,7 +8,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/entries/correction_calculator" -class TestCorrectionCalculator(TestCase): +class TestCorrectionCalculator: def setup_method(self): self.exclude_polyanions = [ "SO4", diff --git a/tests/entries/test_exp_entries.py b/tests/entries/test_exp_entries.py index b9752eae71f..6a555d6e702 100644 --- a/tests/entries/test_exp_entries.py +++ b/tests/entries/test_exp_entries.py @@ -1,7 +1,6 @@ from __future__ import annotations import json -from unittest import TestCase from monty.json import MontyDecoder from pytest import approx @@ -10,7 +9,7 @@ from pymatgen.util.testing import TEST_FILES_DIR -class TestExpEntry(TestCase): +class TestExpEntry: def setup_method(self): with open(f"{TEST_FILES_DIR}/entries/Fe2O3_exp.json") as file: thermo_data = json.load(file, cls=MontyDecoder) diff --git a/tests/io/cp2k/test_outputs.py b/tests/io/cp2k/test_outputs.py index 19762d1bfb2..ee8496beba0 100644 --- a/tests/io/cp2k/test_outputs.py +++ b/tests/io/cp2k/test_outputs.py @@ -1,7 +1,5 @@ from __future__ import annotations -from unittest import TestCase - import numpy as np from numpy.testing import assert_allclose from pytest import approx @@ -12,7 +10,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/io/cp2k" -class TestCp2kOutput(TestCase): +class TestCp2kOutput: def setup_method(self): self.out = Cp2kOutput(f"{TEST_DIR}/cp2k.out", auto_load=True) diff --git a/tests/io/feff/test_inputs.py b/tests/io/feff/test_inputs.py index ea95c1b25e6..0be11ecc836 100644 --- a/tests/io/feff/test_inputs.py +++ b/tests/io/feff/test_inputs.py @@ -1,7 +1,6 @@ from __future__ import annotations import os -from unittest import TestCase from numpy.testing import assert_allclose from pytest import approx @@ -27,7 +26,7 @@ * 4 O 0.333333 0.666667 0.378675""" -class TestHeader(TestCase): +class TestHeader: def test_init(self): filepath = f"{FEFF_TEST_DIR}/HEADER" header = Header.header_string_from_file(filepath) @@ -56,7 +55,7 @@ def test_as_dict_and_from_dict(self): assert str(header) == str(header2), "Header failed to and from dict test" -class TestFeffAtoms(TestCase): +class TestFeffAtoms: @classmethod def setup_class(cls): cls.structure = Structure.from_file(f"{TEST_FILES_DIR}/cif/CoO19128.cif") @@ -143,7 +142,7 @@ def test_atom_num(self): assert atoms.formula == "Pt37" -class TestFeffTags(TestCase): +class TestFeffTags: def test_init(self): filepath = f"{FEFF_TEST_DIR}/PARAMETERS" parameters = Tags.from_file(filepath) @@ -212,7 +211,7 @@ def test_eels_tags(self): assert dict(tags_2) == ans_1 -class TestFeffPot(TestCase): +class TestFeffPot: def test_init(self): filepath = f"{FEFF_TEST_DIR}/POTENTIALS" feff_pot = Potential.pot_string_from_file(filepath) @@ -245,7 +244,7 @@ def test_as_dict_and_from_dict(self): assert str(pot) == str(pot2), "Potential to and from dict does not match" -class TestPaths(TestCase): +class TestPaths: def setup_method(self): feo = Structure.from_dict( { diff --git a/tests/io/feff/test_outputs.py b/tests/io/feff/test_outputs.py index 9fcadc3c5bc..43416551924 100644 --- a/tests/io/feff/test_outputs.py +++ b/tests/io/feff/test_outputs.py @@ -1,14 +1,12 @@ from __future__ import annotations -from unittest import TestCase - from pymatgen.io.feff.outputs import LDos, Xmu from pymatgen.util.testing import TEST_FILES_DIR FEFF_TEST_DIR = f"{TEST_FILES_DIR}/io/feff" -class TestFeffLdos(TestCase): +class TestFeffLdos: filepath1 = f"{FEFF_TEST_DIR}/feff.inp" filepath2 = f"{FEFF_TEST_DIR}/ldos" ldos = LDos.from_file(filepath1, filepath2) @@ -49,7 +47,7 @@ def test_reci_charge(self): assert charge_trans["1"]["O"]["tot"] == -0.594 -class TestXmu(TestCase): +class TestXmu: def test_init(self): filepath1 = f"{FEFF_TEST_DIR}/xmu.dat" filepath2 = f"{FEFF_TEST_DIR}/feff.inp" diff --git a/tests/io/lammps/test_data.py b/tests/io/lammps/test_data.py index 9da40c48b7c..53bc5005080 100644 --- a/tests/io/lammps/test_data.py +++ b/tests/io/lammps/test_data.py @@ -2,7 +2,6 @@ import gzip import json -from unittest import TestCase import numpy as np import pandas as pd @@ -543,7 +542,7 @@ def test_json_dict(self): assert pd.testing.assert_frame_equal(c2h6.topology[key], target_df) is None, key -class TestTopology(TestCase): +class TestTopology: def test_init(self): rng = np.random.default_rng() inner_charge = rng.random(10) - 0.5 @@ -785,7 +784,7 @@ def test_from_dict(self): assert decoded.topo_coeffs == self.ethane.topo_coeffs -class TestFunc(TestCase): +class TestFunc: def test_lattice_2_lmpbox(self): rng = np.random.default_rng() matrix = np.diag(rng.integers(5, 14, size=(3,))) + rng.random((3, 3)) * 0.2 - 0.1 @@ -818,7 +817,7 @@ def test_lattice_2_lmpbox(self): ) -class TestCombinedData(TestCase): +class TestCombinedData: @classmethod def setup_class(cls): cls.ec = LammpsData.from_file(filename=f"{TEST_DIR}/ec.data.gz") diff --git a/tests/io/lammps/test_outputs.py b/tests/io/lammps/test_outputs.py index 15b482c3d7c..cfcea3e2675 100644 --- a/tests/io/lammps/test_outputs.py +++ b/tests/io/lammps/test_outputs.py @@ -2,7 +2,6 @@ import json import os -from unittest import TestCase import numpy as np import pandas as pd @@ -14,7 +13,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/io/lammps" -class TestLammpsDump(TestCase): +class TestLammpsDump: @classmethod def setup_class(cls): with open(f"{TEST_DIR}/dump.rdx_wc.100") as file: @@ -54,7 +53,7 @@ def test_json_dict(self): pd.testing.assert_frame_equal(rdx.data, self.rdx.data) -class TestFunc(TestCase): +class TestFunc: def test_parse_lammps_dumps(self): # gzipped rdx_10_pattern = f"{TEST_DIR}/dump.rdx.gz" diff --git a/tests/io/lammps/test_utils.py b/tests/io/lammps/test_utils.py index ed3f6790580..f3c7551b30f 100644 --- a/tests/io/lammps/test_utils.py +++ b/tests/io/lammps/test_utils.py @@ -1,7 +1,5 @@ from __future__ import annotations -from unittest import TestCase - from pymatgen.core.structure import Molecule from pymatgen.io.lammps.data import Topology from pymatgen.io.lammps.utils import Polymer @@ -10,7 +8,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/io/lammps" -class TestPolymer(TestCase): +class TestPolymer: @classmethod def setup_class(cls): # head molecule @@ -82,7 +80,7 @@ def test_polymer_chain_topologies(self): assert topology_linear.topologies["Dihedrals"] != topology_random.topologies["Dihedrals"] -class TestPackmolOutput(TestCase): +class TestPackmolOutput: @classmethod def setup_class(cls): ethanol_coords = [ diff --git a/tests/io/lobster/test_lobsterenv.py b/tests/io/lobster/test_lobsterenv.py index 52505d4670e..a18b788c926 100644 --- a/tests/io/lobster/test_lobsterenv.py +++ b/tests/io/lobster/test_lobsterenv.py @@ -1,7 +1,5 @@ from __future__ import annotations -from unittest import TestCase - import numpy as np import pytest from pytest import approx @@ -24,7 +22,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/electronic_structure/cohp/environments" -class TestLobsterNeighbors(TestCase): +class TestLobsterNeighbors: def setup_method(self): # test additional conditions first # only consider cation anion bonds diff --git a/tests/io/lobster/test_outputs.py b/tests/io/lobster/test_outputs.py index 91a1a20bd49..5728aac419d 100644 --- a/tests/io/lobster/test_outputs.py +++ b/tests/io/lobster/test_outputs.py @@ -3,7 +3,6 @@ import copy import json import os -from unittest import TestCase import numpy as np import pytest @@ -398,7 +397,7 @@ def test_orbital_resolved_cohp(self): assert len(self.cobi6.orb_res_cohp["21"]["2py-1s-2s"]["COHP"][Spin.down]) == 12 -class TestDoscar(TestCase): +class TestDoscar: def setup_method(self): # first for spin polarized version doscar = f"{VASP_OUT_DIR}/DOSCAR.lobster.spin" @@ -1480,7 +1479,7 @@ def test_get_bandstructure(self): assert bs_p_x.get_projection_on_elements()[Spin.up][0][0]["Si"] == approx(3 * (0.001 + 0.064), abs=1e-2) -class TestBandoverlaps(TestCase): +class TestBandoverlaps: def setup_method(self): # test spin-polarized calc and non spin-polarized calc @@ -1713,7 +1712,7 @@ def test_keys(self): assert len(bo_dict_new[Spin.down]["matrices"]) == 73 -class TestGrosspop(TestCase): +class TestGrosspop: def setup_method(self): self.grosspop1 = Grosspop(f"{TEST_DIR}/GROSSPOP.lobster") self.grosspop_511_sp = Grosspop(f"{TEST_DIR}/GROSSPOP_511_sp.lobster.AlN.gz") @@ -1863,7 +1862,7 @@ def test_msonable(self): assert getattr(grosspop_from_dict, attr_name) == attr_value -class TestIcohplist(TestCase): +class TestIcohplist: def setup_method(self): self.icohp_bise = Icohplist(filename=f"{TEST_DIR}/ICOHPLIST.lobster.BiSe") self.icoop_bise = Icohplist( @@ -2168,7 +2167,7 @@ def test_msonable(self): assert getattr(icohplist_from_dict, attr_name) == attr_value -class TestNciCobiList(TestCase): +class TestNciCobiList: def setup_method(self): self.ncicobi = NciCobiList(filename=f"{TEST_DIR}/NcICOBILIST.lobster") self.ncicobi_gz = NciCobiList(filename=f"{TEST_DIR}/NcICOBILIST.lobster.gz") diff --git a/tests/io/test_babel.py b/tests/io/test_babel.py index 32087bd3ac4..803634de0a5 100644 --- a/tests/io/test_babel.py +++ b/tests/io/test_babel.py @@ -2,7 +2,6 @@ import copy import platform -from unittest import TestCase import pytest from pytest import approx @@ -17,7 +16,7 @@ pybel = pytest.importorskip("openbabel.pybel") -class TestBabelMolAdaptor(TestCase): +class TestBabelMolAdaptor: def setup_method(self): coords = [ [0.000000, 0.000000, 0.000000], diff --git a/tests/io/test_cssr.py b/tests/io/test_cssr.py index 951dab817e8..84b67c3e58e 100644 --- a/tests/io/test_cssr.py +++ b/tests/io/test_cssr.py @@ -2,8 +2,6 @@ from __future__ import annotations -from unittest import TestCase - from pymatgen.core.structure import Structure from pymatgen.io.cssr import Cssr from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR @@ -18,7 +16,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/io/cssr" -class TestCssr(TestCase): +class TestCssr: def setup_method(self): filepath = f"{VASP_IN_DIR}/POSCAR" self.cssr = Cssr(Structure.from_file(filepath)) diff --git a/tests/io/test_fiesta.py b/tests/io/test_fiesta.py index d5bce31b5ba..00b7f0acf0d 100644 --- a/tests/io/test_fiesta.py +++ b/tests/io/test_fiesta.py @@ -1,7 +1,5 @@ from __future__ import annotations -from unittest import TestCase - from pymatgen.core.structure import Molecule from pymatgen.io.fiesta import FiestaInput, FiestaOutput from pymatgen.util.testing import TEST_FILES_DIR @@ -9,7 +7,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/io/fiesta" -class TestFiestaInput(TestCase): +class TestFiestaInput: def setup_method(self): coords = [ [0.000000, 0.000000, 0.000000], @@ -71,7 +69,7 @@ def test_str_and_from_str(self): assert cell_in.cohsex_options["eigMethod"] == "C" -class TestFiestaOutput(TestCase): +class TestFiestaOutput: def setup_method(self): self.log_fiesta = FiestaOutput(f"{TEST_DIR}/log_fiesta") diff --git a/tests/io/test_gaussian.py b/tests/io/test_gaussian.py index 9a5ec7ad0e1..208ef9762e7 100644 --- a/tests/io/test_gaussian.py +++ b/tests/io/test_gaussian.py @@ -1,7 +1,5 @@ from __future__ import annotations -from unittest import TestCase - import pytest from pytest import approx @@ -13,7 +11,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/io/gaussian" -class TestGaussianInput(TestCase): +class TestGaussianInput: def setup_method(self): coords = [ [0, 0, 0], @@ -278,7 +276,7 @@ def test_no_molecule_func_bset_charge_mult(self): assert input_str == gau_str -class TestGaussianOutput(TestCase): +class TestGaussianOutput: # TODO: Add unittest for PCM type output. def setup_method(self): diff --git a/tests/io/test_nwchem.py b/tests/io/test_nwchem.py index beb3e40366a..cf08d9d96f2 100644 --- a/tests/io/test_nwchem.py +++ b/tests/io/test_nwchem.py @@ -1,7 +1,6 @@ from __future__ import annotations import json -from unittest import TestCase import pytest from pytest import approx @@ -22,7 +21,7 @@ mol = Molecule(["C", "H", "H", "H", "H"], coords) -class TestNwTask(TestCase): +class TestNwTask: def setup_method(self): self.task = NwTask( 0, @@ -136,7 +135,7 @@ def test_esp_task(self): assert str(task) == answer -class TestNwInput(TestCase): +class TestNwInput: def setup_method(self): tasks = [ NwTask.dft_task(mol, operation="optimize", xc="b3lyp", basis_set="6-31++G*"), diff --git a/tests/io/test_phonopy.py b/tests/io/test_phonopy.py index b9ff2ccaf9a..a34bb5bb9a2 100644 --- a/tests/io/test_phonopy.py +++ b/tests/io/test_phonopy.py @@ -3,7 +3,6 @@ import os import platform from pathlib import Path -from unittest import TestCase import numpy as np import pytest @@ -162,7 +161,7 @@ def test_get_displaced_structures(self): platform.system() == "Windows" and int(np.__version__[0]) >= 2, reason="See https://github.com/conda-forge/phonopy-feedstock/pull/158#issuecomment-2227506701", ) -class TestPhonopyFromForceConstants(TestCase): +class TestPhonopyFromForceConstants: def setup_method(self) -> None: test_path = Path(TEST_DIR) structure_file = test_path / "POSCAR-NaCl" diff --git a/tests/io/test_xr.py b/tests/io/test_xr.py index 8321c2340af..78068a65d81 100644 --- a/tests/io/test_xr.py +++ b/tests/io/test_xr.py @@ -1,7 +1,5 @@ from __future__ import annotations -from unittest import TestCase - from pymatgen.core.structure import Structure from pymatgen.io.xr import Xr from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR @@ -14,7 +12,7 @@ __date__ = "June 23, 2016" -class TestXr(TestCase): +class TestXr: def setup_method(self): struct = Structure.from_file(f"{VASP_IN_DIR}/POSCAR") self.xr = Xr(struct) diff --git a/tests/io/test_xyz.py b/tests/io/test_xyz.py index e0ad2ea6f1a..2e23887708e 100644 --- a/tests/io/test_xyz.py +++ b/tests/io/test_xyz.py @@ -1,7 +1,5 @@ from __future__ import annotations -from unittest import TestCase - import pandas as pd import pytest from pytest import approx @@ -12,7 +10,7 @@ from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR -class TestXYZ(TestCase): +class TestXYZ: def setup_method(self): coords = [ [0, 0, 0], diff --git a/tests/io/test_zeopp.py b/tests/io/test_zeopp.py index f049ffccc97..4ea07b5766b 100644 --- a/tests/io/test_zeopp.py +++ b/tests/io/test_zeopp.py @@ -1,7 +1,5 @@ from __future__ import annotations -from unittest import TestCase - import pytest from pytest import approx @@ -28,7 +26,7 @@ __date__ = "Aug 2, 2013" -class TestZeoCssr(TestCase): +class TestZeoCssr: def setup_method(self): filepath = f"{VASP_IN_DIR}/POSCAR" self.zeo_cssr = ZeoCssr(Structure.from_file(filepath)) @@ -70,7 +68,7 @@ def test_from_file(self): assert isinstance(zeo_cssr.structure, Structure) -class TestZeoCssrOxi(TestCase): +class TestZeoCssrOxi: def setup_method(self): filepath = f"{VASP_IN_DIR}/POSCAR" structure = BVAnalyzer().get_oxi_state_decorated_structure(Structure.from_file(filepath)) @@ -113,7 +111,7 @@ def test_from_file(self): assert isinstance(zeocssr.structure, Structure) -class TestZeoVoronoiXYZ(TestCase): +class TestZeoVoronoiXYZ: def setup_method(self): coords = [ [0.000000, 0.000000, 0.000000], @@ -143,7 +141,7 @@ def test_from_file(self): assert isinstance(voronoi.molecule, Molecule) -class TestGetVoronoiNodes(TestCase): +class TestGetVoronoiNodes: def setup_method(self): filepath = f"{VASP_IN_DIR}/POSCAR" self.structure = Structure.from_file(filepath) @@ -167,7 +165,7 @@ def test_get_voronoi_nodes(self): @pytest.mark.skip("TODO: file free_sph.cif not present") -class TestGetFreeSphereParams(TestCase): +class TestGetFreeSphereParams: def setup_method(self): filepath = f"{TEST_FILES_DIR}/cif/free_sph.cif" self.structure = Structure.from_file(filepath) @@ -188,7 +186,7 @@ def test_get_free_sphere_params(self): assert free_sph_params["inc_sph_along_free_sph_path_max_dia"] == approx(2.58251, abs=1e-1) -class TestGetHighAccuracyVoronoiNodes(TestCase): +class TestGetHighAccuracyVoronoiNodes: def setup_method(self): filepath = f"{VASP_IN_DIR}/POSCAR" self.structure = Structure.from_file(filepath) @@ -207,7 +205,7 @@ def test_get_voronoi_nodes(self): assert isinstance(vor_node_struct, Structure) -class TestGetVoronoiNodesMultiOxi(TestCase): +class TestGetVoronoiNodesMultiOxi: def setup_method(self): filepath = f"{VASP_IN_DIR}/POSCAR" self.structure = Structure.from_file(filepath) diff --git a/tests/io/vasp/test_inputs.py b/tests/io/vasp/test_inputs.py index decccb7a344..6cc48511378 100644 --- a/tests/io/vasp/test_inputs.py +++ b/tests/io/vasp/test_inputs.py @@ -7,7 +7,6 @@ import re import warnings from shutil import copyfile -from unittest import TestCase from unittest.mock import patch import numpy as np @@ -1297,7 +1296,7 @@ def test_automatic_monkhorst_vs_gamma_style_selection(self): @pytest.mark.filterwarnings( "ignore:POTCAR data with symbol .* is not known to pymatgen:pymatgen.io.vasp.inputs.UnknownPotcarWarning" ) -class TestPotcarSingle(TestCase): +class TestPotcarSingle: def setup_method(self): self.psingle_Mn_pv = PotcarSingle.from_file(f"{FAKE_POTCAR_DIR}/POT_GGA_PAW_PBE/POTCAR.Mn_pv.gz") self.psingle_Fe = PotcarSingle.from_file(f"{FAKE_POTCAR_DIR}/POT_GGA_PAW_PBE/POTCAR.Fe.gz") diff --git a/tests/optimization/test_linear_assignment.py b/tests/optimization/test_linear_assignment.py index 961a5032b6d..cc29fe5d713 100644 --- a/tests/optimization/test_linear_assignment.py +++ b/tests/optimization/test_linear_assignment.py @@ -1,7 +1,5 @@ from __future__ import annotations -from unittest import TestCase - import numpy as np import pytest from pytest import approx @@ -9,7 +7,7 @@ from pymatgen.optimization.linear_assignment import LinearAssignment -class TestLinearAssignment(TestCase): +class TestLinearAssignment: def test(self): w0 = np.array( [ diff --git a/tests/phonon/test_plotter.py b/tests/phonon/test_plotter.py index 49e32b1c326..8ad15dd55e0 100644 --- a/tests/phonon/test_plotter.py +++ b/tests/phonon/test_plotter.py @@ -1,7 +1,6 @@ from __future__ import annotations import json -from unittest import TestCase import matplotlib.pyplot as plt import pytest @@ -16,7 +15,7 @@ plt.rc("text", usetex=False) # Disabling latex for testing -class TestPhononDosPlotter(TestCase): +class TestPhononDosPlotter: def setup_method(self): with open(f"{TEST_DIR}/NaCl_complete_ph_dos.json") as file: self.dos = CompletePhononDos.from_dict(json.load(file)) @@ -54,7 +53,7 @@ def test_plot(self): assert ax3.get_ylim() == ax.get_xlim() -class TestPhononBSPlotter(TestCase): +class TestPhononBSPlotter: def setup_method(self): with open(f"{TEST_FILES_DIR}/electronic_structure/bandstructure/NaCl_phonon_bandstructure.json") as file: dct = json.loads(file.read()) @@ -113,7 +112,7 @@ def test_plot_compare(self): assert ax is None -class TestThermoPlotter(TestCase): +class TestThermoPlotter: def setup_method(self): with open(f"{TEST_DIR}/NaCl_complete_ph_dos.json") as file: self.dos = CompletePhononDos.from_dict(json.load(file)) diff --git a/tests/symmetry/test_analyzer.py b/tests/symmetry/test_analyzer.py index a4faa165678..7500b959576 100644 --- a/tests/symmetry/test_analyzer.py +++ b/tests/symmetry/test_analyzer.py @@ -1,7 +1,6 @@ from __future__ import annotations from dataclasses import asdict -from unittest import TestCase import numpy as np import pytest @@ -444,7 +443,7 @@ def test_bad_structure(self): SpacegroupAnalyzer(struct, 0.1) -class TestSpacegroup(TestCase): +class TestSpacegroup: def setup_method(self): self.structure = Structure.from_file(f"{VASP_IN_DIR}/POSCAR") self.sg1 = SpacegroupAnalyzer(self.structure, 0.001).get_space_group_operations() @@ -703,7 +702,7 @@ def test_get_kpoint_weights(self): spga.get_kpoint_weights(kpts) -class TestFunc(TestCase): +class TestFunc: def test_cluster_sites(self): site, cluster = cluster_sites(CH4, 0.1) assert isinstance(site, Site) diff --git a/tests/symmetry/test_settings.py b/tests/symmetry/test_settings.py index be51dfbb1df..5d4d2db24be 100644 --- a/tests/symmetry/test_settings.py +++ b/tests/symmetry/test_settings.py @@ -1,7 +1,5 @@ from __future__ import annotations -from unittest import TestCase - import numpy as np from numpy.testing import assert_allclose @@ -16,7 +14,7 @@ __date__ = "Apr 2017" -class TestJonesFaithfulTransformation(TestCase): +class TestJonesFaithfulTransformation: def setup_method(self): self.test_strings = [ "a,b,c;0,0,0", # identity diff --git a/tests/transformations/test_site_transformations.py b/tests/transformations/test_site_transformations.py index b63057c5f80..8e5efebf250 100644 --- a/tests/transformations/test_site_transformations.py +++ b/tests/transformations/test_site_transformations.py @@ -1,7 +1,6 @@ from __future__ import annotations from shutil import which -from unittest import TestCase import numpy as np import pytest @@ -78,7 +77,7 @@ def test_as_from_dict(self): str(t2) -class TestReplaceSiteSpeciesTransformation(TestCase): +class TestReplaceSiteSpeciesTransformation: def setup_method(self): coords = [ [0, 0, 0], @@ -110,7 +109,7 @@ def test_as_from_dict(self): assert struct.formula == "Na1 Li3 O4" -class TestRemoveSitesTransformation(TestCase): +class TestRemoveSitesTransformation: def setup_method(self): coords = [ [0, 0, 0], @@ -142,7 +141,7 @@ def test_as_from_dict(self): assert struct.formula == "Li2 O4" -class TestInsertSitesTransformation(TestCase): +class TestInsertSitesTransformation: def setup_method(self): coords = [ [0, 0, 0], @@ -179,7 +178,7 @@ def test_as_from_dict(self): assert struct.formula == "Li4 Mn1 Fe1 O4" -class TestPartialRemoveSitesTransformation(TestCase): +class TestPartialRemoveSitesTransformation: def setup_method(self): coords = [ [0, 0, 0], diff --git a/tests/transformations/test_standard_transformations.py b/tests/transformations/test_standard_transformations.py index 741081e052a..9aa2d387d69 100644 --- a/tests/transformations/test_standard_transformations.py +++ b/tests/transformations/test_standard_transformations.py @@ -4,7 +4,6 @@ import json import operator from shutil import which -from unittest import TestCase import numpy as np import pytest @@ -41,7 +40,7 @@ enumlib_present = which("enum.x") and which("makestr.x") -class TestRotationTransformations(TestCase): +class TestRotationTransformations: def setup_method(self): coords = [[0, 0, 0], [0.75, 0.5, 0.75]] lattice = [ @@ -108,7 +107,7 @@ def test_fractional_substitution(self): assert struct_trafo.formula == "Na2 Se1 S1" -class TestSupercellTransformation(TestCase): +class TestSupercellTransformation: def setup_method(self): coords = [[0, 0, 0], [0.75, 0.75, 0.75], [0.5, 0.5, 0.5], [0.25, 0.25, 0.25]] lattice = [ diff --git a/tests/util/test_coord.py b/tests/util/test_coord.py index 985d4100804..b8c9b08aaba 100644 --- a/tests/util/test_coord.py +++ b/tests/util/test_coord.py @@ -1,7 +1,5 @@ from __future__ import annotations -from unittest import TestCase - import numpy as np import pytest from numpy.testing import assert_allclose, assert_array_equal @@ -250,7 +248,7 @@ def test_get_angle(self): assert coord.get_angle(v1, v2, units="radians") == approx(0.9553166181245092) -class TestSimplex(TestCase): +class TestSimplex: def setup_method(self): coords = [[0, 0, 0], [0, 1, 0], [0, 0, 1], [1, 0, 0]] self.simplex = coord.Simplex(coords) diff --git a/tests/util/test_provenance.py b/tests/util/test_provenance.py index 41a1bea230e..c6c2d59bd72 100644 --- a/tests/util/test_provenance.py +++ b/tests/util/test_provenance.py @@ -3,7 +3,6 @@ from __future__ import annotations from datetime import datetime, timedelta, timezone -from unittest import TestCase import numpy as np import pytest @@ -20,7 +19,7 @@ __date__ = "2/14/13" -class TestStructureNL(TestCase): +class TestStructureNL: def setup_method(self): # set up a Structure self.struct = Structure(np.eye(3, 3) * 3, ["Fe"], [[0, 0, 0]]) From 98f7fc7df9ed1212a034e7a21dff5bac845ef7bc Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Wed, 4 Dec 2024 23:25:08 +0800 Subject: [PATCH 17/31] global replace inheritance from PymatgenTest --- tests/alchemy/test_filters.py | 4 +- tests/alchemy/test_materials.py | 2 +- tests/alchemy/test_transmuters.py | 4 +- .../connectivity/test_connected_components.py | 2 +- .../connectivity/test_environment_nodes.py | 2 +- .../test_structure_connectivity.py | 2 +- .../test_chemenv_strategies.py | 2 +- .../test_coordination_geometries.py | 2 +- .../test_coordination_geometry_finder.py | 2 +- .../test_read_write.py | 2 +- .../test_structure_environments.py | 2 +- .../coordination_environments/test_voronoi.py | 2 +- .../coordination_environments/test_weights.py | 2 +- .../chemenv/utils/test_chemenv_config.py | 2 +- .../utils/test_coordination_geometry_utils.py | 2 +- .../chemenv/utils/test_graph_utils.py | 4 +- .../analysis/chemenv/utils/test_math_utils.py | 2 +- tests/analysis/diffraction/test_neutron.py | 2 +- tests/analysis/diffraction/test_tem.py | 2 +- tests/analysis/diffraction/test_xrd.py | 2 +- tests/analysis/elasticity/test_elastic.py | 8 +-- tests/analysis/elasticity/test_strain.py | 6 +-- tests/analysis/elasticity/test_stress.py | 2 +- .../ferroelectricity/test_polarization.py | 6 +-- .../interfaces/test_coherent_interface.py | 2 +- tests/analysis/interfaces/test_zsl.py | 2 +- tests/analysis/solar/test_slme.py | 2 +- .../structure_prediction/test_substitutor.py | 2 +- .../test_volume_predictor.py | 4 +- tests/analysis/test_adsorption.py | 2 +- tests/analysis/test_bond_valence.py | 4 +- tests/analysis/test_chempot_diagram.py | 2 +- tests/analysis/test_dimensionality.py | 6 +-- tests/analysis/test_disorder.py | 2 +- tests/analysis/test_eos.py | 2 +- tests/analysis/test_fragmenter.py | 2 +- tests/analysis/test_graphs.py | 2 +- tests/analysis/test_local_env.py | 28 +++++----- tests/analysis/test_nmr.py | 4 +- tests/analysis/test_phase_diagram.py | 2 +- tests/analysis/test_piezo.py | 2 +- tests/analysis/test_piezo_sensitivity.py | 2 +- tests/analysis/test_pourbaix_diagram.py | 2 +- tests/analysis/test_prototypes.py | 2 +- tests/analysis/test_structure_analyzer.py | 6 +-- tests/analysis/test_structure_matcher.py | 2 +- tests/analysis/test_surface_analysis.py | 8 +-- tests/analysis/test_transition_state.py | 2 +- tests/analysis/test_wulff.py | 2 +- tests/analysis/test_xps.py | 2 +- tests/analysis/topological/test_spillage.py | 2 +- tests/analysis/xas/test_spectrum.py | 2 +- tests/apps/battery/test_analyzer.py | 2 +- tests/command_line/test_bader_caller.py | 2 +- tests/command_line/test_enumlib_caller.py | 2 +- tests/command_line/test_mcsqs_caller.py | 2 +- tests/command_line/test_vampire_caller.py | 2 +- tests/core/test_composition.py | 2 +- tests/core/test_interface.py | 6 +-- tests/core/test_lattice.py | 2 +- tests/core/test_libxcfunc.py | 2 +- tests/core/test_molecular_orbitals.py | 2 +- tests/core/test_operations.py | 4 +- tests/core/test_periodic_table.py | 4 +- tests/core/test_sites.py | 4 +- tests/core/test_spectrum.py | 2 +- tests/core/test_structure.py | 10 ++-- tests/core/test_surface.py | 8 +-- tests/core/test_tensors.py | 6 +-- tests/core/test_trajectory.py | 2 +- tests/core/test_units.py | 8 +-- tests/core/test_xcfunc.py | 2 +- .../test_bandstructure.py | 6 +-- tests/electronic_structure/test_cohp.py | 2 +- tests/electronic_structure/test_dos.py | 2 +- tests/electronic_structure/test_plotter.py | 6 +-- tests/entries/test_entry_tools.py | 4 +- tests/ext/test_matproj.py | 4 +- tests/ext/test_optimade.py | 2 +- tests/io/abinit/test_abiobjects.py | 16 +++--- tests/io/abinit/test_inputs.py | 8 +-- tests/io/abinit/test_netcdf.py | 4 +- tests/io/abinit/test_pseudos.py | 4 +- tests/io/cp2k/test_inputs.py | 8 +-- tests/io/cp2k/test_sets.py | 2 +- tests/io/exciting/test_inputs.py | 2 +- tests/io/feff/test_sets.py | 2 +- tests/io/lammps/test_data.py | 6 +-- tests/io/lammps/test_generators.py | 2 +- tests/io/lammps/test_inputs.py | 8 +-- tests/io/lobster/test_inputs.py | 4 +- tests/io/lobster/test_outputs.py | 20 +++---- tests/io/pwmat/test_inputs.py | 8 +-- tests/io/pwmat/test_outputs.py | 8 +-- tests/io/qchem/test_inputs.py | 2 +- tests/io/qchem/test_outputs.py | 2 +- tests/io/qchem/test_sets.py | 14 ++--- tests/io/qchem/test_utils.py | 2 +- tests/io/test_adf.py | 2 +- tests/io/test_atat.py | 2 +- tests/io/test_cif.py | 6 +-- tests/io/test_core.py | 4 +- tests/io/test_lmto.py | 4 +- tests/io/test_packmol.py | 2 +- tests/io/test_phonopy.py | 8 +-- tests/io/test_pwscf.py | 4 +- tests/io/test_shengbte.py | 2 +- tests/io/test_template_input.py | 2 +- tests/io/test_wannier90.py | 2 +- tests/io/test_xcrysden.py | 2 +- tests/io/vasp/test_inputs.py | 8 +-- tests/io/vasp/test_optics.py | 2 +- tests/io/vasp/test_outputs.py | 26 +++++----- tests/io/vasp/test_sets.py | 52 +++++++++---------- tests/io/xtb/test_inputs.py | 2 +- tests/io/xtb/test_outputs.py | 2 +- tests/optimization/test_neighbors.py | 2 +- tests/phonon/test_bandstructure.py | 2 +- tests/phonon/test_dos.py | 4 +- tests/phonon/test_gruneisen.py | 4 +- tests/phonon/test_ir_spectra.py | 2 +- tests/phonon/test_thermal_displacements.py | 2 +- tests/symmetry/test_analyzer.py | 4 +- tests/symmetry/test_kpath_hin.py | 2 +- tests/symmetry/test_kpath_lm.py | 2 +- tests/symmetry/test_kpath_sc.py | 2 +- tests/symmetry/test_kpaths.py | 2 +- tests/symmetry/test_maggroups.py | 2 +- tests/symmetry/test_site_symmetries.py | 2 +- .../test_advanced_transformations.py | 22 ++++---- .../test_site_transformations.py | 6 +-- tests/util/test_io.py | 2 +- tests/util/test_plotting.py | 2 +- tests/vis/test_plotters.py | 2 +- 134 files changed, 295 insertions(+), 295 deletions(-) diff --git a/tests/alchemy/test_filters.py b/tests/alchemy/test_filters.py index a5bcc72ea10..f068db3cf91 100644 --- a/tests/alchemy/test_filters.py +++ b/tests/alchemy/test_filters.py @@ -16,7 +16,7 @@ from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest -class TestContainsSpecieFilter(PymatgenTest): +class TestContainsSpecieFilter(MatSciTest): def test_filtering(self): coords = [[0, 0, 0], [0.75, 0.75, 0.75], [0.5, 0.5, 0.5], [0.25, 0.25, 0.25]] lattice = Lattice([[3.0, 0.0, 0.0], [1.0, 3.0, 0], [0, -2.0, 3.0]]) @@ -51,7 +51,7 @@ def test_as_from_dict(self): assert isinstance(ContainsSpecieFilter.from_dict(dct), ContainsSpecieFilter) -class TestSpecieProximityFilter(PymatgenTest): +class TestSpecieProximityFilter(MatSciTest): def test_filter(self): struct = self.get_structure("Li10GeP2S12") sf = SpecieProximityFilter({"Li": 1}) diff --git a/tests/alchemy/test_materials.py b/tests/alchemy/test_materials.py index 1e946163473..10115842f8f 100644 --- a/tests/alchemy/test_materials.py +++ b/tests/alchemy/test_materials.py @@ -21,7 +21,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/alchemy" -class TestTransformedStructure(PymatgenTest): +class TestTransformedStructure(MatSciTest): def setup_method(self): structure = PymatgenTest.get_structure("LiFePO4") self.structure = structure diff --git a/tests/alchemy/test_transmuters.py b/tests/alchemy/test_transmuters.py index 653a98c5326..fa249c2d500 100644 --- a/tests/alchemy/test_transmuters.py +++ b/tests/alchemy/test_transmuters.py @@ -11,7 +11,7 @@ from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, PymatgenTest -class TestCifTransmuter(PymatgenTest): +class TestCifTransmuter(MatSciTest): def test_init(self): trafos = [SubstitutionTransformation({"Fe": "Mn", "Fe2+": "Mn2+"})] tsc = CifTransmuter.from_filenames([f"{TEST_FILES_DIR}/cif/MultiStructure.cif"], trafos) @@ -22,7 +22,7 @@ def test_init(self): assert expected == els -class TestPoscarTransmuter(PymatgenTest): +class TestPoscarTransmuter(MatSciTest): def test_init(self): trafos = [SubstitutionTransformation({"Fe": "Mn"})] tsc = PoscarTransmuter.from_filenames([f"{VASP_IN_DIR}/POSCAR", f"{VASP_IN_DIR}/POSCAR"], trafos) diff --git a/tests/analysis/chemenv/connectivity/test_connected_components.py b/tests/analysis/chemenv/connectivity/test_connected_components.py index fc9e561c57e..915f0bf1bae 100644 --- a/tests/analysis/chemenv/connectivity/test_connected_components.py +++ b/tests/analysis/chemenv/connectivity/test_connected_components.py @@ -25,7 +25,7 @@ __author__ = "waroquiers" -class TestConnectedComponent(PymatgenTest): +class TestConnectedComponent(MatSciTest): def test_init(self): # Generic connected component not using EnvironmentNodes # (as_dict won't work on such a ConnectedComponent instance) diff --git a/tests/analysis/chemenv/connectivity/test_environment_nodes.py b/tests/analysis/chemenv/connectivity/test_environment_nodes.py index 60af01acff7..dc7956ab764 100644 --- a/tests/analysis/chemenv/connectivity/test_environment_nodes.py +++ b/tests/analysis/chemenv/connectivity/test_environment_nodes.py @@ -13,7 +13,7 @@ __author__ = "waroquiers" -class TestEnvironmentNodes(PymatgenTest): +class TestEnvironmentNodes(MatSciTest): def test_equal(self): struct = self.get_structure("SiO2") en = EnvironmentNode(central_site=struct[0], i_central_site=0, ce_symbol="T:4") diff --git a/tests/analysis/chemenv/connectivity/test_structure_connectivity.py b/tests/analysis/chemenv/connectivity/test_structure_connectivity.py index 37f8da4b98a..604f3018744 100644 --- a/tests/analysis/chemenv/connectivity/test_structure_connectivity.py +++ b/tests/analysis/chemenv/connectivity/test_structure_connectivity.py @@ -14,7 +14,7 @@ __author__ = "waroquiers" -class TestStructureConnectivity(PymatgenTest): +class TestStructureConnectivity(MatSciTest): def test_serialization(self): BaTiO3_se_fpath = f"{TEST_FILES_DIR}/analysis/chemenv/structure_environments/se_mp-5020.json" with open(BaTiO3_se_fpath) as file: diff --git a/tests/analysis/chemenv/coordination_environments/test_chemenv_strategies.py b/tests/analysis/chemenv/coordination_environments/test_chemenv_strategies.py index 64516b22c41..d7cd8a2a474 100644 --- a/tests/analysis/chemenv/coordination_environments/test_chemenv_strategies.py +++ b/tests/analysis/chemenv/coordination_environments/test_chemenv_strategies.py @@ -15,7 +15,7 @@ __author__ = "waroquiers" -class TestStrategyOptions(PymatgenTest): +class TestStrategyOptions(MatSciTest): def test_options(self): # DistanceCutoffFloat with pytest.raises(ValueError, match=r"Distance cutoff should be between 1 and \+infinity"): diff --git a/tests/analysis/chemenv/coordination_environments/test_coordination_geometries.py b/tests/analysis/chemenv/coordination_environments/test_coordination_geometries.py index 18fc1675835..e07ead94557 100644 --- a/tests/analysis/chemenv/coordination_environments/test_coordination_geometries.py +++ b/tests/analysis/chemenv/coordination_environments/test_coordination_geometries.py @@ -23,7 +23,7 @@ def __init__(self, coords): self.coords = coords -class TestCoordinationGeometries(PymatgenTest): +class TestCoordinationGeometries(MatSciTest): def test_algorithms(self): expl_algo = ExplicitPermutationsAlgorithm(permutations=[[0, 1, 2], [1, 2, 3]]) expl_algo2 = ExplicitPermutationsAlgorithm.from_dict(expl_algo.as_dict()) diff --git a/tests/analysis/chemenv/coordination_environments/test_coordination_geometry_finder.py b/tests/analysis/chemenv/coordination_environments/test_coordination_geometry_finder.py index 74120fa0d94..d518fd0d466 100644 --- a/tests/analysis/chemenv/coordination_environments/test_coordination_geometry_finder.py +++ b/tests/analysis/chemenv/coordination_environments/test_coordination_geometry_finder.py @@ -26,7 +26,7 @@ json_dir = f"{TEST_FILES_DIR}/analysis/chemenv/json" -class TestCoordinationGeometryFinder(PymatgenTest): +class TestCoordinationGeometryFinder(MatSciTest): def setup_method(self): self.lgf = LocalGeometryFinder() self.lgf.setup_parameters( diff --git a/tests/analysis/chemenv/coordination_environments/test_read_write.py b/tests/analysis/chemenv/coordination_environments/test_read_write.py index dba1f04b070..f1be06c44ca 100644 --- a/tests/analysis/chemenv/coordination_environments/test_read_write.py +++ b/tests/analysis/chemenv/coordination_environments/test_read_write.py @@ -30,7 +30,7 @@ struct_env_dir = f"{TEST_FILES_DIR}/analysis/chemenv/structure_environments" -class TestReadWriteChemenv(PymatgenTest): +class TestReadWriteChemenv(MatSciTest): @classmethod def setup_class(cls): cls.lgf = LocalGeometryFinder() diff --git a/tests/analysis/chemenv/coordination_environments/test_structure_environments.py b/tests/analysis/chemenv/coordination_environments/test_structure_environments.py index 3f8bde41636..16fa2a4d16e 100644 --- a/tests/analysis/chemenv/coordination_environments/test_structure_environments.py +++ b/tests/analysis/chemenv/coordination_environments/test_structure_environments.py @@ -24,7 +24,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/analysis/chemenv/structure_environments" -class TestStructureEnvironments(PymatgenTest): +class TestStructureEnvironments(MatSciTest): def test_structure_environments(self): with open(f"{TEST_DIR}/se_mp-7000.json") as file: dct = json.load(file) diff --git a/tests/analysis/chemenv/coordination_environments/test_voronoi.py b/tests/analysis/chemenv/coordination_environments/test_voronoi.py index 492cc00df36..60dafdf3af9 100644 --- a/tests/analysis/chemenv/coordination_environments/test_voronoi.py +++ b/tests/analysis/chemenv/coordination_environments/test_voronoi.py @@ -12,7 +12,7 @@ img_files_dir = f"{TEST_FILES_DIR}/analysis/chemenv/images" -class TestVoronoiContainer(PymatgenTest): +class TestVoronoiContainer(MatSciTest): def test_voronoi(self): # Define a cubic lattice and a list of species (to be used for the fake structures) cubic_lattice = Lattice.cubic(10) diff --git a/tests/analysis/chemenv/coordination_environments/test_weights.py b/tests/analysis/chemenv/coordination_environments/test_weights.py index 6a5b2ffe50a..586af7a31bf 100644 --- a/tests/analysis/chemenv/coordination_environments/test_weights.py +++ b/tests/analysis/chemenv/coordination_environments/test_weights.py @@ -39,7 +39,7 @@ class DummyVoronoiContainer: pass -class StrategyWeights(PymatgenTest): +class StrategyWeights(MatSciTest): def test_angle_weight(self): fake_nb_set = FakeNbSet() dummy_se = DummyStructureEnvironments() diff --git a/tests/analysis/chemenv/utils/test_chemenv_config.py b/tests/analysis/chemenv/utils/test_chemenv_config.py index bea8a66770f..1c3efa2c8c4 100644 --- a/tests/analysis/chemenv/utils/test_chemenv_config.py +++ b/tests/analysis/chemenv/utils/test_chemenv_config.py @@ -9,7 +9,7 @@ config_file_dir = f"{TEST_FILES_DIR}/analysis/chemenv/config" -class TestChemenvConfig(PymatgenTest): +class TestChemenvConfig(MatSciTest): def test_chemenv_config(self): config = ChemEnvConfig() diff --git a/tests/analysis/chemenv/utils/test_coordination_geometry_utils.py b/tests/analysis/chemenv/utils/test_coordination_geometry_utils.py index 60801c5a0b6..9b459d736e2 100644 --- a/tests/analysis/chemenv/utils/test_coordination_geometry_utils.py +++ b/tests/analysis/chemenv/utils/test_coordination_geometry_utils.py @@ -12,7 +12,7 @@ __author__ = "David Waroquiers" -class TestPlanesUtils(PymatgenTest): +class TestPlanesUtils(MatSciTest): def setup_method(self): # Test of plane 4x + 2y - 4z + 3 = 0 (used in most test cases) self.expected_coefficients = np.array([4, 2, -4, 3], float) diff --git a/tests/analysis/chemenv/utils/test_graph_utils.py b/tests/analysis/chemenv/utils/test_graph_utils.py index b5f32fe7e94..25a791d1e1b 100644 --- a/tests/analysis/chemenv/utils/test_graph_utils.py +++ b/tests/analysis/chemenv/utils/test_graph_utils.py @@ -68,7 +68,7 @@ def __lt__(self, other): return self.isite % 2 < other.isite % 2 -class TestGraphUtils(PymatgenTest): +class TestGraphUtils(MatSciTest): def test_get_delta(self): n1 = FakeNode(3) n2 = FakeNode(7) @@ -664,7 +664,7 @@ def test_multigraph_cycle(self): assert mgc.edge_indices == edges_ref, f"Edges not equal for inodes = ({str_nodes})" -class TestEnvironmentNodesGraphUtils(PymatgenTest): +class TestEnvironmentNodesGraphUtils(MatSciTest): def test_cycle(self): e1 = EnvironmentNode(central_site="Si", i_central_site=0, ce_symbol="T:4") e2 = EnvironmentNode(central_site="Si", i_central_site=3, ce_symbol="T:4") diff --git a/tests/analysis/chemenv/utils/test_math_utils.py b/tests/analysis/chemenv/utils/test_math_utils.py index d3583a24851..184f3364a26 100644 --- a/tests/analysis/chemenv/utils/test_math_utils.py +++ b/tests/analysis/chemenv/utils/test_math_utils.py @@ -21,7 +21,7 @@ __author__ = "waroquiers" -class TestMathUtils(PymatgenTest): +class TestMathUtils(MatSciTest): def test_list_cartesian_product(self): list_of_lists = [[0, 1], [2, 5, 4], [5]] assert _cartesian_product(lists=list_of_lists) == [ diff --git a/tests/analysis/diffraction/test_neutron.py b/tests/analysis/diffraction/test_neutron.py index 4de897d85d6..eb031175743 100644 --- a/tests/analysis/diffraction/test_neutron.py +++ b/tests/analysis/diffraction/test_neutron.py @@ -20,7 +20,7 @@ __date__ = "4/19/18" -class TestNDCalculator(PymatgenTest): +class TestNDCalculator(MatSciTest): def test_get_pattern(self): struct = self.get_structure("CsCl") c = NDCalculator(wavelength=1.54184) # CuKa radiation diff --git a/tests/analysis/diffraction/test_tem.py b/tests/analysis/diffraction/test_tem.py index c8cfee3b1d5..2e491e6b486 100644 --- a/tests/analysis/diffraction/test_tem.py +++ b/tests/analysis/diffraction/test_tem.py @@ -21,7 +21,7 @@ __date__ = "2/20/20" -class TestTEMCalculator(PymatgenTest): +class TestTEMCalculator(MatSciTest): def test_wavelength_rel(self): # Test that the relativistic wavelength formula (for 200 kV electron beam) is correct tem_calc = TEMCalculator() diff --git a/tests/analysis/diffraction/test_xrd.py b/tests/analysis/diffraction/test_xrd.py index 997c43de42b..ce2e13851f0 100644 --- a/tests/analysis/diffraction/test_xrd.py +++ b/tests/analysis/diffraction/test_xrd.py @@ -16,7 +16,7 @@ __date__ = "5/22/14" -class TestXRDCalculator(PymatgenTest): +class TestXRDCalculator(MatSciTest): def test_type_wavelength(self): """Test TypeError is raised if wavelength is unaccepted type.""" wavelength = [1.78, 2.78] # just a list diff --git a/tests/analysis/elasticity/test_elastic.py b/tests/analysis/elasticity/test_elastic.py index 97917144d2e..788ce69d13e 100644 --- a/tests/analysis/elasticity/test_elastic.py +++ b/tests/analysis/elasticity/test_elastic.py @@ -32,7 +32,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/analysis/elasticity" -class TestElasticTensor(PymatgenTest): +class TestElasticTensor(MatSciTest): def setup_method(self): self.voigt_1 = [ [59.33, 28.08, 28.08, 0, 0, 0], @@ -263,7 +263,7 @@ def test_energy_density(self): ) -class TestElasticTensorExpansion(PymatgenTest): +class TestElasticTensorExpansion(MatSciTest): def setup_method(self): with open(f"{TEST_DIR}/test_toec_data.json") as file: self.data_dict = json.load(file) @@ -364,7 +364,7 @@ def test_get_yield_stress(self): self.exp_cu_4.get_yield_stress([1, 0, 0]) -class TestNthOrderElasticTensor(PymatgenTest): +class TestNthOrderElasticTensor(MatSciTest): def setup_method(self): with open(f"{TEST_DIR}/test_toec_data.json") as file: self.data_dict = json.load(file) @@ -401,7 +401,7 @@ def test_energy_density(self): self.c3.energy_density(self.strains[0]) -class TestDiffFit(PymatgenTest): +class TestDiffFit(MatSciTest): """Test various functions related to diff fitting.""" def setup_method(self): diff --git a/tests/analysis/elasticity/test_strain.py b/tests/analysis/elasticity/test_strain.py index 9b2daee68fb..56bab6cf982 100644 --- a/tests/analysis/elasticity/test_strain.py +++ b/tests/analysis/elasticity/test_strain.py @@ -10,7 +10,7 @@ from pymatgen.util.testing import PymatgenTest -class TestDeformation(PymatgenTest): +class TestDeformation(MatSciTest): def setup_method(self): self.norm_defo = Deformation.from_index_amount((0, 0), 0.02) self.ind_defo = Deformation.from_index_amount((0, 1), 0.02) @@ -81,7 +81,7 @@ def test_apply_to_structure(self): assert_allclose(new_coord, defo_coord) -class TestStrain(PymatgenTest): +class TestStrain(MatSciTest): def setup_method(self): self.norm_str = Strain.from_deformation([[1.02, 0, 0], [0, 1, 0], [0, 0, 1]]) self.ind_str = Strain.from_deformation([[1, 0.02, 0], [0, 1, 0], [0, 0, 1]]) @@ -142,7 +142,7 @@ def test_convert_strain_to_deformation(self): assert_allclose(defo.green_lagrange_strain, strain) -class TestDeformedStructureSet(PymatgenTest): +class TestDeformedStructureSet(MatSciTest): def setup_method(self): self.structure = self.get_structure("Sn") self.default_dss = DeformedStructureSet(self.structure) diff --git a/tests/analysis/elasticity/test_stress.py b/tests/analysis/elasticity/test_stress.py index 303c7d0f87c..f37192cf4c7 100644 --- a/tests/analysis/elasticity/test_stress.py +++ b/tests/analysis/elasticity/test_stress.py @@ -10,7 +10,7 @@ from pymatgen.util.testing import PymatgenTest -class TestStress(PymatgenTest): +class TestStress(MatSciTest): def setup_method(self): self.rand_stress = Stress(np.random.default_rng().standard_normal((3, 3))) self.symm_stress = Stress([[0.51, 2.29, 2.42], [2.29, 5.14, 5.07], [2.42, 5.07, 5.33]]) diff --git a/tests/analysis/ferroelectricity/test_polarization.py b/tests/analysis/ferroelectricity/test_polarization.py index f6fca157600..f1cc15358ae 100644 --- a/tests/analysis/ferroelectricity/test_polarization.py +++ b/tests/analysis/ferroelectricity/test_polarization.py @@ -38,7 +38,7 @@ ) -class TestUtils(PymatgenTest): +class TestUtils(MatSciTest): def setup_method(self): self.potcar = Potcar.from_file(f"{TEST_DIR}/POTCAR") self.zval_dict = {"Ba": 10, "Ti": 10, "O": 6} @@ -54,7 +54,7 @@ def test_get_total_ionic_dipole(self): assert_allclose(p_ion, self.ions[-1].ravel().tolist()) -class TestPolarization(PymatgenTest): +class TestPolarization(MatSciTest): def setup_method(self): self.p_ions = ions self.p_ions_outcar = np.array( @@ -258,7 +258,7 @@ def test_smoothness(self): assert_allclose(self.smoothness_all_in_polar, smoothness) -class TestEnergyTrend(PymatgenTest): +class TestEnergyTrend(MatSciTest): def setup_method(self): self.energies = [ -7.97738049, diff --git a/tests/analysis/interfaces/test_coherent_interface.py b/tests/analysis/interfaces/test_coherent_interface.py index 2b19cafd1cb..5ad0c9e78ec 100644 --- a/tests/analysis/interfaces/test_coherent_interface.py +++ b/tests/analysis/interfaces/test_coherent_interface.py @@ -17,7 +17,7 @@ from pymatgen.util.testing import PymatgenTest -class TestInterfaceBuilder(PymatgenTest): +class TestInterfaceBuilder(MatSciTest): @classmethod def setup_class(cls): si_struct = cls.get_structure("Si") diff --git a/tests/analysis/interfaces/test_zsl.py b/tests/analysis/interfaces/test_zsl.py index 3030a3d3074..c18a6042fc7 100644 --- a/tests/analysis/interfaces/test_zsl.py +++ b/tests/analysis/interfaces/test_zsl.py @@ -23,7 +23,7 @@ __date__ = "2/5/16" -class TestZSLGen(PymatgenTest): +class TestZSLGen(MatSciTest): def setup_method(self): # Film VO2 self.film = SpacegroupAnalyzer(self.get_structure("VO2"), symprec=0.1).get_conventional_standard_structure() diff --git a/tests/analysis/solar/test_slme.py b/tests/analysis/solar/test_slme.py index 3ccf3256d11..e83ede5b062 100644 --- a/tests/analysis/solar/test_slme.py +++ b/tests/analysis/solar/test_slme.py @@ -8,7 +8,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/analysis/solar" -class TestSolar(PymatgenTest): +class TestSolar(MatSciTest): def test_slme_from_vasprun(self): en, abz, dir_gap, indir_gap = optics(f"{TEST_DIR}/vasprun.xml") abz *= 100.0 diff --git a/tests/analysis/structure_prediction/test_substitutor.py b/tests/analysis/structure_prediction/test_substitutor.py index 87ba7b2e787..a8626b5bf33 100644 --- a/tests/analysis/structure_prediction/test_substitutor.py +++ b/tests/analysis/structure_prediction/test_substitutor.py @@ -20,7 +20,7 @@ def get_table(): return json.load(file) -class TestSubstitutor(PymatgenTest): +class TestSubstitutor(MatSciTest): def setup_method(self): self.substitutor = Substitutor(threshold=1e-3, lambda_table=get_table(), alpha=-5.0) diff --git a/tests/analysis/structure_prediction/test_volume_predictor.py b/tests/analysis/structure_prediction/test_volume_predictor.py index 20ecf2bd24b..b94bf999a50 100644 --- a/tests/analysis/structure_prediction/test_volume_predictor.py +++ b/tests/analysis/structure_prediction/test_volume_predictor.py @@ -10,7 +10,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/analysis/structure_prediction" -class TestRLSVolumePredictor(PymatgenTest): +class TestRLSVolumePredictor(MatSciTest): def test_predict(self): struct = PymatgenTest.get_structure("CsCl") nacl = PymatgenTest.get_structure("CsCl") @@ -77,7 +77,7 @@ def test_modes(self): assert vol_pred.predict(cs_cl, na_cl) == approx(342.84905395082535) -class TestDLSVolumePredictor(PymatgenTest): +class TestDLSVolumePredictor(MatSciTest): def test_predict(self): vol_pred = DLSVolumePredictor() p_fast = DLSVolumePredictor(cutoff=0.0) # for speed on compressed cells diff --git a/tests/analysis/test_adsorption.py b/tests/analysis/test_adsorption.py index 1b90989c410..9bc84be4b83 100644 --- a/tests/analysis/test_adsorption.py +++ b/tests/analysis/test_adsorption.py @@ -11,7 +11,7 @@ from pymatgen.util.testing import PymatgenTest -class TestAdsorbateSiteFinder(PymatgenTest): +class TestAdsorbateSiteFinder(MatSciTest): def setup_method(self): self.structure = Structure.from_spacegroup("Fm-3m", Lattice.cubic(3.5), ["Ni"], [[0, 0, 0]]) lattice = Lattice.cubic(3.010) diff --git a/tests/analysis/test_bond_valence.py b/tests/analysis/test_bond_valence.py index 17c94ad404d..fb50139d78b 100644 --- a/tests/analysis/test_bond_valence.py +++ b/tests/analysis/test_bond_valence.py @@ -10,7 +10,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/analysis/bond_valence" -class TestBVAnalyzer(PymatgenTest): +class TestBVAnalyzer(MatSciTest): def setup_method(self): self.analyzer = BVAnalyzer() @@ -44,7 +44,7 @@ def test_get_oxi_state_structure(self): assert Species("Mn4+") in oxi_struct.composition.elements -class TestBondValenceSum(PymatgenTest): +class TestBondValenceSum(MatSciTest): def test_calculate_bv_sum(self): struct = Structure.from_file(f"{TEST_DIR}/LiMn2O4.json") neighbors = struct.get_neighbors(struct[0], 3.0) diff --git a/tests/analysis/test_chempot_diagram.py b/tests/analysis/test_chempot_diagram.py index 3c4a87b6262..1c6377db8f9 100644 --- a/tests/analysis/test_chempot_diagram.py +++ b/tests/analysis/test_chempot_diagram.py @@ -17,7 +17,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/analysis" -class TestChemicalPotentialDiagram(PymatgenTest): +class TestChemicalPotentialDiagram(MatSciTest): def setup_method(self): self.entries = EntrySet.from_csv(f"{TEST_DIR}/pd_entries_test.csv") self.cpd_ternary, self.cpd_ternary_formal = ( diff --git a/tests/analysis/test_dimensionality.py b/tests/analysis/test_dimensionality.py index 49482280d61..7f700969292 100644 --- a/tests/analysis/test_dimensionality.py +++ b/tests/analysis/test_dimensionality.py @@ -18,7 +18,7 @@ from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest -class TestLarsenDimensionality(PymatgenTest): +class TestLarsenDimensionality(MatSciTest): def setup_method(self): cnn = CrystalNN() self.lifepo = cnn.get_bonded_structure(self.get_structure("LiFePO4")) @@ -114,7 +114,7 @@ def test_zero_d_to_molecule_graph(self): assert len(mol_graph.molecule) == 12 -class TestCheonDimensionality(PymatgenTest): +class TestCheonDimensionality(MatSciTest): def test_get_dimensionality(self): struct = self.get_structure("LiFePO4") assert get_dimensionality_cheon(struct) == "intercalated ion" @@ -152,7 +152,7 @@ def test_tricky_structure(self): assert get_dimensionality_cheon(tricky_structure, larger_cell=True) == "3D" -class TestGoraiDimensionality(PymatgenTest): +class TestGoraiDimensionality(MatSciTest): def test_get_dimensionality(self): struct = self.get_structure("LiFePO4") assert get_dimensionality_gorai(struct) == 3 diff --git a/tests/analysis/test_disorder.py b/tests/analysis/test_disorder.py index f1fbd2f58d5..ab4a7a7b315 100644 --- a/tests/analysis/test_disorder.py +++ b/tests/analysis/test_disorder.py @@ -7,7 +7,7 @@ from pymatgen.util.testing import PymatgenTest -class TestOrderParameter(PymatgenTest): +class TestOrderParameter(MatSciTest): def test_compute_warren_cowley_parameters(self): struct = Structure.from_prototype("CsCl", ["Mo", "W"], a=4) aij = get_warren_cowley_parameters(struct, r=3.4, dr=0.3) diff --git a/tests/analysis/test_eos.py b/tests/analysis/test_eos.py index 9138fe905ab..a388440cc2b 100644 --- a/tests/analysis/test_eos.py +++ b/tests/analysis/test_eos.py @@ -8,7 +8,7 @@ from pymatgen.util.testing import PymatgenTest -class TestEOS(PymatgenTest): +class TestEOS(MatSciTest): def setup_method(self): # Si data from Cormac self.volumes = [ diff --git a/tests/analysis/test_fragmenter.py b/tests/analysis/test_fragmenter.py index be951ed19f0..477742b1132 100644 --- a/tests/analysis/test_fragmenter.py +++ b/tests/analysis/test_fragmenter.py @@ -17,7 +17,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/analysis/local_env/fragmenter_files" -class TestFragmentMolecule(PymatgenTest): +class TestFragmentMolecule(MatSciTest): @classmethod def setup_class(cls): cls.pc = Molecule.from_file(f"{TEST_DIR}/PC.xyz") diff --git a/tests/analysis/test_graphs.py b/tests/analysis/test_graphs.py index 89e4c4d1281..72b125aa12d 100644 --- a/tests/analysis/test_graphs.py +++ b/tests/analysis/test_graphs.py @@ -45,7 +45,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/analysis/graphs" -class TestStructureGraph(PymatgenTest): +class TestStructureGraph(MatSciTest): def setup_method(self): # trivial example, simple square lattice for testing structure = Structure(Lattice.tetragonal(5, 50), ["H"], [[0, 0, 0]]) diff --git a/tests/analysis/test_local_env.py b/tests/analysis/test_local_env.py index 039282e2cc3..8bf1e95e614 100644 --- a/tests/analysis/test_local_env.py +++ b/tests/analysis/test_local_env.py @@ -54,7 +54,7 @@ def test_opt_params(): assert cn_opt_params == CN_OPT_PARAMS -class TestValenceIonicRadiusEvaluator(PymatgenTest): +class TestValenceIonicRadiusEvaluator(MatSciTest): def setup_method(self): """Setup MgO rocksalt structure for testing Vacancy.""" mgo_latt = np.eye(3) * 4.212 @@ -89,7 +89,7 @@ def test_radii_ionic_structure(self): assert rad in {0.86, 1.26} -class TestVoronoiNN(PymatgenTest): +class TestVoronoiNN(MatSciTest): def setup_method(self): self.struct = self.get_structure("LiFePO4") self.nn = VoronoiNN(targets=[Element("O")]) @@ -260,7 +260,7 @@ def test_filtered(self): assert [len(x) for x in all_nns] == [8] * 16 -class TestJmolNN(PymatgenTest): +class TestJmolNN(MatSciTest): def setup_method(self): self.jmol = JmolNN() self.jmol_update = JmolNN(el_radius_updates={"Li": 1}) @@ -290,7 +290,7 @@ def test_get_nn(self): assert len(self.jmol_update.get_nn(struct, 0)) == 2 -class TestIsayevNN(PymatgenTest): +class TestIsayevNN(MatSciTest): def test_get_nn(self): inn = IsayevNN() struct = self.get_structure("LiFePO4") @@ -301,7 +301,7 @@ def test_get_nn(self): assert len(inn.get_nn(struct, 0)) == 2 -class TestOpenBabelNN(PymatgenTest): +class TestOpenBabelNN(MatSciTest): def setup_method(self): pytest.importorskip("openbabel") self.benzene = Molecule.from_file(f"{TEST_DIR}/../benzene.xyz") @@ -333,7 +333,7 @@ def test_nn_length(self): assert strategy.get_nn_info(self.acetylene, 0)[0]["weight"] == approx(1.19, abs=1e-2) -class TestCovalentBondNN(PymatgenTest): +class TestCovalentBondNN(MatSciTest): def setup_method(self): self.benzene = Molecule.from_file(f"{TEST_DIR}/../benzene.xyz") self.acetylene = Molecule.from_file(f"{TEST_FILES_DIR}/io/xyz/acetylene.xyz") @@ -372,7 +372,7 @@ def test_bonded_structure(self): assert len(acetylene.graph.nodes) == 4 -class TestMiniDistNN(PymatgenTest): +class TestMiniDistNN(MatSciTest): def setup_method(self): self.diamond = Structure( Lattice([[2.189, 0, 1.264], [0.73, 2.064, 1.264], [0, 0, 2.528]]), @@ -485,7 +485,7 @@ def test_get_local_order_params(self): assert ops["octahedral"] == approx(0.9999995266669) -class TestMotifIdentification(PymatgenTest): +class TestMotifIdentification(MatSciTest): def setup_method(self): self.silicon = Structure( Lattice.cubic(5.47), @@ -583,7 +583,7 @@ def test_get_neighbors_of_site_with_index(self): assert len(get_neighbors_of_site_with_index(self.diamond, 0, approach="min_VIRE")) == 4 -class TestNearNeighbor(PymatgenTest): +class TestNearNeighbor(MatSciTest): def setup_method(self): self.diamond = Structure( Lattice([[2.189, 0, 1.264], [0.73, 2.064, 1.264], [0, 0, 2.528]]), @@ -617,7 +617,7 @@ def test_on_disorder_options(self): ) -class TestLocalStructOrderParams(PymatgenTest): +class TestLocalStructOrderParams(MatSciTest): def setup_method(self): self.single_bond = Structure( Lattice.cubic(10), @@ -1182,7 +1182,7 @@ def test_get_order_parameters(self): ops_101.get_order_parameters(self.bcc, 0, indices_neighs=[2]) -class TestCrystalNN(PymatgenTest): +class TestCrystalNN(MatSciTest): def setup_method(self): self.lifepo4 = self.get_structure("LiFePO4") self.lifepo4.add_oxidation_state_by_guess() @@ -1329,7 +1329,7 @@ def test_get_bonded_structure(self): cnn.get_bonded_structure(self.disordered_struct, 0, on_disorder="error") -class TestCutOffDictNN(PymatgenTest): +class TestCutOffDictNN(MatSciTest): def setup_method(self): self.diamond = Structure( Lattice([[2.189, 0, 1.264], [0.73, 2.064, 1.264], [0, 0, 2.528]]), @@ -1355,7 +1355,7 @@ def test_from_preset(self): @pytest.mark.skipif(not which("critic2"), reason="critic2 executable not present") -class TestCritic2NN(PymatgenTest): +class TestCritic2NN(MatSciTest): def setup_method(self): self.diamond = Structure( Lattice([[2.189, 0, 1.264], [0.73, 2.064, 1.264], [0, 0, 2.528]]), @@ -1369,7 +1369,7 @@ def test_cn(self): # assert nn.get_cn(self.diamond, 0) == 4 -class TestMetalEdgeExtender(PymatgenTest): +class TestMetalEdgeExtender(MatSciTest): def setup_method(self): self.LiEC = Molecule.from_file(f"{TEST_DIR}/LiEC.xyz") self.phsh = Molecule.from_file(f"{TEST_DIR}/phsh.xyz") diff --git a/tests/analysis/test_nmr.py b/tests/analysis/test_nmr.py index 14490ec7a0c..b3f97fe2c3e 100644 --- a/tests/analysis/test_nmr.py +++ b/tests/analysis/test_nmr.py @@ -8,7 +8,7 @@ from pymatgen.util.testing import PymatgenTest -class TestChemicalShieldingNotation(PymatgenTest): +class TestChemicalShieldingNotation(MatSciTest): def test_construction(self): cs = ChemicalShielding(np.arange(9).reshape((3, 3))) assert cs.shape == (3, 3) @@ -46,7 +46,7 @@ def test_notations(self): assert mary1.kappa == approx(0.8337, abs=1e-5) -class TestElectricFieldGradient(PymatgenTest): +class TestElectricFieldGradient(MatSciTest): def test_construction(self): efg = ElectricFieldGradient(np.arange(9).reshape((3, 3))) assert efg.shape == (3, 3) diff --git a/tests/analysis/test_phase_diagram.py b/tests/analysis/test_phase_diagram.py index 25b84f2f7ca..61ee1930028 100644 --- a/tests/analysis/test_phase_diagram.py +++ b/tests/analysis/test_phase_diagram.py @@ -178,7 +178,7 @@ def test_normalize(self): assert norm_entry.composition == expected_comp -class TestPhaseDiagram(PymatgenTest): +class TestPhaseDiagram(MatSciTest): def setup_method(self): self.entries = EntrySet.from_csv(f"{TEST_DIR}/pd_entries_test.csv") self.pd = PhaseDiagram(self.entries) diff --git a/tests/analysis/test_piezo.py b/tests/analysis/test_piezo.py index 59eb96e5996..42d659976c1 100644 --- a/tests/analysis/test_piezo.py +++ b/tests/analysis/test_piezo.py @@ -17,7 +17,7 @@ __date__ = "4/1/16" -class TestPiezo(PymatgenTest): +class TestPiezo(MatSciTest): def setup_method(self): self.piezo_struct = self.get_structure("BaNiO3") self.voigt_matrix = np.array( diff --git a/tests/analysis/test_piezo_sensitivity.py b/tests/analysis/test_piezo_sensitivity.py index 454f1caed77..bf9c10ffcf5 100644 --- a/tests/analysis/test_piezo_sensitivity.py +++ b/tests/analysis/test_piezo_sensitivity.py @@ -34,7 +34,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/analysis/piezo_sensitivity" -class TestPiezoSensitivity(PymatgenTest): +class TestPiezoSensitivity(MatSciTest): def setup_method(self): self.piezo_struct = self.get_structure("Pb2TiZrO6") self.IST = np.load(f"{TEST_DIR}/pztist.npy", allow_pickle=True) diff --git a/tests/analysis/test_pourbaix_diagram.py b/tests/analysis/test_pourbaix_diagram.py index 77f71721327..38fce08fa90 100644 --- a/tests/analysis/test_pourbaix_diagram.py +++ b/tests/analysis/test_pourbaix_diagram.py @@ -16,7 +16,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/analysis/pourbaix_diagram" -class TestPourbaixEntry(PymatgenTest): +class TestPourbaixEntry(MatSciTest): """Test all functions using a fictitious entry""" def setup_method(self): diff --git a/tests/analysis/test_prototypes.py b/tests/analysis/test_prototypes.py index d2a16258d03..acf8b8472fd 100644 --- a/tests/analysis/test_prototypes.py +++ b/tests/analysis/test_prototypes.py @@ -4,7 +4,7 @@ from pymatgen.util.testing import PymatgenTest -class TestAflowPrototypeMatcher(PymatgenTest): +class TestAflowPrototypeMatcher(MatSciTest): def test_prototype_matching(self): af = AflowPrototypeMatcher() diff --git a/tests/analysis/test_structure_analyzer.py b/tests/analysis/test_structure_analyzer.py index d92b954f79a..35463013dce 100644 --- a/tests/analysis/test_structure_analyzer.py +++ b/tests/analysis/test_structure_analyzer.py @@ -19,7 +19,7 @@ from pymatgen.util.testing import VASP_IN_DIR, VASP_OUT_DIR, PymatgenTest -class TestVoronoiAnalyzer(PymatgenTest): +class TestVoronoiAnalyzer(MatSciTest): def setup_method(self): self.structs = Xdatcar(f"{VASP_OUT_DIR}/XDATCAR.MD").structures self.struct = self.structs[1] @@ -60,7 +60,7 @@ def test_get_percentage_bond_dist_changes(self): assert approx(v2) == -0.009204092115527862 -class TestVoronoiConnectivity(PymatgenTest): +class TestVoronoiConnectivity(MatSciTest): def test_connectivity_array(self): vc = VoronoiConnectivity(self.get_structure("LiFePO4")) ca = vc.connectivity_array @@ -76,7 +76,7 @@ def test_connectivity_array(self): assert_allclose(site.frac_coords, expected) -class TestMiscFunction(PymatgenTest): +class TestMiscFunction(MatSciTest): def test_average_coordination_number(self): xdatcar = Xdatcar(f"{VASP_OUT_DIR}/XDATCAR.MD") coordination_numbers = average_coordination_number(xdatcar.structures, freq=1) diff --git a/tests/analysis/test_structure_matcher.py b/tests/analysis/test_structure_matcher.py index 5106f19a527..bf6f9f00500 100644 --- a/tests/analysis/test_structure_matcher.py +++ b/tests/analysis/test_structure_matcher.py @@ -22,7 +22,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/analysis/structure_matcher" -class TestStructureMatcher(PymatgenTest): +class TestStructureMatcher(MatSciTest): def setup_method(self): with open(f"{TEST_FILES_DIR}/entries/TiO2_entries.json") as file: entries = json.load(file, cls=MontyDecoder) diff --git a/tests/analysis/test_surface_analysis.py b/tests/analysis/test_surface_analysis.py index 2f95ad7edbb..18274d6ded3 100644 --- a/tests/analysis/test_surface_analysis.py +++ b/tests/analysis/test_surface_analysis.py @@ -22,7 +22,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/surfaces" -class TestSlabEntry(PymatgenTest): +class TestSlabEntry(MatSciTest): def setup_method(self): with open(f"{TEST_DIR}/ucell_entries.txt") as file: ucell_entries = json.loads(file.read()) @@ -118,7 +118,7 @@ def test_cleaned_up_slab(self): assert slab_clean.composition.reduced_composition == clean.composition.reduced_composition -class TestSurfaceEnergyPlotter(PymatgenTest): +class TestSurfaceEnergyPlotter(MatSciTest): def setup_method(self): entry_dict = get_entry_dict(f"{TEST_DIR}/Cu_entries.txt") self.Cu_entry_dict = entry_dict @@ -292,7 +292,7 @@ def test_surface_chempot_range_map(self): analyzer.chempot_vs_gamma_facet(hkl) -class TestWorkFunctionAnalyzer(PymatgenTest): +class TestWorkFunctionAnalyzer(MatSciTest): def setup_method(self): self.kwargs = { "poscar_filename": f"{TEST_DIR}/CONTCAR.relax1.gz", @@ -309,7 +309,7 @@ def test_is_converged(self): assert self.wf_analyzer.is_converged() -class TestNanoscaleStability(PymatgenTest): +class TestNanoscaleStability(MatSciTest): def setup_method(self): # Load all entries La_hcp_entry_dict = get_entry_dict(f"{TEST_DIR}/La_hcp_entries.txt") diff --git a/tests/analysis/test_transition_state.py b/tests/analysis/test_transition_state.py index 96841bc482a..78b22aeb305 100644 --- a/tests/analysis/test_transition_state.py +++ b/tests/analysis/test_transition_state.py @@ -23,7 +23,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/io/vasp/fixtures/neb_analysis" -class TestNEBAnalysis(PymatgenTest): +class TestNEBAnalysis(MatSciTest): def test_run(self): neb_analysis1 = NEBAnalysis.from_dir(f"{TEST_DIR}/neb1/neb") neb_analysis1_from_dict = NEBAnalysis.from_dict(neb_analysis1.as_dict()) diff --git a/tests/analysis/test_wulff.py b/tests/analysis/test_wulff.py index 8ecba2e2e41..1a8eeb0284d 100644 --- a/tests/analysis/test_wulff.py +++ b/tests/analysis/test_wulff.py @@ -21,7 +21,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/analysis/wulff" -class TestWulffShape(PymatgenTest): +class TestWulffShape(MatSciTest): def setup_method(self): with open(f"{TEST_DIR}/surface_samples.json") as data_file: surface_properties = json.load(data_file) diff --git a/tests/analysis/test_xps.py b/tests/analysis/test_xps.py index 45b250e3100..a4358f7ad98 100644 --- a/tests/analysis/test_xps.py +++ b/tests/analysis/test_xps.py @@ -5,7 +5,7 @@ from pymatgen.util.testing import VASP_OUT_DIR, PymatgenTest -class TestXPS(PymatgenTest): +class TestXPS(MatSciTest): def test_from_dos(self): vasp_run = Vasprun(f"{VASP_OUT_DIR}/vasprun.LiF.xml.gz") dos = vasp_run.complete_dos diff --git a/tests/analysis/topological/test_spillage.py b/tests/analysis/topological/test_spillage.py index 39224cdfc52..d605e8c2c63 100644 --- a/tests/analysis/topological/test_spillage.py +++ b/tests/analysis/topological/test_spillage.py @@ -8,7 +8,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/analysis/topological" -class TestSolar(PymatgenTest): +class TestSolar(MatSciTest): def test_spillage_from_vasprun(self): wf_noso = f"{TEST_DIR}/WAVECAR-NonSOC" wf_so = f"{TEST_DIR}/WAVECAR-SOC" diff --git a/tests/analysis/xas/test_spectrum.py b/tests/analysis/xas/test_spectrum.py index 54dd93760a7..16a06965e39 100644 --- a/tests/analysis/xas/test_spectrum.py +++ b/tests/analysis/xas/test_spectrum.py @@ -28,7 +28,7 @@ site2_xanes_dict = json.load(file, cls=MontyDecoder) -class TestXAS(PymatgenTest): +class TestXAS(MatSciTest): def setup_method(self): self.k_xanes = XAS.from_dict(k_xanes_dict) self.k_exafs = XAS.from_dict(k_exafs_dict) diff --git a/tests/apps/battery/test_analyzer.py b/tests/apps/battery/test_analyzer.py index 52e59c5680d..d2ee3c75610 100644 --- a/tests/apps/battery/test_analyzer.py +++ b/tests/apps/battery/test_analyzer.py @@ -8,7 +8,7 @@ from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest -class TestBatteryAnalyzer(PymatgenTest): +class TestBatteryAnalyzer(MatSciTest): def load_from_cif(self, filename, oxidations, working_ion="Li"): struct = Structure.from_file(f"{TEST_FILES_DIR}/cif/{filename}") struct.add_oxidation_state_by_element(oxidations) diff --git a/tests/command_line/test_bader_caller.py b/tests/command_line/test_bader_caller.py index 6b63ce9aa9a..019b71af9cd 100644 --- a/tests/command_line/test_bader_caller.py +++ b/tests/command_line/test_bader_caller.py @@ -16,7 +16,7 @@ @pytest.mark.skipif(not which("bader"), reason="bader executable not present") -class TestBaderAnalysis(PymatgenTest): +class TestBaderAnalysis(MatSciTest): def setup_method(self): warnings.catch_warnings() diff --git a/tests/command_line/test_enumlib_caller.py b/tests/command_line/test_enumlib_caller.py index aa3cebff4a3..9717e176e48 100644 --- a/tests/command_line/test_enumlib_caller.py +++ b/tests/command_line/test_enumlib_caller.py @@ -18,7 +18,7 @@ @pytest.mark.skipif(not (ENUM_CMD and MAKESTR_CMD), reason="enumlib not present.") -class TestEnumlibAdaptor(PymatgenTest): +class TestEnumlibAdaptor(MatSciTest): def test_init(self): struct = self.get_structure("LiFePO4") sub_trans = SubstitutionTransformation({"Li": {"Li": 0.5}}) diff --git a/tests/command_line/test_mcsqs_caller.py b/tests/command_line/test_mcsqs_caller.py index aa749e1bab8..f32aba85833 100644 --- a/tests/command_line/test_mcsqs_caller.py +++ b/tests/command_line/test_mcsqs_caller.py @@ -18,7 +18,7 @@ @pytest.mark.skipif(not (which("mcsqs") and which("str2cif")), reason="mcsqs executable not present") -class TestMcsqsCaller(PymatgenTest): +class TestMcsqsCaller(MatSciTest): def setup_method(self): self.pzt_structs = loadfn(f"{TEST_DIR}/pzt-structs.json") self.pzt_structs2 = loadfn(f"{TEST_DIR}/pzt-structs-2.json") diff --git a/tests/command_line/test_vampire_caller.py b/tests/command_line/test_vampire_caller.py index 439c14344c4..30cf129343a 100644 --- a/tests/command_line/test_vampire_caller.py +++ b/tests/command_line/test_vampire_caller.py @@ -14,7 +14,7 @@ @pytest.mark.skipif(not which("vampire-serial"), reason="vampire executable not present") -class TestVampireCaller(PymatgenTest): +class TestVampireCaller(MatSciTest): @classmethod def setup_class(cls): cls.Mn3Al = pd.read_json(f"{TEST_DIR}/Mn3Al.json") diff --git a/tests/core/test_composition.py b/tests/core/test_composition.py index 52d38e0079c..b0a5e3bfe75 100644 --- a/tests/core/test_composition.py +++ b/tests/core/test_composition.py @@ -16,7 +16,7 @@ from pymatgen.util.testing import PymatgenTest -class TestComposition(PymatgenTest): +class TestComposition(MatSciTest): def setup_method(self): self.comps = [ Composition("Li3Fe2(PO4)3"), diff --git a/tests/core/test_interface.py b/tests/core/test_interface.py index ccaaa59dcf6..d9b7ace45b2 100644 --- a/tests/core/test_interface.py +++ b/tests/core/test_interface.py @@ -13,7 +13,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/core/grain_boundary" -class TestGrainBoundary(PymatgenTest): +class TestGrainBoundary(MatSciTest): def setup_method(self): self.Cu_conv = Structure.from_file(f"{TEST_DIR}/Cu_mp-30_conventional_standard.cif") GB_Cu_conv = GrainBoundaryGenerator(self.Cu_conv) @@ -104,7 +104,7 @@ def test_as_dict_and_from_dict(self): assert_allclose(Cu_GB2_new.lattice.matrix, self.Cu_GB2.lattice.matrix) -class TestGrainBoundaryGenerator(PymatgenTest): +class TestGrainBoundaryGenerator(MatSciTest): @classmethod def setup_class(cls): cls.Cu_prim = Structure.from_file(f"{TEST_DIR}/Cu_mp-30_primitive.cif") @@ -331,7 +331,7 @@ def test_get_rotation_angle_from_sigma(self): assert_allclose(close_angle, angle) -class TestInterface(PymatgenTest): +class TestInterface(MatSciTest): def setup_method(self): self.interface: Interface = self.get_structure("Si_SiO2_Interface") diff --git a/tests/core/test_lattice.py b/tests/core/test_lattice.py index 1bbe8f4b865..622da5c9b24 100644 --- a/tests/core/test_lattice.py +++ b/tests/core/test_lattice.py @@ -12,7 +12,7 @@ from pymatgen.util.testing import PymatgenTest -class TestLattice(PymatgenTest): +class TestLattice(MatSciTest): def setup_method(self): self.lattice = Lattice.cubic(10.0) self.cubic = self.lattice diff --git a/tests/core/test_libxcfunc.py b/tests/core/test_libxcfunc.py index 435b71c389e..7fb82780466 100644 --- a/tests/core/test_libxcfunc.py +++ b/tests/core/test_libxcfunc.py @@ -4,7 +4,7 @@ from pymatgen.util.testing import PymatgenTest -class TestLibxcFunc(PymatgenTest): +class TestLibxcFunc(MatSciTest): def test_libxcfunc_api(self): """Testing libxcfunc_api.""" # LDA correlation: Hedin & Lundqvist diff --git a/tests/core/test_molecular_orbitals.py b/tests/core/test_molecular_orbitals.py index 4476c856d17..4943a17ec7a 100644 --- a/tests/core/test_molecular_orbitals.py +++ b/tests/core/test_molecular_orbitals.py @@ -8,7 +8,7 @@ test_case = MolecularOrbitals("NaCl") -class TestMolecularOrbital(PymatgenTest): +class TestMolecularOrbital(MatSciTest): def test_max_electronegativity(self): test_elec_neg = 2.23 assert test_elec_neg == test_case.max_electronegativity() diff --git a/tests/core/test_operations.py b/tests/core/test_operations.py index 63efb6317c3..3376993f310 100644 --- a/tests/core/test_operations.py +++ b/tests/core/test_operations.py @@ -8,7 +8,7 @@ from pymatgen.util.testing import PymatgenTest -class TestSymmOp(PymatgenTest): +class TestSymmOp(MatSciTest): def setup_method(self): self.op = SymmOp.from_axis_angle_and_translation([0, 0, 1], 30, translation_vec=[0, 0, 1]) @@ -236,7 +236,7 @@ def test_xyz(self): assert_allclose(symm_op.translation_vector, [0.5, 0.25, 0.75]) -class TestMagSymmOp(PymatgenTest): +class TestMagSymmOp(MatSciTest): def test_xyzt_string(self): xyzt_strings = ["x, y, z, +1", "x, y, z, -1", "-y+1/2, x+1/2, x+1/2, +1"] diff --git a/tests/core/test_periodic_table.py b/tests/core/test_periodic_table.py index 1a1c2fa68fe..1bb2e76473b 100644 --- a/tests/core/test_periodic_table.py +++ b/tests/core/test_periodic_table.py @@ -17,7 +17,7 @@ from pymatgen.util.testing import PymatgenTest -class TestElement(PymatgenTest): +class TestElement(MatSciTest): def test_init(self): assert Element("Fe").symbol == "Fe" @@ -392,7 +392,7 @@ def test_isotope(self): ] -class TestSpecies(PymatgenTest): +class TestSpecies(MatSciTest): def setup_method(self): self.specie1 = Species.from_str("Fe2+") self.specie2 = Species("Fe", 3) diff --git a/tests/core/test_sites.py b/tests/core/test_sites.py index c8d53ca6f19..b1d3cfa0675 100644 --- a/tests/core/test_sites.py +++ b/tests/core/test_sites.py @@ -12,7 +12,7 @@ from pymatgen.util.testing import PymatgenTest -class TestSite(PymatgenTest): +class TestSite(MatSciTest): def setup_method(self): self.ordered_site = Site("Fe", [0.25, 0.35, 0.45]) self.disordered_site = Site({"Fe": 0.5, "Mn": 0.5}, [0.25, 0.35, 0.45]) @@ -79,7 +79,7 @@ def test_setters(self): self.disordered_site.species = {"Cu": 0.5, "Gd": 0.6} -class TestPeriodicSite(PymatgenTest): +class TestPeriodicSite(MatSciTest): def setup_method(self): self.lattice = Lattice.cubic(10.0) self.si = Element("Si") diff --git a/tests/core/test_spectrum.py b/tests/core/test_spectrum.py index 4d317e016ad..5c2cd5780e1 100644 --- a/tests/core/test_spectrum.py +++ b/tests/core/test_spectrum.py @@ -9,7 +9,7 @@ from pymatgen.util.testing import PymatgenTest -class TestSpectrum(PymatgenTest): +class TestSpectrum(MatSciTest): def setup_method(self): rng = np.random.default_rng() self.spec1 = Spectrum(np.arange(0, 10, 0.1), rng.standard_normal(100)) diff --git a/tests/core/test_structure.py b/tests/core/test_structure.py index 365cdfbab6d..028cc36b234 100644 --- a/tests/core/test_structure.py +++ b/tests/core/test_structure.py @@ -44,7 +44,7 @@ mcsqs_cmd = which("mcsqs") -class TestNeighbor(PymatgenTest): +class TestNeighbor(MatSciTest): def test_msonable(self): struct = PymatgenTest.get_structure("Li2O") nn = struct.get_neighbors(struct[0], r=3) @@ -63,7 +63,7 @@ def test_neighbor_labels(self): assert p_neighbor.label == label if label is not None else "C" -class TestIStructure(PymatgenTest): +class TestIStructure(MatSciTest): def setup_method(self): coords = [[0, 0, 0], [0.75, 0.5, 0.75]] self.lattice = Lattice( @@ -965,7 +965,7 @@ def test_sites_setter(self): assert struct.sites == new_sites -class TestStructure(PymatgenTest): +class TestStructure(MatSciTest): def setup_method(self): coords = [[0, 0, 0], [0.75, 0.5, 0.75]] lattice = Lattice( @@ -2032,7 +2032,7 @@ def test_struct_with_isotope(self): assert "Deuterium" not in [el.long_name for el in struct.composition.elements] -class TestIMolecule(PymatgenTest): +class TestIMolecule(MatSciTest): def setup_method(self): coords = [ [0, 0, 0], @@ -2327,7 +2327,7 @@ def test_to_file_alias(self): assert os.path.isfile(out_path) -class TestMolecule(PymatgenTest): +class TestMolecule(MatSciTest): def setup_method(self): coords = [ [0, 0, 0], diff --git a/tests/core/test_surface.py b/tests/core/test_surface.py index e57f7a3edb6..ceff64a3457 100644 --- a/tests/core/test_surface.py +++ b/tests/core/test_surface.py @@ -29,7 +29,7 @@ PMG_CORE_DIR = os.path.dirname(pymatgen.core.__file__) -class TestSlab(PymatgenTest): +class TestSlab(MatSciTest): def setup_method(self): zno1 = Structure.from_file(f"{TEST_FILES_DIR}/surfaces/ZnO-wz.cif", primitive=False) zno55 = SlabGenerator(zno1, [1, 0, 0], 5, 5, lll_reduce=False, center_slab=False).get_slab() @@ -346,7 +346,7 @@ def test_as_dict(self): assert slab == Slab.from_dict(d) -class TestSlabGenerator(PymatgenTest): +class TestSlabGenerator(MatSciTest): def setup_method(self): lattice = Lattice.cubic(3.010) frac_coords = [ @@ -634,7 +634,7 @@ def test_bonds_broken(self): assert slabs[1].energy, 6.0 -class ReconstructionGeneratorTests(PymatgenTest): +class ReconstructionGeneratorTests(MatSciTest): def setup_method(self): lattice = Lattice.cubic(3.51) species = ["Ni"] @@ -723,7 +723,7 @@ def test_previous_reconstructions(self): assert any(len(match.group_structures([struct, slab])) == 1 for slab in slabs) -class TestMillerIndexFinder(PymatgenTest): +class TestMillerIndexFinder(MatSciTest): def setup_method(self): self.cscl = Structure.from_spacegroup("Pm-3m", Lattice.cubic(4.2), ["Cs", "Cl"], [[0, 0, 0], [0.5, 0.5, 0.5]]) self.Fe = Structure.from_spacegroup("Im-3m", Lattice.cubic(2.82), ["Fe"], [[0, 0, 0]]) diff --git a/tests/core/test_tensors.py b/tests/core/test_tensors.py index 94c3a24d395..972e8b3f207 100644 --- a/tests/core/test_tensors.py +++ b/tests/core/test_tensors.py @@ -14,7 +14,7 @@ from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest -class TestTensor(PymatgenTest): +class TestTensor(MatSciTest): def setup_method(self): rng = np.random.default_rng() @@ -379,7 +379,7 @@ def test_round(self): assert isinstance(rounded, Tensor) -class TestTensorCollection(PymatgenTest): +class TestTensorCollection(MatSciTest): def setup_method(self): self.seq_tc = list(np.arange(4 * 3**3).reshape((4, 3, 3, 3))) self.seq_tc = TensorCollection(self.seq_tc) @@ -472,7 +472,7 @@ def test_serialization(self): assert_allclose(t, t_new) -class TestSquareTensor(PymatgenTest): +class TestSquareTensor(MatSciTest): def setup_method(self): self.rand_sqtensor = SquareTensor(np.random.default_rng().standard_normal((3, 3))) self.symm_sqtensor = SquareTensor([[0.1, 0.3, 0.4], [0.3, 0.5, 0.2], [0.4, 0.2, 0.6]]) diff --git a/tests/core/test_trajectory.py b/tests/core/test_trajectory.py index 9259b5f1b44..1ff941ecbf9 100644 --- a/tests/core/test_trajectory.py +++ b/tests/core/test_trajectory.py @@ -17,7 +17,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/core/trajectory" -class TestTrajectory(PymatgenTest): +class TestTrajectory(MatSciTest): def setup_method(self): xdatcar = Xdatcar(f"{VASP_OUT_DIR}/XDATCAR_traj") self.traj = Trajectory.from_file(f"{VASP_OUT_DIR}/XDATCAR_traj") diff --git a/tests/core/test_units.py b/tests/core/test_units.py index 88e06d92517..3e420bdad8f 100644 --- a/tests/core/test_units.py +++ b/tests/core/test_units.py @@ -37,7 +37,7 @@ def test_unit_conversions(): assert amu_to_kg == approx(1.66053906660e-27) -class TestUnit(PymatgenTest): +class TestUnit(MatSciTest): def test_init(self): u1 = Unit((("m", 1), ("s", -1))) assert str(u1) == "m s^-1" @@ -53,7 +53,7 @@ def test_init(self): assert str(newton * Unit("m")) == "N m" -class TestFloatWithUnit(PymatgenTest): +class TestFloatWithUnit(MatSciTest): def test_energy(self): a = Energy(1.1, "eV") b = a.to("Ha") @@ -185,7 +185,7 @@ def test_neg(self): assert FloatWithUnit(-5, "MPa") == -x -class TestArrayWithUnit(PymatgenTest): +class TestArrayWithUnit(MatSciTest): def test_energy(self): """Similar to TestFloatWithUnit.test_energy. Check whether EnergyArray and FloatWithUnit have same behavior. @@ -293,7 +293,7 @@ def test_as_base_units(self): assert_array_equal(ArrayWithUnit([5000000, 10000000], "Pa"), pressure_arr.as_base_units) -class TestDataPersistence(PymatgenTest): +class TestDataPersistence(MatSciTest): def test_pickle(self): """Test whether FloatWithUnit and ArrayWithUnit support pickle.""" for cls in [FloatWithUnit, ArrayWithUnit]: diff --git a/tests/core/test_xcfunc.py b/tests/core/test_xcfunc.py index 793fb9f7cad..fb95376d4b9 100644 --- a/tests/core/test_xcfunc.py +++ b/tests/core/test_xcfunc.py @@ -6,7 +6,7 @@ from pymatgen.util.testing import PymatgenTest -class TestLibxcFunc(PymatgenTest): +class TestLibxcFunc(MatSciTest): def setup_method(self) -> None: self.ixc_11 = XcFunc.from_abinit_ixc(11) diff --git a/tests/electronic_structure/test_bandstructure.py b/tests/electronic_structure/test_bandstructure.py index a1e88e8ab0e..5547a61dc40 100644 --- a/tests/electronic_structure/test_bandstructure.py +++ b/tests/electronic_structure/test_bandstructure.py @@ -67,7 +67,7 @@ def test_from_dict(self): assert kpoint.label == "X" -class TestBandStructureSymmLine(PymatgenTest): +class TestBandStructureSymmLine(MatSciTest): def setup_method(self): self.bs: BandStructureSymmLine = loadfn(f"{TEST_DIR}/Cu2O_361_bandstructure.json") self.bs2: BandStructureSymmLine = loadfn(f"{TEST_DIR}/CaO_2605_bandstructure.json") @@ -257,7 +257,7 @@ def test_apply_scissor_spin_polarized(self): assert bs_scissored.efermi != approx(orig_efermi) -class TestReconstructBandStructure(PymatgenTest): +class TestReconstructBandStructure(MatSciTest): def setup_method(self): self.bs_cu: BandStructureSymmLine = loadfn(f"{TEST_DIR}/Cu_30_bandstructure.json") self.bs_cu2: BandStructureSymmLine = loadfn(f"{TEST_DIR}/Cu_30_bandstructure.json") @@ -276,7 +276,7 @@ def test_vasprun_bs(self): bs.get_projection_on_elements() -class TestLobsterBandStructureSymmLine(PymatgenTest): +class TestLobsterBandStructureSymmLine(MatSciTest): def setup_method(self): with open( f"{TEST_FILES_DIR}/electronic_structure/cohp/Fatband_SiO2/Test_p/lobster_band_structure_spin.json", diff --git a/tests/electronic_structure/test_cohp.py b/tests/electronic_structure/test_cohp.py index 78f09623d09..2f4bfdfb73b 100644 --- a/tests/electronic_structure/test_cohp.py +++ b/tests/electronic_structure/test_cohp.py @@ -796,7 +796,7 @@ def test_extremum_icohpvalue(self): assert self.icoopcollection_Fe.extremum_icohpvalue(summed_spin_channels=False, spin=Spin.down) == -0.05756 -class TestCompleteCohp(PymatgenTest): +class TestCompleteCohp(MatSciTest): def setup_method(self): filepath = f"{TEST_DIR}/complete_cohp_lobster.json" with open(filepath) as file: diff --git a/tests/electronic_structure/test_dos.py b/tests/electronic_structure/test_dos.py index fa0f5b1ff91..3474d31f2be 100644 --- a/tests/electronic_structure/test_dos.py +++ b/tests/electronic_structure/test_dos.py @@ -322,7 +322,7 @@ def test_dos_fp_exceptions(self): self.dos.get_dos_fp_similarity(dos_fp, dos_fp2, col=1, metric=metric, normalize=False) -class TestDOS(PymatgenTest): +class TestDOS(MatSciTest): def setup_method(self): with open(f"{TEST_DIR}/complete_dos.json") as file: dct = json.load(file) diff --git a/tests/electronic_structure/test_plotter.py b/tests/electronic_structure/test_plotter.py index 813dfa4a556..5ddfe2405e9 100644 --- a/tests/electronic_structure/test_plotter.py +++ b/tests/electronic_structure/test_plotter.py @@ -36,7 +36,7 @@ rc("text", usetex=False) # Disabling latex is needed for this test to work. -class TestDosPlotter(PymatgenTest): +class TestDosPlotter(MatSciTest): def setup_method(self): with open(f"{BAND_TEST_DIR}/../dos/complete_dos.json") as file: self.dos = CompleteDos.from_dict(json.load(file)) @@ -90,7 +90,7 @@ def get_plot_attributes(ax: plt.Axes): } -class TestBSPlotter(PymatgenTest): +class TestBSPlotter(MatSciTest): def setup_method(self): with open(f"{BAND_TEST_DIR}/CaO_2605_bandstructure.json") as file: dct = json.loads(file.read()) @@ -443,7 +443,7 @@ def test_plot_zt_temp(self): plt.close() -class TestCohpPlotter(PymatgenTest): +class TestCohpPlotter(MatSciTest): def setup_method(self): path = f"{TEST_FILES_DIR}/electronic_structure/cohp/complete_cohp_lobster.json" with open(path) as file: diff --git a/tests/entries/test_entry_tools.py b/tests/entries/test_entry_tools.py index a3c559239ed..26e673af718 100644 --- a/tests/entries/test_entry_tools.py +++ b/tests/entries/test_entry_tools.py @@ -14,7 +14,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/entries" -class TestFunc(PymatgenTest): +class TestFunc(MatSciTest): def test_group_entries_by_structure(self): entries = loadfn(f"{TEST_DIR}/TiO2_entries.json") groups = group_entries_by_structure(entries) @@ -49,7 +49,7 @@ def test_group_entries_by_composition(self): assert group == sorted(group, key=lambda e: e.energy_per_atom) -class TestEntrySet(PymatgenTest): +class TestEntrySet(MatSciTest): def setup_method(self): entries = loadfn(f"{TEST_DIR}/Li-Fe-P-O_entries.json") self.entry_set = EntrySet(entries) diff --git a/tests/ext/test_matproj.py b/tests/ext/test_matproj.py index 7f4093d8d84..65c0fd64444 100644 --- a/tests/ext/test_matproj.py +++ b/tests/ext/test_matproj.py @@ -48,7 +48,7 @@ not 10 < len(PMG_MAPI_KEY) <= 20, reason="Legacy PMG_MAPI_KEY environment variable not set.", ) -class TestMPResterOld(PymatgenTest): +class TestMPResterOld(MatSciTest): def setup_method(self): self.rester = _MPResterLegacy() @@ -528,7 +528,7 @@ def test_api_key_is_none(self): not len(PMG_MAPI_KEY) > 20, reason="PMG_MAPI_KEY environment variable not set.", ) -class TestMPResterNewBasic(PymatgenTest): +class TestMPResterNewBasic(MatSciTest): def setup_method(self): self.rester = _MPResterBasic() diff --git a/tests/ext/test_optimade.py b/tests/ext/test_optimade.py index e2710ddeaff..01882b19cfc 100644 --- a/tests/ext/test_optimade.py +++ b/tests/ext/test_optimade.py @@ -36,7 +36,7 @@ mc2d_down = True -class TestOptimade(PymatgenTest): +class TestOptimade(MatSciTest): @pytest.mark.skipif(mp_website_down, reason="MP OPTIMADE is down.") def test_get_structures_mp(self): with OptimadeRester("mp") as optimade: diff --git a/tests/io/abinit/test_abiobjects.py b/tests/io/abinit/test_abiobjects.py index ad38c49dafe..f6afb2de78a 100644 --- a/tests/io/abinit/test_abiobjects.py +++ b/tests/io/abinit/test_abiobjects.py @@ -22,7 +22,7 @@ from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest -class TestLatticeFromAbivars(PymatgenTest): +class TestLatticeFromAbivars(MatSciTest): def test_rprim_acell(self): l1 = lattice_from_abivars(acell=3 * [10], rprim=np.eye(3)) assert l1.volume == approx(bohr_to_ang**3 * 1000) @@ -108,7 +108,7 @@ def test_znucl_typat(self): structure_to_abivars(gan, enforce_znucl=enforce_znucl, enforce_typat=None) -class TestSpinMode(PymatgenTest): +class TestSpinMode(MatSciTest): def test_base(self): polarized = SpinMode.as_spinmode("polarized") other_polarized = SpinMode.as_spinmode("polarized") @@ -128,7 +128,7 @@ def test_base(self): self.assert_msonable(unpolarized) -class TestSmearing(PymatgenTest): +class TestSmearing(MatSciTest): def test_base(self): fd1ev = Smearing.as_smearing("fermi_dirac:1 eV") fd1ev.to_abivars() @@ -156,7 +156,7 @@ def test_base(self): self.assert_msonable(fd1ev) -class TestElectronsAlgorithm(PymatgenTest): +class TestElectronsAlgorithm(MatSciTest): def test_base(self): algo = ElectronsAlgorithm(nstep=70) _ = algo.to_abivars() @@ -168,7 +168,7 @@ def test_base(self): self.assert_msonable(algo) -class TestElectrons(PymatgenTest): +class TestElectrons(MatSciTest): def test_base(self): default_electrons = Electrons() assert default_electrons.nsppol == 2 @@ -195,7 +195,7 @@ def test_base(self): self.assert_msonable(custom_electrons) -class TestKSampling(PymatgenTest): +class TestKSampling(MatSciTest): def test_base(self): monkhorst = KSampling.monkhorst((3, 3, 3), (0.5, 0.5, 0.5), 0, use_symmetries=False, use_time_reversal=False) gamma_centered = KSampling.gamma_centered((3, 3, 3), use_symmetries=False, use_time_reversal=False) @@ -207,7 +207,7 @@ def test_base(self): self.assert_msonable(gamma_centered) -class TestRelaxation(PymatgenTest): +class TestRelaxation(MatSciTest): def test_base(self): atoms_and_cell = RelaxationMethod.atoms_and_cell() atoms_only = RelaxationMethod.atoms_only() @@ -227,7 +227,7 @@ def test_base(self): self.assert_msonable(atoms_only) -class TestPPModel(PymatgenTest): +class TestPPModel(MatSciTest): def test_base(self): godby = PPModel.as_ppmodel("godby:12 eV") godby.to_abivars() diff --git a/tests/io/abinit/test_inputs.py b/tests/io/abinit/test_inputs.py index 4bc0229b0f3..e16ac9abb66 100644 --- a/tests/io/abinit/test_inputs.py +++ b/tests/io/abinit/test_inputs.py @@ -33,7 +33,7 @@ def abiref_files(*filenames): return [f"{TEST_DIR}/{file}" for file in filenames] -class TestAbinitInput(PymatgenTest): +class TestAbinitInput(MatSciTest): """Unit tests for BasicAbinitInput.""" def test_api(self): @@ -168,7 +168,7 @@ def test_helper_functions(self): assert len(inp["kptbounds"]) == 12 -class TestMultiDataset(PymatgenTest): +class TestMultiDataset(MatSciTest): """Unit tests for BasicMultiDataset.""" def test_api(self): @@ -251,7 +251,7 @@ def test_api(self): self.serialize_with_pickle(multi, test_eq=False) -class TestShiftMode(PymatgenTest): +class TestShiftMode(MatSciTest): def test_shiftmode(self): gamma = ShiftMode.GammaCentered assert ShiftMode.from_object("G") == gamma @@ -260,7 +260,7 @@ def test_shiftmode(self): ShiftMode.from_object({}) -class TestFactory(PymatgenTest): +class TestFactory(MatSciTest): def setup_method(self): # Si ebands self.si_structure = Structure.from_file(abiref_file("si.cif")) diff --git a/tests/io/abinit/test_netcdf.py b/tests/io/abinit/test_netcdf.py index 16c0babe320..c0d9cff9a53 100644 --- a/tests/io/abinit/test_netcdf.py +++ b/tests/io/abinit/test_netcdf.py @@ -21,7 +21,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/io/abinit" -class TestEtsfReader(PymatgenTest): +class TestEtsfReader(MatSciTest): def setup_method(self): formulas = ["Si2"] self.GSR_paths = dct = {} @@ -117,7 +117,7 @@ def test_read_fe(self): assert structure.site_properties["magmom"] == ref_magmom_noncollinear -class TestAbinitHeader(PymatgenTest): +class TestAbinitHeader(MatSciTest): def test_api(self): head = AbinitHeader(foo=1, bar=2) assert head.foo == 1 diff --git a/tests/io/abinit/test_pseudos.py b/tests/io/abinit/test_pseudos.py index 518036ce6ed..752518d4d6b 100644 --- a/tests/io/abinit/test_pseudos.py +++ b/tests/io/abinit/test_pseudos.py @@ -14,7 +14,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/io/abinit" -class TestPseudo(PymatgenTest): +class TestPseudo(MatSciTest): def setup_method(self): nc_pseudo_fnames = defaultdict(list) nc_pseudo_fnames["Si"] = [f"{TEST_DIR}/{file}" for file in ("14si.pspnc", "14si.4.hgh", "14-Si.LDA.fhi")] @@ -198,7 +198,7 @@ def test_oncvpsp_pseudo_fr(self): assert pb.supports_soc -class TestPseudoTable(PymatgenTest): +class TestPseudoTable(MatSciTest): def test_methods(self): """Test PseudoTable methods.""" table = PseudoTable([f"{TEST_DIR}/{file}" for file in ("14si.pspnc", "14si.4.hgh", "14-Si.LDA.fhi")]) diff --git a/tests/io/cp2k/test_inputs.py b/tests/io/cp2k/test_inputs.py index d55100773fe..9e4ae2ae50c 100644 --- a/tests/io/cp2k/test_inputs.py +++ b/tests/io/cp2k/test_inputs.py @@ -41,7 +41,7 @@ """ -class TestBasis(PymatgenTest): +class TestBasis(MatSciTest): def test_basis_info(self): # Ensure basis metadata can be read from string basis_info = BasisInfo.from_str("cc-pc-DZVP-MOLOPT-q1-SCAN") @@ -92,7 +92,7 @@ def test_basis(self): mol_opt.info.admm = False -class TestPotential(PymatgenTest): +class TestPotential(MatSciTest): all_hydrogen_str = """ H ALLELECTRON ALL 1 0 0 @@ -144,7 +144,7 @@ def test_potentials(self): assert kw.values[0] == "ALL" -class TestCp2kInput(PymatgenTest): +class TestCp2kInput(MatSciTest): si_struct = Structure( lattice=[ [0, 2.734364, 2.734364], @@ -268,7 +268,7 @@ def test_mongo(self): assert cp2k_input.check("global/subsec2") -class TestDataFile(PymatgenTest): +class TestDataFile(MatSciTest): def test_data_file(self): # make temp file with BASIS_FILE_STR data_file = self.tmp_path / "data-file" diff --git a/tests/io/cp2k/test_sets.py b/tests/io/cp2k/test_sets.py index e2c74bc31a6..3c28e85c953 100644 --- a/tests/io/cp2k/test_sets.py +++ b/tests/io/cp2k/test_sets.py @@ -46,7 +46,7 @@ } -class TestDftSet(PymatgenTest): +class TestDftSet(MatSciTest): def test_dft_set(self) -> None: """Test various DFT set configurations.""" SETTINGS["PMG_CP2K_DATA_DIR"] = CP2K_TEST_DIR diff --git a/tests/io/exciting/test_inputs.py b/tests/io/exciting/test_inputs.py index ccbac253944..89b6fa0cfcf 100644 --- a/tests/io/exciting/test_inputs.py +++ b/tests/io/exciting/test_inputs.py @@ -19,7 +19,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/io/exciting" -class TestExcitingInput(PymatgenTest): +class TestExcitingInput(MatSciTest): def test_fromfile(self): # Test for the import of a structure directly from an exciting # input file diff --git a/tests/io/feff/test_sets.py b/tests/io/feff/test_sets.py index faf3aa85b78..87b5e5896be 100644 --- a/tests/io/feff/test_sets.py +++ b/tests/io/feff/test_sets.py @@ -14,7 +14,7 @@ FEFF_TEST_DIR = f"{TEST_FILES_DIR}/io/feff" -class TestFeffInputSet(PymatgenTest): +class TestFeffInputSet(MatSciTest): @classmethod def setup_class(cls): cls.header_string = """* This FEFF.inp file generated by pymatgen diff --git a/tests/io/lammps/test_data.py b/tests/io/lammps/test_data.py index 53bc5005080..e57303a49eb 100644 --- a/tests/io/lammps/test_data.py +++ b/tests/io/lammps/test_data.py @@ -18,7 +18,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/io/lammps" -class TestLammpsBox(PymatgenTest): +class TestLammpsBox(MatSciTest): @classmethod def setup_class(cls): cls.peptide = LammpsBox( @@ -72,7 +72,7 @@ def test_to_lattice(self): ) -class TestLammpsData(PymatgenTest): +class TestLammpsData(MatSciTest): @classmethod def setup_class(cls): cls.peptide = LammpsData.from_file(filename=f"{TEST_DIR}/data.peptide") @@ -664,7 +664,7 @@ def test_from_bonding(self): assert "Dihedrals" not in topo_etoh2.topologies -class TestForceField(PymatgenTest): +class TestForceField(MatSciTest): @classmethod def setup_class(cls): mass_info = [ diff --git a/tests/io/lammps/test_generators.py b/tests/io/lammps/test_generators.py index 950542da6ff..ea3d91b18b4 100644 --- a/tests/io/lammps/test_generators.py +++ b/tests/io/lammps/test_generators.py @@ -8,7 +8,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/io/lammps" -class TestLammpsMinimization(PymatgenTest): +class TestLammpsMinimization(MatSciTest): @classmethod def setup_class(cls): cls.filename = f"{TEST_DIR}/lgps.in" diff --git a/tests/io/lammps/test_inputs.py b/tests/io/lammps/test_inputs.py index 23e3df888fd..09efce63c81 100644 --- a/tests/io/lammps/test_inputs.py +++ b/tests/io/lammps/test_inputs.py @@ -16,7 +16,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/io/lammps" -class TestLammpsInputFile(PymatgenTest): +class TestLammpsInputFile(MatSciTest): @classmethod def setup_class(cls): cls.filename = f"{TEST_DIR}/lgps.in" @@ -640,7 +640,7 @@ def test_add_comment(self): ] -class TestLammpsRun(PymatgenTest): +class TestLammpsRun(MatSciTest): def test_md(self): struct = Structure.from_spacegroup(225, Lattice.cubic(3.62126), ["Cu"], [[0, 0, 0]]) ld = LammpsData.from_structure(struct, atom_style="atomic") @@ -690,7 +690,7 @@ def test_md(self): assert os.path.isfile(f"{self.tmp_path}/md/md.data") -class TestFunc(PymatgenTest): +class TestFunc(MatSciTest): @pytest.mark.filterwarnings("ignore:write_lammps_inputs is deprecated") def test_write_lammps_inputs(self): # script template @@ -727,7 +727,7 @@ def test_write_lammps_inputs(self): pd.testing.assert_frame_equal(obj_read.atoms, obj.atoms) -class TestLammpsTemplateGen(PymatgenTest): +class TestLammpsTemplateGen(MatSciTest): def test_write_inputs(self): # simple script without data file lis = LammpsTemplateGen().get_input_set( diff --git a/tests/io/lobster/test_inputs.py b/tests/io/lobster/test_inputs.py index 9e7dbe2b97e..a5140a0ed36 100644 --- a/tests/io/lobster/test_inputs.py +++ b/tests/io/lobster/test_inputs.py @@ -19,7 +19,7 @@ __date__ = "Dec 10, 2017" -class TestLobsterin(PymatgenTest): +class TestLobsterin(MatSciTest): def setup_method(self): self.Lobsterin = Lobsterin.from_file(f"{TEST_DIR}/lobsterin.1") self.Lobsterin2 = Lobsterin.from_file(f"{TEST_DIR}/lobsterin.2") @@ -579,7 +579,7 @@ def test_as_from_dict(self): new_lobsterin.to_json() -class TestUtils(PymatgenTest): +class TestUtils(MatSciTest): def test_get_all_possible_basis_combinations(self): # this basis is just for testing (not correct) min_basis = ["Li 1s 2s ", "Na 1s 2s", "Si 1s 2s"] diff --git a/tests/io/lobster/test_outputs.py b/tests/io/lobster/test_outputs.py index 5728aac419d..17fc2ff122e 100644 --- a/tests/io/lobster/test_outputs.py +++ b/tests/io/lobster/test_outputs.py @@ -41,7 +41,7 @@ __date__ = "Dec 10, 2017" -class TestBwdf(PymatgenTest): +class TestBwdf(MatSciTest): def setup_method(self): self.bwdf_coop = Bwdf(filename=f"{TEST_DIR}/BWDF.lobster.AlN.gz") self.bwdf_cohp = Bwdf(filename=f"{TEST_DIR}/BWDFCOHP.lobster.NaCl.gz") @@ -56,7 +56,7 @@ def test_attributes(self): assert self.bwdf_cohp.bwdf[Spin.up][103] == approx(-0.01392, abs=1e-4) -class TestCohpcar(PymatgenTest): +class TestCohpcar(MatSciTest): def setup_method(self): self.cohp_bise = Cohpcar(filename=f"{TEST_DIR}/COHPCAR.lobster.BiSe.gz") self.coop_bise = Cohpcar( @@ -636,7 +636,7 @@ def test_is_spin_polarized(self): assert not self.DOSCAR_nonspin_pol.is_spin_polarized -class TestCharge(PymatgenTest): +class TestCharge(MatSciTest): def setup_method(self): self.charge2 = Charge(filename=f"{TEST_DIR}/CHARGE.lobster.MnO") # gzipped file @@ -715,7 +715,7 @@ def test_msonable(self): assert getattr(charge_from_dict, attr_name) == attr_value -class TestLobsterout(PymatgenTest): +class TestLobsterout(MatSciTest): def setup_method(self): self.lobsterout_normal = Lobsterout(filename=f"{TEST_DIR}/lobsterout.normal") # make sure .gz files are also read correctly @@ -1244,7 +1244,7 @@ def test_msonable(self): Lobsterout(filename=None, invalid="val") -class TestFatband(PymatgenTest): +class TestFatband(MatSciTest): def setup_method(self): self.structure = Vasprun( filename=f"{TEST_DIR}/Fatband_SiO2/Test_p_x/vasprun.xml", @@ -2203,7 +2203,7 @@ def test_ncicobilist(self): ) -class TestWavefunction(PymatgenTest): +class TestWavefunction(MatSciTest): def test_parse_file(self): grid, points, real, imaginary, distance = Wavefunction._parse_file( f"{TEST_DIR}/LCAOWaveFunctionAfterLSO1PlotOfSpin1Kpoint1band1.gz" @@ -2271,7 +2271,7 @@ def test_write_file(self): assert os.path.isfile(density_wavecar_path) -class TestSitePotentials(PymatgenTest): +class TestSitePotentials(MatSciTest): def setup_method(self) -> None: self.sitepotential = SitePotential(filename=f"{TEST_DIR}/SitePotentials.lobster.perovskite") @@ -2322,7 +2322,7 @@ def test_msonable(self): assert getattr(sitepotential_from_dict, attr_name) == attr_value -class TestMadelungEnergies(PymatgenTest): +class TestMadelungEnergies(MatSciTest): def setup_method(self) -> None: self.madelungenergies = MadelungEnergies(filename=f"{TEST_DIR}/MadelungEnergies.lobster.perovskite") @@ -2339,7 +2339,7 @@ def test_msonable(self): assert getattr(madelung_from_dict, attr_name) == attr_value -class TestLobsterMatrices(PymatgenTest): +class TestLobsterMatrices(MatSciTest): def setup_method(self) -> None: self.hamilton_matrices = LobsterMatrices( filename=f"{TEST_DIR}/Na_hamiltonMatrices.lobster.gz", e_fermi=-2.79650354 @@ -2489,7 +2489,7 @@ def test_raises(self): self.hamilton_matrices = LobsterMatrices(filename=f"{TEST_DIR}/hamiltonMatrices.lobster") -class TestPolarization(PymatgenTest): +class TestPolarization(MatSciTest): def setup_method(self) -> None: self.polarization = Polarization(filename=f"{TEST_DIR}/POLARIZATION.lobster.AlN.gz") diff --git a/tests/io/pwmat/test_inputs.py b/tests/io/pwmat/test_inputs.py index 7618e7ecdf6..075446cfb52 100644 --- a/tests/io/pwmat/test_inputs.py +++ b/tests/io/pwmat/test_inputs.py @@ -43,7 +43,7 @@ def test_list_locator(exclusion: str, expected_idx: int): assert aim_idx == expected_idx -class TestACstrExtractor(PymatgenTest): +class TestACstrExtractor(MatSciTest): def test_extract(self): filepath = f"{TEST_DIR}/atom.config" ac_extractor = ACExtractor(file_path=filepath) @@ -60,7 +60,7 @@ def test_extract(self): assert ac_extractor.magmoms[idx] == ac_str_extractor.get_magmoms()[idx] -class TestAtomConfig(PymatgenTest): +class TestAtomConfig(MatSciTest): def test_init(self): filepath = f"{TEST_DIR}/atom.config" structure = Structure.from_file(filepath) @@ -82,7 +82,7 @@ def test_write_file(self): assert_allclose(atom_config.structure.lattice.abc, tmp_atom_config.structure.lattice.abc, 5) -class TestGenKpt(PymatgenTest): +class TestGenKpt(MatSciTest): def test_from_structure(self): pytest.importorskip("seekpath") filepath = f"{TEST_DIR}/atom.config" @@ -107,7 +107,7 @@ def test_write_file(self): assert gen_kpt.get_str() == tmp_gen_kpt_str -class TestHighSymmetryPoint(PymatgenTest): +class TestHighSymmetryPoint(MatSciTest): def test_from_structure(self): pytest.importorskip("seekpath") filepath = f"{TEST_DIR}/atom.config" diff --git a/tests/io/pwmat/test_outputs.py b/tests/io/pwmat/test_outputs.py index b2a97f891fe..d086baea1b8 100644 --- a/tests/io/pwmat/test_outputs.py +++ b/tests/io/pwmat/test_outputs.py @@ -6,7 +6,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/io/pwmat" -class TestMovement(PymatgenTest): +class TestMovement(MatSciTest): def test_init_and_properties(self): filepath = f"{TEST_DIR}/MOVEMENT.lzma" movement = Movement(filepath) @@ -26,14 +26,14 @@ def test_init_and_properties(self): assert movement.ionic_steps[0]["e_tot"] == -357677.2281 -class TestOutFermi(PymatgenTest): +class TestOutFermi(MatSciTest): def test_init_and_properties(self): filepath = f"{TEST_DIR}/OUT.FERMI.lzma" out_fermi = OutFermi(filepath) assert out_fermi.e_fermi == -2.359 -class TestReport(PymatgenTest): +class TestReport(MatSciTest): def test_init_and_properties(self): filepath = f"{TEST_DIR}/REPORT" report = Report(filepath) @@ -46,7 +46,7 @@ def test_init_and_properties(self): assert report.hsps == {} -class TestDosSpin(PymatgenTest): +class TestDosSpin(MatSciTest): def test_init_and_properties(self): filepath = f"{TEST_DIR}/DOS.spinup_projected" dos_spin = DosSpin(filepath) diff --git a/tests/io/qchem/test_inputs.py b/tests/io/qchem/test_inputs.py index fe87a29a095..b9bf1bca998 100644 --- a/tests/io/qchem/test_inputs.py +++ b/tests/io/qchem/test_inputs.py @@ -20,7 +20,7 @@ __credits__ = "Xiaohui Qu" -class TestQCInput(PymatgenTest): +class TestQCInput(MatSciTest): def test_molecule_template(self): species = ["C", "O"] coords = [ diff --git a/tests/io/qchem/test_outputs.py b/tests/io/qchem/test_outputs.py index 22f681f8918..6c837d28fca 100644 --- a/tests/io/qchem/test_outputs.py +++ b/tests/io/qchem/test_outputs.py @@ -260,7 +260,7 @@ } -class TestQCOutput(PymatgenTest): +class TestQCOutput(MatSciTest): @staticmethod def generate_single_job_dict(): """Used to generate test dictionary for single jobs.""" diff --git a/tests/io/qchem/test_sets.py b/tests/io/qchem/test_sets.py index 9a677b02ab8..beb3d9a8230 100644 --- a/tests/io/qchem/test_sets.py +++ b/tests/io/qchem/test_sets.py @@ -26,7 +26,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/io/qchem/new_qchem_files" -class TestQChemDictSet(PymatgenTest): +class TestQChemDictSet(MatSciTest): def test_init(self): test_molecule = QCInput.from_file(f"{TEST_DIR}/pcm.qin").molecule test_dict_set = QChemDictSet( @@ -469,7 +469,7 @@ def test_solvation_warnings(self): ) -class TestSinglePointSet(PymatgenTest): +class TestSinglePointSet(MatSciTest): def test_init(self): test_molecule = QCInput.from_file(f"{TEST_DIR}/pcm.qin").molecule test_sp_set = SinglePointSet(molecule=test_molecule) @@ -671,7 +671,7 @@ def test_plots_init(self): assert test_sp_set.molecule == test_molecule -class TestOptSet(PymatgenTest): +class TestOptSet(MatSciTest): def test_init(self): test_molecule = QCInput.from_file(f"{TEST_DIR}/pcm.qin").molecule test_opt_set = OptSet(molecule=test_molecule) @@ -846,7 +846,7 @@ def test_v5_vs_v6(self): assert v6_opt_set_modified.geom_opt == ref_dict -class TestTransitionStateSet(PymatgenTest): +class TestTransitionStateSet(MatSciTest): def test_init(self): test_molecule = QCInput.from_file(f"{TEST_DIR}/pcm.qin").molecule test_ts_set = TransitionStateSet(molecule=test_molecule) @@ -927,7 +927,7 @@ def test_smd_init(self): assert test_ts_set.molecule == test_molecule -class TestForceSet(PymatgenTest): +class TestForceSet(MatSciTest): def test_init(self): test_molecule = QCInput.from_file(f"{TEST_DIR}/pcm.qin").molecule test_forceset = ForceSet(molecule=test_molecule) @@ -1004,7 +1004,7 @@ def test_smd_init(self): assert test_forceset.molecule == test_molecule -class TestPESScanSet(PymatgenTest): +class TestPESScanSet(MatSciTest): def test_init(self): test_molecule = QCInput.from_file(f"{TEST_DIR}/pes_scan.qin").molecule @@ -1097,7 +1097,7 @@ def test_smd_init(self): assert test_pes_scan.molecule == test_molecule -class TestFreqSet(PymatgenTest): +class TestFreqSet(MatSciTest): def test_init(self): test_molecule = QCInput.from_file(f"{TEST_DIR}/pcm.qin").molecule test_freq_set = FreqSet(molecule=test_molecule) diff --git a/tests/io/qchem/test_utils.py b/tests/io/qchem/test_utils.py index 4ad091b8242..d77db30c9a9 100644 --- a/tests/io/qchem/test_utils.py +++ b/tests/io/qchem/test_utils.py @@ -15,7 +15,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/io/qchem/new_qchem_files" -class TestUtil(PymatgenTest): +class TestUtil(MatSciTest): """test utils.""" def test_lower_and_check_unique(self): diff --git a/tests/io/test_adf.py b/tests/io/test_adf.py index d3b6785320f..477b190b61f 100644 --- a/tests/io/test_adf.py +++ b/tests/io/test_adf.py @@ -242,7 +242,7 @@ def test_serialization(self): } -class TestAdfInput(PymatgenTest): +class TestAdfInput(MatSciTest): def test_main(self): tmp_file = f"{self.tmp_path}/adf.temp" mol = Molecule.from_str(rhb18_xyz, "xyz") diff --git a/tests/io/test_atat.py b/tests/io/test_atat.py index a9562f92511..628cb292c6b 100644 --- a/tests/io/test_atat.py +++ b/tests/io/test_atat.py @@ -10,7 +10,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/io/atat/mcsqs" -class TestAtat(PymatgenTest): +class TestAtat(MatSciTest): def test_mcsqs_import(self): test_str = """1.000000 0.000000 0.000000 0.000000 1.000000 0.000000 diff --git a/tests/io/test_cif.py b/tests/io/test_cif.py index eecb2261e84..a437515bff6 100644 --- a/tests/io/test_cif.py +++ b/tests/io/test_cif.py @@ -20,7 +20,7 @@ MCIF_TEST_DIR = f"{TEST_FILES_DIR}/io/cif/mcif" -class TestCifBlock(PymatgenTest): +class TestCifBlock(MatSciTest): def test_to_str(self): with open(f"{TEST_FILES_DIR}/cif/Graphite.cif") as file: cif_str = file.read() @@ -164,7 +164,7 @@ def test_long_loop(self): assert str(CifBlock(data, loops, "test")) == cif_str -class TestCifIO(PymatgenTest): +class TestCifIO(MatSciTest): def test_cif_parser(self): parser = CifParser(f"{TEST_FILES_DIR}/cif/LiFePO4.cif") for struct in parser.parse_structures(): @@ -999,7 +999,7 @@ def test_cif_writer_site_properties(self): assert "O O23 1 0.95662769 0.25000000 0.29286233 1 -1.0" in cif_str -class TestMagCif(PymatgenTest): +class TestMagCif(MatSciTest): def setup_method(self): self.mcif = CifParser(f"{MCIF_TEST_DIR}/magnetic.example.NiO.mcif") self.mcif_ncl = CifParser(f"{MCIF_TEST_DIR}/magnetic.ncl.example.GdB4.mcif") diff --git a/tests/io/test_core.py b/tests/io/test_core.py index 560bd35848b..7a719bb7a4d 100644 --- a/tests/io/test_core.py +++ b/tests/io/test_core.py @@ -44,7 +44,7 @@ def __str__(self): return f"{self.a}\n{self.b}" -class TestInputFile(PymatgenTest): +class TestInputFile(MatSciTest): def test_file_io(self): with pytest.raises(FileNotFoundError, match="No such file or directory: 'fakepath.cif'"): StructInputFile.from_file("fakepath.cif") @@ -64,7 +64,7 @@ def test_msonable(self): assert sif.structure == temp_sif.structure -class TestInputSet(PymatgenTest): +class TestInputSet(MatSciTest): @classmethod def setup_class(cls): cls.sif1 = StructInputFile.from_file(f"{TEST_FILES_DIR}/cif/Li.cif") diff --git a/tests/io/test_lmto.py b/tests/io/test_lmto.py index 25e75d4daa8..8d1b924f7cf 100644 --- a/tests/io/test_lmto.py +++ b/tests/io/test_lmto.py @@ -23,7 +23,7 @@ MODULE_DIR = os.path.dirname(os.path.abspath(__file__)) -class TestCtrl(PymatgenTest): +class TestCtrl(MatSciTest): def setup_method(self): os.chdir(TEST_DIR) self.ref_bise = LMTOCtrl.from_file(filename="CTRL.BiSe") @@ -47,7 +47,7 @@ def test_read_write(self): assert self.ref_bise.structure.matches(ctrl_file.structure) -class TestCopl(PymatgenTest): +class TestCopl(MatSciTest): def setup_method(self): os.chdir(TEST_DIR) self.copl_bise = LMTOCopl("COPL.BiSe") diff --git a/tests/io/test_packmol.py b/tests/io/test_packmol.py index c6d25953dcd..0b671f9f62d 100644 --- a/tests/io/test_packmol.py +++ b/tests/io/test_packmol.py @@ -48,7 +48,7 @@ water = Molecule(water_atoms, water_coords) -class TestPackmolSet(PymatgenTest): +class TestPackmolSet(MatSciTest): def test_packmol_with_molecule(self): """Test coords input as Molecule.""" pw = PackmolBoxGen().get_input_set( diff --git a/tests/io/test_phonopy.py b/tests/io/test_phonopy.py index a34bb5bb9a2..e84414e72d7 100644 --- a/tests/io/test_phonopy.py +++ b/tests/io/test_phonopy.py @@ -41,7 +41,7 @@ PHONON_DIR = f"{TEST_FILES_DIR}/phonon" -class TestPhonopyParser(PymatgenTest): +class TestPhonopyParser(MatSciTest): def test_get_ph_bs(self): ph_bs = get_ph_bs_symm_line(f"{TEST_DIR}/NaCl_band.yaml", has_nac=True) @@ -97,7 +97,7 @@ def test_get_complete_dos(self): @pytest.mark.skipif(Phonopy is None, reason="Phonopy not present") -class TestStructureConversion(PymatgenTest): +class TestStructureConversion(MatSciTest): def test_structure_conversion(self): struct_pmg = PymatgenTest.get_structure("LiFePO4") # add magmoms to site_properties @@ -125,7 +125,7 @@ def test_structure_conversion(self): @pytest.mark.skipif(Phonopy is None, reason="Phonopy not present") -class TestGetDisplacedStructures(PymatgenTest): +class TestGetDisplacedStructures(MatSciTest): def test_get_displaced_structures(self): pmg_s = Structure.from_file(f"{TEST_DIR}/POSCAR-unitcell", primitive=False) supercell_matrix = np.diag((2, 1, 2)) @@ -245,7 +245,7 @@ def test_gruneisen_parameter(self): @pytest.mark.skipif(Phonopy is None, reason="Phonopy not present") -class TestThermalDisplacementMatrices(PymatgenTest): +class TestThermalDisplacementMatrices(MatSciTest): def test_get_thermal_displacement_matrix(self): list_matrices = get_thermal_displacement_matrices( f"{PHONON_DIR}/thermal_displacement_matrices/thermal_displacement_matrices.yaml", diff --git a/tests/io/test_pwscf.py b/tests/io/test_pwscf.py index 5954e02cfd4..bf4db56552c 100644 --- a/tests/io/test_pwscf.py +++ b/tests/io/test_pwscf.py @@ -11,7 +11,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/io/pwscf" -class TestPWInput(PymatgenTest): +class TestPWInput(MatSciTest): def test_init(self): struct = self.get_structure("Li2O") with pytest.raises(PWInputError, match="Missing O2- in pseudo specification"): @@ -542,7 +542,7 @@ def test_custom_decimal_precision_write_and_read_str(self): assert pw_str.strip() == str(PWInput.from_str(pw_str)).strip() -class TestPWOutput(PymatgenTest): +class TestPWOutput(MatSciTest): def setup_method(self): self.pw_out = PWOutput(f"{TEST_DIR}/Si.pwscf.out") diff --git a/tests/io/test_shengbte.py b/tests/io/test_shengbte.py index 2c733a10a9c..641b82c86bc 100644 --- a/tests/io/test_shengbte.py +++ b/tests/io/test_shengbte.py @@ -10,7 +10,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/io/shengbte" -class TestShengBTE(PymatgenTest): +class TestShengBTE(MatSciTest): def setup_method(self): self.filename = f"{TEST_DIR}/CONTROL-CSLD_Si" self.test_dict = { diff --git a/tests/io/test_template_input.py b/tests/io/test_template_input.py index 3be8ae45374..8dfef0d758d 100644 --- a/tests/io/test_template_input.py +++ b/tests/io/test_template_input.py @@ -10,7 +10,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/io" -class TestTemplateInputGen(PymatgenTest): +class TestTemplateInputGen(MatSciTest): def test_write_inputs(self): input_set = TemplateInputGen().get_input_set( template=f"{TEST_DIR}/template_input_file.txt", diff --git a/tests/io/test_wannier90.py b/tests/io/test_wannier90.py index b72e00acc27..b6e9eec3a46 100644 --- a/tests/io/test_wannier90.py +++ b/tests/io/test_wannier90.py @@ -13,7 +13,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/io/wannier90" -class TestUnk(PymatgenTest): +class TestUnk(MatSciTest): def setup_method(self): rng = np.random.default_rng() self.data_std = rng.random((10, 5, 5, 5)) diff --git a/tests/io/test_xcrysden.py b/tests/io/test_xcrysden.py index d742f9ed4b4..bd217b15fbd 100644 --- a/tests/io/test_xcrysden.py +++ b/tests/io/test_xcrysden.py @@ -7,7 +7,7 @@ from pymatgen.util.testing import PymatgenTest -class TestXSF(PymatgenTest): +class TestXSF(MatSciTest): def setup_method(self): self.coords = [[0, 0, 0], [0.75, 0.5, 0.75]] self.lattice = [ diff --git a/tests/io/vasp/test_inputs.py b/tests/io/vasp/test_inputs.py index 6cc48511378..87dd14e1c83 100644 --- a/tests/io/vasp/test_inputs.py +++ b/tests/io/vasp/test_inputs.py @@ -71,7 +71,7 @@ def _mock_complete_potcar_summary_stats(monkeypatch: pytest.MonkeyPatch) -> None @pytest.mark.filterwarnings( "ignore:POTCAR data with symbol .* is not known to pymatgen:pymatgen.io.vasp.inputs.UnknownPotcarWarning" ) -class TestPoscar(PymatgenTest): +class TestPoscar(MatSciTest): def test_init(self): comp = Structure.from_file(f"{VASP_IN_DIR}/POSCAR").composition assert comp == Composition("Fe4P4O16") @@ -648,7 +648,7 @@ def test_vasp_6_4_2_format(self): assert poscar.structure.formula == "Li4 Fe4 P4 O16" -class TestIncar(PymatgenTest): +class TestIncar(MatSciTest): def setup_method(self): self.incar = Incar.from_file(f"{VASP_IN_DIR}/INCAR") @@ -1536,7 +1536,7 @@ def test_copy(self): @pytest.mark.filterwarnings( "ignore:POTCAR data with symbol .* is not known to pymatgen:pymatgen.io.vasp.inputs.UnknownPotcarWarning" ) -class TestPotcar(PymatgenTest): +class TestPotcar(MatSciTest): def setup_method(self): SETTINGS.setdefault("PMG_VASP_PSP_DIR", str(TEST_FILES_DIR)) self.filepath = f"{FAKE_POTCAR_DIR}/POTCAR.gz" @@ -1615,7 +1615,7 @@ def test_pickle(self): @pytest.mark.filterwarnings( "ignore:POTCAR data with symbol .* is not known to pymatgen:pymatgen.io.vasp.inputs.UnknownPotcarWarning" ) -class TestVaspInput(PymatgenTest): +class TestVaspInput(MatSciTest): def setup_method(self): filepath = f"{VASP_IN_DIR}/INCAR" incar = Incar.from_file(filepath) diff --git a/tests/io/vasp/test_optics.py b/tests/io/vasp/test_optics.py index 3a2caf7a94a..db1db1e9fc2 100644 --- a/tests/io/vasp/test_optics.py +++ b/tests/io/vasp/test_optics.py @@ -16,7 +16,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/io/vasp" -class TestVasprun(PymatgenTest): +class TestVasprun(MatSciTest): def test_optics(self): eps_data_path = f"{TEST_DIR}/fixtures/reproduce_eps" vrun = Vasprun(f"{eps_data_path}/vasprun.xml") diff --git a/tests/io/vasp/test_outputs.py b/tests/io/vasp/test_outputs.py index b14510f1778..d76cb004d21 100644 --- a/tests/io/vasp/test_outputs.py +++ b/tests/io/vasp/test_outputs.py @@ -53,7 +53,7 @@ kpts_opt_vrun_path = f"{TEST_DIR}/fixtures/kpoints_opt/vasprun.xml.gz" -class TestVasprun(PymatgenTest): +class TestVasprun(MatSciTest): def test_vasprun_ml(self): # Test for ML MD simulation # The trajectory data is stored in md_data @@ -832,7 +832,7 @@ def test_parse_potcar_cwd_relative(self): assert vrun.potcar_spec[ipot]["summary_stats"] == potcar[ipot]._summary_stats -class TestOutcar(PymatgenTest): +class TestOutcar(MatSciTest): def test_init(self): outcar = Outcar(f"{VASP_OUT_DIR}/OUTCAR.gz") expected_mag = ( @@ -1423,7 +1423,7 @@ def test_read_table_pattern(self): ) -class TestBSVasprun(PymatgenTest): +class TestBSVasprun(MatSciTest): def test_get_band_structure(self): filepath = f"{VASP_OUT_DIR}/vasprun_Si_bands.xml.gz" vasprun = BSVasprun(filepath, parse_potcar_file=False) @@ -1477,7 +1477,7 @@ def test_kpoints_opt(self): assert {*vrun_dct["output"]} >= {"eigenvalues", "eigenvalues_kpoints_opt"} -class TestOszicar(PymatgenTest): +class TestOszicar(MatSciTest): def test_init(self): fpath = f"{VASP_OUT_DIR}/OSZICAR" oszicar = Oszicar(fpath) @@ -1493,7 +1493,7 @@ def test_static(self): assert set(oszicar.ionic_steps[-1]) == set({"F", "E0", "dE", "mag"}) -class TestLocpot(PymatgenTest): +class TestLocpot(MatSciTest): def test_init(self): filepath = f"{VASP_OUT_DIR}/LOCPOT.gz" locpot = Locpot.from_file(filepath) @@ -1514,7 +1514,7 @@ def test_vasp_6x_style(self): assert {str(ele) for ele in locpot.structure.composition} == {"Mg", "Si"} -class TestChgcar(PymatgenTest): +class TestChgcar(MatSciTest): @classmethod def setup_class(cls): filepath = f"{VASP_OUT_DIR}/CHGCAR.nospin.gz" @@ -1638,7 +1638,7 @@ def test_as_dict_and_from_dict(self): ) -class TestAeccars(PymatgenTest): +class TestAeccars(MatSciTest): # https://github.com/materialsproject/pymatgen/pull/3343 def test_read_write_file(self): aeccar0_test = Chgcar.from_file(f"{TEST_FILES_DIR}/command_line/bader/AECCAR0.gz") @@ -1654,7 +1654,7 @@ def test_read_write_file(self): assert_allclose(aeccar2.data["total"], aeccar2_read.data["total"]) -class TestElfcar(PymatgenTest): +class TestElfcar(MatSciTest): def test_init(self): elfcar = Elfcar.from_file(f"{VASP_OUT_DIR}/ELFCAR.gz") assert approx(np.mean(elfcar.data["total"])) == 0.19076207645194002 @@ -1674,7 +1674,7 @@ def test_interpolation(self): assert len(elfcar.linear_slice([0.0, 0.0, 0.0], [1.0, 1.0, 1.0])) == 100 -class TestProcar(PymatgenTest): +class TestProcar(MatSciTest): def test_init(self): filepath = f"{VASP_OUT_DIR}/PROCAR.simple" procar = Procar(filepath) @@ -1817,7 +1817,7 @@ def test_init(self): # TODO: test get_phonon_frequencies once cross-checked -class TestWavecar(PymatgenTest): +class TestWavecar(MatSciTest): def setup_method(self): latt_mat = np.array(np.eye(3) * 10, dtype=float) # lattice vectors self.vol = np.dot(latt_mat[0, :], np.cross(latt_mat[1, :], latt_mat[2, :])) # unit cell volume @@ -2095,7 +2095,7 @@ def test_write_unks(self): assert unk == unk_ncl -class TestEigenval(PymatgenTest): +class TestEigenval(MatSciTest): def test_init(self): eig = Eigenval(f"{VASP_OUT_DIR}/EIGENVAL.gz") assert eig.ispin == 1 @@ -2135,7 +2135,7 @@ def test_eigenvalue_band_properties_separate_spins(self): assert props[3][1] -class TestWaveder(PymatgenTest): +class TestWaveder(MatSciTest): def setup_method(self): wder = Waveder.from_binary(f"{VASP_OUT_DIR}/WAVEDER", "float64") assert wder.nbands == 36 @@ -2168,7 +2168,7 @@ def _check(wder): _check(wderf) -class TestWSWQ(PymatgenTest): +class TestWSWQ(MatSciTest): def setup_method(self): self.wswq = WSWQ.from_file(f"{VASP_OUT_DIR}/WSWQ.gz") diff --git a/tests/io/vasp/test_sets.py b/tests/io/vasp/test_sets.py index 726e8a199fc..ec4a88bd0fc 100644 --- a/tests/io/vasp/test_sets.py +++ b/tests/io/vasp/test_sets.py @@ -91,7 +91,7 @@ def test_yb_2_warning(input_set: VaspInputSet) -> None: assert expected in str(record[0].message) -class TestSetChangeCheck(PymatgenTest): +class TestSetChangeCheck(MatSciTest): def test_sets_changed(self): msg = ( "WARNING! These tests will fail when you change an input set. They are included " @@ -128,7 +128,7 @@ def test_sets_changed(self): assert hash_str == known_hashes[input_set], f"{input_set=}\n{msg}" -class TestVaspInputSet(PymatgenTest): +class TestVaspInputSet(MatSciTest): @classmethod def setup_class(cls): filepath = f"{VASP_IN_DIR}/POSCAR" @@ -165,7 +165,7 @@ def test_as_dict(self): assert dict_set.potcar_functional == dict_set.user_potcar_functional -class TestMITMPRelaxSet(PymatgenTest): +class TestMITMPRelaxSet(MatSciTest): @classmethod def setup_class(cls): cls.set = MITRelaxSet @@ -718,7 +718,7 @@ def test_get_nedos(self): assert vis._get_nedos(0.1) == pytest.approx(741, abs=1) -class TestMPStaticSet(PymatgenTest): +class TestMPStaticSet(MatSciTest): def setup_method(self): self.set = MPStaticSet @@ -870,7 +870,7 @@ def test_grid_size_from_struct(self): ) -class TestMatPESStaticSet(PymatgenTest): +class TestMatPESStaticSet(MatSciTest): def setup_method(self): self.struct = Structure.from_file(f"{VASP_IN_DIR}/POSCAR") self.prev_incar = Incar.from_file(f"{VASP_IN_DIR}/INCAR") @@ -987,7 +987,7 @@ def test_from_prev_calc(self): assert vis.kpoints is None -class TestMPNonSCFSet(PymatgenTest): +class TestMPNonSCFSet(MatSciTest): def setup_method(self): self.set = MPNonSCFSet @@ -1153,7 +1153,7 @@ def test_user_kpoint_override(self): assert vis.kpoints.style == Kpoints.supported_modes.Gamma -class TestMagmomLdau(PymatgenTest): +class TestMagmomLdau(MatSciTest): def test_structure_from_prev_run(self): vrun = Vasprun(f"{VASP_OUT_DIR}/vasprun.magmom_ldau.xml.gz") structure = vrun.final_structure @@ -1188,7 +1188,7 @@ def test_ln_magmom(self): assert vis.incar["MAGMOM"] == magmom_ans -class TestMITMDSet(PymatgenTest): +class TestMITMDSet(MatSciTest): def setup_method(self): self.set = MITMDSet filepath = f"{VASP_IN_DIR}/POSCAR" @@ -1230,7 +1230,7 @@ def test_user_heat_speed(self): @skip_if_no_psp_dir -class TestMVLNPTMDSet(PymatgenTest): +class TestMVLNPTMDSet(MatSciTest): def setup_method(self): file_path = f"{VASP_IN_DIR}/POSCAR" self.struct = Structure.from_file(file_path) @@ -1266,7 +1266,7 @@ def test_as_from_dict(self): assert input_set.incar["NSW"] == 1000 -class TestMPMDSet(PymatgenTest): +class TestMPMDSet(MatSciTest): def setup_method(self): filepath = f"{VASP_IN_DIR}/POSCAR" self.struct = Structure.from_file(filepath) @@ -1308,7 +1308,7 @@ def test_as_from_dict(self): assert v.incar["NSW"] == 1000 -class TestMITNEBSet(PymatgenTest): +class TestMITNEBSet(MatSciTest): def setup_method(self): c1 = [[0.5] * 3, [0.9] * 3] c2 = [[0.5] * 3, [0.9, 0.1, 0.1]] @@ -1356,7 +1356,7 @@ def test_write_input(self): assert not os.path.isfile("04/POSCAR") -class TestMPSOCSet(PymatgenTest): +class TestMPSOCSet(MatSciTest): def setup_method(self): self.set = MPSOCSet @@ -1393,7 +1393,7 @@ def test_override_from_prev_calc(self): assert vis.incar["SIGMA"] == 0.025 -class TestMPNMRSet(PymatgenTest): +class TestMPNMRSet(MatSciTest): def test_incar(self): filepath = f"{TEST_FILES_DIR}/cif/Li.cif" structure = Structure.from_file(filepath) @@ -1415,7 +1415,7 @@ def test_incar(self): @skip_if_no_psp_dir -class TestMVLSlabSet(PymatgenTest): +class TestMVLSlabSet(MatSciTest): def setup_method(self): self.set = MVLSlabSet struct = self.get_structure("Li2O") @@ -1487,7 +1487,7 @@ def test_as_from_dict(self): assert "structure" not in self.vis.as_dict(verbosity=1) -class TestMVLElasticSet(PymatgenTest): +class TestMVLElasticSet(MatSciTest): def test_incar(self): mvlparam = MVLElasticSet(self.get_structure("Graphite")) incar = mvlparam.incar @@ -1498,7 +1498,7 @@ def test_incar(self): @skip_if_no_psp_dir -class TestMVLGWSet(PymatgenTest): +class TestMVLGWSet(MatSciTest): def setup_method(self): self.set = MVLGWSet self.struct = PymatgenTest.get_structure("Li2O") @@ -1576,7 +1576,7 @@ def test_bse(self): assert mvlgwgbse1.incar["ALGO"] == "Bse" -class TestMPHSERelaxSet(PymatgenTest): +class TestMPHSERelaxSet(MatSciTest): def setup_method(self): self.structure = dummy_structure self.set = MPHSERelaxSet @@ -1643,7 +1643,7 @@ def test_override_from_prev_calc(self): assert "VDW_S8" in vis_bj.incar -class TestMPHSEBS(PymatgenTest): +class TestMPHSEBS(MatSciTest): def setup_method(self): self.set = MPHSEBSSet @@ -1699,7 +1699,7 @@ def test_override_from_prev_calc(self): assert len(vis.kpoints.kpts) == 180 -class TestMVLScanRelaxSet(PymatgenTest): +class TestMVLScanRelaxSet(MatSciTest): def setup_method(self): self.set = MVLScanRelaxSet file_path = f"{VASP_IN_DIR}/POSCAR" @@ -1777,7 +1777,7 @@ def test_as_from_dict(self): assert v.user_incar_settings["NSW"] == 500 -class TestMPScanRelaxSet(PymatgenTest): +class TestMPScanRelaxSet(MatSciTest): def setup_method(self): file_path = f"{VASP_IN_DIR}/POSCAR" self.struct = Structure.from_file(file_path) @@ -1898,7 +1898,7 @@ def test_write_input(self): assert os.path.isfile(f"{self.tmp_path}/POSCAR") -class TestMPScanStaticSet(PymatgenTest): +class TestMPScanStaticSet(MatSciTest): def setup_method(self): self.set = MPScanStaticSet self.prev_run = f"{TEST_DIR}/fixtures/scan_relaxation" @@ -1988,7 +1988,7 @@ def test_override_from_prev_calc(self): assert lepsilon_vis.incar.get("NPAR") is None -class TestFunc(PymatgenTest): +class TestFunc(MatSciTest): @skip_if_no_psp_dir def test_batch_write_input(self): structs = list(map(PymatgenTest.get_structure, ("Li2O", "LiFePO4"))) @@ -2000,7 +2000,7 @@ def test_batch_write_input(self): @skip_if_no_psp_dir -class TestMVLGBSet(PymatgenTest): +class TestMVLGBSet(MatSciTest): def setup_method(self): filepath = f"{TEST_FILES_DIR}/cif/Li.cif" self.struct = Structure.from_file(filepath) @@ -2026,7 +2026,7 @@ def test_kpoints(self): assert kpoints.kpts == [(k_a, k_b, 1)] -class TestMVLRelax52Set(PymatgenTest): +class TestMVLRelax52Set(MatSciTest): def setup_method(self): self.set = MVLRelax52Set file_path = f"{VASP_IN_DIR}/POSCAR" @@ -2064,7 +2064,7 @@ def test_as_from_dict(self): assert vasp_input.incar["NSW"] == 500 -class TestLobsterSet(PymatgenTest): +class TestLobsterSet(MatSciTest): def setup_method(self): self.set = LobsterSet file_path = f"{VASP_IN_DIR}/POSCAR" @@ -2163,7 +2163,7 @@ def test_as_from_dict(self): @skip_if_no_psp_dir -class TestMPAbsorptionSet(PymatgenTest): +class TestMPAbsorptionSet(MatSciTest): def setup_method(self): file_path = f"{TEST_DIR}/fixtures/absorption/static/POSCAR" self.structure = Structure.from_file(file_path) diff --git a/tests/io/xtb/test_inputs.py b/tests/io/xtb/test_inputs.py index 546386c6391..32f2f2c8030 100644 --- a/tests/io/xtb/test_inputs.py +++ b/tests/io/xtb/test_inputs.py @@ -12,7 +12,7 @@ EXPECTED_DIR = f"{TEST_FILES_DIR}/io/xtb/expected_output" -class TestCRESTInput(PymatgenTest): +class TestCRESTInput(MatSciTest): """ Checks that all attributes of CRESTInput match the expected values for sample inputs. diff --git a/tests/io/xtb/test_outputs.py b/tests/io/xtb/test_outputs.py index c4d3fe69777..2bd19d6c6a6 100644 --- a/tests/io/xtb/test_outputs.py +++ b/tests/io/xtb/test_outputs.py @@ -23,7 +23,7 @@ EXPECTED_DIR = f"{TEST_FILES_DIR}/io/xtb/expected_output" -class TestCRESTOutput(PymatgenTest): +class TestCRESTOutput(MatSciTest): """ Checks that all attributes of CRESTOutput match the expected values for a sample CREST output directory. diff --git a/tests/optimization/test_neighbors.py b/tests/optimization/test_neighbors.py index cd022d34dde..f08f4929428 100644 --- a/tests/optimization/test_neighbors.py +++ b/tests/optimization/test_neighbors.py @@ -7,7 +7,7 @@ from pymatgen.util.testing import PymatgenTest -class TestNeighbors(PymatgenTest): +class TestNeighbors(MatSciTest): def setup_method(self): self.lattice = Lattice.cubic(10.0) self.cubic = self.lattice diff --git a/tests/phonon/test_bandstructure.py b/tests/phonon/test_bandstructure.py index ac6727628cf..0bccefb6399 100644 --- a/tests/phonon/test_bandstructure.py +++ b/tests/phonon/test_bandstructure.py @@ -13,7 +13,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/electronic_structure/bandstructure" -class TestPhononBandStructureSymmLine(PymatgenTest): +class TestPhononBandStructureSymmLine(MatSciTest): def setup_method(self): with open(f"{TEST_DIR}/NaCl_phonon_bandstructure.json") as file: dct = json.load(file) diff --git a/tests/phonon/test_dos.py b/tests/phonon/test_dos.py index a1c14cd00b2..16164585bf1 100644 --- a/tests/phonon/test_dos.py +++ b/tests/phonon/test_dos.py @@ -14,7 +14,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/phonon/dos" -class TestPhononDos(PymatgenTest): +class TestPhononDos(MatSciTest): def setup_method(self): with open(f"{TEST_DIR}/NaCl_ph_dos.json") as file: self.dos = PhononDos.from_dict(json.load(file)) @@ -182,7 +182,7 @@ def test_dos_fp_exceptions(self): self.dos.get_dos_fp_similarity(dos_fp, dos_fp2, col=1, metric=metric, normalize=False) -class TestCompletePhononDos(PymatgenTest): +class TestCompletePhononDos(MatSciTest): def setup_method(self): with open(f"{TEST_DIR}/NaCl_complete_ph_dos.json") as file: self.cdos = CompletePhononDos.from_dict(json.load(file)) diff --git a/tests/phonon/test_gruneisen.py b/tests/phonon/test_gruneisen.py index fac97aaebab..12298435cd9 100644 --- a/tests/phonon/test_gruneisen.py +++ b/tests/phonon/test_gruneisen.py @@ -21,7 +21,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/phonon/gruneisen" -class TestGruneisenPhononBandStructureSymmLine(PymatgenTest): +class TestGruneisenPhononBandStructureSymmLine(MatSciTest): def setup_method(self) -> None: self.bs_symm_line = get_gruneisen_ph_bs_symm_line( gruneisen_path=f"{TEST_DIR}/gruneisen_eq_plus_minus_InP.yaml", @@ -76,7 +76,7 @@ def test_as_dict_from_dict(self): @pytest.mark.skipif(TotalDos is None, reason="Phonopy not present") -class TestGruneisenParameter(PymatgenTest): +class TestGruneisenParameter(MatSciTest): def setup_method(self) -> None: self.gruneisen_obj = get_gruneisenparameter( f"{TEST_DIR}/gruneisen_mesh_InP.yaml", diff --git a/tests/phonon/test_ir_spectra.py b/tests/phonon/test_ir_spectra.py index 07fa82e678b..b910b86f11e 100644 --- a/tests/phonon/test_ir_spectra.py +++ b/tests/phonon/test_ir_spectra.py @@ -5,7 +5,7 @@ from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest -class TestIRDielectricTensor(PymatgenTest): +class TestIRDielectricTensor(MatSciTest): def setup_method(self): self.ir_spectra = loadfn(f"{TEST_FILES_DIR}/phonon/dos/ir_spectra_mp-991652_DDB.json") diff --git a/tests/phonon/test_thermal_displacements.py b/tests/phonon/test_thermal_displacements.py index 23afe16e670..40b49d1df17 100644 --- a/tests/phonon/test_thermal_displacements.py +++ b/tests/phonon/test_thermal_displacements.py @@ -11,7 +11,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/phonon/thermal_displacement_matrices" -class TestThermalDisplacement(PymatgenTest): +class TestThermalDisplacement(MatSciTest): """Test data from J. George's matlab code https://github.com/JaGeo/MolecularToolbox.""" def setup_method(self) -> None: diff --git a/tests/symmetry/test_analyzer.py b/tests/symmetry/test_analyzer.py index 7500b959576..f67c9576b8c 100644 --- a/tests/symmetry/test_analyzer.py +++ b/tests/symmetry/test_analyzer.py @@ -23,7 +23,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/symmetry/analyzer" -class TestSpacegroupAnalyzer(PymatgenTest): +class TestSpacegroupAnalyzer(MatSciTest): def setup_method(self): self.structure = Structure.from_file(f"{VASP_IN_DIR}/POSCAR") self.sg = SpacegroupAnalyzer(self.structure, 0.001) @@ -536,7 +536,7 @@ def test_are_symmetrically_equivalent(self): ) -class TestPointGroupAnalyzer(PymatgenTest): +class TestPointGroupAnalyzer(MatSciTest): def test_spherical(self): pg_analyzer = PointGroupAnalyzer(CH4) assert pg_analyzer.sch_symbol == "Td" diff --git a/tests/symmetry/test_kpath_hin.py b/tests/symmetry/test_kpath_hin.py index 2a7cce41712..08ae60e71bb 100644 --- a/tests/symmetry/test_kpath_hin.py +++ b/tests/symmetry/test_kpath_hin.py @@ -11,7 +11,7 @@ pytest.importorskip("seekpath", reason="seekpath not installed") -class TestKPathSeek(PymatgenTest): +class TestKPathSeek(MatSciTest): def test_kpath_generation(self): triclinic = [1, 2] monoclinic = range(3, 16) diff --git a/tests/symmetry/test_kpath_lm.py b/tests/symmetry/test_kpath_lm.py index 479ffecb65d..2151cff606a 100644 --- a/tests/symmetry/test_kpath_lm.py +++ b/tests/symmetry/test_kpath_lm.py @@ -11,7 +11,7 @@ from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest -class TestKPathLatimerMunro(PymatgenTest): +class TestKPathLatimerMunro(MatSciTest): def test_kpath_generation(self): triclinic = [1, 2] monoclinic = range(3, 16) diff --git a/tests/symmetry/test_kpath_sc.py b/tests/symmetry/test_kpath_sc.py index d88c97f79dd..ed465262f55 100644 --- a/tests/symmetry/test_kpath_sc.py +++ b/tests/symmetry/test_kpath_sc.py @@ -11,7 +11,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/symmetry/space_group_structs" -class TestBandStructureSC(PymatgenTest): +class TestBandStructureSC(MatSciTest): def test_kpath_generation(self): triclinic = [1, 2] monoclinic = range(3, 16) diff --git a/tests/symmetry/test_kpaths.py b/tests/symmetry/test_kpaths.py index 87c8bd16480..1d252a396a8 100644 --- a/tests/symmetry/test_kpaths.py +++ b/tests/symmetry/test_kpaths.py @@ -17,7 +17,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/electronic_structure/bandstructure" -class TestHighSymmKpath(PymatgenTest): +class TestHighSymmKpath(MatSciTest): @pytest.mark.skipif(get_path is None, reason="No seek path present.") def test_kpath_generation(self): triclinic = [1, 2] diff --git a/tests/symmetry/test_maggroups.py b/tests/symmetry/test_maggroups.py index 21475b7a4c9..2b474285836 100644 --- a/tests/symmetry/test_maggroups.py +++ b/tests/symmetry/test_maggroups.py @@ -17,7 +17,7 @@ __date__ = "Feb 2017" -class TestMagneticSpaceGroup(PymatgenTest): +class TestMagneticSpaceGroup(MatSciTest): def setup_method(self): self.msg_1 = MagneticSpaceGroup([70, 530]) self.msg_2 = MagneticSpaceGroup([62, 448]) diff --git a/tests/symmetry/test_site_symmetries.py b/tests/symmetry/test_site_symmetries.py index 24bb53b22e8..c2d4159cf0b 100644 --- a/tests/symmetry/test_site_symmetries.py +++ b/tests/symmetry/test_site_symmetries.py @@ -18,7 +18,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/symmetry/site_symmetries" -class TestSiteSymmetries(PymatgenTest): +class TestSiteSymmetries(MatSciTest): def setup_method(self): with gzip.open(f"{TEST_DIR}/point_ops.json.gz", mode="rt") as file: self.point_ops = MontyDecoder().process_decoded(json.load(file)) diff --git a/tests/transformations/test_advanced_transformations.py b/tests/transformations/test_advanced_transformations.py index 1bba0acb289..3e508b89867 100644 --- a/tests/transformations/test_advanced_transformations.py +++ b/tests/transformations/test_advanced_transformations.py @@ -276,7 +276,7 @@ def test_as_dict(self): @pytest.mark.skipif(not enumlib_present, reason="enum_lib not present.") -class TestMagOrderingTransformation(PymatgenTest): +class TestMagOrderingTransformation(MatSciTest): def setup_method(self): lattice = Lattice.cubic(4.17) species = ["Ni", "O"] @@ -488,7 +488,7 @@ def test_advanced_usage(self): @pytest.mark.skipif(not enumlib_present, reason="enum_lib not present.") -class TestDopingTransformation(PymatgenTest): +class TestDopingTransformation(MatSciTest): def test_apply_transformation(self): structure = PymatgenTest.get_structure("LiFePO4") spga = SpacegroupAnalyzer(structure, 0.1) @@ -551,7 +551,7 @@ def test_find_codopant(self): assert find_codopant(Species("Fe", 2), 3) == Species("In", 3) -class TestSlabTransformation(PymatgenTest): +class TestSlabTransformation(MatSciTest): def test_apply_transformation(self): struct = self.get_structure("LiFePO4") trans = SlabTransformation([0, 0, 1], 10, 10, shift=0.25) @@ -570,7 +570,7 @@ def test_apply_transformation(self): assert_allclose(slab_from_gen.cart_coords, slab_from_trans.cart_coords) -class TestGrainBoundaryTransformation(PymatgenTest): +class TestGrainBoundaryTransformation(MatSciTest): def test_apply_transformation(self): Al_bulk = Structure.from_spacegroup("Fm-3m", Lattice.cubic(2.8575585), ["Al"], [[0, 0, 0]]) gb_gen_params_s5 = { @@ -590,7 +590,7 @@ def test_apply_transformation(self): assert_allclose(gb_from_generator.cart_coords, gb_from_trans.cart_coords) -class TestDisorderedOrderedTransformation(PymatgenTest): +class TestDisorderedOrderedTransformation(MatSciTest): def test_apply_transformation(self): # nonsensical example just for testing purposes struct = self.get_structure("BaNiO3") @@ -603,7 +603,7 @@ def test_apply_transformation(self): @pytest.mark.skipif(not mcsqs_cmd, reason="mcsqs not present.") -class TestSQSTransformation(PymatgenTest): +class TestSQSTransformation(MatSciTest): def test_apply_transformation(self): pzt_structs = loadfn(f"{TEST_FILES_DIR}/io/atat/mcsqs/pzt-structs.json") trans = SQSTransformation(scaling=[2, 1, 1], search_time=0.01, instances=1, wd=0) @@ -649,7 +649,7 @@ def test_spin(self): @pytest.mark.skipif(ClusterSpace is None, reason="icet not installed.") -class TestSQSTransformationIcet(PymatgenTest): +class TestSQSTransformationIcet(MatSciTest): stored_run: dict = loadfn(f"{TEST_FILES_DIR}/transformations/icet-sqs-fcc-Mg_75-Al_25-scaling_8.json.gz") scaling: int = 8 @@ -699,7 +699,7 @@ def test_monte_carlo(self): assert isinstance(sqs_output[0][key], val) -class TestCubicSupercellTransformation(PymatgenTest): +class TestCubicSupercellTransformation(MatSciTest): def test_apply_transformation_cubic_supercell(self): structure = self.get_structure("TlBiSe2") min_atoms = 100 @@ -848,7 +848,7 @@ def test_apply_transformation_orthorhombic_supercell(self): assert transformed_cubic.lattice.angles == transformed_orthorhombic.lattice.angles -class TestAddAdsorbateTransformation(PymatgenTest): +class TestAddAdsorbateTransformation(MatSciTest): def test_apply_transformation(self): co = Molecule(["C", "O"], [[0, 0, 0], [0, 0, 1.23]]) trans = AddAdsorbateTransformation(co) @@ -859,7 +859,7 @@ def test_apply_transformation(self): assert out.reduced_formula == "Pt4CO" -class TestSubstituteSurfaceSiteTransformation(PymatgenTest): +class TestSubstituteSurfaceSiteTransformation(MatSciTest): def test_apply_transformation(self): trans = SubstituteSurfaceSiteTransformation("Au") pt = Structure(Lattice.cubic(5), ["Pt"], [[0, 0, 0]]) # fictitious @@ -870,7 +870,7 @@ def test_apply_transformation(self): @pytest.mark.skipif(not hiphive, reason="hiphive not present") -class TestMonteCarloRattleTransformation(PymatgenTest): +class TestMonteCarloRattleTransformation(MatSciTest): def test_apply_transformation(self): struct = self.get_structure("Si") mcrt = MonteCarloRattleTransformation(0.01, 2, seed=1) diff --git a/tests/transformations/test_site_transformations.py b/tests/transformations/test_site_transformations.py index 8e5efebf250..e7e5be40efe 100644 --- a/tests/transformations/test_site_transformations.py +++ b/tests/transformations/test_site_transformations.py @@ -23,7 +23,7 @@ enumlib_present = enum_cmd and makestr_cmd -class TestTranslateSitesTransformation(PymatgenTest): +class TestTranslateSitesTransformation(MatSciTest): def setup_method(self): coords = [ [0, 0, 0], @@ -263,7 +263,7 @@ def test_str(self): ) -class TestAddSitePropertyTransformation(PymatgenTest): +class TestAddSitePropertyTransformation(MatSciTest): def test_apply_transformation(self): struct = self.get_structure("Li2O2") sd = [[True, True, True] for _ in struct] @@ -278,7 +278,7 @@ def test_apply_transformation(self): assert_allclose(trans_set.site_properties[prop], manually_set.site_properties[prop]) -class TestRadialSiteDistortionTransformation(PymatgenTest): +class TestRadialSiteDistortionTransformation(MatSciTest): def setup_method(self): self.molecule = Molecule( species=["C", "H", "H", "H", "H", "H", "H", "H", "H", "H", "H", "H", "H"], diff --git a/tests/util/test_io.py b/tests/util/test_io.py index 09458240656..fcd250a0bff 100644 --- a/tests/util/test_io.py +++ b/tests/util/test_io.py @@ -4,7 +4,7 @@ from pymatgen.util.testing import VASP_OUT_DIR, PymatgenTest -class TestFunc(PymatgenTest): +class TestFunc(MatSciTest): def test_micro_pyawk(self): data = [] diff --git a/tests/util/test_plotting.py b/tests/util/test_plotting.py index ec68c960d88..b8c13bd1480 100644 --- a/tests/util/test_plotting.py +++ b/tests/util/test_plotting.py @@ -12,7 +12,7 @@ pymatviz = None -class TestFunc(PymatgenTest): +class TestFunc(MatSciTest): def test_plot_periodic_heatmap(self): random_data = {"Te": 0.11083, "Au": 0.75756, "Th": 1.24758, "Ni": -2.0354} fig = periodic_table_heatmap(random_data) diff --git a/tests/vis/test_plotters.py b/tests/vis/test_plotters.py index d6f5d535117..e2838de0d5f 100644 --- a/tests/vis/test_plotters.py +++ b/tests/vis/test_plotters.py @@ -15,7 +15,7 @@ spect_data_dict = json.load(file, cls=MontyDecoder) -class TestSpectrumPlotter(PymatgenTest): +class TestSpectrumPlotter(MatSciTest): def setup_method(self): self.xanes = XAS.from_dict(spect_data_dict) From dfb616c0ac574fc100a28b9a7ffb213dece9a6d3 Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Wed, 4 Dec 2024 23:27:58 +0800 Subject: [PATCH 18/31] global replace PymatgenTest import --- .../analysis/chemenv/connectivity/test_environment_nodes.py | 2 +- .../coordination_environments/test_chemenv_strategies.py | 2 +- .../test_coordination_geometries.py | 2 +- .../chemenv/utils/test_coordination_geometry_utils.py | 2 +- tests/analysis/chemenv/utils/test_graph_utils.py | 2 +- tests/analysis/chemenv/utils/test_math_utils.py | 2 +- tests/analysis/diffraction/test_neutron.py | 2 +- tests/analysis/diffraction/test_tem.py | 2 +- tests/analysis/diffraction/test_xrd.py | 2 +- tests/analysis/elasticity/test_strain.py | 2 +- tests/analysis/elasticity/test_stress.py | 2 +- tests/analysis/interfaces/test_coherent_interface.py | 2 +- tests/analysis/interfaces/test_substrate_analyzer.py | 6 +++--- tests/analysis/interfaces/test_zsl.py | 2 +- tests/analysis/test_adsorption.py | 2 +- tests/analysis/test_disorder.py | 2 +- tests/analysis/test_eos.py | 2 +- tests/analysis/test_nmr.py | 2 +- tests/analysis/test_piezo.py | 2 +- tests/analysis/test_prototypes.py | 2 +- tests/core/test_composition.py | 2 +- tests/core/test_lattice.py | 2 +- tests/core/test_libxcfunc.py | 2 +- tests/core/test_molecular_orbitals.py | 2 +- tests/core/test_operations.py | 2 +- tests/core/test_periodic_table.py | 2 +- tests/core/test_sites.py | 2 +- tests/core/test_spectrum.py | 2 +- tests/core/test_units.py | 2 +- tests/core/test_xcfunc.py | 2 +- tests/ext/test_optimade.py | 2 +- tests/io/test_xcrysden.py | 2 +- tests/optimization/test_neighbors.py | 2 +- tests/symmetry/test_kpath_hin.py | 2 +- tests/symmetry/test_maggroups.py | 2 +- tests/transformations/test_site_transformations.py | 2 +- tests/util/test_plotting.py | 2 +- 37 files changed, 39 insertions(+), 39 deletions(-) diff --git a/tests/analysis/chemenv/connectivity/test_environment_nodes.py b/tests/analysis/chemenv/connectivity/test_environment_nodes.py index dc7956ab764..e9a8e07bea0 100644 --- a/tests/analysis/chemenv/connectivity/test_environment_nodes.py +++ b/tests/analysis/chemenv/connectivity/test_environment_nodes.py @@ -3,7 +3,7 @@ import json from pymatgen.analysis.chemenv.connectivity.environment_nodes import EnvironmentNode -from pymatgen.util.testing import PymatgenTest +from pymatgen.util.testing import MatSciTest try: import bson diff --git a/tests/analysis/chemenv/coordination_environments/test_chemenv_strategies.py b/tests/analysis/chemenv/coordination_environments/test_chemenv_strategies.py index d7cd8a2a474..2c7903385fb 100644 --- a/tests/analysis/chemenv/coordination_environments/test_chemenv_strategies.py +++ b/tests/analysis/chemenv/coordination_environments/test_chemenv_strategies.py @@ -10,7 +10,7 @@ DistanceCutoffFloat, SimplestChemenvStrategy, ) -from pymatgen.util.testing import PymatgenTest +from pymatgen.util.testing import MatSciTest __author__ = "waroquiers" diff --git a/tests/analysis/chemenv/coordination_environments/test_coordination_geometries.py b/tests/analysis/chemenv/coordination_environments/test_coordination_geometries.py index e07ead94557..b64d1406a16 100644 --- a/tests/analysis/chemenv/coordination_environments/test_coordination_geometries.py +++ b/tests/analysis/chemenv/coordination_environments/test_coordination_geometries.py @@ -11,7 +11,7 @@ ExplicitPermutationsAlgorithm, SeparationPlane, ) -from pymatgen.util.testing import PymatgenTest +from pymatgen.util.testing import MatSciTest __author__ = "waroquiers" diff --git a/tests/analysis/chemenv/utils/test_coordination_geometry_utils.py b/tests/analysis/chemenv/utils/test_coordination_geometry_utils.py index 9b459d736e2..03db878145c 100644 --- a/tests/analysis/chemenv/utils/test_coordination_geometry_utils.py +++ b/tests/analysis/chemenv/utils/test_coordination_geometry_utils.py @@ -7,7 +7,7 @@ from pytest import approx from pymatgen.analysis.chemenv.utils.coordination_geometry_utils import Plane -from pymatgen.util.testing import PymatgenTest +from pymatgen.util.testing import MatSciTest __author__ = "David Waroquiers" diff --git a/tests/analysis/chemenv/utils/test_graph_utils.py b/tests/analysis/chemenv/utils/test_graph_utils.py index 25a791d1e1b..e086b862d8c 100644 --- a/tests/analysis/chemenv/utils/test_graph_utils.py +++ b/tests/analysis/chemenv/utils/test_graph_utils.py @@ -5,7 +5,7 @@ from pymatgen.analysis.chemenv.connectivity.environment_nodes import EnvironmentNode from pymatgen.analysis.chemenv.utils.graph_utils import MultiGraphCycle, SimpleGraphCycle, get_delta -from pymatgen.util.testing import PymatgenTest +from pymatgen.util.testing import MatSciTest __author__ = "waroquiers" diff --git a/tests/analysis/chemenv/utils/test_math_utils.py b/tests/analysis/chemenv/utils/test_math_utils.py index 184f3364a26..889a836e8e0 100644 --- a/tests/analysis/chemenv/utils/test_math_utils.py +++ b/tests/analysis/chemenv/utils/test_math_utils.py @@ -16,7 +16,7 @@ smootherstep, smoothstep, ) -from pymatgen.util.testing import PymatgenTest +from pymatgen.util.testing import MatSciTest __author__ = "waroquiers" diff --git a/tests/analysis/diffraction/test_neutron.py b/tests/analysis/diffraction/test_neutron.py index eb031175743..16a137c8301 100644 --- a/tests/analysis/diffraction/test_neutron.py +++ b/tests/analysis/diffraction/test_neutron.py @@ -6,7 +6,7 @@ from pymatgen.analysis.diffraction.neutron import NDCalculator from pymatgen.core.lattice import Lattice from pymatgen.core.structure import Structure -from pymatgen.util.testing import PymatgenTest +from pymatgen.util.testing import MatSciTest """ These calculated values were verified with VESTA and FullProf. diff --git a/tests/analysis/diffraction/test_tem.py b/tests/analysis/diffraction/test_tem.py index 2e491e6b486..bf28f0b4bb1 100644 --- a/tests/analysis/diffraction/test_tem.py +++ b/tests/analysis/diffraction/test_tem.py @@ -11,7 +11,7 @@ from pymatgen.analysis.diffraction.tem import TEMCalculator from pymatgen.core.lattice import Lattice from pymatgen.core.structure import Structure -from pymatgen.util.testing import PymatgenTest +from pymatgen.util.testing import MatSciTest __author__ = "Frank Wan, Jason Liang" __copyright__ = "Copyright 2019, The Materials Project" diff --git a/tests/analysis/diffraction/test_xrd.py b/tests/analysis/diffraction/test_xrd.py index ce2e13851f0..b3b5f180f7d 100644 --- a/tests/analysis/diffraction/test_xrd.py +++ b/tests/analysis/diffraction/test_xrd.py @@ -6,7 +6,7 @@ from pymatgen.analysis.diffraction.xrd import XRDCalculator from pymatgen.core.lattice import Lattice from pymatgen.core.structure import Structure -from pymatgen.util.testing import PymatgenTest +from pymatgen.util.testing import MatSciTest __author__ = "Shyue Ping Ong" __copyright__ = "Copyright 2012, The Materials Project" diff --git a/tests/analysis/elasticity/test_strain.py b/tests/analysis/elasticity/test_strain.py index 56bab6cf982..0ff2d2ed590 100644 --- a/tests/analysis/elasticity/test_strain.py +++ b/tests/analysis/elasticity/test_strain.py @@ -7,7 +7,7 @@ from pymatgen.analysis.elasticity.strain import Deformation, DeformedStructureSet, Strain, convert_strain_to_deformation from pymatgen.core.structure import Structure from pymatgen.core.tensors import Tensor -from pymatgen.util.testing import PymatgenTest +from pymatgen.util.testing import MatSciTest class TestDeformation(MatSciTest): diff --git a/tests/analysis/elasticity/test_stress.py b/tests/analysis/elasticity/test_stress.py index f37192cf4c7..100604b9700 100644 --- a/tests/analysis/elasticity/test_stress.py +++ b/tests/analysis/elasticity/test_stress.py @@ -7,7 +7,7 @@ from pymatgen.analysis.elasticity.strain import Deformation from pymatgen.analysis.elasticity.stress import Stress -from pymatgen.util.testing import PymatgenTest +from pymatgen.util.testing import MatSciTest class TestStress(MatSciTest): diff --git a/tests/analysis/interfaces/test_coherent_interface.py b/tests/analysis/interfaces/test_coherent_interface.py index 5ad0c9e78ec..7115f85f7f3 100644 --- a/tests/analysis/interfaces/test_coherent_interface.py +++ b/tests/analysis/interfaces/test_coherent_interface.py @@ -14,7 +14,7 @@ from pymatgen.core.lattice import Lattice from pymatgen.core.structure import Structure from pymatgen.symmetry.analyzer import SpacegroupAnalyzer -from pymatgen.util.testing import PymatgenTest +from pymatgen.util.testing import MatSciTest class TestInterfaceBuilder(MatSciTest): diff --git a/tests/analysis/interfaces/test_substrate_analyzer.py b/tests/analysis/interfaces/test_substrate_analyzer.py index 06f6ddba240..29002cbfff8 100644 --- a/tests/analysis/interfaces/test_substrate_analyzer.py +++ b/tests/analysis/interfaces/test_substrate_analyzer.py @@ -5,10 +5,10 @@ from pymatgen.analysis.elasticity.elastic import ElasticTensor from pymatgen.analysis.interfaces.substrate_analyzer import SubstrateAnalyzer from pymatgen.symmetry.analyzer import SpacegroupAnalyzer -from pymatgen.util.testing import PymatgenTest +from pymatgen.util.testing import MatSciTest -VO2 = PymatgenTest.get_structure("VO2") -TiO2 = PymatgenTest.get_structure("TiO2") +VO2 = MatSciTest.get_structure("VO2") +TiO2 = MatSciTest.get_structure("TiO2") # Film VO2 film = SpacegroupAnalyzer(VO2, symprec=0.1).get_conventional_standard_structure() diff --git a/tests/analysis/interfaces/test_zsl.py b/tests/analysis/interfaces/test_zsl.py index c18a6042fc7..f38892b8753 100644 --- a/tests/analysis/interfaces/test_zsl.py +++ b/tests/analysis/interfaces/test_zsl.py @@ -13,7 +13,7 @@ vec_area, ) from pymatgen.symmetry.analyzer import SpacegroupAnalyzer -from pymatgen.util.testing import PymatgenTest +from pymatgen.util.testing import MatSciTest __author__ = "Shyam Dwaraknath" __copyright__ = "Copyright 2016, The Materials Project" diff --git a/tests/analysis/test_adsorption.py b/tests/analysis/test_adsorption.py index 9bc84be4b83..e3b9d0070fe 100644 --- a/tests/analysis/test_adsorption.py +++ b/tests/analysis/test_adsorption.py @@ -8,7 +8,7 @@ from pymatgen.core.structure import Molecule, Structure from pymatgen.symmetry.analyzer import SpacegroupAnalyzer from pymatgen.util.coord import in_coord_list -from pymatgen.util.testing import PymatgenTest +from pymatgen.util.testing import MatSciTest class TestAdsorbateSiteFinder(MatSciTest): diff --git a/tests/analysis/test_disorder.py b/tests/analysis/test_disorder.py index ab4a7a7b315..c6d449eccf5 100644 --- a/tests/analysis/test_disorder.py +++ b/tests/analysis/test_disorder.py @@ -4,7 +4,7 @@ from pymatgen.analysis.disorder import get_warren_cowley_parameters from pymatgen.core import Element, Structure -from pymatgen.util.testing import PymatgenTest +from pymatgen.util.testing import MatSciTest class TestOrderParameter(MatSciTest): diff --git a/tests/analysis/test_eos.py b/tests/analysis/test_eos.py index a388440cc2b..874c476ce3b 100644 --- a/tests/analysis/test_eos.py +++ b/tests/analysis/test_eos.py @@ -5,7 +5,7 @@ from pytest import approx from pymatgen.analysis.eos import EOS, NumericalEOS -from pymatgen.util.testing import PymatgenTest +from pymatgen.util.testing import MatSciTest class TestEOS(MatSciTest): diff --git a/tests/analysis/test_nmr.py b/tests/analysis/test_nmr.py index b3f97fe2c3e..b0ca34759b3 100644 --- a/tests/analysis/test_nmr.py +++ b/tests/analysis/test_nmr.py @@ -5,7 +5,7 @@ from pytest import approx from pymatgen.analysis.nmr import ChemicalShielding, ElectricFieldGradient -from pymatgen.util.testing import PymatgenTest +from pymatgen.util.testing import MatSciTest class TestChemicalShieldingNotation(MatSciTest): diff --git a/tests/analysis/test_piezo.py b/tests/analysis/test_piezo.py index 42d659976c1..06f89320b12 100644 --- a/tests/analysis/test_piezo.py +++ b/tests/analysis/test_piezo.py @@ -7,7 +7,7 @@ from numpy.testing import assert_allclose, assert_array_equal from pymatgen.analysis.piezo import PiezoTensor -from pymatgen.util.testing import PymatgenTest +from pymatgen.util.testing import MatSciTest __author__ = "Shyam Dwaraknath" __version__ = "0.1" diff --git a/tests/analysis/test_prototypes.py b/tests/analysis/test_prototypes.py index acf8b8472fd..887b5d598d4 100644 --- a/tests/analysis/test_prototypes.py +++ b/tests/analysis/test_prototypes.py @@ -1,7 +1,7 @@ from __future__ import annotations from pymatgen.analysis.prototypes import AflowPrototypeMatcher -from pymatgen.util.testing import PymatgenTest +from pymatgen.util.testing import MatSciTest class TestAflowPrototypeMatcher(MatSciTest): diff --git a/tests/core/test_composition.py b/tests/core/test_composition.py index b0a5e3bfe75..bb9d2bd4364 100644 --- a/tests/core/test_composition.py +++ b/tests/core/test_composition.py @@ -13,7 +13,7 @@ from pymatgen.core import Composition, DummySpecies, Element, Species from pymatgen.core.composition import ChemicalPotential -from pymatgen.util.testing import PymatgenTest +from pymatgen.util.testing import MatSciTest class TestComposition(MatSciTest): diff --git a/tests/core/test_lattice.py b/tests/core/test_lattice.py index 622da5c9b24..32a42a62e16 100644 --- a/tests/core/test_lattice.py +++ b/tests/core/test_lattice.py @@ -9,7 +9,7 @@ from pymatgen.core.lattice import Lattice, get_points_in_spheres from pymatgen.core.operations import SymmOp -from pymatgen.util.testing import PymatgenTest +from pymatgen.util.testing import MatSciTest class TestLattice(MatSciTest): diff --git a/tests/core/test_libxcfunc.py b/tests/core/test_libxcfunc.py index 7fb82780466..1436f08e42e 100644 --- a/tests/core/test_libxcfunc.py +++ b/tests/core/test_libxcfunc.py @@ -1,7 +1,7 @@ from __future__ import annotations from pymatgen.core.libxcfunc import LibxcFunc -from pymatgen.util.testing import PymatgenTest +from pymatgen.util.testing import MatSciTest class TestLibxcFunc(MatSciTest): diff --git a/tests/core/test_molecular_orbitals.py b/tests/core/test_molecular_orbitals.py index 4943a17ec7a..c2275268a33 100644 --- a/tests/core/test_molecular_orbitals.py +++ b/tests/core/test_molecular_orbitals.py @@ -3,7 +3,7 @@ import pytest from pymatgen.core.molecular_orbitals import MolecularOrbitals -from pymatgen.util.testing import PymatgenTest +from pymatgen.util.testing import MatSciTest test_case = MolecularOrbitals("NaCl") diff --git a/tests/core/test_operations.py b/tests/core/test_operations.py index 3376993f310..286b9ce1ae9 100644 --- a/tests/core/test_operations.py +++ b/tests/core/test_operations.py @@ -5,7 +5,7 @@ from pymatgen.core.operations import MagSymmOp, SymmOp from pymatgen.electronic_structure.core import Magmom -from pymatgen.util.testing import PymatgenTest +from pymatgen.util.testing import MatSciTest class TestSymmOp(MatSciTest): diff --git a/tests/core/test_periodic_table.py b/tests/core/test_periodic_table.py index 1bb2e76473b..2357ee1a924 100644 --- a/tests/core/test_periodic_table.py +++ b/tests/core/test_periodic_table.py @@ -14,7 +14,7 @@ from pymatgen.core.periodic_table import ElementBase, ElementType from pymatgen.core.units import Ha_to_eV from pymatgen.io.core import ParseError -from pymatgen.util.testing import PymatgenTest +from pymatgen.util.testing import MatSciTest class TestElement(MatSciTest): diff --git a/tests/core/test_sites.py b/tests/core/test_sites.py index b1d3cfa0675..83120018eb0 100644 --- a/tests/core/test_sites.py +++ b/tests/core/test_sites.py @@ -9,7 +9,7 @@ from pymatgen.core import Composition, Element, Lattice, PeriodicSite, Site, Species from pymatgen.electronic_structure.core import Magmom -from pymatgen.util.testing import PymatgenTest +from pymatgen.util.testing import MatSciTest class TestSite(MatSciTest): diff --git a/tests/core/test_spectrum.py b/tests/core/test_spectrum.py index 5c2cd5780e1..32d7760a992 100644 --- a/tests/core/test_spectrum.py +++ b/tests/core/test_spectrum.py @@ -6,7 +6,7 @@ from scipy import stats from pymatgen.core.spectrum import Spectrum -from pymatgen.util.testing import PymatgenTest +from pymatgen.util.testing import MatSciTest class TestSpectrum(MatSciTest): diff --git a/tests/core/test_units.py b/tests/core/test_units.py index 3e420bdad8f..c7d89c60436 100644 --- a/tests/core/test_units.py +++ b/tests/core/test_units.py @@ -26,7 +26,7 @@ eV_to_Ha, unitized, ) -from pymatgen.util.testing import PymatgenTest +from pymatgen.util.testing import MatSciTest def test_unit_conversions(): diff --git a/tests/core/test_xcfunc.py b/tests/core/test_xcfunc.py index fb95376d4b9..bafedc17902 100644 --- a/tests/core/test_xcfunc.py +++ b/tests/core/test_xcfunc.py @@ -3,7 +3,7 @@ import pytest from pymatgen.core.xcfunc import XcFunc -from pymatgen.util.testing import PymatgenTest +from pymatgen.util.testing import MatSciTest class TestLibxcFunc(MatSciTest): diff --git a/tests/ext/test_optimade.py b/tests/ext/test_optimade.py index 01882b19cfc..1f95a28bb86 100644 --- a/tests/ext/test_optimade.py +++ b/tests/ext/test_optimade.py @@ -4,7 +4,7 @@ import requests from pymatgen.ext.optimade import OptimadeRester -from pymatgen.util.testing import PymatgenTest +from pymatgen.util.testing import MatSciTest try: # 403 is returned when server detects bot-like behavior diff --git a/tests/io/test_xcrysden.py b/tests/io/test_xcrysden.py index bd217b15fbd..59f57a56a1b 100644 --- a/tests/io/test_xcrysden.py +++ b/tests/io/test_xcrysden.py @@ -4,7 +4,7 @@ from pymatgen.core.structure import Structure from pymatgen.io.xcrysden import XSF -from pymatgen.util.testing import PymatgenTest +from pymatgen.util.testing import MatSciTest class TestXSF(MatSciTest): diff --git a/tests/optimization/test_neighbors.py b/tests/optimization/test_neighbors.py index f08f4929428..2e550d7274d 100644 --- a/tests/optimization/test_neighbors.py +++ b/tests/optimization/test_neighbors.py @@ -4,7 +4,7 @@ from pymatgen.core.lattice import Lattice from pymatgen.optimization.neighbors import find_points_in_spheres -from pymatgen.util.testing import PymatgenTest +from pymatgen.util.testing import MatSciTest class TestNeighbors(MatSciTest): diff --git a/tests/symmetry/test_kpath_hin.py b/tests/symmetry/test_kpath_hin.py index 08ae60e71bb..de384d7fe3c 100644 --- a/tests/symmetry/test_kpath_hin.py +++ b/tests/symmetry/test_kpath_hin.py @@ -6,7 +6,7 @@ from pymatgen.core.lattice import Lattice from pymatgen.core.structure import Structure from pymatgen.symmetry.kpath import KPathSeek -from pymatgen.util.testing import PymatgenTest +from pymatgen.util.testing import MatSciTest pytest.importorskip("seekpath", reason="seekpath not installed") diff --git a/tests/symmetry/test_maggroups.py b/tests/symmetry/test_maggroups.py index 2b474285836..57a2da36dfb 100644 --- a/tests/symmetry/test_maggroups.py +++ b/tests/symmetry/test_maggroups.py @@ -6,7 +6,7 @@ from pymatgen.core.lattice import Lattice from pymatgen.symmetry.groups import SpaceGroup from pymatgen.symmetry.maggroups import MagneticSpaceGroup -from pymatgen.util.testing import PymatgenTest +from pymatgen.util.testing import MatSciTest __author__ = "Matthew Horton" __copyright__ = "Copyright 2017, The Materials Project" diff --git a/tests/transformations/test_site_transformations.py b/tests/transformations/test_site_transformations.py index e7e5be40efe..bddf1ca817f 100644 --- a/tests/transformations/test_site_transformations.py +++ b/tests/transformations/test_site_transformations.py @@ -16,7 +16,7 @@ ReplaceSiteSpeciesTransformation, TranslateSitesTransformation, ) -from pymatgen.util.testing import PymatgenTest +from pymatgen.util.testing import MatSciTest enum_cmd = which("enum.x") or which("multienum.x") makestr_cmd = which("makestr.x") or which("makeStr.x") or which("makeStr.py") diff --git a/tests/util/test_plotting.py b/tests/util/test_plotting.py index b8c13bd1480..e8c55875fbd 100644 --- a/tests/util/test_plotting.py +++ b/tests/util/test_plotting.py @@ -3,7 +3,7 @@ import matplotlib.pyplot as plt from pymatgen.util.plotting import periodic_table_heatmap, van_arkel_triangle -from pymatgen.util.testing import PymatgenTest +from pymatgen.util.testing import MatSciTest try: import pymatviz From 9ae0debc0fa1604b138e5a42292b4fa57102f6eb Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Wed, 4 Dec 2024 23:31:57 +0800 Subject: [PATCH 19/31] global replace get_structure --- tests/alchemy/test_materials.py | 4 ++-- tests/alchemy/test_transmuters.py | 2 +- .../structure_prediction/test_substitutor.py | 4 ++-- .../test_volume_predictor.py | 24 +++++++++---------- tests/core/test_structure.py | 8 +++---- tests/io/test_phonopy.py | 4 ++-- tests/io/vasp/test_sets.py | 8 +++---- tests/symmetry/test_analyzer.py | 8 +++---- .../test_advanced_transformations.py | 6 ++--- 9 files changed, 34 insertions(+), 34 deletions(-) diff --git a/tests/alchemy/test_materials.py b/tests/alchemy/test_materials.py index 10115842f8f..cd5d19b6d24 100644 --- a/tests/alchemy/test_materials.py +++ b/tests/alchemy/test_materials.py @@ -16,14 +16,14 @@ SupercellTransformation, ) from pymatgen.util.provenance import StructureNL -from pymatgen.util.testing import FAKE_POTCAR_DIR, TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import FAKE_POTCAR_DIR, TEST_FILES_DIR, MatSciTest TEST_DIR = f"{TEST_FILES_DIR}/alchemy" class TestTransformedStructure(MatSciTest): def setup_method(self): - structure = PymatgenTest.get_structure("LiFePO4") + structure = MatSciTest.get_structure("LiFePO4") self.structure = structure trafos = [SubstitutionTransformation({"Li": "Na"})] self.trans = TransformedStructure(structure, trafos) diff --git a/tests/alchemy/test_transmuters.py b/tests/alchemy/test_transmuters.py index fa249c2d500..e5697a459f0 100644 --- a/tests/alchemy/test_transmuters.py +++ b/tests/alchemy/test_transmuters.py @@ -8,7 +8,7 @@ RemoveSpeciesTransformation, SubstitutionTransformation, ) -from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, MatSciTest class TestCifTransmuter(MatSciTest): diff --git a/tests/analysis/structure_prediction/test_substitutor.py b/tests/analysis/structure_prediction/test_substitutor.py index a8626b5bf33..84ad08f4b6a 100644 --- a/tests/analysis/structure_prediction/test_substitutor.py +++ b/tests/analysis/structure_prediction/test_substitutor.py @@ -4,7 +4,7 @@ from pymatgen.analysis.structure_prediction.substitutor import Substitutor from pymatgen.core import Composition, Species -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest TEST_DIR = f"{TEST_FILES_DIR}/analysis/struct_predictor" @@ -32,7 +32,7 @@ def test_substitutor(self): subs = self.substitutor.pred_from_comp(comp) assert len(subs) == 4, "incorrect number of substitutions" - structures = [{"structure": PymatgenTest.get_structure("Li2O"), "id": "pmgtest"}] + structures = [{"structure": MatSciTest.get_structure("Li2O"), "id": "pmgtest"}] subs = self.substitutor.pred_from_structures(["Na+", "O2-"], structures) assert subs[0].formula == "Na2 O1" diff --git a/tests/analysis/structure_prediction/test_volume_predictor.py b/tests/analysis/structure_prediction/test_volume_predictor.py index b94bf999a50..da96904a990 100644 --- a/tests/analysis/structure_prediction/test_volume_predictor.py +++ b/tests/analysis/structure_prediction/test_volume_predictor.py @@ -5,38 +5,38 @@ from pymatgen.analysis.structure_prediction.volume_predictor import DLSVolumePredictor, RLSVolumePredictor from pymatgen.core import Structure -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest TEST_DIR = f"{TEST_FILES_DIR}/analysis/structure_prediction" class TestRLSVolumePredictor(MatSciTest): def test_predict(self): - struct = PymatgenTest.get_structure("CsCl") - nacl = PymatgenTest.get_structure("CsCl") + struct = MatSciTest.get_structure("CsCl") + nacl = MatSciTest.get_structure("CsCl") nacl.replace_species({"Cs": "Na"}) nacl.scale_lattice(184.384551033) predictor = RLSVolumePredictor(radii_type="ionic") assert predictor.predict(struct, nacl) == approx(342.84905395082535) predictor = RLSVolumePredictor(radii_type="atomic") assert predictor.predict(struct, nacl) == approx(391.884366481) - lif = PymatgenTest.get_structure("CsCl") + lif = MatSciTest.get_structure("CsCl") lif.replace_species({"Cs": "Li", "Cl": "F"}) predictor = RLSVolumePredictor(radii_type="ionic") assert predictor.predict(lif, nacl) == approx(74.268402413690467) predictor = RLSVolumePredictor(radii_type="atomic") assert predictor.predict(lif, nacl) == approx(62.2808125839) - lfpo = PymatgenTest.get_structure("LiFePO4") - lmpo = PymatgenTest.get_structure("LiFePO4") + lfpo = MatSciTest.get_structure("LiFePO4") + lmpo = MatSciTest.get_structure("LiFePO4") lmpo.replace_species({"Fe": "Mn"}) predictor = RLSVolumePredictor(radii_type="ionic") assert predictor.predict(lmpo, lfpo) == approx(310.08253254420134) predictor = RLSVolumePredictor(radii_type="atomic") assert predictor.predict(lmpo, lfpo) == approx(299.607967711) - sto = PymatgenTest.get_structure("SrTiO3") - scoo = PymatgenTest.get_structure("SrTiO3") + sto = MatSciTest.get_structure("SrTiO3") + scoo = MatSciTest.get_structure("SrTiO3") scoo.replace_species({"Ti4+": "Co4+"}) predictor = RLSVolumePredictor(radii_type="ionic") assert predictor.predict(scoo, sto) == approx(56.162534974936463) @@ -61,8 +61,8 @@ def test_predict(self): assert predictor.predict(apo, aps) == approx(1196.31384276) def test_modes(self): - cs_cl = PymatgenTest.get_structure("CsCl") - na_cl = PymatgenTest.get_structure("CsCl") + cs_cl = MatSciTest.get_structure("CsCl") + na_cl = MatSciTest.get_structure("CsCl") na_cl.replace_species({"Cs": "Na"}) na_cl.scale_lattice(184.384551033) vol_pred = RLSVolumePredictor(radii_type="ionic", use_bv=False) @@ -94,7 +94,7 @@ def test_predict(self): assert vol_pred.predict(fen) == approx(fen.volume * 1.5) assert p_fast.predict(fen) == approx(fen.volume * 1.5) - lfpo = PymatgenTest.get_structure("LiFePO4") + lfpo = MatSciTest.get_structure("LiFePO4") lfpo.scale_lattice(lfpo.volume * 3.0) assert p_nolimit.predict(lfpo) == approx(291.62094410192924) @@ -104,6 +104,6 @@ def test_predict(self): assert vol_pred.predict(lfpo) == approx(lfpo.volume * 1.5) assert p_fast.predict(lfpo) == approx(lfpo.volume * 1.5) - lmpo = PymatgenTest.get_structure("LiFePO4") + lmpo = MatSciTest.get_structure("LiFePO4") lmpo.replace_species({"Fe": "Mn"}) assert vol_pred.predict(lmpo) == approx(290.795329052) diff --git a/tests/core/test_structure.py b/tests/core/test_structure.py index 028cc36b234..24599a1c45b 100644 --- a/tests/core/test_structure.py +++ b/tests/core/test_structure.py @@ -30,7 +30,7 @@ from pymatgen.io.ase import AseAtomsAdaptor from pymatgen.io.cif import CifParser from pymatgen.symmetry.analyzer import SpacegroupAnalyzer -from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, MatSciTest try: from ase.atoms import Atoms @@ -46,7 +46,7 @@ class TestNeighbor(MatSciTest): def test_msonable(self): - struct = PymatgenTest.get_structure("Li2O") + struct = MatSciTest.get_structure("Li2O") nn = struct.get_neighbors(struct[0], r=3) assert isinstance(nn[0], PeriodicNeighbor) str_ = json.dumps(nn, cls=MontyEncoder) @@ -1024,7 +1024,7 @@ def test_mutable_sequence_methods(self): assert struct.formula == "Mn1" # Test slice replacement. - struct = PymatgenTest.get_structure("Li2O") + struct = MatSciTest.get_structure("Li2O") struct[:2] = "S" assert struct.formula == "Li1 S2" @@ -1267,7 +1267,7 @@ def test_remove_oxidation_states(self): assert struct_elem == struct_specie, "Oxidation state remover failed" def test_add_oxidation_state_by_guess(self): - struct = PymatgenTest.get_structure("Li2O") + struct = MatSciTest.get_structure("Li2O") returned = struct.add_oxidation_state_by_guess() assert returned is struct expected = [Species("Li", 1), Species("O", -2)] diff --git a/tests/io/test_phonopy.py b/tests/io/test_phonopy.py index e84414e72d7..d5e87392d69 100644 --- a/tests/io/test_phonopy.py +++ b/tests/io/test_phonopy.py @@ -28,7 +28,7 @@ get_pmg_structure, get_thermal_displacement_matrices, ) -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest try: from phonopy import Phonopy @@ -99,7 +99,7 @@ def test_get_complete_dos(self): @pytest.mark.skipif(Phonopy is None, reason="Phonopy not present") class TestStructureConversion(MatSciTest): def test_structure_conversion(self): - struct_pmg = PymatgenTest.get_structure("LiFePO4") + struct_pmg = MatSciTest.get_structure("LiFePO4") # add magmoms to site_properties struct_pmg.add_site_property("magmom", magmoms := [1] * len(struct_pmg)) struct_ph = get_phonopy_structure(struct_pmg) diff --git a/tests/io/vasp/test_sets.py b/tests/io/vasp/test_sets.py index ec4a88bd0fc..db021659d33 100644 --- a/tests/io/vasp/test_sets.py +++ b/tests/io/vasp/test_sets.py @@ -54,7 +54,7 @@ get_valid_magmom_struct, ) from pymatgen.symmetry.analyzer import SpacegroupAnalyzer -from pymatgen.util.testing import FAKE_POTCAR_DIR, TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR, PymatgenTest +from pymatgen.util.testing import FAKE_POTCAR_DIR, TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR, MatSciTest TEST_DIR = f"{TEST_FILES_DIR}/io/vasp" @@ -1501,7 +1501,7 @@ def test_incar(self): class TestMVLGWSet(MatSciTest): def setup_method(self): self.set = MVLGWSet - self.struct = PymatgenTest.get_structure("Li2O") + self.struct = MatSciTest.get_structure("Li2O") def test_static(self): assert self.set.mode == "STATIC" @@ -1675,7 +1675,7 @@ def test_init(self): assert vis.reciprocal_density == 100 with pytest.warns(BadInputSetWarning, match=r"Hybrid functionals"): - vis = self.set(PymatgenTest.get_structure("Li2O"), user_incar_settings={"ALGO": "Fast"}) + vis = self.set(MatSciTest.get_structure("Li2O"), user_incar_settings={"ALGO": "Fast"}) vis.incar.items() def test_override_from_prev_calc(self): @@ -1991,7 +1991,7 @@ def test_override_from_prev_calc(self): class TestFunc(MatSciTest): @skip_if_no_psp_dir def test_batch_write_input(self): - structs = list(map(PymatgenTest.get_structure, ("Li2O", "LiFePO4"))) + structs = list(map(MatSciTest.get_structure, ("Li2O", "LiFePO4"))) batch_write_input(structs, sanitize=True) for formula in ("Li4Fe4P4O16_1", "Li2O1_0"): diff --git a/tests/symmetry/test_analyzer.py b/tests/symmetry/test_analyzer.py index f67c9576b8c..baec09b105d 100644 --- a/tests/symmetry/test_analyzer.py +++ b/tests/symmetry/test_analyzer.py @@ -18,7 +18,7 @@ iterative_symmetrize, ) from pymatgen.symmetry.structure import SymmetrizedStructure -from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR, MatSciTest TEST_DIR = f"{TEST_FILES_DIR}/symmetry/analyzer" @@ -54,7 +54,7 @@ def test_is_laue(self): assert self.disordered_sg.is_laue() def test_magnetic(self): - lfp = PymatgenTest.get_structure("LiFePO4") + lfp = MatSciTest.get_structure("LiFePO4") sg = SpacegroupAnalyzer(lfp, 0.1) assert sg.get_space_group_symbol() == "Pnma" magmoms = [0] * len(lfp) @@ -670,7 +670,7 @@ def test_symmetrize_molecule2(self): def test_get_kpoint_weights(self): for name in ("SrTiO3", "LiFePO4", "Graphite"): - struct = PymatgenTest.get_structure(name) + struct = MatSciTest.get_structure(name) spga = SpacegroupAnalyzer(struct) ir_mesh = spga.get_ir_reciprocal_mesh((4, 4, 4)) weights = [i[1] for i in ir_mesh] @@ -679,7 +679,7 @@ def test_get_kpoint_weights(self): assert weight == approx(expected) for name in ("SrTiO3", "LiFePO4", "Graphite"): - struct = PymatgenTest.get_structure(name) + struct = MatSciTest.get_structure(name) spga = SpacegroupAnalyzer(struct) ir_mesh = spga.get_ir_reciprocal_mesh((1, 2, 3)) weights = [i[1] for i in ir_mesh] diff --git a/tests/transformations/test_advanced_transformations.py b/tests/transformations/test_advanced_transformations.py index 3e508b89867..7ba24428559 100644 --- a/tests/transformations/test_advanced_transformations.py +++ b/tests/transformations/test_advanced_transformations.py @@ -40,7 +40,7 @@ OxidationStateDecorationTransformation, SubstitutionTransformation, ) -from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, MatSciTest try: import hiphive @@ -490,7 +490,7 @@ def test_advanced_usage(self): @pytest.mark.skipif(not enumlib_present, reason="enum_lib not present.") class TestDopingTransformation(MatSciTest): def test_apply_transformation(self): - structure = PymatgenTest.get_structure("LiFePO4") + structure = MatSciTest.get_structure("LiFePO4") spga = SpacegroupAnalyzer(structure, 0.1) structure = spga.get_refined_structure() trafo = DopingTransformation("Ca2+", min_length=10) @@ -524,7 +524,7 @@ def test_apply_transformation(self): assert d["structure"].charge == 0 # Make sure compensation is done with lowest oxi state - structure = PymatgenTest.get_structure("SrTiO3") + structure = MatSciTest.get_structure("SrTiO3") trafo = DopingTransformation( "Nb5+", min_length=5, From 42f9fb601582023bff0dd3255e48cffce1ebb2e0 Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Wed, 4 Dec 2024 23:34:03 +0800 Subject: [PATCH 20/31] global replace PymatgenTest with MatSciTest --- tests/alchemy/test_filters.py | 2 +- .../chemenv/connectivity/test_connected_components.py | 2 +- .../chemenv/connectivity/test_structure_connectivity.py | 2 +- .../test_coordination_geometry_finder.py | 2 +- .../chemenv/coordination_environments/test_read_write.py | 2 +- .../test_structure_environments.py | 2 +- .../chemenv/coordination_environments/test_voronoi.py | 2 +- .../chemenv/coordination_environments/test_weights.py | 2 +- tests/analysis/chemenv/utils/test_chemenv_config.py | 2 +- tests/analysis/elasticity/test_elastic.py | 2 +- tests/analysis/ferroelectricity/test_polarization.py | 2 +- tests/analysis/solar/test_slme.py | 2 +- tests/analysis/test_bond_valence.py | 2 +- tests/analysis/test_chempot_diagram.py | 2 +- tests/analysis/test_dimensionality.py | 2 +- tests/analysis/test_fragmenter.py | 2 +- tests/analysis/test_graphs.py | 2 +- tests/analysis/test_local_env.py | 2 +- tests/analysis/test_phase_diagram.py | 2 +- tests/analysis/test_piezo_sensitivity.py | 2 +- tests/analysis/test_pourbaix_diagram.py | 2 +- tests/analysis/test_structure_analyzer.py | 2 +- tests/analysis/test_structure_matcher.py | 2 +- tests/analysis/test_surface_analysis.py | 2 +- tests/analysis/test_transition_state.py | 2 +- tests/analysis/test_wulff.py | 2 +- tests/analysis/test_xps.py | 2 +- tests/analysis/topological/test_spillage.py | 2 +- tests/analysis/xas/test_spectrum.py | 2 +- tests/apps/battery/test_analyzer.py | 2 +- tests/command_line/test_bader_caller.py | 2 +- tests/command_line/test_enumlib_caller.py | 2 +- tests/command_line/test_mcsqs_caller.py | 2 +- tests/command_line/test_vampire_caller.py | 2 +- tests/core/test_interface.py | 2 +- tests/core/test_surface.py | 2 +- tests/core/test_tensors.py | 2 +- tests/core/test_trajectory.py | 2 +- tests/electronic_structure/test_bandstructure.py | 2 +- tests/electronic_structure/test_cohp.py | 2 +- tests/electronic_structure/test_dos.py | 2 +- tests/electronic_structure/test_plotter.py | 2 +- tests/entries/test_entry_tools.py | 2 +- tests/ext/test_matproj.py | 2 +- tests/io/abinit/test_abiobjects.py | 2 +- tests/io/abinit/test_inputs.py | 2 +- tests/io/abinit/test_netcdf.py | 2 +- tests/io/abinit/test_pseudos.py | 2 +- tests/io/cp2k/test_inputs.py | 2 +- tests/io/cp2k/test_sets.py | 2 +- tests/io/exciting/test_inputs.py | 2 +- tests/io/feff/test_sets.py | 2 +- tests/io/lammps/test_data.py | 2 +- tests/io/lammps/test_generators.py | 2 +- tests/io/lammps/test_inputs.py | 2 +- tests/io/lobster/test_inputs.py | 2 +- tests/io/lobster/test_outputs.py | 2 +- tests/io/pwmat/test_inputs.py | 2 +- tests/io/pwmat/test_outputs.py | 2 +- tests/io/qchem/test_inputs.py | 2 +- tests/io/qchem/test_outputs.py | 2 +- tests/io/qchem/test_sets.py | 2 +- tests/io/qchem/test_utils.py | 2 +- tests/io/test_adf.py | 2 +- tests/io/test_atat.py | 2 +- tests/io/test_cif.py | 2 +- tests/io/test_core.py | 2 +- tests/io/test_lmto.py | 2 +- tests/io/test_packmol.py | 6 +++--- tests/io/test_pwscf.py | 2 +- tests/io/test_shengbte.py | 2 +- tests/io/test_template_input.py | 2 +- tests/io/test_wannier90.py | 2 +- tests/io/vasp/test_inputs.py | 2 +- tests/io/vasp/test_optics.py | 2 +- tests/io/vasp/test_outputs.py | 2 +- tests/io/xtb/test_inputs.py | 2 +- tests/io/xtb/test_outputs.py | 2 +- tests/phonon/test_bandstructure.py | 2 +- tests/phonon/test_dos.py | 2 +- tests/phonon/test_gruneisen.py | 2 +- tests/phonon/test_ir_spectra.py | 2 +- tests/phonon/test_thermal_displacements.py | 2 +- tests/symmetry/test_kpath_lm.py | 2 +- tests/symmetry/test_kpath_sc.py | 2 +- tests/symmetry/test_kpaths.py | 2 +- tests/symmetry/test_site_symmetries.py | 2 +- tests/util/test_io.py | 2 +- tests/vis/test_plotters.py | 2 +- 89 files changed, 91 insertions(+), 91 deletions(-) diff --git a/tests/alchemy/test_filters.py b/tests/alchemy/test_filters.py index f068db3cf91..ddccba64607 100644 --- a/tests/alchemy/test_filters.py +++ b/tests/alchemy/test_filters.py @@ -13,7 +13,7 @@ from pymatgen.alchemy.transmuters import StandardTransmuter from pymatgen.analysis.structure_matcher import StructureMatcher from pymatgen.core import Lattice, Species, Structure -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest class TestContainsSpecieFilter(MatSciTest): diff --git a/tests/analysis/chemenv/connectivity/test_connected_components.py b/tests/analysis/chemenv/connectivity/test_connected_components.py index 915f0bf1bae..7a2b6e3917d 100644 --- a/tests/analysis/chemenv/connectivity/test_connected_components.py +++ b/tests/analysis/chemenv/connectivity/test_connected_components.py @@ -20,7 +20,7 @@ from pymatgen.core.lattice import Lattice from pymatgen.core.sites import PeriodicSite from pymatgen.core.structure import Structure -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest __author__ = "waroquiers" diff --git a/tests/analysis/chemenv/connectivity/test_structure_connectivity.py b/tests/analysis/chemenv/connectivity/test_structure_connectivity.py index 604f3018744..9a0be08b8a9 100644 --- a/tests/analysis/chemenv/connectivity/test_structure_connectivity.py +++ b/tests/analysis/chemenv/connectivity/test_structure_connectivity.py @@ -9,7 +9,7 @@ LightStructureEnvironments, StructureEnvironments, ) -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest __author__ = "waroquiers" diff --git a/tests/analysis/chemenv/coordination_environments/test_coordination_geometry_finder.py b/tests/analysis/chemenv/coordination_environments/test_coordination_geometry_finder.py index d518fd0d466..d586b6cd946 100644 --- a/tests/analysis/chemenv/coordination_environments/test_coordination_geometry_finder.py +++ b/tests/analysis/chemenv/coordination_environments/test_coordination_geometry_finder.py @@ -19,7 +19,7 @@ symmetry_measure, ) from pymatgen.core.structure import Lattice, Structure -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest __author__ = "waroquiers" diff --git a/tests/analysis/chemenv/coordination_environments/test_read_write.py b/tests/analysis/chemenv/coordination_environments/test_read_write.py index f1be06c44ca..8e07b0b6bda 100644 --- a/tests/analysis/chemenv/coordination_environments/test_read_write.py +++ b/tests/analysis/chemenv/coordination_environments/test_read_write.py @@ -22,7 +22,7 @@ ) from pymatgen.analysis.chemenv.coordination_environments.voronoi import DetailedVoronoiContainer from pymatgen.core.structure import Structure -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest __author__ = "waroquiers" diff --git a/tests/analysis/chemenv/coordination_environments/test_structure_environments.py b/tests/analysis/chemenv/coordination_environments/test_structure_environments.py index 16fa2a4d16e..4e7e1973eba 100644 --- a/tests/analysis/chemenv/coordination_environments/test_structure_environments.py +++ b/tests/analysis/chemenv/coordination_environments/test_structure_environments.py @@ -17,7 +17,7 @@ StructureEnvironments, ) from pymatgen.core import Species, Structure -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest __author__ = "waroquiers" diff --git a/tests/analysis/chemenv/coordination_environments/test_voronoi.py b/tests/analysis/chemenv/coordination_environments/test_voronoi.py index 60dafdf3af9..ad65dacf081 100644 --- a/tests/analysis/chemenv/coordination_environments/test_voronoi.py +++ b/tests/analysis/chemenv/coordination_environments/test_voronoi.py @@ -5,7 +5,7 @@ from pymatgen.analysis.chemenv.coordination_environments.voronoi import DetailedVoronoiContainer from pymatgen.core.lattice import Lattice from pymatgen.core.structure import Structure -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest __author__ = "waroquiers" diff --git a/tests/analysis/chemenv/coordination_environments/test_weights.py b/tests/analysis/chemenv/coordination_environments/test_weights.py index 586af7a31bf..dda21e57417 100644 --- a/tests/analysis/chemenv/coordination_environments/test_weights.py +++ b/tests/analysis/chemenv/coordination_environments/test_weights.py @@ -16,7 +16,7 @@ SelfCSMNbSetWeight, ) from pymatgen.analysis.chemenv.coordination_environments.structure_environments import StructureEnvironments -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest __author__ = "waroquiers" diff --git a/tests/analysis/chemenv/utils/test_chemenv_config.py b/tests/analysis/chemenv/utils/test_chemenv_config.py index 1c3efa2c8c4..3fa00994682 100644 --- a/tests/analysis/chemenv/utils/test_chemenv_config.py +++ b/tests/analysis/chemenv/utils/test_chemenv_config.py @@ -2,7 +2,7 @@ from pymatgen.analysis.chemenv.utils.chemenv_config import ChemEnvConfig from pymatgen.core import SETTINGS -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest __author__ = "waroquiers" diff --git a/tests/analysis/elasticity/test_elastic.py b/tests/analysis/elasticity/test_elastic.py index 788ce69d13e..6f66a73ecdb 100644 --- a/tests/analysis/elasticity/test_elastic.py +++ b/tests/analysis/elasticity/test_elastic.py @@ -27,7 +27,7 @@ from pymatgen.core.structure import Structure from pymatgen.core.tensors import Tensor from pymatgen.core.units import FloatWithUnit -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest TEST_DIR = f"{TEST_FILES_DIR}/analysis/elasticity" diff --git a/tests/analysis/ferroelectricity/test_polarization.py b/tests/analysis/ferroelectricity/test_polarization.py index f1cc15358ae..7a68b1a805e 100644 --- a/tests/analysis/ferroelectricity/test_polarization.py +++ b/tests/analysis/ferroelectricity/test_polarization.py @@ -13,7 +13,7 @@ from pymatgen.core.structure import Structure from pymatgen.io.vasp.inputs import Potcar from pymatgen.io.vasp.outputs import Outcar -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest TEST_DIR = f"{TEST_FILES_DIR}/io/vasp/fixtures/BTO_221_99_polarization" bto_folders = ["nonpolar_polarization"] diff --git a/tests/analysis/solar/test_slme.py b/tests/analysis/solar/test_slme.py index e83ede5b062..3bcfd828495 100644 --- a/tests/analysis/solar/test_slme.py +++ b/tests/analysis/solar/test_slme.py @@ -3,7 +3,7 @@ from pytest import approx from pymatgen.analysis.solar.slme import optics, slme -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest TEST_DIR = f"{TEST_FILES_DIR}/analysis/solar" diff --git a/tests/analysis/test_bond_valence.py b/tests/analysis/test_bond_valence.py index fb50139d78b..dbc68adf22d 100644 --- a/tests/analysis/test_bond_valence.py +++ b/tests/analysis/test_bond_valence.py @@ -5,7 +5,7 @@ from pymatgen.analysis.bond_valence import BVAnalyzer, calculate_bv_sum, calculate_bv_sum_unordered from pymatgen.core import Composition, Species, Structure -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest TEST_DIR = f"{TEST_FILES_DIR}/analysis/bond_valence" diff --git a/tests/analysis/test_chempot_diagram.py b/tests/analysis/test_chempot_diagram.py index 1c6377db8f9..24efd0e5317 100644 --- a/tests/analysis/test_chempot_diagram.py +++ b/tests/analysis/test_chempot_diagram.py @@ -12,7 +12,7 @@ ) from pymatgen.core.composition import Element from pymatgen.entries.entry_tools import EntrySet -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest TEST_DIR = f"{TEST_FILES_DIR}/analysis" diff --git a/tests/analysis/test_dimensionality.py b/tests/analysis/test_dimensionality.py index 7f700969292..ced0094926b 100644 --- a/tests/analysis/test_dimensionality.py +++ b/tests/analysis/test_dimensionality.py @@ -15,7 +15,7 @@ from pymatgen.analysis.graphs import StructureGraph from pymatgen.analysis.local_env import CrystalNN from pymatgen.core.structure import Structure -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest class TestLarsenDimensionality(MatSciTest): diff --git a/tests/analysis/test_fragmenter.py b/tests/analysis/test_fragmenter.py index 477742b1132..05af88a8edf 100644 --- a/tests/analysis/test_fragmenter.py +++ b/tests/analysis/test_fragmenter.py @@ -8,7 +8,7 @@ from pymatgen.analysis.graphs import MoleculeGraph from pymatgen.analysis.local_env import OpenBabelNN from pymatgen.core.structure import Molecule -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest __author__ = "Samuel Blau" __email__ = "samblau1@gmail.com" diff --git a/tests/analysis/test_graphs.py b/tests/analysis/test_graphs.py index 72b125aa12d..d631d0f1823 100644 --- a/tests/analysis/test_graphs.py +++ b/tests/analysis/test_graphs.py @@ -23,7 +23,7 @@ from pymatgen.command_line.critic2_caller import Critic2Analysis from pymatgen.core import Lattice, Molecule, Site, Structure from pymatgen.core.structure import FunctionalGroups -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest try: from openbabel import openbabel diff --git a/tests/analysis/test_local_env.py b/tests/analysis/test_local_env.py index 8bf1e95e614..f9478dfa605 100644 --- a/tests/analysis/test_local_env.py +++ b/tests/analysis/test_local_env.py @@ -40,7 +40,7 @@ solid_angle, ) from pymatgen.core import Element, Lattice, Molecule, Structure -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest TEST_DIR = f"{TEST_FILES_DIR}/analysis/local_env/fragmenter_files" diff --git a/tests/analysis/test_phase_diagram.py b/tests/analysis/test_phase_diagram.py index 61ee1930028..825c077a64b 100644 --- a/tests/analysis/test_phase_diagram.py +++ b/tests/analysis/test_phase_diagram.py @@ -31,7 +31,7 @@ from pymatgen.core import Composition, DummySpecies, Element from pymatgen.entries.computed_entries import ComputedEntry from pymatgen.entries.entry_tools import EntrySet -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest TEST_DIR = f"{TEST_FILES_DIR}/analysis" diff --git a/tests/analysis/test_piezo_sensitivity.py b/tests/analysis/test_piezo_sensitivity.py index bf9c10ffcf5..7e2d3045487 100644 --- a/tests/analysis/test_piezo_sensitivity.py +++ b/tests/analysis/test_piezo_sensitivity.py @@ -17,7 +17,7 @@ rand_piezo, ) from pymatgen.io.phonopy import get_phonopy_structure -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest try: from phonopy import Phonopy diff --git a/tests/analysis/test_pourbaix_diagram.py b/tests/analysis/test_pourbaix_diagram.py index 38fce08fa90..743ea557a68 100644 --- a/tests/analysis/test_pourbaix_diagram.py +++ b/tests/analysis/test_pourbaix_diagram.py @@ -11,7 +11,7 @@ from pymatgen.core.composition import Composition from pymatgen.core.ion import Ion from pymatgen.entries.computed_entries import ComputedEntry -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest TEST_DIR = f"{TEST_FILES_DIR}/analysis/pourbaix_diagram" diff --git a/tests/analysis/test_structure_analyzer.py b/tests/analysis/test_structure_analyzer.py index 35463013dce..e4b153e9ebd 100644 --- a/tests/analysis/test_structure_analyzer.py +++ b/tests/analysis/test_structure_analyzer.py @@ -16,7 +16,7 @@ ) from pymatgen.core import Element, Lattice, Structure from pymatgen.io.vasp.outputs import Xdatcar -from pymatgen.util.testing import VASP_IN_DIR, VASP_OUT_DIR, PymatgenTest +from pymatgen.util.testing import VASP_IN_DIR, VASP_OUT_DIR, MatSciTest class TestVoronoiAnalyzer(MatSciTest): diff --git a/tests/analysis/test_structure_matcher.py b/tests/analysis/test_structure_matcher.py index bf6f9f00500..096568f5d62 100644 --- a/tests/analysis/test_structure_matcher.py +++ b/tests/analysis/test_structure_matcher.py @@ -17,7 +17,7 @@ ) from pymatgen.core import Element, Lattice, Structure, SymmOp from pymatgen.util.coord import find_in_coord_list_pbc -from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, MatSciTest TEST_DIR = f"{TEST_FILES_DIR}/analysis/structure_matcher" diff --git a/tests/analysis/test_surface_analysis.py b/tests/analysis/test_surface_analysis.py index 18274d6ded3..2129038b16c 100644 --- a/tests/analysis/test_surface_analysis.py +++ b/tests/analysis/test_surface_analysis.py @@ -9,7 +9,7 @@ from pymatgen.analysis.surface_analysis import NanoscaleStability, SlabEntry, SurfaceEnergyPlotter, WorkFunctionAnalyzer from pymatgen.entries.computed_entries import ComputedStructureEntry -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest __author__ = "Richard Tran" __copyright__ = "Copyright 2012, The Materials Project" diff --git a/tests/analysis/test_transition_state.py b/tests/analysis/test_transition_state.py index 78b22aeb305..dd31117b406 100644 --- a/tests/analysis/test_transition_state.py +++ b/tests/analysis/test_transition_state.py @@ -6,7 +6,7 @@ from numpy.testing import assert_allclose from pymatgen.analysis.transition_state import NEBAnalysis, combine_neb_plots -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest """ TODO: Modify unittest doc. diff --git a/tests/analysis/test_wulff.py b/tests/analysis/test_wulff.py index 1a8eeb0284d..e022608b12e 100644 --- a/tests/analysis/test_wulff.py +++ b/tests/analysis/test_wulff.py @@ -9,7 +9,7 @@ from pymatgen.core.structure import Structure from pymatgen.symmetry.analyzer import SpacegroupAnalyzer from pymatgen.util.coord import in_coord_list -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest __author__ = "Zihan Xu, Richard Tran, Balachandran Radhakrishnan" __copyright__ = "Copyright 2013, The Materials Virtual Lab" diff --git a/tests/analysis/test_xps.py b/tests/analysis/test_xps.py index a4358f7ad98..e21381fcaee 100644 --- a/tests/analysis/test_xps.py +++ b/tests/analysis/test_xps.py @@ -2,7 +2,7 @@ from pymatgen.analysis.xps import XPS from pymatgen.io.vasp import Vasprun -from pymatgen.util.testing import VASP_OUT_DIR, PymatgenTest +from pymatgen.util.testing import VASP_OUT_DIR, MatSciTest class TestXPS(MatSciTest): diff --git a/tests/analysis/topological/test_spillage.py b/tests/analysis/topological/test_spillage.py index d605e8c2c63..ae1953d2b93 100644 --- a/tests/analysis/topological/test_spillage.py +++ b/tests/analysis/topological/test_spillage.py @@ -3,7 +3,7 @@ from pytest import approx from pymatgen.analysis.topological.spillage import SOCSpillage -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest TEST_DIR = f"{TEST_FILES_DIR}/analysis/topological" diff --git a/tests/analysis/xas/test_spectrum.py b/tests/analysis/xas/test_spectrum.py index 16a06965e39..7aa098a088c 100644 --- a/tests/analysis/xas/test_spectrum.py +++ b/tests/analysis/xas/test_spectrum.py @@ -10,7 +10,7 @@ from pymatgen.analysis.xas.spectrum import XAS, site_weighted_spectrum from pymatgen.core import Element -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest TEST_DIR = f"{TEST_FILES_DIR}/analysis/spectrum_test" diff --git a/tests/apps/battery/test_analyzer.py b/tests/apps/battery/test_analyzer.py index d2ee3c75610..41e1b6b4f2c 100644 --- a/tests/apps/battery/test_analyzer.py +++ b/tests/apps/battery/test_analyzer.py @@ -5,7 +5,7 @@ from pymatgen.apps.battery.analyzer import BatteryAnalyzer from pymatgen.core.structure import Structure -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest class TestBatteryAnalyzer(MatSciTest): diff --git a/tests/command_line/test_bader_caller.py b/tests/command_line/test_bader_caller.py index 019b71af9cd..86f3bd5d3a4 100644 --- a/tests/command_line/test_bader_caller.py +++ b/tests/command_line/test_bader_caller.py @@ -10,7 +10,7 @@ from pytest import approx from pymatgen.command_line.bader_caller import BaderAnalysis, bader_analysis_from_path -from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR, MatSciTest TEST_DIR = f"{TEST_FILES_DIR}/command_line/bader" diff --git a/tests/command_line/test_enumlib_caller.py b/tests/command_line/test_enumlib_caller.py index 9717e176e48..2e538207603 100644 --- a/tests/command_line/test_enumlib_caller.py +++ b/tests/command_line/test_enumlib_caller.py @@ -11,7 +11,7 @@ from pymatgen.symmetry.analyzer import SpacegroupAnalyzer from pymatgen.transformations.site_transformations import RemoveSitesTransformation from pymatgen.transformations.standard_transformations import SubstitutionTransformation -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest ENUM_CMD = which("enum.x") or which("multienum.x") MAKESTR_CMD = which("makestr.x") or which("makeStr.x") or which("makeStr.py") diff --git a/tests/command_line/test_mcsqs_caller.py b/tests/command_line/test_mcsqs_caller.py index f32aba85833..d7b56ce64ab 100644 --- a/tests/command_line/test_mcsqs_caller.py +++ b/tests/command_line/test_mcsqs_caller.py @@ -7,7 +7,7 @@ from pymatgen.command_line.mcsqs_caller import run_mcsqs from pymatgen.core.structure import Structure -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest __author__ = "Handong Ling, Rachel Woods-Robinson" __maintainer__ = "Handong Ling, Rachel Woods-Robinson" diff --git a/tests/command_line/test_vampire_caller.py b/tests/command_line/test_vampire_caller.py index 30cf129343a..b2246508682 100644 --- a/tests/command_line/test_vampire_caller.py +++ b/tests/command_line/test_vampire_caller.py @@ -8,7 +8,7 @@ from pymatgen.command_line.vampire_caller import VampireCaller from pymatgen.core.structure import Structure -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest TEST_DIR = f"{TEST_FILES_DIR}/analysis/magnetic_orderings" diff --git a/tests/core/test_interface.py b/tests/core/test_interface.py index d9b7ace45b2..41bb16ec56d 100644 --- a/tests/core/test_interface.py +++ b/tests/core/test_interface.py @@ -8,7 +8,7 @@ from pymatgen.core.structure import Structure from pymatgen.core.surface import SlabGenerator from pymatgen.symmetry.analyzer import SpacegroupAnalyzer -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest TEST_DIR = f"{TEST_FILES_DIR}/core/grain_boundary" diff --git a/tests/core/test_surface.py b/tests/core/test_surface.py index ceff64a3457..2f5f11479b5 100644 --- a/tests/core/test_surface.py +++ b/tests/core/test_surface.py @@ -24,7 +24,7 @@ ) from pymatgen.symmetry.analyzer import SpacegroupAnalyzer from pymatgen.symmetry.groups import SpaceGroup -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest PMG_CORE_DIR = os.path.dirname(pymatgen.core.__file__) diff --git a/tests/core/test_tensors.py b/tests/core/test_tensors.py index 972e8b3f207..ea015d29c32 100644 --- a/tests/core/test_tensors.py +++ b/tests/core/test_tensors.py @@ -11,7 +11,7 @@ from pymatgen.core.operations import SymmOp from pymatgen.core.tensors import SquareTensor, Tensor, TensorCollection, TensorMapping, itertools, symmetry_reduce from pymatgen.symmetry.analyzer import SpacegroupAnalyzer -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest class TestTensor(MatSciTest): diff --git a/tests/core/test_trajectory.py b/tests/core/test_trajectory.py index 1ff941ecbf9..b76ecac91ad 100644 --- a/tests/core/test_trajectory.py +++ b/tests/core/test_trajectory.py @@ -12,7 +12,7 @@ from pymatgen.core.trajectory import Trajectory from pymatgen.io.qchem.outputs import QCOutput from pymatgen.io.vasp.outputs import Xdatcar -from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR, MatSciTest TEST_DIR = f"{TEST_FILES_DIR}/core/trajectory" diff --git a/tests/electronic_structure/test_bandstructure.py b/tests/electronic_structure/test_bandstructure.py index 5547a61dc40..de61b2510ba 100644 --- a/tests/electronic_structure/test_bandstructure.py +++ b/tests/electronic_structure/test_bandstructure.py @@ -19,7 +19,7 @@ from pymatgen.electronic_structure.core import Orbital, Spin from pymatgen.electronic_structure.plotter import BSPlotterProjected from pymatgen.io.vasp import BSVasprun -from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR, MatSciTest TEST_DIR = f"{TEST_FILES_DIR}/electronic_structure/bandstructure" diff --git a/tests/electronic_structure/test_cohp.py b/tests/electronic_structure/test_cohp.py index 2f4bfdfb73b..abd24054e6e 100644 --- a/tests/electronic_structure/test_cohp.py +++ b/tests/electronic_structure/test_cohp.py @@ -14,7 +14,7 @@ get_integrated_cohp_in_energy_range, ) from pymatgen.electronic_structure.core import Orbital, Spin -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest TEST_DIR = f"{TEST_FILES_DIR}/electronic_structure/cohp" diff --git a/tests/electronic_structure/test_dos.py b/tests/electronic_structure/test_dos.py index 3474d31f2be..5a51520d37a 100644 --- a/tests/electronic_structure/test_dos.py +++ b/tests/electronic_structure/test_dos.py @@ -13,7 +13,7 @@ from pymatgen.core import Element, Structure from pymatgen.electronic_structure.core import Orbital, OrbitalType, Spin from pymatgen.electronic_structure.dos import DOS, CompleteDos, FermiDos, LobsterCompleteDos -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest TEST_DIR = f"{TEST_FILES_DIR}/electronic_structure/dos" diff --git a/tests/electronic_structure/test_plotter.py b/tests/electronic_structure/test_plotter.py index 5ddfe2405e9..d8df183019f 100644 --- a/tests/electronic_structure/test_plotter.py +++ b/tests/electronic_structure/test_plotter.py @@ -29,7 +29,7 @@ plot_ellipsoid, ) from pymatgen.io.vasp import Vasprun -from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR, MatSciTest BAND_TEST_DIR = f"{TEST_FILES_DIR}/electronic_structure/bandstructure" diff --git a/tests/entries/test_entry_tools.py b/tests/entries/test_entry_tools.py index 26e673af718..0ce519a2176 100644 --- a/tests/entries/test_entry_tools.py +++ b/tests/entries/test_entry_tools.py @@ -9,7 +9,7 @@ from pymatgen.core import Element from pymatgen.entries.computed_entries import ComputedEntry from pymatgen.entries.entry_tools import EntrySet, group_entries_by_composition, group_entries_by_structure -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest TEST_DIR = f"{TEST_FILES_DIR}/entries" diff --git a/tests/ext/test_matproj.py b/tests/ext/test_matproj.py index 65c0fd64444..d87eb4e3328 100644 --- a/tests/ext/test_matproj.py +++ b/tests/ext/test_matproj.py @@ -23,7 +23,7 @@ from pymatgen.ext.matproj_legacy import MPRestError, TaskType, _MPResterLegacy from pymatgen.phonon.bandstructure import PhononBandStructureSymmLine from pymatgen.phonon.dos import CompletePhononDos -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest PMG_MAPI_KEY = SETTINGS.get("PMG_MAPI_KEY", "") if (10 < len(PMG_MAPI_KEY) <= 20) and "PMG_MAPI_KEY" in SETTINGS: diff --git a/tests/io/abinit/test_abiobjects.py b/tests/io/abinit/test_abiobjects.py index f6afb2de78a..18da2286a01 100644 --- a/tests/io/abinit/test_abiobjects.py +++ b/tests/io/abinit/test_abiobjects.py @@ -19,7 +19,7 @@ species_by_znucl, structure_to_abivars, ) -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest class TestLatticeFromAbivars(MatSciTest): diff --git a/tests/io/abinit/test_inputs.py b/tests/io/abinit/test_inputs.py index e16ac9abb66..f39a4ce656d 100644 --- a/tests/io/abinit/test_inputs.py +++ b/tests/io/abinit/test_inputs.py @@ -18,7 +18,7 @@ ion_ioncell_relax_input, num_valence_electrons, ) -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest TEST_DIR = f"{TEST_FILES_DIR}/io/abinit" diff --git a/tests/io/abinit/test_netcdf.py b/tests/io/abinit/test_netcdf.py index c0d9cff9a53..d53e86d6bff 100644 --- a/tests/io/abinit/test_netcdf.py +++ b/tests/io/abinit/test_netcdf.py @@ -11,7 +11,7 @@ from pymatgen.core.structure import Structure from pymatgen.io.abinit import EtsfReader from pymatgen.io.abinit.netcdf import AbinitHeader -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest try: import netCDF4 diff --git a/tests/io/abinit/test_pseudos.py b/tests/io/abinit/test_pseudos.py index 752518d4d6b..5badaada393 100644 --- a/tests/io/abinit/test_pseudos.py +++ b/tests/io/abinit/test_pseudos.py @@ -9,7 +9,7 @@ from pytest import approx from pymatgen.io.abinit.pseudos import Pseudo, PseudoTable -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest TEST_DIR = f"{TEST_FILES_DIR}/io/abinit" diff --git a/tests/io/cp2k/test_inputs.py b/tests/io/cp2k/test_inputs.py index 9e4ae2ae50c..152b62d9804 100644 --- a/tests/io/cp2k/test_inputs.py +++ b/tests/io/cp2k/test_inputs.py @@ -22,7 +22,7 @@ Section, SectionList, ) -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest TEST_DIR = f"{TEST_FILES_DIR}/io/cp2k" diff --git a/tests/io/cp2k/test_sets.py b/tests/io/cp2k/test_sets.py index 3c28e85c953..8f7a0249bc3 100644 --- a/tests/io/cp2k/test_sets.py +++ b/tests/io/cp2k/test_sets.py @@ -6,7 +6,7 @@ from pymatgen.core.structure import Molecule, Structure from pymatgen.io.cp2k.sets import SETTINGS, Cp2kValidationError, DftSet, GaussianTypeOrbitalBasisSet, GthPotential -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest CP2K_TEST_DIR = f"{TEST_FILES_DIR}/io/cp2k" diff --git a/tests/io/exciting/test_inputs.py b/tests/io/exciting/test_inputs.py index 89b6fa0cfcf..55a9ed5a0ef 100644 --- a/tests/io/exciting/test_inputs.py +++ b/tests/io/exciting/test_inputs.py @@ -6,7 +6,7 @@ from pymatgen.core import Lattice, Structure from pymatgen.io.exciting import ExcitingInput -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest __author__ = "Christian Vorwerk" __copyright__ = "Copyright 2016" diff --git a/tests/io/feff/test_sets.py b/tests/io/feff/test_sets.py index 87b5e5896be..f1f07970729 100644 --- a/tests/io/feff/test_sets.py +++ b/tests/io/feff/test_sets.py @@ -9,7 +9,7 @@ from pymatgen.core.structure import Lattice, Molecule, Structure from pymatgen.io.feff.inputs import Atoms, Header, Potential, Tags from pymatgen.io.feff.sets import FEFFDictSet, MPELNESSet, MPEXAFSSet, MPXANESSet -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest FEFF_TEST_DIR = f"{TEST_FILES_DIR}/io/feff" diff --git a/tests/io/lammps/test_data.py b/tests/io/lammps/test_data.py index e57303a49eb..6dd700e6ea9 100644 --- a/tests/io/lammps/test_data.py +++ b/tests/io/lammps/test_data.py @@ -13,7 +13,7 @@ from pymatgen.core import Element, Lattice, Molecule, Structure from pymatgen.io.lammps.data import CombinedData, ForceField, LammpsBox, LammpsData, Topology, lattice_2_lmpbox -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest TEST_DIR = f"{TEST_FILES_DIR}/io/lammps" diff --git a/tests/io/lammps/test_generators.py b/tests/io/lammps/test_generators.py index ea3d91b18b4..8cb549c8d6e 100644 --- a/tests/io/lammps/test_generators.py +++ b/tests/io/lammps/test_generators.py @@ -3,7 +3,7 @@ from pymatgen.core.structure import Structure from pymatgen.io.lammps.data import LammpsData from pymatgen.io.lammps.generators import LammpsMinimization -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest TEST_DIR = f"{TEST_FILES_DIR}/io/lammps" diff --git a/tests/io/lammps/test_inputs.py b/tests/io/lammps/test_inputs.py index 09efce63c81..8806b2e3e80 100644 --- a/tests/io/lammps/test_inputs.py +++ b/tests/io/lammps/test_inputs.py @@ -11,7 +11,7 @@ from pymatgen.core.structure import Structure from pymatgen.io.lammps.data import LammpsData from pymatgen.io.lammps.inputs import LammpsInputFile, LammpsRun, LammpsTemplateGen, write_lammps_inputs -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest TEST_DIR = f"{TEST_FILES_DIR}/io/lammps" diff --git a/tests/io/lobster/test_inputs.py b/tests/io/lobster/test_inputs.py index a5140a0ed36..d2d1cfd527c 100644 --- a/tests/io/lobster/test_inputs.py +++ b/tests/io/lobster/test_inputs.py @@ -8,7 +8,7 @@ from pymatgen.io.lobster import Lobsterin from pymatgen.io.lobster.inputs import get_all_possible_basis_combinations from pymatgen.io.vasp.inputs import Incar, Kpoints, Potcar -from pymatgen.util.testing import FAKE_POTCAR_DIR, TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR, PymatgenTest +from pymatgen.util.testing import FAKE_POTCAR_DIR, TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR, MatSciTest TEST_DIR = f"{TEST_FILES_DIR}/electronic_structure/cohp" diff --git a/tests/io/lobster/test_outputs.py b/tests/io/lobster/test_outputs.py index 17fc2ff122e..9d8de825ad7 100644 --- a/tests/io/lobster/test_outputs.py +++ b/tests/io/lobster/test_outputs.py @@ -30,7 +30,7 @@ Wavefunction, ) from pymatgen.io.vasp import Vasprun -from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR, MatSciTest TEST_DIR = f"{TEST_FILES_DIR}/electronic_structure/cohp" diff --git a/tests/io/pwmat/test_inputs.py b/tests/io/pwmat/test_inputs.py index 075446cfb52..927f3cefdfd 100644 --- a/tests/io/pwmat/test_inputs.py +++ b/tests/io/pwmat/test_inputs.py @@ -18,7 +18,7 @@ LineLocator, ListLocator, ) -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest TEST_DIR = f"{TEST_FILES_DIR}/io/pwmat" diff --git a/tests/io/pwmat/test_outputs.py b/tests/io/pwmat/test_outputs.py index d086baea1b8..597fee5f657 100644 --- a/tests/io/pwmat/test_outputs.py +++ b/tests/io/pwmat/test_outputs.py @@ -1,7 +1,7 @@ from __future__ import annotations from pymatgen.io.pwmat.outputs import DosSpin, Movement, OutFermi, Report -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest TEST_DIR = f"{TEST_FILES_DIR}/io/pwmat" diff --git a/tests/io/qchem/test_inputs.py b/tests/io/qchem/test_inputs.py index b9bf1bca998..2a326c8ee7e 100644 --- a/tests/io/qchem/test_inputs.py +++ b/tests/io/qchem/test_inputs.py @@ -8,7 +8,7 @@ from pymatgen.core.structure import Molecule from pymatgen.io.qchem.inputs import QCInput from pymatgen.io.qchem.sets import OptSet -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest TEST_DIR = f"{TEST_FILES_DIR}/io/qchem" diff --git a/tests/io/qchem/test_outputs.py b/tests/io/qchem/test_outputs.py index 6c837d28fca..f81d374f2af 100644 --- a/tests/io/qchem/test_outputs.py +++ b/tests/io/qchem/test_outputs.py @@ -17,7 +17,7 @@ hessian_parser, orbital_coeffs_parser, ) -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest try: from openbabel import openbabel diff --git a/tests/io/qchem/test_sets.py b/tests/io/qchem/test_sets.py index beb3d9a8230..51caaadc5b0 100644 --- a/tests/io/qchem/test_sets.py +++ b/tests/io/qchem/test_sets.py @@ -14,7 +14,7 @@ SinglePointSet, TransitionStateSet, ) -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest __author__ = "Samuel Blau, Brandon Wood, Shyam Dwaraknath, Evan Spotte-Smith, Ryan Kingsbury" __copyright__ = "Copyright 2018-2022, The Materials Project" diff --git a/tests/io/qchem/test_utils.py b/tests/io/qchem/test_utils.py index d77db30c9a9..feb65c1158e 100644 --- a/tests/io/qchem/test_utils.py +++ b/tests/io/qchem/test_utils.py @@ -6,7 +6,7 @@ from monty.io import zopen from pymatgen.io.qchem.utils import lower_and_check_unique, process_parsed_hess -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest __author__ = "Ryan Kingsbury, Samuel Blau" __copyright__ = "Copyright 2018-2022, The Materials Project" diff --git a/tests/io/test_adf.py b/tests/io/test_adf.py index 477b190b61f..46b002d94fb 100644 --- a/tests/io/test_adf.py +++ b/tests/io/test_adf.py @@ -4,7 +4,7 @@ from pymatgen.core.structure import Molecule from pymatgen.io.adf import AdfInput, AdfKey, AdfOutput, AdfTask -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest __author__ = "Xin Chen, chenxin13@mails.tsinghua.edu.cn" diff --git a/tests/io/test_atat.py b/tests/io/test_atat.py index 628cb292c6b..32758929837 100644 --- a/tests/io/test_atat.py +++ b/tests/io/test_atat.py @@ -5,7 +5,7 @@ from pymatgen.core.structure import Structure from pymatgen.io.atat import Mcsqs -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest TEST_DIR = f"{TEST_FILES_DIR}/io/atat/mcsqs" diff --git a/tests/io/test_cif.py b/tests/io/test_cif.py index a437515bff6..8a6af5a3cef 100644 --- a/tests/io/test_cif.py +++ b/tests/io/test_cif.py @@ -9,7 +9,7 @@ from pymatgen.electronic_structure.core import Magmom from pymatgen.io.cif import CifBlock, CifParser, CifWriter from pymatgen.symmetry.structure import SymmetrizedStructure -from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, MatSciTest try: import pybtex diff --git a/tests/io/test_core.py b/tests/io/test_core.py index 7a719bb7a4d..26149705ff2 100644 --- a/tests/io/test_core.py +++ b/tests/io/test_core.py @@ -10,7 +10,7 @@ from pymatgen.core.structure import Structure from pymatgen.io.cif import CifParser, CifWriter from pymatgen.io.core import InputFile, InputSet -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest if TYPE_CHECKING: from typing_extensions import Self diff --git a/tests/io/test_lmto.py b/tests/io/test_lmto.py index 8d1b924f7cf..f032c56b98b 100644 --- a/tests/io/test_lmto.py +++ b/tests/io/test_lmto.py @@ -10,7 +10,7 @@ from pymatgen.electronic_structure.core import Spin from pymatgen.io.lmto import LMTOCopl, LMTOCtrl from pymatgen.util.num import round_to_sigfigs -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest __author__ = "Marco Esters" __copyright__ = "Copyright 2017, The Materials Project" diff --git a/tests/io/test_packmol.py b/tests/io/test_packmol.py index 0b671f9f62d..03b2017353c 100644 --- a/tests/io/test_packmol.py +++ b/tests/io/test_packmol.py @@ -10,7 +10,7 @@ from pymatgen.analysis.molecule_matcher import MoleculeMatcher from pymatgen.core import Molecule from pymatgen.io.packmol import PackmolBoxGen -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest TEST_DIR = f"{TEST_FILES_DIR}/io/packmol" # error message is different in CI for unknown reasons (as of 2024-04-12) @@ -91,7 +91,7 @@ def test_packmol_with_path(self): {"name": "LiTFSi", "number": 20, "coords": p2}, ], ) - # PymatgenTest makes each test change to a temporary directory + # MatSciTest makes each test change to a temporary directory # Check here we can run in the current directory pw.write_input(".") pw.run(".") @@ -99,7 +99,7 @@ def test_packmol_with_path(self): assert os.path.isfile(f"{self.tmp_path}/packmol.stdout") out = Molecule.from_file(f"{self.tmp_path}/packmol_out.xyz") assert out.composition.num_atoms == 10 * 15 + 20 * 16 - # PymatgenTest makes each test change to a temporary directory + # MatSciTest makes each test change to a temporary directory # Check here we can run in a relative directory pw.write_input("somedir") pw.run("somedir") diff --git a/tests/io/test_pwscf.py b/tests/io/test_pwscf.py index bf4db56552c..c082e9801c0 100644 --- a/tests/io/test_pwscf.py +++ b/tests/io/test_pwscf.py @@ -6,7 +6,7 @@ from pytest import approx from pymatgen.io.pwscf import PWInput, PWInputError, PWOutput -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest TEST_DIR = f"{TEST_FILES_DIR}/io/pwscf" diff --git a/tests/io/test_shengbte.py b/tests/io/test_shengbte.py index 641b82c86bc..56c9652f1a2 100644 --- a/tests/io/test_shengbte.py +++ b/tests/io/test_shengbte.py @@ -4,7 +4,7 @@ from numpy.testing import assert_array_equal from pymatgen.io.shengbte import Control -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest f90nml = pytest.importorskip("f90nml") TEST_DIR = f"{TEST_FILES_DIR}/io/shengbte" diff --git a/tests/io/test_template_input.py b/tests/io/test_template_input.py index 8dfef0d758d..5395c002151 100644 --- a/tests/io/test_template_input.py +++ b/tests/io/test_template_input.py @@ -5,7 +5,7 @@ import pytest from pymatgen.io.template import TemplateInputGen -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest TEST_DIR = f"{TEST_FILES_DIR}/io" diff --git a/tests/io/test_wannier90.py b/tests/io/test_wannier90.py index b6e9eec3a46..df084c6ee3f 100644 --- a/tests/io/test_wannier90.py +++ b/tests/io/test_wannier90.py @@ -8,7 +8,7 @@ from pytest import approx from pymatgen.io.wannier90 import Unk -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest TEST_DIR = f"{TEST_FILES_DIR}/io/wannier90" diff --git a/tests/io/vasp/test_inputs.py b/tests/io/vasp/test_inputs.py index 87dd14e1c83..a7459098a29 100644 --- a/tests/io/vasp/test_inputs.py +++ b/tests/io/vasp/test_inputs.py @@ -37,7 +37,7 @@ VaspInput, _gen_potcar_summary_stats, ) -from pymatgen.util.testing import FAKE_POTCAR_DIR, TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR, PymatgenTest +from pymatgen.util.testing import FAKE_POTCAR_DIR, TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR, MatSciTest # Filter some expected warnings warnings.filterwarnings( diff --git a/tests/io/vasp/test_optics.py b/tests/io/vasp/test_optics.py index db1db1e9fc2..8ce09028b40 100644 --- a/tests/io/vasp/test_optics.py +++ b/tests/io/vasp/test_optics.py @@ -7,7 +7,7 @@ from pymatgen.io.vasp.optics import DielectricFunctionCalculator, delta_func, delta_methfessel_paxton, step_func from pymatgen.io.vasp.outputs import Vasprun -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest __author__ = "Jimmy-Xuan Shen" __copyright__ = "Copyright 2022, The Materials Project" diff --git a/tests/io/vasp/test_outputs.py b/tests/io/vasp/test_outputs.py index d76cb004d21..a9bcf8d50bf 100644 --- a/tests/io/vasp/test_outputs.py +++ b/tests/io/vasp/test_outputs.py @@ -41,7 +41,7 @@ Xdatcar, ) from pymatgen.io.wannier90 import Unk -from pymatgen.util.testing import FAKE_POTCAR_DIR, TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR, PymatgenTest +from pymatgen.util.testing import FAKE_POTCAR_DIR, TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR, MatSciTest try: import h5py diff --git a/tests/io/xtb/test_inputs.py b/tests/io/xtb/test_inputs.py index 32f2f2c8030..9cba4039088 100644 --- a/tests/io/xtb/test_inputs.py +++ b/tests/io/xtb/test_inputs.py @@ -2,7 +2,7 @@ from pymatgen.core.structure import Molecule from pymatgen.io.xtb.inputs import CRESTInput -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest __author__ = "Alex Epstein" __copyright__ = "Copyright 2020, The Materials Project" diff --git a/tests/io/xtb/test_outputs.py b/tests/io/xtb/test_outputs.py index 2bd19d6c6a6..ddec65b5a69 100644 --- a/tests/io/xtb/test_outputs.py +++ b/tests/io/xtb/test_outputs.py @@ -7,7 +7,7 @@ from pymatgen.core.structure import Molecule from pymatgen.io.qchem.outputs import check_for_structure_changes from pymatgen.io.xtb.outputs import CRESTOutput -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest try: from openbabel import openbabel diff --git a/tests/phonon/test_bandstructure.py b/tests/phonon/test_bandstructure.py index 0bccefb6399..cd5454d171c 100644 --- a/tests/phonon/test_bandstructure.py +++ b/tests/phonon/test_bandstructure.py @@ -8,7 +8,7 @@ from pymatgen.electronic_structure.bandstructure import Kpoint from pymatgen.phonon.bandstructure import PhononBandStructureSymmLine -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest TEST_DIR = f"{TEST_FILES_DIR}/electronic_structure/bandstructure" diff --git a/tests/phonon/test_dos.py b/tests/phonon/test_dos.py index 16164585bf1..2ce211ddcbe 100644 --- a/tests/phonon/test_dos.py +++ b/tests/phonon/test_dos.py @@ -9,7 +9,7 @@ from pymatgen.core import Element from pymatgen.phonon.dos import CompletePhononDos, PhononDos -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest TEST_DIR = f"{TEST_FILES_DIR}/phonon/dos" diff --git a/tests/phonon/test_gruneisen.py b/tests/phonon/test_gruneisen.py index 12298435cd9..365d9fa229b 100644 --- a/tests/phonon/test_gruneisen.py +++ b/tests/phonon/test_gruneisen.py @@ -9,7 +9,7 @@ from pymatgen.io.phonopy import get_gruneisen_ph_bs_symm_line, get_gruneisenparameter from pymatgen.phonon.gruneisen import GruneisenParameter from pymatgen.phonon.plotter import GruneisenPhononBandStructureSymmLine, GruneisenPhononBSPlotter, GruneisenPlotter -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest try: import phonopy diff --git a/tests/phonon/test_ir_spectra.py b/tests/phonon/test_ir_spectra.py index b910b86f11e..f9374b96051 100644 --- a/tests/phonon/test_ir_spectra.py +++ b/tests/phonon/test_ir_spectra.py @@ -2,7 +2,7 @@ from monty.serialization import loadfn -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest class TestIRDielectricTensor(MatSciTest): diff --git a/tests/phonon/test_thermal_displacements.py b/tests/phonon/test_thermal_displacements.py index 40b49d1df17..ee339fd069a 100644 --- a/tests/phonon/test_thermal_displacements.py +++ b/tests/phonon/test_thermal_displacements.py @@ -6,7 +6,7 @@ from pymatgen.core.structure import Structure from pymatgen.phonon.thermal_displacements import ThermalDisplacementMatrices -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest TEST_DIR = f"{TEST_FILES_DIR}/phonon/thermal_displacement_matrices" diff --git a/tests/symmetry/test_kpath_lm.py b/tests/symmetry/test_kpath_lm.py index 2151cff606a..bb6299f9ffd 100644 --- a/tests/symmetry/test_kpath_lm.py +++ b/tests/symmetry/test_kpath_lm.py @@ -8,7 +8,7 @@ from pymatgen.core.structure import Structure from pymatgen.symmetry.analyzer import SpacegroupAnalyzer from pymatgen.symmetry.kpath import KPathLatimerMunro -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest class TestKPathLatimerMunro(MatSciTest): diff --git a/tests/symmetry/test_kpath_sc.py b/tests/symmetry/test_kpath_sc.py index ed465262f55..bede6afd292 100644 --- a/tests/symmetry/test_kpath_sc.py +++ b/tests/symmetry/test_kpath_sc.py @@ -6,7 +6,7 @@ from pymatgen.core.lattice import Lattice from pymatgen.core.structure import Structure from pymatgen.symmetry.kpath import KPathSetyawanCurtarolo -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest TEST_DIR = f"{TEST_FILES_DIR}/symmetry/space_group_structs" diff --git a/tests/symmetry/test_kpaths.py b/tests/symmetry/test_kpaths.py index 1d252a396a8..dc3f4c44c5a 100644 --- a/tests/symmetry/test_kpaths.py +++ b/tests/symmetry/test_kpaths.py @@ -7,7 +7,7 @@ from pymatgen.core.lattice import Lattice from pymatgen.core.structure import Structure from pymatgen.symmetry.bandstructure import HighSymmKpath -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest try: from seekpath import get_path diff --git a/tests/symmetry/test_site_symmetries.py b/tests/symmetry/test_site_symmetries.py index c2d4159cf0b..504f3a81dc6 100644 --- a/tests/symmetry/test_site_symmetries.py +++ b/tests/symmetry/test_site_symmetries.py @@ -6,7 +6,7 @@ from monty.json import MontyDecoder from pymatgen.symmetry import site_symmetries as ss -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest __author__ = "Handong Ling" __version__ = "0.1" diff --git a/tests/util/test_io.py b/tests/util/test_io.py index fcd250a0bff..7b05276169a 100644 --- a/tests/util/test_io.py +++ b/tests/util/test_io.py @@ -1,7 +1,7 @@ from __future__ import annotations from pymatgen.util.io_utils import micro_pyawk -from pymatgen.util.testing import VASP_OUT_DIR, PymatgenTest +from pymatgen.util.testing import VASP_OUT_DIR, MatSciTest class TestFunc(MatSciTest): diff --git a/tests/vis/test_plotters.py b/tests/vis/test_plotters.py index e2838de0d5f..06207f583a6 100644 --- a/tests/vis/test_plotters.py +++ b/tests/vis/test_plotters.py @@ -8,7 +8,7 @@ from monty.json import MontyDecoder from pymatgen.analysis.xas.spectrum import XAS -from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest +from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest from pymatgen.vis.plotters import SpectrumPlotter with open(f"{TEST_FILES_DIR}/analysis/spectrum_test/LiCoO2_k_xanes.json") as file: From 96ccce481c202555eb095df2cf1fdaad5a246624 Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Wed, 4 Dec 2024 23:58:51 +0800 Subject: [PATCH 21/31] fix tests --- tests/analysis/interfaces/test_coherent_interface.py | 4 +--- tests/analysis/test_phase_diagram.py | 5 ++--- tests/core/test_structure.py | 3 +-- tests/core/test_units.py | 1 - tests/io/pwmat/test_inputs.py | 4 ++-- tests/io/test_ase.py | 4 ++-- tests/io/test_lmto.py | 4 ++-- 7 files changed, 10 insertions(+), 15 deletions(-) diff --git a/tests/analysis/interfaces/test_coherent_interface.py b/tests/analysis/interfaces/test_coherent_interface.py index 7115f85f7f3..9f578f30c32 100644 --- a/tests/analysis/interfaces/test_coherent_interface.py +++ b/tests/analysis/interfaces/test_coherent_interface.py @@ -1,7 +1,5 @@ from __future__ import annotations -import unittest - from numpy.testing import assert_allclose from pymatgen.analysis.interfaces.coherent_interfaces import ( @@ -51,7 +49,7 @@ def test_coherent_interface_builder(self): assert len(list(builder.get_interfaces(termination=("O2_Pmmm_1", "Si_R-3m_1")))) >= 6 -class TestCoherentInterfaceBuilder(unittest.TestCase): +class TestCoherentInterfaceBuilder: def setup_method(self): # build substrate & film structure basis = [[0, 0, 0], [0.25, 0.25, 0.25]] diff --git a/tests/analysis/test_phase_diagram.py b/tests/analysis/test_phase_diagram.py index 825c077a64b..b118344d3ac 100644 --- a/tests/analysis/test_phase_diagram.py +++ b/tests/analysis/test_phase_diagram.py @@ -1,10 +1,9 @@ from __future__ import annotations import collections -import unittest -import unittest.mock from itertools import combinations from numbers import Number +from unittest.mock import patch import matplotlib.pyplot as plt import numpy as np @@ -1008,7 +1007,7 @@ def test_plotly_plots(self): # test show() # suppress default plotly behavior of opening figure in browser by patching plotly.io.show to noop - with unittest.mock.patch("plotly.io.show") as mock_show: + with patch("plotly.io.show") as mock_show: assert self.plotter_ternary_plotly_2d.show() is None mock_show.assert_called_once() diff --git a/tests/core/test_structure.py b/tests/core/test_structure.py index 24599a1c45b..e382c7c912e 100644 --- a/tests/core/test_structure.py +++ b/tests/core/test_structure.py @@ -5,7 +5,6 @@ from fractions import Fraction from pathlib import Path from shutil import which -from unittest import skipIf import numpy as np import pytest @@ -102,7 +101,7 @@ def setup_method(self): ) self.V2O3 = IStructure.from_file(f"{TEST_FILES_DIR}/cif/V2O3.cif") - @skipIf(not (mcsqs_cmd and enum_cmd), reason="enumlib or mcsqs executable not present") + @pytest.mark.skipif(not (mcsqs_cmd and enum_cmd), reason="enumlib or mcsqs executable not present") def test_get_orderings(self): ordered = Structure.from_spacegroup("Im-3m", Lattice.cubic(3), ["Fe"], [[0, 0, 0]]) assert ordered.get_orderings()[0] == ordered diff --git a/tests/core/test_units.py b/tests/core/test_units.py index c7d89c60436..83b583154b8 100644 --- a/tests/core/test_units.py +++ b/tests/core/test_units.py @@ -202,7 +202,6 @@ def test_energy(self): assert e_in_ha == approx(0.0404242579378) e_in_j = EnergyArray(3.14, "J") assert (e_in_j.to("eV")) == approx(1.9598338493806797e19) - # self.assertRaises(ValueError, Energy, 1, "m") e2_in_ha = EnergyArray(1, "Ha") assert (e_in_ev + e2_in_ha) == approx(28.311386245987997) diff --git a/tests/io/pwmat/test_inputs.py b/tests/io/pwmat/test_inputs.py index 927f3cefdfd..315ae936dcd 100644 --- a/tests/io/pwmat/test_inputs.py +++ b/tests/io/pwmat/test_inputs.py @@ -1,7 +1,7 @@ from __future__ import annotations import importlib -from unittest import mock +from unittest.mock import patch import pytest from monty.io import zopen @@ -136,7 +136,7 @@ def test_write_file(self): def test_err_msg_on_seekpath_not_installed(): """Simulate and test error message when seekpath is not installed.""" - with mock.patch.dict("sys.modules", {"seekpath": None}): + with patch.dict("sys.modules", {"seekpath": None}): # As the import error is raised during init of KPathSeek, # have to import it as well (order matters) importlib.reload(pymatgen.symmetry.kpath) diff --git a/tests/io/test_ase.py b/tests/io/test_ase.py index 4459b4ea5f0..d9a886a9a9d 100644 --- a/tests/io/test_ase.py +++ b/tests/io/test_ase.py @@ -2,7 +2,7 @@ import importlib from importlib.metadata import PackageNotFoundError -from unittest import mock +from unittest.mock import patch import numpy as np import pytest @@ -356,7 +356,7 @@ def test_msonable_atoms(): def test_no_ase_err(): import pymatgen.io.ase - with mock.patch.dict("sys.modules", {"ase.atoms": None}): + with patch.dict("sys.modules", {"ase.atoms": None}): importlib.reload(pymatgen.io.ase) from pymatgen.io.ase import MSONAtoms diff --git a/tests/io/test_lmto.py b/tests/io/test_lmto.py index f032c56b98b..486bcc3810e 100644 --- a/tests/io/test_lmto.py +++ b/tests/io/test_lmto.py @@ -26,7 +26,7 @@ class TestCtrl(MatSciTest): def setup_method(self): os.chdir(TEST_DIR) - self.ref_bise = LMTOCtrl.from_file(filename="CTRL.BiSe") + self.ref_bise = LMTOCtrl.from_file(filename=f"{TEST_DIR}/CTRL.BiSe") self.ref_fe = LMTOCtrl.from_file() def teardown_method(self): @@ -36,7 +36,7 @@ def test_dict(self): assert self.ref_bise == LMTOCtrl.from_dict(self.ref_bise.as_dict()) def test_structure(self): - bise_poscar = Structure.from_file("POSCAR.BiSe") + bise_poscar = Structure.from_file(f"{TEST_DIR}/POSCAR.BiSe") assert bise_poscar.matches(self.ref_bise.structure) assert self.ref_bise == LMTOCtrl(self.ref_bise.structure, header="Bi6Se6, hexagonal") From 631ef93be07cb88c24aa2ea2792960062282c8e4 Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Thu, 5 Dec 2024 00:08:43 +0800 Subject: [PATCH 22/31] fix internal index and add require for pytest style --- docs/contributing.md | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/docs/contributing.md b/docs/contributing.md index 3080cdb14d1..0bc32d675bf 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -13,13 +13,13 @@ the [`pymatgen` GitHub repo](https://github.com/materialsproject/pymatgen). Here 1. Create a free GitHub account (if you don't already have one) and perform the necessary setup (e.g., install SSH keys etc.). -1. Fork the `pymatgen` GitHub repo, i.e., go to the +2. Fork the `pymatgen` GitHub repo, i.e., go to the main [`pymatgen` GitHub repo](https://github.com/materialsproject/pymatgen) and click fork to create a copy of the `pymatgen` code base on your own GitHub account. -1. Install `git` on your local machine (if you don't already have it). +3. Install `git` on your local machine (if you don't already have it). -1. Clone *your forked repo* to your local machine. You will work mostly with your local repo and only publish changes +4. Clone *your forked repo* to your local machine. You will work mostly with your local repo and only publish changes when they are ready to be merged: ```sh @@ -30,33 +30,33 @@ the [`pymatgen` GitHub repo](https://github.com/materialsproject/pymatgen). Here Note that the entire Github repo is fairly large because of the presence of test files, but these are necessary for rigorous testing. -1. Install the [uv package manager](https://github.com/astral-sh/uv): +5. Install the [uv package manager](https://github.com/astral-sh/uv): ```sh pip install uv ``` -1. Create a virtual env for pymatgen. +6. Create a virtual env for pymatgen. ```sh uv create venv # A virtual env will be created in the .venv directory in the repo. source .venv/bin/activate ``` -1. Install pymatgen in editable mode with dev and optional dependencies: +7. Install pymatgen in editable mode with dev and optional dependencies: ```sh uv pip install -e '.[ci,optional]' pre-commit install # Install pre-commit hook for linters. ``` -1. Make a new branch for your contributions +8. Make a new branch for your contributions ```sh git checkout -b my-new-fix-or-feature # should be run from up-to-date master ``` -1. Code (see [Coding Guidelines](#coding-guidelines)). Commit early and commit often. Keep your code up to date. You +9. Code (see [Coding Guidelines](#coding-guidelines)). Commit early and commit often. Keep your code up to date. You need to add the main repository to the list of your remotes. ```sh @@ -79,24 +79,24 @@ the [`pymatgen` GitHub repo](https://github.com/materialsproject/pymatgen). Here Remember, pull is a combination of the commands fetch and merge, so there may be merge conflicts to be manually resolved. -1. Publish your contributions. Assuming that you now have a couple of commits that you would like to contribute to the +10. Publish your contributions. Assuming that you now have a couple of commits that you would like to contribute to the main repository. Please follow the following steps: 1. If your change is based on a relatively old state of the main repository, then you should probably bring your repository up-to-date first to see if the change is not creating any merge conflicts. - 1. Check that everything compiles cleanly and passes all tests. The `pymatgen` repo comes with a complete set of + 2. Check that everything compiles cleanly and passes all tests. The `pymatgen` repo comes with a complete set of tests for all modules. If you have written new modules or methods, you must write tests for the new code as well (see [Coding Guidelines](#coding-guidelines)). Install and run `pytest` in your local repo directory and fix all errors before continuing further. - 1. If everything is ok, publish the commits to your GitHub repository. + 3. If everything is ok, publish the commits to your GitHub repository. ```sh git push origin master ``` -1. Now that your commit is published, it doesn't mean that it has already been merged into the main repository. You +11. Now that your commit is published, it doesn't mean that it has already been merged into the main repository. You should issue a merge request to `pymatgen` maintainers. They will pull your commits and run their own tests before releasing. @@ -111,8 +111,8 @@ guidelines for all contributions to `pymatgen`. The following must be satisfied into `pymatgen`. 1. **Unit tests** are required for all new modules and methods. The only way to minimize code regression is to ensure - that all code is well tested. Untested contributions will not be accepted. -1. **Python PEP 8** [code style](https://python.org/dev/peps/pep-0008). We allow a few exceptions when they are + that all code is well tested. Untested contributions will not be accepted. Please use the modern [`pytest`](https://docs.pytest.org/en/stable/how-to/index.html) framework for tests and avoid the legacy `unittest` style. +2. **Python PEP 8** [code style](https://python.org/dev/peps/pep-0008). We allow a few exceptions when they are well-justified (e.g., Element's atomic number is given a variable name of capital Z, in line with accepted scientific convention), but generally, PEP 8 must be observed. Code style will be automatically checked for all PRs and must pass before any PR is merged. To aid you, you can install and run the same set of formatters and linters that will @@ -125,8 +125,8 @@ into `pymatgen`. pre-commit run --all-files # ensure your entire codebase passes linters ``` -1. **Python 3**. Check the `pyproject.toml` for the supported Python versions. -1. **Documentation** is required for all modules, classes and methods. In particular, the method doc strings should make +3. **Python 3**. Check the `pyproject.toml` for the supported Python versions. +4. **Documentation** is required for all modules, classes and methods. In particular, the method doc strings should make clear the arguments expected and the return values. For complex algorithms (e.g., an Ewald summation), a summary of the algorithm should be provided and preferably with a link to a publication outlining the method in detail. From 5c89fc0684c271bfb5c7b207bc8f353f2472adae Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Thu, 5 Dec 2024 00:30:47 +0800 Subject: [PATCH 23/31] fix test --- tests/core/test_operations.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/core/test_operations.py b/tests/core/test_operations.py index 286b9ce1ae9..370b8bc1d2f 100644 --- a/tests/core/test_operations.py +++ b/tests/core/test_operations.py @@ -1,6 +1,7 @@ from __future__ import annotations import numpy as np +import pytest from numpy.testing import assert_allclose from pymatgen.core.operations import MagSymmOp, SymmOp @@ -228,7 +229,8 @@ def test_xyz(self): assert op4 == op5 assert op3 == op5 - self.assertWarns(UserWarning, self.op.as_xyz_str) + with pytest.warns(UserWarning, match="Rotation matrix should be integer"): + self.op.as_xyz_str() symm_op = SymmOp.from_xyz_str("0.5+x, 0.25+y, 0.75+z") assert_allclose(symm_op.translation_vector, [0.5, 0.25, 0.75]) From e4ac465a5f4eb83035c3d7ab96c59e10c24b50dd Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Thu, 5 Dec 2024 00:45:20 +0800 Subject: [PATCH 24/31] remove seemingly unused conftest --- tests/conftest.py | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 tests/conftest.py diff --git a/tests/conftest.py b/tests/conftest.py deleted file mode 100644 index 6c83b348172..00000000000 --- a/tests/conftest.py +++ /dev/null @@ -1,7 +0,0 @@ -"""Test fixes for pymatgen.""" - -from __future__ import annotations - -from pathlib import Path - -TEST_DIR = Path(__file__).absolute().parent From 4292f38c3445db1c251040e301efd209c8c9723b Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Thu, 5 Dec 2024 10:21:34 +0800 Subject: [PATCH 25/31] add deprecated decorator and enhance docstring --- src/pymatgen/util/testing/__init__.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/pymatgen/util/testing/__init__.py b/src/pymatgen/util/testing/__init__.py index af6b0c61667..b4ae478e436 100644 --- a/src/pymatgen/util/testing/__init__.py +++ b/src/pymatgen/util/testing/__init__.py @@ -15,6 +15,7 @@ from unittest import TestCase import pytest +from monty.dev import deprecated from monty.json import MontyDecoder, MontyEncoder, MSONable from monty.serialization import loadfn @@ -36,13 +37,13 @@ class MatSciTest: - """TODO: name might need discussion. - - TODO: finish docstring - - TODO: reduce code duplicate - - TODO: add deprecation warning + """`pytest` based test framework extended to facilitate testing with + the following methods: + - tmp_path (attribute): Temporary directory. + - get_structure: Load a Structure from `util.structures` with its name. + - assert_str_content_equal: Check if two strings are equal (ignore whitespaces). + - serialize_with_pickle: Test whether object(s) can be (de)serialized with pickle. + - assert_msonable: Test if obj is MSONable and return its serialized string. """ # dict of lazily-loaded test structures (initialized to None) @@ -158,6 +159,7 @@ def assert_msonable(self, obj: MSONable, test_is_subclass: bool = True) -> str: return json_str +@deprecated(MatSciTest) class PymatgenTest(TestCase): """Extends unittest.TestCase with several assert methods for array and str comparison. From 027f84b31b6d4372749e703fafeebd6bb8ff5b4e Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Thu, 5 Dec 2024 10:28:03 +0800 Subject: [PATCH 26/31] inherit to reduce code duplicate --- src/pymatgen/util/testing/__init__.py | 113 +------------------------- 1 file changed, 2 insertions(+), 111 deletions(-) diff --git a/src/pymatgen/util/testing/__init__.py b/src/pymatgen/util/testing/__init__.py index b4ae478e436..ba894365f99 100644 --- a/src/pymatgen/util/testing/__init__.py +++ b/src/pymatgen/util/testing/__init__.py @@ -159,118 +159,9 @@ def assert_msonable(self, obj: MSONable, test_is_subclass: bool = True) -> str: return json_str -@deprecated(MatSciTest) -class PymatgenTest(TestCase): +@deprecated(MatSciTest, deadline=(2026, 1, 1)) +class PymatgenTest(TestCase, MatSciTest): """Extends unittest.TestCase with several assert methods for array and str comparison. Deprecated: please use `MatSciTest` instead (migrate from `unittest` to `pytest`). """ - - # dict of lazily-loaded test structures (initialized to None) - TEST_STRUCTURES: ClassVar[dict[str | Path, Structure | None]] = dict.fromkeys(STRUCTURES_DIR.glob("*")) - - @pytest.fixture(autouse=True) # make all tests run a in a temporary directory accessible via self.tmp_path - def _tmp_dir(self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None: - # https://pytest.org/en/latest/how-to/unittest.html#using-autouse-fixtures-and-accessing-other-fixtures - monkeypatch.chdir(tmp_path) # change to pytest-provided temporary directory - self.tmp_path = tmp_path - - @classmethod - def get_structure(cls, name: str) -> Structure: - """ - Lazily load a structure from pymatgen/util/structures. - - Args: - name (str): Name of structure file. - - Returns: - Structure - """ - return MatSciTest.get_structure(name) - - @staticmethod - def assert_str_content_equal(actual, expected): - """Test if two strings are equal, ignoring things like trailing spaces, etc.""" - MatSciTest.assert_str_content_equal(actual, expected) - - def serialize_with_pickle(self, objects: Any, protocols: Sequence[int] | None = None, test_eq: bool = True): - """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. - - Args: - 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. - """ - # Build a list even when we receive a single object. - got_single_object = False - if not isinstance(objects, list | tuple): - got_single_object = True - objects = [objects] - - protocols = protocols or [pickle.HIGHEST_PROTOCOL] - - # This list will contain the objects deserialized with the different protocols. - objects_by_protocol, errors = [], [] - - for protocol in protocols: - # Serialize and deserialize the object. - tmpfile = self.tmp_path / f"tempfile_{protocol}.pkl" - - try: - with open(tmpfile, "wb") as file: - pickle.dump(objects, file, protocol=protocol) - except Exception as exc: - errors.append(f"pickle.dump with {protocol=} raised:\n{exc}") - continue - - try: - with open(tmpfile, "rb") as file: - unpickled_objs = pickle.load(file) # noqa: S301 - except Exception as exc: - errors.append(f"pickle.load with {protocol=} raised:\n{exc}") - continue - - # Test for equality - if test_eq: - for orig, unpickled in zip(objects, unpickled_objs, strict=True): - if orig != unpickled: - raise ValueError( - f"Unpickled and original objects are unequal for {protocol=}\n{orig=}\n{unpickled=}" - ) - - # Save the deserialized objects and test for equality. - objects_by_protocol.append(unpickled_objs) - - if errors: - raise ValueError("\n".join(errors)) - - # Return nested list so that client code can perform additional tests. - if got_single_object: - return [o[0] for o in objects_by_protocol] - return objects_by_protocol - - def assert_msonable(self, obj: MSONable, test_is_subclass: bool = True) -> str: - """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. - """ - if test_is_subclass and not isinstance(obj, MSONable): - raise TypeError("obj is not MSONable") - if obj.as_dict() != type(obj).from_dict(obj.as_dict()).as_dict(): - raise ValueError("obj could not be reconstructed accurately from its dict representation.") - json_str = json.dumps(obj.as_dict(), cls=MontyEncoder) - round_trip = json.loads(json_str, cls=MontyDecoder) - if not issubclass(type(round_trip), type(obj)): - raise TypeError(f"{type(round_trip)} != {type(obj)}") - return json_str From 73328d01f53c590a511b3317c96bf39306749833 Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Thu, 5 Dec 2024 10:46:52 +0800 Subject: [PATCH 27/31] add some test for legacy tester --- tests/util/test_testing.py | 42 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 tests/util/test_testing.py diff --git a/tests/util/test_testing.py b/tests/util/test_testing.py new file mode 100644 index 00000000000..1acd7d8e41d --- /dev/null +++ b/tests/util/test_testing.py @@ -0,0 +1,42 @@ +"""Test testing utils.""" + +from __future__ import annotations + +from pathlib import Path + +from pymatgen.core import Element, Structure +from pymatgen.io.vasp.inputs import Kpoints +from pymatgen.util.testing import PymatgenTest + + +class TestPymatgenTest(PymatgenTest): + def test_tmp_dir(self): + current_dir = Path.cwd() + assert current_dir == self.tmp_path + + assert self.tmp_path.is_dir() + + test_file = self.tmp_path / "test_file.txt" + test_file.write_text("Hello, pytest!") + + assert test_file.exists() + assert test_file.read_text() == "Hello, pytest!" + + def test_get_structure(self): + assert isinstance(self.get_structure("LiFePO4"), Structure) + + def test_assert_str_content_equal(self): + # TODO: see PR 4205, assert_str_content_equal has a minor bug + # and would not raise AssertError but return a boolean only + assert self.assert_str_content_equal("hi", " hi") + assert not self.assert_str_content_equal("hi", "world") + + def test_serialize_with_pickle(self): + result = self.serialize_with_pickle(Element.from_Z(1)) + assert isinstance(result, list) + assert result[0] is Element.H + + def test_assert_msonable(self): + kpoints = Kpoints.gamma_automatic((3, 3, 3), [0, 0, 0]) + kp_str = self.assert_msonable(kpoints) + assert "Automatic kpoint scheme" in kp_str From ebd48ce810889d335585c301c8704785f27113c4 Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Thu, 5 Dec 2024 12:53:35 +0800 Subject: [PATCH 28/31] also check future warning --- tests/util/test_testing.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/util/test_testing.py b/tests/util/test_testing.py index 1acd7d8e41d..29d2ff2750f 100644 --- a/tests/util/test_testing.py +++ b/tests/util/test_testing.py @@ -2,14 +2,23 @@ from __future__ import annotations +import warnings from pathlib import Path +import pytest + from pymatgen.core import Element, Structure from pymatgen.io.vasp.inputs import Kpoints from pymatgen.util.testing import PymatgenTest +warnings.filterwarnings("ignore", message="PymatgenTest is deprecated", category=FutureWarning) + class TestPymatgenTest(PymatgenTest): + def test_deprecated_warning(self): + with pytest.warns(FutureWarning, match="PymatgenTest is deprecated"): + TestPymatgenTest() + def test_tmp_dir(self): current_dir = Path.cwd() assert current_dir == self.tmp_path From f6bda1ece055c76a8872ee83b9770321c9aa5bed Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Thu, 5 Dec 2024 12:57:07 +0800 Subject: [PATCH 29/31] remove unnecessary chdir --- tests/io/test_lmto.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/tests/io/test_lmto.py b/tests/io/test_lmto.py index 486bcc3810e..b38d31a3781 100644 --- a/tests/io/test_lmto.py +++ b/tests/io/test_lmto.py @@ -25,12 +25,8 @@ class TestCtrl(MatSciTest): def setup_method(self): - os.chdir(TEST_DIR) self.ref_bise = LMTOCtrl.from_file(filename=f"{TEST_DIR}/CTRL.BiSe") - self.ref_fe = LMTOCtrl.from_file() - - def teardown_method(self): - os.chdir(MODULE_DIR) + self.ref_fe = LMTOCtrl.from_file(filename=f"{TEST_DIR}/CTRL") def test_dict(self): assert self.ref_bise == LMTOCtrl.from_dict(self.ref_bise.as_dict()) @@ -49,13 +45,9 @@ def test_read_write(self): class TestCopl(MatSciTest): def setup_method(self): - os.chdir(TEST_DIR) - self.copl_bise = LMTOCopl("COPL.BiSe") - self.copl_bise_eV = LMTOCopl(filename="COPL.BiSe", to_eV=True) - self.copl_fe = LMTOCopl() - - def teardown_method(self): - os.chdir(MODULE_DIR) + self.copl_bise = LMTOCopl(f"{TEST_DIR}/COPL.BiSe") + self.copl_bise_eV = LMTOCopl(filename=f"{TEST_DIR}/COPL.BiSe", to_eV=True) + self.copl_fe = LMTOCopl(f"{TEST_DIR}/COPL") def test_attributes(self): assert not self.copl_bise.is_spin_polarized From 58dc537a62eb60f1d3b21ed49de753147318f473 Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Wed, 11 Dec 2024 23:21:35 +0800 Subject: [PATCH 30/31] prep for merge --- src/pymatgen/util/{testing/__init__.py => testing.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/pymatgen/util/{testing/__init__.py => testing.py} (100%) diff --git a/src/pymatgen/util/testing/__init__.py b/src/pymatgen/util/testing.py similarity index 100% rename from src/pymatgen/util/testing/__init__.py rename to src/pymatgen/util/testing.py From def9886a3d7e32aeb6b235e71f3948a66307dba1 Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Thu, 12 Dec 2024 13:38:37 +0800 Subject: [PATCH 31/31] fix bad merge behaviour --- src/pymatgen/util/testing.py | 121 +++++++++++++++++++---------------- 1 file changed, 67 insertions(+), 54 deletions(-) diff --git a/src/pymatgen/util/testing.py b/src/pymatgen/util/testing.py index 1a0f42dea9a..266490fbaf0 100644 --- a/src/pymatgen/util/testing.py +++ b/src/pymatgen/util/testing.py @@ -8,7 +8,7 @@ from __future__ import annotations import json -import pickle # use pickle, not cPickle so that we get the traceback in case of errors +import pickle # use pickle over cPickle to get traceback in case of errors import string from pathlib import Path from typing import TYPE_CHECKING @@ -19,12 +19,15 @@ from monty.json import MontyDecoder, MontyEncoder, MSONable from monty.serialization import loadfn -from pymatgen.core import ROOT, SETTINGS, Structure +from pymatgen.core import ROOT, SETTINGS if TYPE_CHECKING: from collections.abc import Sequence from typing import Any, ClassVar + from pymatgen.core import Structure + from pymatgen.util.typing import PathLike + _MODULE_DIR: Path = Path(__file__).absolute().parent STRUCTURES_DIR: Path = _MODULE_DIR / "structures" @@ -33,10 +36,10 @@ VASP_IN_DIR: str = f"{TEST_FILES_DIR}/io/vasp/inputs" VASP_OUT_DIR: str = f"{TEST_FILES_DIR}/io/vasp/outputs" -# fake POTCARs have original header information, meaning properties like number of electrons, +# Fake POTCARs have original header information, meaning properties like number of electrons, # nuclear charge, core radii, etc. are unchanged (important for testing) while values of the and # pseudopotential kinetic energy corrections are scrambled to avoid VASP copyright infringement -FAKE_POTCAR_DIR = f"{VASP_IN_DIR}/fake_potcars" +FAKE_POTCAR_DIR: str = f"{VASP_IN_DIR}/fake_potcars" class MatSciTest: @@ -50,36 +53,53 @@ class MatSciTest: """ # dict of lazily-loaded test structures (initialized to None) - TEST_STRUCTURES: ClassVar[dict[str | Path, Structure | None]] = dict.fromkeys(STRUCTURES_DIR.glob("*")) + TEST_STRUCTURES: ClassVar[dict[PathLike, Structure | None]] = dict.fromkeys(STRUCTURES_DIR.glob("*")) - @pytest.fixture(autouse=True) # make all tests run a in a temporary directory accessible via self.tmp_path + @pytest.fixture(autouse=True) def _tmp_dir(self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None: - # https://pytest.org/en/latest/how-to/unittest.html#using-autouse-fixtures-and-accessing-other-fixtures - monkeypatch.chdir(tmp_path) # change to pytest-provided temporary directory - self.tmp_path = tmp_path + """Make all tests run a in a temporary directory accessible via self.tmp_path. - @classmethod - def get_structure(cls, name: str) -> Structure: + References: + https://docs.pytest.org/en/stable/how-to/tmp_path.html """ - Load a structure from `pymatgen.util.structures`. + monkeypatch.chdir(tmp_path) # change to temporary directory + self.tmp_path = tmp_path + + @staticmethod + def assert_msonable(obj: Any, test_is_subclass: bool = True) -> str: + """Test if an object is MSONable and verify the contract is fulfilled, + and return the serialized object. + + By default, the method tests whether obj is an instance of MSONable. + This check can be deactivated by setting `test_is_subclass` to False. Args: - name (str): Name of the structure file, for example "LiFePO4". + obj (Any): The object to be checked. + test_is_subclass (bool): Check if object is an instance of MSONable + or its subclasses. Returns: - Structure + str: Serialized object. """ - try: - struct = cls.TEST_STRUCTURES.get(name) or loadfn(f"{STRUCTURES_DIR}/{name}.json") - except FileNotFoundError as exc: - raise FileNotFoundError(f"structure for {name} doesn't exist") from exc + obj_name = obj.__class__.__name__ - cls.TEST_STRUCTURES[name] = struct + # Check if is an instance of MONable (or its subclasses) + if test_is_subclass and not isinstance(obj, MSONable): + raise TypeError(f"{obj_name} object is not MSONable") - return struct.copy() + # Check if the object can be accurately reconstructed from its dict representation + if obj.as_dict() != type(obj).from_dict(obj.as_dict()).as_dict(): + raise ValueError(f"{obj_name} object could not be reconstructed accurately from its dict representation.") + + # Verify that the deserialized object's class is a subclass of the original object's class + json_str = json.dumps(obj.as_dict(), cls=MontyEncoder) + round_trip = json.loads(json_str, cls=MontyDecoder) + if not issubclass(type(round_trip), type(obj)): + raise TypeError(f"The reconstructed {round_trip.__class__.__name__} object is not a subclass of {obj_name}") + return json_str @staticmethod - def assert_str_content_equal(actual, expected): + def assert_str_content_equal(actual: str, expected: str) -> None: """Test if two strings are equal, ignoring whitespaces. Args: @@ -99,7 +119,32 @@ def assert_str_content_equal(actual, expected): f"{expected}\n" ) - def serialize_with_pickle(self, objects: Any, protocols: Sequence[int] | None = None, test_eq: bool = True): + @classmethod + def get_structure(cls, name: str) -> Structure: + """ + Load a structure from `pymatgen.util.structures`. + + Args: + name (str): Name of the structure file, for example "LiFePO4". + + Returns: + Structure + """ + try: + struct = cls.TEST_STRUCTURES.get(name) or loadfn(f"{STRUCTURES_DIR}/{name}.json") + except FileNotFoundError as exc: + raise FileNotFoundError(f"structure for {name} doesn't exist") from exc + + cls.TEST_STRUCTURES[name] = struct + + return struct.copy() + + def serialize_with_pickle( + self, + objects: Any, + protocols: Sequence[int] | None = None, + test_eq: bool = True, + ) -> list: """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 pickled format @@ -163,38 +208,6 @@ def serialize_with_pickle(self, objects: Any, protocols: Sequence[int] | None = return [o[0] for o in objects_by_protocol] return objects_by_protocol - def assert_msonable(self, obj: MSONable, test_is_subclass: bool = True) -> str: - """Test if an object is MSONable and verify the contract is fulfilled, - and return the serialized object. - - By default, the method tests whether obj is an instance of MSONable. - This check can be deactivated by setting `test_is_subclass` to False. - - Args: - obj (Any): The object to be checked. - test_is_subclass (bool): Check if object is an instance of MSONable - or its subclasses. - - Returns: - str: Serialized object. - """ - obj_name = obj.__class__.__name__ - - # Check if is an instance of MONable (or its subclasses) - if test_is_subclass and not isinstance(obj, MSONable): - raise TypeError(f"{obj_name} object is not MSONable") - - # Check if the object can be accurately reconstructed from its dict representation - if obj.as_dict() != type(obj).from_dict(obj.as_dict()).as_dict(): - raise ValueError(f"{obj_name} object could not be reconstructed accurately from its dict representation.") - - # Verify that the deserialized object's class is a subclass of the original object's class - json_str = json.dumps(obj.as_dict(), cls=MontyEncoder) - round_trip = json.loads(json_str, cls=MontyDecoder) - if not issubclass(type(round_trip), type(obj)): - raise TypeError(f"The reconstructed {round_trip.__class__.__name__} object is not a subclass of {obj_name}") - return json_str - @deprecated(MatSciTest, deadline=(2026, 1, 1)) class PymatgenTest(TestCase, MatSciTest):