Skip to content

Commit 2500664

Browse files
authored
Remove unnecessary unittest.TestCase subclassing (#3718)
* rename QuasiHarmonicDebyeApprox and deprecate old class * remove unnecessary subclassing of unittest.TestCase
1 parent 0f3a938 commit 2500664

File tree

80 files changed

+283
-305
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+283
-305
lines changed

pymatgen/analysis/quasiharmonic.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from collections import defaultdict
1515

1616
import numpy as np
17+
from monty.dev import deprecated
1718
from scipy.constants import physical_constants
1819
from scipy.integrate import quadrature
1920
from scipy.misc import derivative
@@ -45,7 +46,7 @@
4546
"temperature, and Grüneisen parameter using a quasiharmonic Debye model",
4647
path="pymatgen.analysis.quasiharmonic",
4748
)
48-
class QuasiharmonicDebyeApprox:
49+
class QuasiHarmonicDebyeApprox:
4950
"""Quasi-harmonic approximation."""
5051

5152
def __init__(
@@ -356,3 +357,12 @@ def get_summary_dict(self):
356357
dct["gruneisen_parameter"].append(self.gruneisen_parameter(t, v))
357358
dct["thermal_conductivity"].append(self.thermal_conductivity(t, v))
358359
return dct
360+
361+
362+
@deprecated(
363+
replacement=QuasiHarmonicDebyeApprox,
364+
message="Use PascalCased QuasiHarmonicDebyeApprox instead. "
365+
"Deprecated on 2024-03-27, to be removed on 2025-03-27.",
366+
)
367+
class QuasiharmonicDebyeApprox(QuasiHarmonicDebyeApprox):
368+
pass

pymatgen/util/testing/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
import json
1111
import pickle # use pickle, not cPickle so that we get the traceback in case of errors
1212
import string
13-
import unittest
1413
from pathlib import Path
1514
from typing import TYPE_CHECKING, Any, ClassVar
15+
from unittest import TestCase
1616

1717
import pytest
1818
from monty.json import MontyDecoder, MSONable
@@ -34,7 +34,7 @@
3434
FAKE_POTCAR_DIR = f"{VASP_IN_DIR}/fake_potcars"
3535

3636

37-
class PymatgenTest(unittest.TestCase):
37+
class PymatgenTest(TestCase):
3838
"""Extends unittest.TestCase with several assert methods for array and str comparison."""
3939

4040
# dict of lazily-loaded test structures (initialized to None)

tests/alchemy/test_filters.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
import json
4-
import unittest
4+
from unittest import TestCase
55

66
from monty.json import MontyDecoder
77

@@ -70,7 +70,7 @@ def test_as_from_dict(self):
7070
assert isinstance(SpecieProximityFilter.from_dict(dct), SpecieProximityFilter)
7171

7272

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

9191

92-
class TestRemoveExistingFilter(unittest.TestCase):
92+
class TestRemoveExistingFilter(TestCase):
9393
def setUp(self):
9494
with open(f"{TEST_FILES_DIR}/TiO2_entries.json") as file:
9595
entries = json.load(file, cls=MontyDecoder)

tests/analysis/chemenv/utils/test_func_utils.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from __future__ import annotations
22

3-
import unittest
4-
53
import numpy as np
64
import pytest
75
from pytest import approx
@@ -15,7 +13,7 @@
1513
__author__ = "waroquiers"
1614

1715

18-
class TestFuncUtils(unittest.TestCase):
16+
class TestFuncUtils:
1917
def test_csm_finite_ratio_function(self):
2018
max_csm = 8
2119
alpha = 1

tests/analysis/magnetism/test_analyzer.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

3-
import unittest
43
from shutil import which
4+
from unittest import TestCase
55

66
import pytest
77
from monty.serialization import loadfn
@@ -22,7 +22,7 @@
2222
enumlib_present = enum_cmd and makestr_cmd
2323

2424

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

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

245245

246-
class TestMagneticStructureEnumerator(unittest.TestCase):
246+
class TestMagneticStructureEnumerator:
247247
@pytest.mark.skipif(not enumlib_present, reason="enumlib not present")
248248
def test_ordering_enumeration(self):
249249
# simple afm
@@ -282,7 +282,7 @@ def test_ordering_enumeration(self):
282282
assert enumerator.input_origin == "afm_by_motif_2a"
283283

284284

285-
class TestMagneticDeformation(unittest.TestCase):
285+
class TestMagneticDeformation:
286286
def test_magnetic_deformation(self):
287287
test_structs = loadfn(f"{TEST_FILES_DIR}/magnetic_deformation.json")
288288
mag_def = magnetic_deformation(test_structs[0], test_structs[1])

tests/analysis/magnetism/test_heisenberg.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
import unittest
3+
from unittest import TestCase
44

55
import pandas as pd
66

@@ -11,7 +11,7 @@
1111
TEST_DIR = f"{TEST_FILES_DIR}/magnetic_orderings"
1212

1313

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

34-
def setUp(self):
35-
pass
36-
3734
def test_graphs(self):
3835
for hm in self.hms:
3936
struct_graphs = hm.sgraphs

tests/analysis/magnetism/test_jahnteller.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
import unittest
3+
from unittest import TestCase
44

55
import numpy as np
66
from pytest import approx
@@ -10,7 +10,7 @@
1010
from pymatgen.util.testing import TEST_FILES_DIR
1111

1212

13-
class TestJahnTeller(unittest.TestCase):
13+
class TestJahnTeller(TestCase):
1414
def setUp(self):
1515
self.jt = JahnTellerAnalyzer()
1616

tests/analysis/structure_prediction/test_dopant_predictor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
import unittest
3+
from unittest import TestCase
44

55
from pytest import approx
66

@@ -12,7 +12,7 @@
1212
from pymatgen.core import Species, Structure
1313

1414

15-
class TestDopantPrediction(unittest.TestCase):
15+
class TestDopantPrediction(TestCase):
1616
def setUp(self):
1717
self.tin_dioxide = Structure(
1818
[3.24, 0, 0, 0, 4.83, 0, 0, 0, 4.84],

tests/analysis/structure_prediction/test_substitution_probability.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
import json
4-
import unittest
4+
from unittest import TestCase
55

66
from pytest import approx
77

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

2626

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

5858

59-
class TestSubstitutionPredictor(unittest.TestCase):
59+
class TestSubstitutionPredictor(TestCase):
6060
def test_prediction(self):
6161
sp = SubstitutionPredictor(threshold=8e-3)
6262
result = sp.list_prediction(["Na+", "Cl-"], to_this_composition=True)[5]

tests/analysis/test_bond_dissociation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
import os
4-
import unittest
4+
from unittest import TestCase
55

66
import pytest
77
from monty.serialization import loadfn
@@ -11,7 +11,7 @@
1111
module_dir = os.path.dirname(os.path.abspath(__file__))
1212

1313

14-
class TestBondDissociation(unittest.TestCase):
14+
class TestBondDissociation(TestCase):
1515
def setUp(self):
1616
pytest.importorskip("openbabel")
1717
self.PC_65_principle = loadfn(f"{module_dir}/PC_65_principle.json")

0 commit comments

Comments
 (0)