Skip to content

Commit e9cc87a

Browse files
committed
remove unneeded unittest tearDown methods
1 parent 9a0eb81 commit e9cc87a

19 files changed

+85
-112
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Runs the complete test suite incl. many external command line dependencies (like Openbabel)
2-
# as well as the pymatgen.ext package. Coverage is computed based on this workflow.
2+
# as well as the pymatgen.ext package. Coverage used to be computed based on this workflow.
33
name: Tests
44

55
on:

pymatgen/analysis/interface_reactions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ def _get_reaction(self, x: float) -> Reaction:
304304

305305
reactants = self._get_reactants(x)
306306

307-
product = [Composition(k.name) for k, v in decomp.items()]
307+
product = [Composition(entry.name) for entry in decomp]
308308
reaction = Reaction(reactants, product)
309309

310310
x_original = self._get_original_composition_ratio(reaction)
@@ -695,7 +695,7 @@ def get_no_mixing_energy(self):
695695
def _get_reactants(self, x: float) -> list[Composition]:
696696
"""Returns a list of relevant reactant compositions given an x coordinate."""
697697
reactants = super()._get_reactants(x)
698-
reactants += [Composition(e.symbol) for e, v in self.pd.chempots.items()]
698+
reactants += [Composition(entry.symbol) for entry in self.pd.chempots]
699699

700700
return reactants
701701

pymatgen/analysis/phase_diagram.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,7 @@ def get_critical_compositions(self, comp1, comp2):
10951095
num_atoms = n1 + (n2 - n1) * x_unnormalized
10961096
cs *= num_atoms[:, None]
10971097

1098-
return [Composition((c, v) for c, v in zip(pd_els, m)) for m in cs]
1098+
return [Composition((elem, val) for elem, val in zip(pd_els, m)) for m in cs]
10991099

