Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary unittest.TestCase subclassing #3718

Merged
merged 3 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion pymatgen/analysis/quasiharmonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from collections import defaultdict

import numpy as np
from monty.dev import deprecated
from scipy.constants import physical_constants
from scipy.integrate import quadrature
from scipy.misc import derivative
Expand Down Expand Up @@ -45,7 +46,7 @@
"temperature, and Grüneisen parameter using a quasiharmonic Debye model",
path="pymatgen.analysis.quasiharmonic",
)
class QuasiharmonicDebyeApprox:
class QuasiHarmonicDebyeApprox:
"""Quasi-harmonic approximation."""

def __init__(
Expand Down Expand Up @@ -356,3 +357,12 @@ def get_summary_dict(self):
dct["gruneisen_parameter"].append(self.gruneisen_parameter(t, v))
dct["thermal_conductivity"].append(self.thermal_conductivity(t, v))
return dct


@deprecated(
replacement=QuasiHarmonicDebyeApprox,
message="Use PascalCased QuasiHarmonicDebyeApprox instead. "
"Deprecated on 2024-03-27, to be removed on 2025-03-27.",
)
class QuasiharmonicDebyeApprox(QuasiHarmonicDebyeApprox):
pass
4 changes: 2 additions & 2 deletions pymatgen/util/testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
import json
import pickle # use pickle, not cPickle so that we get the traceback in case of errors
import string
import unittest
from pathlib import Path
from typing import TYPE_CHECKING, Any, ClassVar
from unittest import TestCase

import pytest
from monty.json import MontyDecoder, MSONable
Expand All @@ -34,7 +34,7 @@
FAKE_POTCAR_DIR = f"{VASP_IN_DIR}/fake_potcars"


class PymatgenTest(unittest.TestCase):
class PymatgenTest(TestCase):
"""Extends unittest.TestCase with several assert methods for array and str comparison."""

# dict of lazily-loaded test structures (initialized to None)
Expand Down
6 changes: 3 additions & 3 deletions tests/alchemy/test_filters.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import json
import unittest
from unittest import TestCase

from monty.json import MontyDecoder

Expand Down Expand Up @@ -70,7 +70,7 @@ def test_as_from_dict(self):
assert isinstance(SpecieProximityFilter.from_dict(dct), SpecieProximityFilter)


class TestRemoveDuplicatesFilter(unittest.TestCase):
class TestRemoveDuplicatesFilter(TestCase):
def setUp(self):
with open(f"{TEST_FILES_DIR}/TiO2_entries.json") as file:
entries = json.load(file, cls=MontyDecoder)
Expand All @@ -89,7 +89,7 @@ def test_as_from_dict(self):
assert isinstance(RemoveDuplicatesFilter().from_dict(dct), RemoveDuplicatesFilter)


class TestRemoveExistingFilter(unittest.TestCase):
class TestRemoveExistingFilter(TestCase):
def setUp(self):
with open(f"{TEST_FILES_DIR}/TiO2_entries.json") as file:
entries = json.load(file, cls=MontyDecoder)
Expand Down
4 changes: 1 addition & 3 deletions tests/analysis/chemenv/utils/test_func_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from __future__ import annotations

import unittest

import numpy as np
import pytest
from pytest import approx
Expand All @@ -15,7 +13,7 @@
__author__ = "waroquiers"


class TestFuncUtils(unittest.TestCase):
class TestFuncUtils:
def test_csm_finite_ratio_function(self):
max_csm = 8
alpha = 1
Expand Down
8 changes: 4 additions & 4 deletions tests/analysis/magnetism/test_analyzer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import unittest
from shutil import which
from unittest import TestCase

import pytest
from monty.serialization import loadfn
Expand All @@ -22,7 +22,7 @@
enumlib_present = enum_cmd and makestr_cmd


class TestCollinearMagneticStructureAnalyzer(unittest.TestCase):
class TestCollinearMagneticStructureAnalyzer(TestCase):
def setUp(self):
self.Fe = Structure.from_file(f"{TEST_FILES_DIR}/Fe.cif", primitive=True)

Expand Down Expand Up @@ -243,7 +243,7 @@ def test_missing_spin(self):
assert msa.structure.site_properties["magmom"] == [-5, 5, 0, 0]


class TestMagneticStructureEnumerator(unittest.TestCase):
class TestMagneticStructureEnumerator:
@pytest.mark.skipif(not enumlib_present, reason="enumlib not present")
def test_ordering_enumeration(self):
# simple afm
Expand Down Expand Up @@ -282,7 +282,7 @@ def test_ordering_enumeration(self):
assert enumerator.input_origin == "afm_by_motif_2a"


class TestMagneticDeformation(unittest.TestCase):
class TestMagneticDeformation:
def test_magnetic_deformation(self):
test_structs = loadfn(f"{TEST_FILES_DIR}/magnetic_deformation.json")
mag_def = magnetic_deformation(test_structs[0], test_structs[1])
Expand Down
7 changes: 2 additions & 5 deletions tests/analysis/magnetism/test_heisenberg.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

import unittest
from unittest import TestCase

import pandas as pd

Expand All @@ -11,7 +11,7 @@
TEST_DIR = f"{TEST_FILES_DIR}/magnetic_orderings"


class TestHeisenbergMapper(unittest.TestCase):
class TestHeisenbergMapper(TestCase):
@classmethod
def setUpClass(cls):
cls.df = pd.read_json(f"{TEST_DIR}/mag_orderings_test_cases.json")
Expand All @@ -31,9 +31,6 @@ def setUpClass(cls):
hm = HeisenbergMapper(ordered_structures, energies, cutoff=5.0, tol=0.02)
cls.hms.append(hm)

def setUp(self):
pass

def test_graphs(self):
for hm in self.hms:
struct_graphs = hm.sgraphs
Expand Down
4 changes: 2 additions & 2 deletions tests/analysis/magnetism/test_jahnteller.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

import unittest
from unittest import TestCase

import numpy as np
from pytest import approx
Expand All @@ -10,7 +10,7 @@
from pymatgen.util.testing import TEST_FILES_DIR


class TestJahnTeller(unittest.TestCase):
class TestJahnTeller(TestCase):
def setUp(self):
self.jt = JahnTellerAnalyzer()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

import unittest
from unittest import TestCase

from pytest import approx

Expand All @@ -12,7 +12,7 @@
from pymatgen.core import Species, Structure


class TestDopantPrediction(unittest.TestCase):
class TestDopantPrediction(TestCase):
def setUp(self):
self.tin_dioxide = Structure(
[3.24, 0, 0, 0, 4.83, 0, 0, 0, 4.84],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import json
import unittest
from unittest import TestCase

from pytest import approx

Expand All @@ -24,7 +24,7 @@ def get_table():
return json.load(file)


class TestSubstitutionProbability(unittest.TestCase):
class TestSubstitutionProbability(TestCase):
def test_full_lambda_table(self):
"""
This test tests specific values in the data folder. If the
Expand Down Expand Up @@ -56,7 +56,7 @@ def test_mini_lambda_table(self):
assert prob == approx(0.00102673915742, abs=1e-5), "probability isn't correct"


class TestSubstitutionPredictor(unittest.TestCase):
class TestSubstitutionPredictor(TestCase):
def test_prediction(self):
sp = SubstitutionPredictor(threshold=8e-3)
result = sp.list_prediction(["Na+", "Cl-"], to_this_composition=True)[5]
Expand Down
4 changes: 2 additions & 2 deletions tests/analysis/test_bond_dissociation.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import os
import unittest
from unittest import TestCase

import pytest
from monty.serialization import loadfn
Expand All @@ -11,7 +11,7 @@
module_dir = os.path.dirname(os.path.abspath(__file__))


class TestBondDissociation(unittest.TestCase):
class TestBondDissociation(TestCase):
def setUp(self):
pytest.importorskip("openbabel")
self.PC_65_principle = loadfn(f"{module_dir}/PC_65_principle.json")
Expand Down
6 changes: 3 additions & 3 deletions tests/analysis/test_cost.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from __future__ import annotations

import unittest
from unittest import TestCase

from pytest import approx

from pymatgen.analysis.cost import CostAnalyzer, CostDBCSV, CostDBElements
from pymatgen.util.testing import TEST_FILES_DIR


class TestCostAnalyzer(unittest.TestCase):
class TestCostAnalyzer(TestCase):
def setUp(self):
self.ca1 = CostAnalyzer(CostDBCSV(f"{TEST_FILES_DIR}/costdb_1.csv"))
self.ca2 = CostAnalyzer(CostDBCSV(f"{TEST_FILES_DIR}/costdb_2.csv"))
Expand All @@ -29,7 +29,7 @@ def test_sanity(self):
assert self.ca1.get_cost_per_kg("Ag") == self.ca2.get_cost_per_kg("Ag")


class TestCostDB(unittest.TestCase):
class TestCostDB(TestCase):
def test_sanity(self):
ca = CostAnalyzer(CostDBElements())
assert ca.get_cost_per_kg("PtO") > ca.get_cost_per_kg("MgO")
8 changes: 3 additions & 5 deletions tests/analysis/test_energy_models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from __future__ import annotations

import unittest

from pytest import approx

from pymatgen.analysis.energy_models import EwaldElectrostaticModel, IsingModel, SymmetryModel
Expand All @@ -11,7 +9,7 @@
from pymatgen.util.testing import TEST_FILES_DIR


class TestEwaldElectrostaticModel(unittest.TestCase):
class TestEwaldElectrostaticModel:
def test_get_energy(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]])
Expand Down Expand Up @@ -39,7 +37,7 @@ def test_as_from_dict(self):
assert isinstance(restored, EwaldElectrostaticModel)


class TestSymmetryModel(unittest.TestCase):
class TestSymmetryModel:
def test_get_energy(self):
model = SymmetryModel()
struct = Structure.from_file(f"{TEST_FILES_DIR}/Li2O.cif")
Expand All @@ -52,7 +50,7 @@ def test_as_from_dict(self):
assert restored.symprec == approx(0.2)


class TestIsingModel(unittest.TestCase):
class TestIsingModel:
def test_get_energy(self):
model = IsingModel(5, 6)

Expand Down
6 changes: 3 additions & 3 deletions tests/analysis/test_ewald.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

import unittest
from unittest import TestCase

import numpy as np
import pytest
Expand All @@ -11,7 +11,7 @@
from pymatgen.util.testing import VASP_IN_DIR


class TestEwaldSummation(unittest.TestCase):
class TestEwaldSummation(TestCase):
def setUp(self):
filepath = f"{VASP_IN_DIR}/POSCAR"
self.original_struct = Structure.from_file(filepath)
Expand Down Expand Up @@ -80,7 +80,7 @@ def test_as_dict(self):
assert ham.as_dict() == EwaldSummation.from_dict(dct).as_dict()


class TestEwaldMinimizer(unittest.TestCase):
class TestEwaldMinimizer(TestCase):
def test_init(self):
matrix = np.array(
[
Expand Down
4 changes: 2 additions & 2 deletions tests/analysis/test_functional_groups.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

import unittest
from unittest import TestCase

import pytest

Expand All @@ -24,7 +24,7 @@
__credit__ = "Peiyuan Yu"


class TestFunctionalGroupExtractor(unittest.TestCase):
class TestFunctionalGroupExtractor(TestCase):
def setUp(self):
self.file = f"{TEST_DIR}/func_group_test.mol"
self.mol = Molecule.from_file(self.file)
Expand Down
4 changes: 2 additions & 2 deletions tests/analysis/test_graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import copy
import os
import unittest
from glob import glob
from shutil import which
from unittest import TestCase

import networkx as nx
import networkx.algorithms.isomorphism as iso
Expand Down Expand Up @@ -487,7 +487,7 @@ def test_sort(self):
assert list(sg.graph.edges)[-2:] == [(1, 3, 0), (1, 2, 0)]


class TestMoleculeGraph(unittest.TestCase):
class TestMoleculeGraph(TestCase):
def setUp(self):
cyclohexene_xyz = f"{TEST_FILES_DIR}/graphs/cyclohexene.xyz"
cyclohexene = Molecule.from_file(cyclohexene_xyz)
Expand Down
4 changes: 1 addition & 3 deletions tests/analysis/test_hhi.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
from __future__ import annotations

import unittest

from pytest import approx

from pymatgen.analysis.hhi import HHIModel


class TestHHIModel(unittest.TestCase):
class TestHHIModel:
def test_hhi(self):
hhi = HHIModel()
assert hhi.get_hhi("He") == (3200, 3900)
Expand Down
4 changes: 2 additions & 2 deletions tests/analysis/test_interface_reactions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

import unittest
from unittest import TestCase

import numpy as np
import pytest
Expand All @@ -17,7 +17,7 @@
from pymatgen.entries.computed_entries import ComputedEntry


class TestInterfaceReaction(unittest.TestCase):
class TestInterfaceReaction(TestCase):
def setUp(self):
self.entries = [
ComputedEntry(Composition("Li"), 0),
Expand Down