Skip to content

Commit

Permalink
clean up assert no warning in test
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielYang59 committed Nov 30, 2024
1 parent e2b4c06 commit 255876a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions tests/core/test_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ def test_memory(self):
assert mega_0 == mega_1 == mega_2 == mega_3

def test_deprecated_memory(self):
# TODO: remove after 2025-01-01
"""TODO: remove entire test method after 2025-01-01"""
for unit in ("Kb", "kb", "Mb", "mb", "Gb", "gb", "Tb", "tb"):
with pytest.warns(DeprecationWarning, match=f"Unit {unit} is deprecated"):
Memory(1, unit)

with warnings.catch_warnings():
warnings.simplefilter("error")
for unit in ("KB", "MB", "GB", "TB"):
warnings.filterwarnings("error", message=f"Unit {unit} is deprecated", category=DeprecationWarning)
Memory(1, unit)

def test_unitized(self):
Expand Down
14 changes: 7 additions & 7 deletions tests/io/vasp/test_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,8 @@ def test_from_file_potcar_overwrite_elements(self):
copyfile(f"{VASP_IN_DIR}/POSCAR_C2", tmp_poscar_path := f"{self.tmp_path}/POSCAR")
copyfile(f"{VASP_IN_DIR}/POTCAR_C2.gz", f"{self.tmp_path}/POTCAR.gz")

with warnings.catch_warnings(record=True) as record:
_poscar = Poscar.from_file(tmp_poscar_path)
assert not any("Elements in POSCAR would be overwritten" in str(warning.message) for warning in record)
warnings.filterwarnings("error", message="Elements in POSCAR would be overwritten")
_poscar = Poscar.from_file(tmp_poscar_path)

def test_from_str_default_names(self):
"""Similar to test_from_file_bad_potcar, ensure "default_names"
Expand All @@ -237,18 +236,19 @@ def test_from_str_default_names(self):
assert poscar.site_symbols == ["Si", "O"]

# Assert no warning if using the same elements (or superset)
with warnings.catch_warnings(record=True) as record:
with warnings.catch_warnings():
warnings.filterwarnings("error", message="Elements in POSCAR would be overwritten")

poscar = Poscar.from_str(poscar_str, default_names=["Si", "F"])
assert poscar.site_symbols == ["Si", "F"]

poscar = Poscar.from_str(poscar_str, default_names=["Si", "F", "O"])
assert poscar.site_symbols == ["Si", "F"]
assert not any("Elements in POSCAR would be overwritten" in str(warning.message) for warning in record)

# Make sure it could be bypassed (by using None, when not check_for_potcar)
with warnings.catch_warnings(record=True) as record:
with warnings.catch_warnings():
warnings.filterwarnings("error", message="Elements in POSCAR would be overwritten")
_poscar = Poscar.from_str(poscar_str, default_names=None)
assert not any("Elements in POSCAR would be overwritten" in str(warning.message) for warning in record)

def test_from_str_default_names_vasp4(self):
"""Poscar.from_str with default_names given could also be used to
Expand Down

0 comments on commit 255876a

Please sign in to comment.