Skip to content

Commit 012aacb

Browse files
committed
fix TestAdfInput.test_main TypeError: unsupported operand type(s) for /: 'str' and 'str'
tests/io/test_adf.py:259: TypeError s = readfile(test_dir / "adf" / "RhB18_adf.inp")
1 parent 90e95e2 commit 012aacb

File tree

10 files changed

+129
-158
lines changed

10 files changed

+129
-158
lines changed

pymatgen/analysis/energy_models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ def get_energy(self, structure: Structure):
126126
Returns:
127127
Energy value
128128
"""
129-
f = SpacegroupAnalyzer(structure, symprec=self.symprec, angle_tolerance=self.angle_tolerance)
130-
return -f.get_space_group_number()
129+
spg_analyzer = SpacegroupAnalyzer(structure, symprec=self.symprec, angle_tolerance=self.angle_tolerance)
130+
return -spg_analyzer.get_space_group_number()
131131

132132
def as_dict(self):
133133
"""MSONable dict"""

pymatgen/io/cif.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,13 +1344,13 @@ def __init__(
13441344
loops = []
13451345
spacegroup = ("P 1", 1)
13461346
if symprec is not None:
1347-
sf = SpacegroupAnalyzer(struct, symprec, angle_tolerance=angle_tolerance)
1348-
spacegroup = (sf.get_space_group_symbol(), sf.get_space_group_number())
1347+
spg_analyzer = SpacegroupAnalyzer(struct, symprec, angle_tolerance=angle_tolerance)
1348+
spacegroup = (spg_analyzer.get_space_group_symbol(), spg_analyzer.get_space_group_number())
13491349

13501350
if refine_struct:
13511351
# Needs the refined structure when using symprec. This converts
13521352
# primitive to conventional structures, the standard for CIF.
1353-
struct = sf.get_refined_structure()
1353+
struct = spg_analyzer.get_refined_structure()
13541354

13551355
lattice = struct.lattice
13561356
comp = struct.composition
@@ -1372,10 +1372,10 @@ def __init__(
13721372
block["_symmetry_equiv_pos_site_id"] = ["1"]
13731373
block["_symmetry_equiv_pos_as_xyz"] = ["x, y, z"]
13741374
else:
1375-
sf = SpacegroupAnalyzer(struct, symprec)
1375+
spg_analyzer = SpacegroupAnalyzer(struct, symprec)
13761376

13771377
symm_ops = []
1378-
for op in sf.get_symmetry_operations():
1378+
for op in spg_analyzer.get_symmetry_operations():
13791379
v = op.translation_vector
13801380
symm_ops.append(SymmOp.from_rotation_and_translation(op.rotation_matrix, v))
13811381

@@ -1443,7 +1443,7 @@ def __init__(
14431443
sorted(sites, key=lambda s: tuple(abs(x) for x in s.frac_coords))[0],
14441444
len(sites),
14451445
)
1446-
for sites in sf.get_symmetrized_structure().equivalent_sites
1446+
for sites in spg_analyzer.get_symmetrized_structure().equivalent_sites
14471447
]
14481448
for site, mult in sorted(
14491449
unique_sites,

tests/entries/test_mixing_scheme.py

Lines changed: 103 additions & 131 deletions
Large diffs are not rendered by default.

tests/files/.pytest-split-durations

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2008,7 +2008,7 @@
20082008
"tests/io/test_wannier90.py::TestUnk::test_write_file": 0.004102208011317998,
20092009
"tests/io/test_xcrysden.py::TestXSF::test_to_string": 0.001968374941498041,
20102010
"tests/io/test_xcrysden.py::TestXSF::test_xsf": 0.0019130410510115325,
2011-
"tests/io/test_xcrysden.py::TestXSF::test_xsf_symbolparse": 0.002098832046613097,
2011+
"tests/io/test_xcrysden.py::TestXSF::test_xsf_symbol_parse": 0.002098832046613097,
20122012
"tests/io/test_xr.py::TestXr::test_from_file": 0.029058041982352734,
20132013
"tests/io/test_xr.py::TestXr::test_str": 0.026537916099186987,
20142014
"tests/io/test_xyz.py::TestXYZ::test_as_dataframe": 0.0022536650067195296,

tests/io/test_adf.py

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

3-
import os
4-
53
from pytest import approx
64

75
from pymatgen.core.structure import Molecule
@@ -11,7 +9,7 @@
119
__author__ = "Xin Chen, [email protected]"
1210

1311

14-
test_dir = f"{TEST_FILES_DIR}/molecules"
12+
TEST_DIR = f"{TEST_FILES_DIR}/molecules"
1513

1614
geometry_string = """GEOMETRY
1715
smooth conservepoints
@@ -256,13 +254,13 @@ def test_main(self):
256254
task = AdfTask("optimize", **rhb18)
257255
inp = AdfInput(task)
258256
inp.write_file(mol, tmp_file)
259-
s = readfile(test_dir / "adf" / "RhB18_adf.inp")
260-
assert readfile(tmp_file) == s
257+
expected = readfile(f"{TEST_DIR}/adf/RhB18_adf.inp")
258+
assert readfile(tmp_file) == expected
261259

