LCOV - code coverage report
Current view: top level - tests - conftest.py (source / functions) Hit Total Coverage
Test: coverage.info Lines: 20 20 100.0 %
Date: 2025-04-29 15:59:54 Functions: 4 8 50.0 %

          Line data    Source code
       1             : # SPDX-FileCopyrightText: 2024 Pairinteraction Developers
       2             : # SPDX-License-Identifier: LGPL-3.0-or-later
       3             : 
       4           1 : import os
       5           1 : from typing import TYPE_CHECKING
       6             : 
       7           1 : import pytest
       8           1 : from pint import UnitRegistry
       9             : 
      10             : if TYPE_CHECKING:
      11             :     from _pytest.config import Config
      12             :     from _pytest.config.argparsing import Parser
      13             : 
      14             : 
      15           1 : def pytest_addoption(parser: "Parser") -> None:
      16           1 :     parser.addoption("--generate-reference", action="store_true", default=False, help="Generate reference data")
      17           1 :     parser.addoption(
      18             :         "--database-dir",
      19             :         action="store",
      20             :         default=None,
      21             :         help="Path to the database directory",
      22             :     )
      23           1 :     parser.addoption("--download-missing", action="store_true", default=False, help="Download missing database files")
      24             : 
      25             : 
      26           1 : @pytest.fixture(scope="session")
      27           1 : def generate_reference(pytestconfig: "Config") -> bool:
      28           1 :     return pytestconfig.getoption("--generate-reference")
      29             : 
      30             : 
      31           1 : @pytest.fixture(scope="session")
      32           1 : def ureg() -> UnitRegistry:
      33             :     """Create and return a UnitRegistry with atomic units."""
      34           1 :     return UnitRegistry(system="atomic")
      35             : 
      36             : 
      37           1 : def pytest_sessionstart(session: pytest.Session) -> None:
      38             :     """Initialize everything before the tests are run."""
      39           1 :     download_missing = session.config.getoption("--download-missing")
      40           1 :     database_dir = session.config.getoption("--database-dir")
      41             : 
      42             :     # Disable the test mode of pairinteraction that would call _setup_test_mode
      43             :     # automatically. This would be necessary for testing the jupyter notebooks
      44             :     # but we want to call _setup_test_mode manually.
      45           1 :     os.environ["PAIRINTERACTION_TEST_MODE"] = "0"
      46             : 
      47             :     # Call _setup_test_mode manually with the given options
      48           1 :     from pairinteraction import _setup_test_mode
      49             : 
      50           1 :     _setup_test_mode(download_missing, database_dir)

Generated by: LCOV version 1.16