Skip to content

Commit

Permalink
remove useless with warnings.catch_warnings(): warnings.simplefilter(…
Browse files Browse the repository at this point in the history
…"ignore")

since we have central [tool.pytest.ini_options] addopts = "-p no:warnings" in pyproject.toml
  • Loading branch information
janosh committed Jul 1, 2023
1 parent 4ac4f8a commit ff048cc
Show file tree
Hide file tree
Showing 9 changed files with 294 additions and 341 deletions.
4 changes: 0 additions & 4 deletions pymatgen/analysis/tests/test_surface_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import json
import os
import warnings

from pytest import approx
from sympy import Number, Symbol
Expand All @@ -25,9 +24,6 @@ def get_path(path_str):

class SlabEntryTest(PymatgenTest):
def setUp(self):
with warnings.catch_warnings():
warnings.simplefilter("ignore")

with open(os.path.join(get_path(""), "ucell_entries.txt")) as ucell_entries:
ucell_entries = json.loads(ucell_entries.read())
self.ucell_entries = ucell_entries
Expand Down
26 changes: 12 additions & 14 deletions pymatgen/apps/borg/tests/test_hive.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,18 @@ def test_get_valid_paths(self):
assert len(self.drone.get_valid_paths(path)) > 0

def test_assimilate(self):
with warnings.catch_warnings():
warnings.simplefilter("ignore")
entry = self.drone.assimilate(PymatgenTest.TEST_FILES_DIR)
for p in ["hubbards", "is_hubbard", "potcar_spec", "run_type"]:
assert p in entry.parameters
assert entry.data["efermi"] == approx(-6.62148548)
assert entry.composition.reduced_formula == "Xe"
assert entry.energy == approx(0.5559329)
entry = self.structure_drone.assimilate(PymatgenTest.TEST_FILES_DIR)
assert entry.composition.reduced_formula == "Xe"
assert entry.energy == approx(0.5559329)
assert isinstance(entry, ComputedStructureEntry)
assert entry.structure is not None
# assert len(entry.parameters["history"]) == 2
entry = self.drone.assimilate(PymatgenTest.TEST_FILES_DIR)
for p in ["hubbards", "is_hubbard", "potcar_spec", "run_type"]:
assert p in entry.parameters
assert entry.data["efermi"] == approx(-6.62148548)
assert entry.composition.reduced_formula == "Xe"
assert entry.energy == approx(0.5559329)
entry = self.structure_drone.assimilate(PymatgenTest.TEST_FILES_DIR)
assert entry.composition.reduced_formula == "Xe"
assert entry.energy == approx(0.5559329)
assert isinstance(entry, ComputedStructureEntry)
assert entry.structure is not None
# assert len(entry.parameters["history"]) == 2

def tearDown(self):
warnings.simplefilter("default")
Expand Down
4 changes: 1 addition & 3 deletions pymatgen/command_line/mcsqs_caller.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,7 @@ def _parse_sqs_path(path) -> Sqs:
corr_out = f"bestcorr{i + 1}.out"
with Popen(f"str2cif < {sqs_out} > {sqs_cif}", shell=True, cwd=path) as p:
p.communicate()
with warnings.catch_warnings():
warnings.simplefilter("ignore")
sqs = Structure.from_file(path / sqs_out)
sqs = Structure.from_file(path / sqs_out)
with open(path / corr_out) as f:
lines = f.readlines()

Expand Down
107 changes: 52 additions & 55 deletions pymatgen/command_line/tests/test_enumlib_caller.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import os
import unittest
import warnings
from shutil import which

import pytest
Expand All @@ -26,62 +25,60 @@ class EnumlibAdaptorTest(PymatgenTest):
_multiprocess_shared_ = True

def test_init(self):
with warnings.catch_warnings():
warnings.simplefilter("ignore")
struct = self.get_structure("LiFePO4")
subtrans = SubstitutionTransformation({"Li": {"Li": 0.5}})
adaptor = EnumlibAdaptor(subtrans.apply_transformation(struct), 1, 2)
adaptor.run()
structures = adaptor.structures
assert len(structures) == 86
for s in structures:
assert s.composition.get_atomic_fraction(Element("Li")) == approx(0.5 / 6.5)
adaptor = EnumlibAdaptor(subtrans.apply_transformation(struct), 1, 2, refine_structure=True)
adaptor.run()
structures = adaptor.structures
assert len(structures) == 52
struct = self.get_structure("LiFePO4")
subtrans = SubstitutionTransformation({"Li": {"Li": 0.5}})
adaptor = EnumlibAdaptor(subtrans.apply_transformation(struct), 1, 2)
adaptor.run()
structures = adaptor.structures
assert len(structures) == 86
for s in structures:
assert s.composition.get_atomic_fraction(Element("Li")) == approx(0.5 / 6.5)
adaptor = EnumlibAdaptor(subtrans.apply_transformation(struct), 1, 2, refine_structure=True)
adaptor.run()
structures = adaptor.structures
assert len(structures) == 52