262260

263261
class TestAdfOutput:
264262
def test_analytical_freq(self):
265-
filename = os.path.join(str(test_dir), "adf", "analytical_freq", "adf.out")
263+
filename = f"{TEST_DIR}/adf/analytical_freq/adf.out"
266264
o = AdfOutput(filename)
267265
assert o.final_energy == approx(-0.54340325)
268266
assert len(o.energies) == 4
@@ -275,7 +273,7 @@ def test_analytical_freq(self):
275273
assert o.normal_modes[0][8] == approx(-0.562)
276274

277275
def test_numerical_freq(self):
278-
filename = os.path.join(str(test_dir), "adf", "numerical_freq", "adf.out")
276+
filename = f"{TEST_DIR}/adf/numerical_freq/adf.out"
279277
o = AdfOutput(filename)
280278
assert o.freq_type == "Numerical"
281279
assert len(o.final_structure) == 4
@@ -291,7 +289,7 @@ def test_numerical_freq(self):
291289
assert o.normal_modes[1][9] == approx(-0.536)
292290

293291
def test_single_point(self):
294-
filename = os.path.join(str(test_dir), "adf", "sp", "adf.out")
292+
filename = f"{TEST_DIR}/adf/sp/adf.out"
295293
o = AdfOutput(filename)
296294
assert o.final_energy == approx(-0.74399276)
297295
assert len(o.final_structure) == 4

tests/io/test_atat.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ def test_mcsqs_import(self):
6060
0.000000 -1.000000 -1.500000 O
6161
"""
6262

63-
s = Mcsqs.structure_from_str(test_string)
63+
mcsqs = Mcsqs.structure_from_str(test_string)
6464

65-
assert s.composition.formula == "Sr3 Ca5 Mn7 Fe1 O24"
66-
assert s.lattice.a == approx(2.2360679775)
67-
assert s.lattice.b == approx(2.2360679775)
68-
assert s.lattice.c == approx(1.73205080757)
65+
assert mcsqs.composition.formula == "Sr3 Ca5 Mn7 Fe1 O24"
66+
assert mcsqs.lattice.a == approx(2.2360679775)
67+
assert mcsqs.lattice.b == approx(2.2360679775)
68+
assert mcsqs.lattice.c == approx(1.73205080757)
6969

7070
def test_mcsqs_export(self):
7171
struct = self.get_structure("SrTiO3")

tests/io/test_xcrysden.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def test_to_string(self):
5656
3 1.00309136982516 0.73718000001594 1.58060372967982"""
5757
)
5858

59-
def test_xsf_symbolparse(self):
59+
def test_xsf_symbol_parse(self):
6060
"""
6161
Ensure that the same structure is parsed
6262
even if the atomic symbol / number convention

tests/io/vasp/test_inputs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1294,7 +1294,8 @@ def test_gen_potcar_summary_stats(tmp_path: Path, monkeypatch: MonkeyPatch) -> N
12941294

12951295
# only checking for two directories to save space, fake POTCAR library is big
12961296
summ_stats = loadfn(summ_stats_file)
1297-
assert set(summ_stats) == (expected_funcs := {"LDA_64", "PBE_54_W_HASH"})
1297+
expected_funcs = {"LDA_64", "PBE_54_W_HASH"}
1298+
assert set(summ_stats) == expected_funcs
12981299

12991300
# The fake POTCAR library is pretty big even with just two sub-libraries
13001301
# just copying over entries to work with PotcarSingle.is_valid

tests/symmetry/test_kpath_hin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def test_kpath_generation(self):
4747

4848
struct = Structure.from_spacegroup(sg_num, lattice, species, coords)
4949
kpath = KPathSeek(struct) # Throws error if something doesn't work, causing test to fail.
50-
kpoints = kpath.get_kpoints() # noqa: F841
50+
_ = kpath.get_kpoints()
5151

5252
@unittest.skipIf(get_path is None, "No seek path present.")
5353
def test_kpath_acentered(self):

tests/transformations/test_advanced_transformations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,8 @@ def test_apply_transformation(self):
310310
struct = Structure.from_file(f"{TEST_FILES_DIR}/POSCAR.LiFePO4")
311311
alls = trans.apply_transformation(struct, 10)
312312
assert len(alls) == 3
313-
f = SpacegroupAnalyzer(alls[0]["structure"], 0.1)
314-
assert f.get_space_group_number() == 31
313+
spg_analyzer = SpacegroupAnalyzer(alls[0]["structure"], 0.1)
314+
assert spg_analyzer.get_space_group_number() == 31
315315

316316
model = IsingModel(5, 5)
317317
trans = MagOrderingTransformation({"Fe": 5}, energy_model=model)

0 commit comments

Comments
 (0)