11001100
def get_element_profile(self, element, comp, comp_tol=1e-5):
11011101
"""

pymatgen/analysis/reaction_calculator.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -367,16 +367,16 @@ def as_dict(self):
367367
}
368368

369369
@classmethod
370-
def from_dict(cls, d):
370+
def from_dict(cls, dct):
371371
"""
372372
Args:
373-
d (dict): from as_dict().
373+
dct (dict): from as_dict().
374374
375375
Returns:
376-
A Reaction object.
376+
Reaction
377377
"""
378-
reactants = [Composition(sym_amt) for sym_amt in d["reactants"]]
379-
products = [Composition(sym_amt) for sym_amt in d["products"]]
378+
reactants = [*map(Composition, dct["reactants"])]
379+
products = [*map(Composition, dct["products"])]
380380
return cls(reactants, products)
381381

382382

pymatgen/io/abinit/abiobjects.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -605,16 +605,16 @@ def as_dict(self):
605605
return dct
606606

607607
@classmethod
608-
def from_dict(cls, d):
608+
def from_dict(cls, dct):
609609
"""Build object from dictionary."""
610-
d = d.copy()
611-
d.pop("@module", None)
612-
d.pop("@class", None)
610+
dct = dct.copy()
611+
dct.pop("@module", None)
612+
dct.pop("@class", None)
613613
dec = MontyDecoder()
614-
d["spin_mode"] = dec.process_decoded(d["spin_mode"])
615-
d["smearing"] = dec.process_decoded(d["smearing"])
616-
d["algorithm"] = dec.process_decoded(d["algorithm"]) if d["algorithm"] else None
617-
return cls(**d)
614+
dct["spin_mode"] = dec.process_decoded(dct["spin_mode"])
615+
dct["smearing"] = dec.process_decoded(dct["smearing"])
616+
dct["algorithm"] = dec.process_decoded(dct["algorithm"]) if dct["algorithm"] else None
617+
return cls(**dct)
618618

619619
def to_abivars(self):
620620
"""Return dictionary with Abinit variables."""

tests/analysis/test_interface_reactions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def test_get_reaction(self):
217217

218218
def test_get_get_elmt_amt_in_rxt(self):
219219
rxt1 = Reaction(
220-
[Composition("Mn"), Composition("O2"), Composition("Li")],
220+
[*map(Composition, ["Mn", "O2", "Li"])],
221221
[Composition("LiMnO2")],
222222
)
223223
test1 = np.isclose(self.irs[2]._get_elem_amt_in_rxn(rxt1), 3)

tests/analysis/test_local_env.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,6 @@ def test_filtered(self):
242242
all_nns = nn.get_all_nn_info(bcc * [2, 2, 2])
243243
assert [len(x) for x in all_nns] == [8] * 16
244244

245-
def tearDown(self):
246-
del self.struct
247-
del self.nn
248-
249245

250246
class TestJmolNN(PymatgenTest):
251247
def setUp(self):
@@ -562,12 +558,6 @@ def test_get_neighbors_of_site_with_index(self):
562558
assert len(get_neighbors_of_site_with_index(self.diamond, 0, approach="min_OKeeffe")) == 4
563559
assert len(get_neighbors_of_site_with_index(self.diamond, 0, approach="min_VIRE")) == 4
564560

565-
def tearDown(self):
566-
del self.silicon
567-
del self.diamond
568-
del self.nacl
569-
del self.cscl
570-
571561

572562
class TestNearNeighbor(PymatgenTest):
573563
def setUp(self):

tests/analysis/test_phase_diagram.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ def test_as_from_dict(self):
8080

8181
assert entry.name == "mp-757614"
8282
assert entry.energy_per_atom == 53.0 / 4
83-
gpentry = GrandPotPDEntry.from_dict(gpd)
84-
assert gpentry.name == "mp-757614"
85-
assert gpentry.energy_per_atom == 50.0 / 2
83+
gp_entry = GrandPotPDEntry.from_dict(gpd)
84+
assert gp_entry.name == "mp-757614"
85+
assert gp_entry.energy_per_atom == 50.0 / 2
8686

8787
d_anon = d.copy()
8888
del d_anon["name"]
@@ -109,12 +109,11 @@ def setUp(self):
109109
comp = Composition("LiFeO2")
110110
entry = PDEntry(comp, 53)
111111

112-
terminal_compositions = ["Li2O", "FeO", "LiO8"]
113-
terminal_compositions = [Composition(c) for c in terminal_compositions]
112+
terminal_compositions = [*map(Composition, ("Li2O", "FeO", "LiO8"))]
114113

115114
sp_mapping = {}
116115
for idx, comp in enumerate(terminal_compositions):
117-
sp_mapping[comp] = DummySpecies("X" + chr(102 + idx))
116+
sp_mapping[comp] = DummySpecies(f"X{chr(102 + idx)}")
118117

119118
self.transformed_entry = TransformedPDEntry(entry, sp_mapping)
120119

tests/analysis/test_structure_matcher.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,9 @@ def test_as_dict_and_from_dict(self):
342342
scale=False,
343343
comparator=FrameworkComparator(),
344344
)
345-
d = sm.as_dict()
346-
sm2 = StructureMatcher.from_dict(d)
347-
assert sm2.as_dict() == d
345+
dct = sm.as_dict()
346+
sm2 = StructureMatcher.from_dict(dct)
347+
assert sm2.as_dict() == dct
348348

349349
def test_no_scaling(self):
350350
sm = StructureMatcher(ltol=0.1, stol=0.1, angle_tol=2, scale=False, comparator=ElementComparator())

tests/apps/battery/test_conversion_battery.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,14 @@ def test_init(self):
100100

101101
# try to export/import a voltage pair via a dict
102102
pair = c.voltage_pairs[0]
103-
d = pair.as_dict()
104-
pair2 = ConversionVoltagePair.from_dict(d)
103+
dct = pair.as_dict()
104+
pair2 = ConversionVoltagePair.from_dict(dct)
105105
for prop in ["voltage", "mass_charge", "mass_discharge"]:
106106
assert getattr(pair, prop) == getattr(pair2, prop), 2
107107

108108
# try to create an electrode from a dict and test methods
109-
d = c.as_dict()
110-
electrode = ConversionElectrode.from_dict(d)
109+
dct = c.as_dict()
110+
electrode = ConversionElectrode.from_dict(dct)
111111
for k, v in p.items():
112112
assert getattr(electrode, "get_" + k)() == approx(v, abs=1e-2)
113113

@@ -121,14 +121,14 @@ def test_repr(self):
121121
)
122122

123123
def test_summary(self):
124-
kmap = {"specific_energy": "energy_grav", "energy_density": "energy_vol"}
124+
key_map = {"specific_energy": "energy_grav", "energy_density": "energy_vol"}
125125
for f in self.formulas:
126126
c = self.conversion_electrodes[f]["CE"]
127-
d = c.get_summary_dict()
127+
dct = c.get_summary_dict()
128128
p = self.expected_properties[f]
129129
for k, v in p.items():
130-
summary_key = kmap.get(k, k)
131-
assert d[summary_key] == approx(v, abs=1e-2)
130+
summary_key = key_map.get(k, k)
131+
assert dct[summary_key] == approx(v, abs=1e-2)
132132

133133
def test_composite(self):
134134
# check entries in charged/discharged state

0 commit comments

Comments
 (0)