2022-02-03 10:01:02 +01:00
|
|
|
"""Configuration for pylint tests."""
|
2023-09-06 11:35:57 +02:00
|
|
|
from importlib.util import module_from_spec, spec_from_file_location
|
2022-06-01 09:22:47 +02:00
|
|
|
from pathlib import Path
|
2023-09-06 11:35:57 +02:00
|
|
|
import sys
|
2022-02-03 10:01:02 +01:00
|
|
|
from types import ModuleType
|
|
|
|
|
|
|
|
from pylint.checkers import BaseChecker
|
|
|
|
from pylint.testutils.unittest_linter import UnittestLinter
|
|
|
|
import pytest
|
|
|
|
|
2022-06-01 09:22:47 +02:00
|
|
|
BASE_PATH = Path(__file__).parents[2]
|
2022-02-03 10:01:02 +01:00
|
|
|
|
2022-06-01 09:22:47 +02:00
|
|
|
|
|
|
|
@pytest.fixture(name="hass_enforce_type_hints", scope="session")
|
2022-02-03 10:01:02 +01:00
|
|
|
def hass_enforce_type_hints_fixture() -> ModuleType:
|
|
|
|
"""Fixture to provide a requests mocker."""
|
2023-09-06 11:35:57 +02:00
|
|
|
module_name = "hass_enforce_type_hints"
|
|
|
|
spec = spec_from_file_location(
|
|
|
|
module_name,
|
2022-06-01 09:22:47 +02:00
|
|
|
str(BASE_PATH.joinpath("pylint/plugins/hass_enforce_type_hints.py")),
|
2022-02-03 10:01:02 +01:00
|
|
|
)
|
2023-09-06 11:35:57 +02:00
|
|
|
assert spec and spec.loader
|
|
|
|
|
|
|
|
module = module_from_spec(spec)
|
|
|
|
sys.modules[module_name] = module
|
|
|
|
spec.loader.exec_module(module)
|
|
|
|
return module
|
2022-02-03 10:01:02 +01:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(name="linter")
|
|
|
|
def linter_fixture() -> UnittestLinter:
|
|
|
|
"""Fixture to provide a requests mocker."""
|
|
|
|
return UnittestLinter()
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(name="type_hint_checker")
|
|
|
|
def type_hint_checker_fixture(hass_enforce_type_hints, linter) -> BaseChecker:
|
|
|
|
"""Fixture to provide a requests mocker."""
|
|
|
|
type_hint_checker = hass_enforce_type_hints.HassTypeHintChecker(linter)
|
|
|
|
type_hint_checker.module = "homeassistant.components.pylint_test"
|
|
|
|
return type_hint_checker
|
2022-08-26 14:27:13 +02:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(name="hass_imports", scope="session")
|
|
|
|
def hass_imports_fixture() -> ModuleType:
|
|
|
|
"""Fixture to provide a requests mocker."""
|
2023-09-06 11:35:57 +02:00
|
|
|
module_name = "hass_imports"
|
|
|
|
spec = spec_from_file_location(
|
|
|
|
module_name, str(BASE_PATH.joinpath("pylint/plugins/hass_imports.py"))
|
2022-08-26 14:27:13 +02:00
|
|
|
)
|
2023-09-06 11:35:57 +02:00
|
|
|
assert spec and spec.loader
|
|
|
|
|
|
|
|
module = module_from_spec(spec)
|
|
|
|
sys.modules[module_name] = module
|
|
|
|
spec.loader.exec_module(module)
|
|
|
|
return module
|
2022-08-26 14:27:13 +02:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(name="imports_checker")
|
|
|
|
def imports_checker_fixture(hass_imports, linter) -> BaseChecker:
|
|
|
|
"""Fixture to provide a requests mocker."""
|
|
|
|
type_hint_checker = hass_imports.HassImportsFormatChecker(linter)
|
|
|
|
type_hint_checker.module = "homeassistant.components.pylint_test"
|
|
|
|
return type_hint_checker
|