subtrans = SubstitutionTransformation({"Li": {"Li": 0.25}})
adaptor = EnumlibAdaptor(subtrans.apply_transformation(struct), 1, 1, refine_structure=True)
adaptor.run()
structures = adaptor.structures
assert len(structures) == 1
for s in structures:
assert s.composition.get_atomic_fraction(Element("Li")) == approx(0.25 / 6.25)

# Make sure it works for completely disordered structures.
struct = Structure([[10, 0, 0], [0, 10, 0], [0, 0, 10]], [{"Fe": 0.5}], [[0, 0, 0]])
adaptor = EnumlibAdaptor(struct, 1, 2)
adaptor.run()
assert len(adaptor.structures) == 3

# Make sure it works properly when symmetry is broken by ordered sites.
struct = self.get_structure("LiFePO4")
subtrans = SubstitutionTransformation({"Li": {"Li": 0.25}})
s = subtrans.apply_transformation(struct)
# REmove some ordered sites to break symmetry.
removetrans = RemoveSitesTransformation([4, 7])
s = removetrans.apply_transformation(s)
adaptor = EnumlibAdaptor(s, 1, 1, enum_precision_parameter=0.01)
adaptor.run()
structures = adaptor.structures
assert len(structures) == 4

struct = Structure(
[[3, 0, 0], [0, 3, 0], [0, 0, 3]],
[{"Si": 0.5}] * 2,
[[0, 0, 0], [0.5, 0.5, 0.5]],
)
adaptor = EnumlibAdaptor(struct, 1, 3, enum_precision_parameter=0.01)
adaptor.run()
structures = adaptor.structures
assert len(structures) == 10
subtrans = SubstitutionTransformation({"Li": {"Li": 0.25}})
adaptor = EnumlibAdaptor(subtrans.apply_transformation(struct), 1, 1, refine_structure=True)
adaptor.run()
structures = adaptor.structures
assert len(structures) == 1
for s in structures:
assert s.composition.get_atomic_fraction(Element("Li")) == approx(0.25 / 6.25)

struct = Structure.from_file(os.path.join(PymatgenTest.TEST_FILES_DIR, "EnumerateTest.json"))
adaptor = EnumlibAdaptor(struct, 1, 1)
adaptor.run()
structures = adaptor.structures
assert len(structures) == 2
# Make sure it works for completely disordered structures.
struct = Structure([[10, 0, 0], [0, 10, 0], [0, 0, 10]], [{"Fe": 0.5}], [[0, 0, 0]])
adaptor = EnumlibAdaptor(struct, 1, 2)
adaptor.run()
assert len(adaptor.structures) == 3

# Make sure it works properly when symmetry is broken by ordered sites.
struct = self.get_structure("LiFePO4")
subtrans = SubstitutionTransformation({"Li": {"Li": 0.25}})
s = subtrans.apply_transformation(struct)
# REmove some ordered sites to break symmetry.
removetrans = RemoveSitesTransformation([4, 7])
s = removetrans.apply_transformation(s)
adaptor = EnumlibAdaptor(s, 1, 1, enum_precision_parameter=0.01)
adaptor.run()
structures = adaptor.structures
assert len(structures) == 4

struct = Structure(
[[3, 0, 0], [0, 3, 0], [0, 0, 3]],
[{"Si": 0.5}] * 2,
[[0, 0, 0], [0.5, 0.5, 0.5]],
)
adaptor = EnumlibAdaptor(struct, 1, 3, enum_precision_parameter=0.01)
adaptor.run()
structures = adaptor.structures
assert len(structures) == 10

struct = Structure.from_file(os.path.join(PymatgenTest.TEST_FILES_DIR, "EnumerateTest.json"))
adaptor = EnumlibAdaptor(struct, 1, 1)
adaptor.run()
structures = adaptor.structures
assert len(structures) == 2

def test_rounding_errors(self):
# It used to be that a rounding issue would result in this structure
Expand Down
Loading

0 comments on commit ff048cc

Please sign in to comment.