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

Don't let tests pollute the pymatgen repo #3255

Merged
merged 11 commits into from
Aug 19, 2023
14 changes: 0 additions & 14 deletions tests/alchemy/test_transmuters.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from __future__ import annotations

import warnings

from pymatgen.alchemy.filters import ContainsSpecieFilter
from pymatgen.alchemy.transmuters import CifTransmuter, PoscarTransmuter
from pymatgen.transformations.advanced_transformations import SuperTransformation
Expand All @@ -14,12 +12,6 @@


class TestCifTransmuter(PymatgenTest):
def setUp(self):
warnings.simplefilter("ignore")

def tearDown(self):
warnings.simplefilter("default")

def test_init(self):
trans = []
trans.append(SubstitutionTransformation({"Fe": "Mn", "Fe2+": "Mn2+"}))
Expand Down Expand Up @@ -77,9 +69,3 @@ def test_transmuter(self):
assert tsc.transformed_structures[0].as_dict()["other_parameters"]["para1"] == "hello"
tsc.add_tags(["world", "universe"])
assert tsc.transformed_structures[0].as_dict()["other_parameters"]["tags"] == ["world", "universe"]


if __name__ == "__main__":
import unittest

unittest.main()
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import copy
import json
import os

import networkx as nx
import numpy as np
Expand Down Expand Up @@ -847,12 +846,7 @@ def test_real_systems(self):
assert ccs_periodicities == {"0D", "2D"}

def test_coordination_sequences(self):
BaTiO3_se_fpath = os.path.join(
TEST_FILES_DIR,
"chemenv",
"structure_environments_files",
"se_mp-5020.json",
)
BaTiO3_se_fpath = f"{TEST_FILES_DIR}/chemenv/structure_environments/se_mp-5020.json"
with open(BaTiO3_se_fpath) as file:
dct = json.load(file)
struct_envs = StructureEnvironments.from_dict(dct)
Expand Down
16 changes: 1 addition & 15 deletions tests/analysis/chemenv/connectivity/test_environment_nodes.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from __future__ import annotations

import os

from pymatgen.analysis.chemenv.connectivity.environment_nodes import EnvironmentNode
from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest
from pymatgen.util.testing import PymatgenTest

try:
import bson
Expand All @@ -12,12 +10,6 @@

__author__ = "waroquiers"

json_files_dir = os.path.join(
TEST_FILES_DIR,
"chemenv",
"json_test_files",
)


class TestEnvironmentNodes(PymatgenTest):
def test_equal(self):
Expand Down Expand Up @@ -56,9 +48,3 @@ def test_str(self):
struct = self.get_structure("SiO2")
en = EnvironmentNode(central_site=struct[2], i_central_site=2, ce_symbol="T:4")
assert str(en) == "Node #2 Si (T:4)"


if __name__ == "__main__":
import unittest

unittest.main()
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

import json
import os

from pymatgen.analysis.chemenv.connectivity.connectivity_finder import ConnectivityFinder
from pymatgen.analysis.chemenv.connectivity.structure_connectivity import StructureConnectivity
Expand All @@ -22,12 +21,7 @@

class TestStructureConnectivity(PymatgenTest):
def test_serialization(self):
BaTiO3_se_fpath = os.path.join(
TEST_FILES_DIR,
"chemenv",
"structure_environments_files",
"se_mp-5020.json",
)
BaTiO3_se_fpath = f"{TEST_FILES_DIR}/chemenv/structure_environments/se_mp-5020.json"
with open(BaTiO3_se_fpath) as file:
dd = json.load(file)
struct_envs = StructureEnvironments.from_dict(dd)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from __future__ import annotations

import os

import numpy as np
import pytest
from numpy.testing import assert_allclose
Expand All @@ -18,11 +16,7 @@

__author__ = "waroquiers"

json_files_dir = os.path.join(
TEST_FILES_DIR,
"chemenv",
"json_test_files",
)
json_dir = f"{TEST_FILES_DIR}/chemenv/json"


class TestCoordinationGeometryFinder(PymatgenTest):
Expand Down Expand Up @@ -125,13 +119,13 @@ def test_abstract_geometry(self):

# def _strategy_test(self, strategy):
# files = []
# for _dirpath, _dirnames, filenames in os.walk(json_files_dir):
# for _dirpath, _dirnames, filenames in os.walk(json_dir):
# files.extend(filenames)
# break

# for _ifile, json_file in enumerate(files):
# with self.subTest(json_file=json_file):
# with open(f"{json_files_dir}/{json_file}") as f:
# with open(f"{json_dir}/{json_file}") as f:
# dd = json.load(f)

# atom_indices = dd["atom_indices"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import json
import os
import shutil
import unittest

from numpy.testing import assert_allclose, assert_array_almost_equal
Expand All @@ -29,8 +28,8 @@

__author__ = "waroquiers"

