Migrate test_hall_number_from_symmetry.py to pytest and ignore::DeprecationWarning
+"""Test of get_hall_number_from_symmetry."""
+from __future__ import annotations
+
import os
-import unittest
+from pathlib import Path
+from typing import Callable
-from test_spglib import dirnames
-from vasp import read_vasp
+import pytest
from spglib import get_hall_number_from_symmetry, get_symmetry_dataset
data_dir = os.path.dirname(os.path.abspath(__file__))
-class TestGetHallNumberFromSymmetry(unittest.TestCase):
- def setUp(self):
- self._filenames = []
- for d in dirnames:
- dirname = os.path.join(data_dir, "data", d)
- filenames = os.listdir(dirname)
- self._filenames += [os.path.join(dirname, fname) for fname in filenames]
-
- def tearDown(self):
- pass
-
- def test_get_hall_number_from_symmetry(self):
- for fname in self._filenames:
+@pytest.mark.filterwarnings("ignore::DeprecationWarning")
+def test_get_hall_number_from_symmetry(all_filenames: list[Path], read_vasp: Callable):
+ """Test get_hall_number_from_symmetry."""
+ for fname in all_filenames:
cell = read_vasp(fname)
- if "distorted" in fname:
+ if "distorted" in str(fname):
dataset = get_symmetry_dataset(cell, symprec=1e-1)
hall_number = get_hall_number_from_symmetry(
dataset["rotations"], dataset["translations"], symprec=1e-1
)
if hall_number != dataset["hall_number"]:
- print(
- "%d != %d in %s" % (hall_number, dataset["hall_number"], fname)
- )
+ print("%d != %d in %s" % (hall_number, dataset["hall_number"], fname))
ref_cell = (
dataset["std_lattice"],
dataset["std_positions"],
@@ -50,14 +42,8 @@ class TestGetHallNumberFromSymmetry(unittest.TestCase):
hall_number = get_hall_number_from_symmetry(
dataset["rotations"], dataset["translations"], symprec=1e-5
)
- self.assertEqual(
+ assert hall_number == dataset["hall_number"], "%d != %d in %s" % (
hall_number,
dataset["hall_number"],
- msg=("%d != %d in %s" % (hall_number, dataset["hall_number"], fname)),
+ fname,
)
-
-
-if __name__ == "__main__":
- suite = unittest.TestLoader().loadTestsFromTestCase(TestGetHallNumberFromSymmetry)
- unittest.TextTestRunner(verbosity=2).run(suite)
- # unittest.main()
