<commit_before>import os
import unittest

from test_spglib import dirnames
from vasp import read_vasp

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:
            cell = read_vasp(fname)
            if "distorted" in 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)
                    )
                    ref_cell = (
                        dataset["std_lattice"],
                        dataset["std_positions"],
                        dataset["std_types"],
                    )
                    dataset = get_symmetry_dataset(ref_cell, symprec=1e-5)
                    hall_number = get_hall_number_from_symmetry(
                        dataset["rotations"], dataset["translations"], symprec=1e-5
                    )
                    print(
                        "Using refined cell: %d, %d in %s"
                        % (hall_number, dataset["hall_number"], fname)
                    )
            else:
                dataset = get_symmetry_dataset(cell, symprec=1e-5)
                hall_number = get_hall_number_from_symmetry(
                    dataset["rotations"], dataset["translations"], symprec=1e-5
                )
            self.assertEqual(
                hall_number,
                dataset["hall_number"],
                msg=("%d != %d in %s" % (hall_number, dataset["hall_number"], fname)),
            )


if __name__ == "__main__":
    suite = unittest.TestLoader().loadTestsFromTestCase(TestGetHallNumberFromSymmetry)
    unittest.TextTestRunner(verbosity=2).run(suite)
    # unittest.main()<commit_msg>Migrate test_hall_number_from_symmetry.py to pytest and ignore::DeprecationWarning<commit_after>"""Test of get_hall_number_from_symmetry."""
from __future__ import annotations

import os
from pathlib import Path
from typing import Callable

import pytest

from spglib import get_hall_number_from_symmetry, get_symmetry_dataset

data_dir = os.path.dirname(os.path.abspath(__file__))


@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 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))
                ref_cell = (
                    dataset["std_lattice"],
                    dataset["std_positions"],
                    dataset["std_types"],
                )
                dataset = get_symmetry_dataset(ref_cell, symprec=1e-5)
                hall_number = get_hall_number_from_symmetry(
                    dataset["rotations"], dataset["translations"], symprec=1e-5
                )
                print(
                    "Using refined cell: %d, %d in %s"
                    % (hall_number, dataset["hall_number"], fname)
                )
        else:
            dataset = get_symmetry_dataset(cell, symprec=1e-5)
            hall_number = get_hall_number_from_symmetry(
                dataset["rotations"], dataset["translations"], symprec=1e-5
            )
        assert hall_number == dataset["hall_number"], "%d != %d in %s" % (
            hall_number,
            dataset["hall_number"],
            fname,
        )
{'fraction_non_alphanumeric': 0.1002710027100271, 'fraction_numerical': 0.005645889792231256, 'mean_word_length': 1.97248322147651, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1451101', 'n_tokens_mistral': 1296, 'n_tokens_neox': 1243, 'n_words': 232}