json_files_dir = f"{TEST_FILES_DIR}/chemenv/json_test_files"
se_files_dir = f"{TEST_FILES_DIR}/chemenv/structure_environments_files"
json_dir = f"{TEST_FILES_DIR}/chemenv/json"
struct_env_dir = f"{TEST_FILES_DIR}/chemenv/structure_environments"


class TestReadWriteChemenv(unittest.TestCase):
Expand All @@ -41,7 +40,7 @@ def setUpClass(cls):
os.makedirs("tmp_dir", exist_ok=True)

def test_read_write_structure_environments(self):
with open(f"{json_files_dir}/test_T--4_FePO4_icsd_4266.json") as file:
with open(f"{json_dir}/test_T--4_FePO4_icsd_4266.json") as file:
dd = json.load(file)

atom_indices = dd["atom_indices"]
Expand Down Expand Up @@ -76,7 +75,7 @@ def test_read_write_structure_environments(self):
# assert lse == lse2

def test_structure_environments_neighbors_sets(self):
with open(f"{se_files_dir}/se_mp-7000.json") as f:
with open(f"{struct_env_dir}/se_mp-7000.json") as f:
dd = json.load(f)

struct_envs = StructureEnvironments.from_dict(dd)
Expand Down Expand Up @@ -221,26 +220,21 @@ def test_strategies(self):
assert multi_weights_strategy_2 != multi_weights_strategy_3

def test_read_write_voronoi(self):
with open(f"{json_files_dir}/test_T--4_FePO4_icsd_4266.json") as f:
dd = json.load(f)
with open(f"{json_dir}/test_T--4_FePO4_icsd_4266.json") as file:
dd = json.load(file)

struct = Structure.from_dict(dd["structure"])

valences = [site.specie.oxi_state for site in struct]

detailed_voronoi_container = DetailedVoronoiContainer(structure=struct, valences=valences)

with open("tmp_dir/se.json", "w") as f:
json.dump(detailed_voronoi_container.as_dict(), f)
with open("tmp_dir/se.json", "w") as file:
json.dump(detailed_voronoi_container.as_dict(), file)

with open("tmp_dir/se.json") as f:
dd = json.load(f)
with open("tmp_dir/se.json") as file:
dd = json.load(file)

detailed_voronoi_container2 = DetailedVoronoiContainer.from_dict(dd)

assert detailed_voronoi_container == detailed_voronoi_container2

@classmethod
def tearDownClass(cls):
# Remove the directory in which the temporary files have been created
shutil.rmtree("tmp_dir")
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@

__author__ = "waroquiers"

struct_env_files_dir = f"{TEST_FILES_DIR}/chemenv/structure_environments_files"
struct_env_dir = f"{TEST_FILES_DIR}/chemenv/structure_environments"


class TestStructureEnvironments(PymatgenTest):
def test_structure_environments(self):
with open(f"{struct_env_files_dir}/se_mp-7000.json") as f:
with open(f"{struct_env_dir}/se_mp-7000.json") as f:
dd = json.load(f)

struct_envs = StructureEnvironments.from_dict(dd)
Expand Down Expand Up @@ -118,7 +118,7 @@ def test_structure_environments(self):
assert ce != ce2

def test_light_structure_environments(self):
with open(f"{struct_env_files_dir}/se_mp-7000.json") as f:
with open(f"{struct_env_dir}/se_mp-7000.json") as f:
dd = json.load(f)

struct_envs = StructureEnvironments.from_dict(dd)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

__author__ = "waroquiers"

json_files_dir = f"{TEST_FILES_DIR}/chemenv/json_test_files"
img_files_dir = f"{TEST_FILES_DIR}/chemenv/images"


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

import json
import os

import pytest
from pytest import approx
Expand All @@ -21,11 +20,7 @@

__author__ = "waroquiers"

se_files_dir = os.path.join(
TEST_FILES_DIR,
"chemenv",
"structure_environments_files",
)
struct_env_dir = f"{TEST_FILES_DIR}/chemenv/structure_environments"


class FakeNbSet:
Expand Down Expand Up @@ -248,7 +243,7 @@ def test_CN_bias_weight(self):

def test_self_csms_weight(self):
# Get the StructureEnvironments for K2NaNb2Fe7Si8H4O31 (mp-743972)
with open(f"{se_files_dir}/se_mp-743972.json") as f:
with open(f"{struct_env_dir}/se_mp-743972.json") as f:
dct = json.load(f)
struct_envs = StructureEnvironments.from_dict(dct)

Expand Down Expand Up @@ -324,7 +319,7 @@ def test_self_csms_weight(self):
assert abs(self_w - 0.14204073172729198) < 1e-8

# Get the StructureEnvironments for SiO2 (mp-7000)
with open(f"{se_files_dir}/se_mp-7000.json") as f:
with open(f"{struct_env_dir}/se_mp-7000.json") as f:
dct = json.load(f)
struct_envs = StructureEnvironments.from_dict(dct)

