Skip to content

Commit

Permalink
add some test for legacy tester
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielYang59 committed Dec 5, 2024
1 parent 027f84b commit 083879a
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions tests/util/test_testing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"""Test testing utils."""

from __future__ import annotations

from pathlib import Path

from pymatgen.core import Element, Structure
from pymatgen.io.vasp.inputs import Kpoints
from pymatgen.util.testing import PymatgenTest


class TestPymatgenTest(PymatgenTest):
def test_deprecated(self):
pass

def test_tmp_dir(self):
current_dir = Path.cwd()
assert current_dir == self.tmp_path

assert self.tmp_path.is_dir()

test_file = self.tmp_path / "test_file.txt"
test_file.write_text("Hello, pytest!")

assert test_file.exists()
assert test_file.read_text() == "Hello, pytest!"

def test_get_structure(self):
assert isinstance(self.get_structure("LiFePO4"), Structure)

def test_assert_str_content_equal(self):
# TODO: see PR 4205, assert_str_content_equal has a minor bug
# and would not raise AssertError but return a boolean only
assert self.assert_str_content_equal("hi", " hi")
assert not self.assert_str_content_equal("hi", "world")

def test_serialize_with_pickle(self):
result = self.serialize_with_pickle(Element.from_Z(1))
assert isinstance(result, list)
assert result[0] is Element.H

def test_assert_msonable(self):
kpoints = Kpoints.gamma_automatic((3, 3, 3), [0, 0, 0])
kp_str = self.assert_msonable(kpoints)
assert "Automatic kpoint scheme" in kp_str

0 comments on commit 083879a

Please sign in to comment.