File: test_errors.py

package info (click to toggle)
spglib 2.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 14,180 kB
  • sloc: ansic: 125,066; python: 7,717; cpp: 2,197; f90: 2,143; ruby: 792; makefile: 22; sh: 18
file content (35 lines) | stat: -rw-r--r-- 1,214 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from __future__ import annotations

import warnings

import pytest
import spglib
from spglib import niggli_reduce


@pytest.mark.parametrize("value", ["0", "1", "true", "false", "True", "False"])
def test_deprecation_warning_env(monkeypatch, value: str):
    monkeypatch.setenv("SPGLIB_OLD_ERROR_HANDLING", value)

    if value in ("1", "true", "True"):
        with pytest.warns(DeprecationWarning):
            warnings.simplefilter("always", DeprecationWarning)
            niggli_reduce([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
    else:
        with warnings.catch_warnings():
            warnings.simplefilter("error")
            niggli_reduce([[1, 0, 0], [0, 1, 0], [0, 0, 1]])


@pytest.mark.parametrize("value", [True, False])
def test_deprecation_warning_OLD_ERROR_HANDLING(monkeypatch, value: bool):
    monkeypatch.setattr(spglib.error, "OLD_ERROR_HANDLING", value)

    if value:
        with pytest.warns(DeprecationWarning):
            warnings.simplefilter("always", DeprecationWarning)
            niggli_reduce([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
    else:
        with warnings.catch_warnings():
            warnings.simplefilter("error")
            niggli_reduce([[1, 0, 0], [0, 1, 0], [0, 0, 1]])