Expand Down Expand Up @@ -368,7 +363,7 @@ def test_self_csms_weight(self):

def test_delta_csms_weight(self):
# Get the StructureEnvironments for K2NaNb2Fe7Si8H4O31 (mp-743972)
with open(f"{se_files_dir}/se_mp-743972.json") as f:
with open(f"{struct_env_dir}/se_mp-743972.json") as f:
dd = json.load(f)
struct_envs = StructureEnvironments.from_dict(dd)

Expand Down Expand Up @@ -500,7 +495,7 @@ def test_delta_csms_weight(self):
assert abs(delta_w - 0.103515625) < 1e-8

# Get the StructureEnvironments for SiO2 (mp-7000)
with open(f"{se_files_dir}/se_mp-7000.json") as f:
with open(f"{struct_env_dir}/se_mp-7000.json") as f:
dd = json.load(f)
struct_envs = StructureEnvironments.from_dict(dd)

Expand Down
6 changes: 0 additions & 6 deletions tests/analysis/chemenv/utils/test_graph_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,9 +695,3 @@ def test_cycle(self):
assert c1 == c2
c2 = MultiGraphCycle([e2, e3, e1], [1, 2, 0])
assert c1 == c2


if __name__ == "__main__":
import unittest

unittest.main()
4 changes: 0 additions & 4 deletions tests/analysis/elasticity/test_elastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,6 @@ def setUp(self):
self.exp_cu = ElasticTensorExpansion([cu_c2, cu_c3])
cu_c4 = Tensor.from_voigt(self.data_dict["Cu_fourth_order"])
self.exp_cu_4 = ElasticTensorExpansion([cu_c2, cu_c3, cu_c4])
warnings.simplefilter("ignore")

def tearDown(self):
warnings.simplefilter("default")

def test_init(self):
c_ijkl = Tensor.from_voigt(self.c2)
Expand Down
12 changes: 0 additions & 12 deletions tests/analysis/gb/test_grain.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from __future__ import annotations

import warnings

import numpy as np
from numpy.testing import assert_allclose
from pytest import approx
Expand All @@ -21,7 +19,6 @@
class TestGrainBoundary(PymatgenTest):
@classmethod
def setUpClass(cls):
warnings.filterwarnings("ignore")
cls.Cu_conv = Structure.from_file(f"{test_dir}/Cu_mp-30_conventional_standard.cif")
GB_Cu_conv = GrainBoundaryGenerator(cls.Cu_conv)
cls.Cu_GB1 = GB_Cu_conv.gb_from_parameters(
Expand All @@ -42,10 +39,6 @@ def setUpClass(cls):
rm_ratio=0.0,
)

@classmethod
def tearDownClass(cls):
warnings.simplefilter("default")

def test_init(self):
assert self.Cu_GB1.rotation_angle == approx(123.74898859588858)
assert self.Cu_GB1.vacuum_thickness == approx(1.5)
Expand Down Expand Up @@ -114,7 +107,6 @@ def test_as_dict_and_from_dict(self):
class TestGrainBoundaryGenerator(PymatgenTest):
@classmethod
def setUpClass(cls):
warnings.filterwarnings("ignore")
cls.Cu_prim = Structure.from_file(f"{test_dir}/Cu_mp-30_primitive.cif")
cls.GB_Cu_prim = GrainBoundaryGenerator(cls.Cu_prim)
cls.Cu_conv = Structure.from_file(f"{test_dir}/Cu_mp-30_conventional_standard.cif")
Expand All @@ -128,10 +120,6 @@ def setUpClass(cls):
cls.Bi = Structure.from_file(f"{test_dir}/Bi_mp-23152_primitive.cif")
cls.GB_Bi = GrainBoundaryGenerator(cls.Bi)

@classmethod
def tearDownClass(cls):
warnings.simplefilter("default")

def test_gb_from_parameters(self):
# from fcc primitive cell,axis[1,2,3],sigma 9.
gb_cu_123_prim1 = self.GB_Cu_prim.gb_from_parameters([1, 2, 3], 123.74898859588858, expand_times=2)
Expand Down
6 changes: 0 additions & 6 deletions tests/analysis/magnetism/test_analyzer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

import unittest
import warnings
from shutil import which

import pytest
Expand Down Expand Up @@ -66,11 +65,6 @@ def setUp(self):
coords = [[0.5, 0.5, 0.5], [0, 0, 0], [0, 0.5, 0], [0.5, 0, 0.5]]
self.NiO_unphysical = Structure(latt, species, coords, site_properties={"magmom": [-3, 0, 0, 0]})

warnings.simplefilter("ignore")

def tearDown(self):
warnings.simplefilter("default")

def test_get_representations(self):
# tests to convert between storing magnetic moment information
# on site_properties or on Species 'spin' property
Expand Down
Loading