Coverage for tdom / callables_test.py: 100%
82 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-03 21:23 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-03 21:23 +0000
1import typing as t
3from .callables import get_callable_info
6def callable_zero_args() -> None: # pragma: no cover
7 """Test callable that takes zero arguments."""
10def test_zero_args() -> None:
11 """Test that a callable that takes zero arguments is detected."""
12 info = get_callable_info(callable_zero_args)
13 assert info.id == id(callable_zero_args)
14 assert info.named_params == frozenset()
15 assert info.required_named_params == frozenset()
16 assert not info.requires_positional
17 assert not info.kwargs
18 assert info.supports_zero_args
21def callable_positional(a: int, b: str) -> None: # pragma: no cover
22 """Test callable that takes positional arguments."""
25def test_positional() -> None:
26 """Test that a callable that takes positional arguments is detected."""
27 info = get_callable_info(callable_positional)
28 assert info.id == id(callable_positional)
29 assert info.named_params == frozenset(["a", "b"])
30 assert info.required_named_params == frozenset(["a", "b"])
31 assert not info.requires_positional
32 assert not info.kwargs
33 assert not info.supports_zero_args
36def callable_positional_only(a: int, /, b: str) -> None: # pragma: no cover
37 """Test callable that takes positional-only arguments."""
40def test_positional_only() -> None:
41 """Test that a callable that takes positional-only arguments is detected."""
42 info = get_callable_info(callable_positional_only)
43 assert info.id == id(callable_positional_only)
44 assert info.named_params == frozenset(["b"])
45 assert info.required_named_params == frozenset(["b"])
46 assert info.requires_positional
47 assert not info.kwargs
48 assert not info.supports_zero_args
51def callable_positional_only_default(
52 a: int = 1, /, b: str = "b"
53) -> None: # pragma: no cover
54 """Test callable that takes positional-only arguments with defaults."""
57def test_positional_only_default() -> None:
58 """Test that a callable that takes positional-only arguments with defaults is detected."""
59 info = get_callable_info(callable_positional_only_default)
60 assert info.id == id(callable_positional_only_default)
61 assert info.named_params == frozenset(["b"])
62 assert info.required_named_params == frozenset()
63 assert not info.requires_positional
64 assert not info.kwargs
65 assert info.supports_zero_args
68def callable_kwargs(**kwargs: t.Any) -> None: # pragma: no cover
69 """Test callable that takes **kwargs."""
72def test_kwargs() -> None:
73 """Test that a callable that takes **kwargs is detected."""
74 info = get_callable_info(callable_kwargs)
75 assert info.id == id(callable_kwargs)
76 assert info.named_params == frozenset()
77 assert info.required_named_params == frozenset()
78 assert not info.requires_positional
79 assert info.kwargs
80 assert info.supports_zero_args
83def callable_mixed(
84 a: int, /, b: str, *, c: float = 1.0, **kwargs: t.Any
85) -> None: # pragma: no cover
86 """Test callable that takes a mix of argument types."""
89def test_mixed() -> None:
90 """Test that a callable that takes a mix of argument types is detected."""
91 info = get_callable_info(callable_mixed)
92 assert info.id == id(callable_mixed)
93 assert info.named_params == frozenset(["b", "c"])
94 assert info.required_named_params == frozenset(["b"])
95 assert info.requires_positional
96 assert info.kwargs
97 assert not info.supports_zero_args
100def callable_positional_with_defaults(
101 a: int = 1, b: str = "b", /
102) -> None: # pragma: no cover
103 """Test callable that takes positional arguments with defaults."""
106def test_positional_with_defaults() -> None:
107 """Test that a callable that takes positional arguments with defaults is detected."""
108 info = get_callable_info(callable_positional_with_defaults)
109 assert info.id == id(callable_positional_with_defaults)
110 assert info.named_params == frozenset()
111 assert info.required_named_params == frozenset()
112 assert not info.requires_positional
113 assert not info.kwargs
114 assert info.supports_zero_args
117def callable_keyword_only(*, a: int, b: str = "b") -> None: # pragma: no cover
118 """Test callable that takes keyword-only arguments."""
121def test_keyword_only() -> None:
122 """Test that a callable that takes keyword-only arguments is detected."""
123 info = get_callable_info(callable_keyword_only)
124 assert info.id == id(callable_keyword_only)
125 assert info.named_params == frozenset(["a", "b"])
126 assert info.required_named_params == frozenset(["a"])
127 assert not info.requires_positional
128 assert not info.kwargs
129 assert not info.supports_zero_args
132def callable_var_positional(*args: t.Any) -> None: # pragma: no cover
133 """Test callable that takes *args."""
136def test_var_positional() -> None:
137 """Test that a callable that takes *args is detected."""
138 info = get_callable_info(callable_var_positional)
139 assert info.id == id(callable_var_positional)
140 assert info.named_params == frozenset()
141 assert info.required_named_params == frozenset()
142 assert info.requires_positional
143 assert not info.kwargs
144 assert not info.supports_zero_args
147def callable_all_types(
148 a: int, /, b: str, *, c: float = 1.0, **kwargs: t.Any
149) -> None: # pragma: no cover
150 """Test callable that takes all types of arguments."""
153def test_all_types() -> None:
154 """Test that a callable that takes all types of arguments is detected."""
155 info = get_callable_info(callable_all_types)
156 assert info.id == id(callable_all_types)
157 assert info.named_params == frozenset(["b", "c"])
158 assert info.required_named_params == frozenset(["b"])
159 assert info.requires_positional
160 assert info.kwargs
161 assert not info.supports_zero_args