File: test_plugins.py

package info (click to toggle)
python-typeguard 4.4.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 544 kB
  • sloc: python: 6,271; makefile: 5
file content (26 lines) | stat: -rw-r--r-- 718 bytes parent folder | download | duplicates (2)
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
from pytest import MonkeyPatch

from typeguard import load_plugins


def test_custom_type_checker(monkeypatch: MonkeyPatch) -> None:
    def lookup_func(origin_type, args, extras):
        pass

    class FakeEntryPoint:
        name = "test"

        def load(self):
            return lookup_func

    def fake_entry_points(group):
        assert group == "typeguard.checker_lookup"
        return [FakeEntryPoint()]

    checker_lookup_functions = []
    monkeypatch.setattr("typeguard._checkers.entry_points", fake_entry_points)
    monkeypatch.setattr(
        "typeguard._checkers.checker_lookup_functions", checker_lookup_functions
    )
    load_plugins()
    assert checker_lookup_functions[0] is lookup_func