Skip to content

Commit

Permalink
migrate alchemy and command_line
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielYang59 committed Dec 4, 2024
1 parent 344a872 commit 3ffea5d
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 29 deletions.
8 changes: 4 additions & 4 deletions tests/alchemy/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, PymatgenTest


class TestContainsSpecieFilter:
Expand Down Expand Up @@ -52,7 +52,7 @@ def test_as_from_dict(self):
assert isinstance(ContainsSpecieFilter.from_dict(dct), ContainsSpecieFilter)


class TestSpecieProximityFilter:
class TestSpecieProximityFilter(PymatgenTest):
def test_filter(self):
struct = self.get_structure("Li10GeP2S12")
sf = SpecieProximityFilter({"Li": 1})
Expand All @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion tests/alchemy/test_materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@


class TestTransformedStructure:
def setUp(self):
def setup_method(self):
structure = PymatgenTest.get_structure("LiFePO4")
self.structure = structure
trafos = [SubstitutionTransformation({"Li": "Na"})]
Expand Down
8 changes: 2 additions & 6 deletions tests/command_line/test_bader_caller.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

import warnings
from shutil import which

import numpy as np
Expand All @@ -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, PymatgenTest

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(PymatgenTest):
def test_init(self):
# test with reference file
analysis = BaderAnalysis(
Expand Down
5 changes: 2 additions & 3 deletions tests/command_line/test_critic2_caller.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

from shutil import which
from unittest import TestCase

import pytest
from pytest import approx
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions tests/command_line/test_enumlib_caller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, 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:
class TestEnumlibAdaptor(PymatgenTest):
def test_init(self):
struct = self.get_structure("LiFePO4")
sub_trans = SubstitutionTransformation({"Li": {"Li": 0.5}})
Expand Down
17 changes: 8 additions & 9 deletions tests/command_line/test_gulp_caller.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import os
import sys
from shutil import which
from unittest import TestCase

import numpy as np
import pytest
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions tests/command_line/test_mcsqs_caller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, PymatgenTest

__author__ = "Handong Ling, Rachel Woods-Robinson"
__maintainer__ = "Handong Ling, Rachel Woods-Robinson"
Expand All @@ -18,7 +18,7 @@


@pytest.mark.skipif(not (which("mcsqs") and which("str2cif")), reason="mcsqs executable not present")
class TestMcsqsCaller:
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")
Expand Down Expand Up @@ -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)
2 changes: 1 addition & 1 deletion tests/command_line/test_vampire_caller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 3ffea5d

Please sign in to comment.