forked from matplotlib/matplotlib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_typing.py
More file actions
51 lines (38 loc) · 1.34 KB
/
test_typing.py
File metadata and controls
51 lines (38 loc) · 1.34 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import re
import typing
from pathlib import Path
import matplotlib.pyplot as plt
from matplotlib.colors import Colormap
from matplotlib.typing import RcKeyType, RcGroupKeyType
def test_cm_stub_matches_runtime_colormaps():
runtime_cm = plt.cm
runtime_cmaps = {
name
for name, value in vars(runtime_cm).items()
if isinstance(value, Colormap)
}
cm_pyi_path = Path(__file__).parent.parent / "cm.pyi"
assert cm_pyi_path.exists(), f"{cm_pyi_path} does not exist"
pyi_content = cm_pyi_path.read_text(encoding='utf-8')
stubbed_cmaps = set(
re.findall(r"^(\w+):\s+colors\.Colormap", pyi_content, re.MULTILINE)
)
assert runtime_cmaps, (
"No colormaps variables found at runtime in matplotlib.colors"
)
assert stubbed_cmaps, (
"No colormaps found in cm.pyi"
)
assert runtime_cmaps == stubbed_cmaps
def test_rcparam_stubs():
runtime_rc_keys = {
name for name in plt.rcParamsDefault.keys()
if not name.startswith('_')
}
assert {*typing.get_args(RcKeyType)} == runtime_rc_keys
runtime_rc_group_keys = set()
for name in runtime_rc_keys:
groups = name.split('.')
for i in range(1, len(groups)):
runtime_rc_group_keys.add('.'.join(groups[:i]))
assert {*typing.get_args(RcGroupKeyType)} == runtime_rc_group_keys