-
-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathtest_handler.py
More file actions
100 lines (81 loc) · 2.99 KB
/
Copy pathtest_handler.py
File metadata and controls
100 lines (81 loc) · 2.99 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
"""Tests for the `handler` module."""
import os
from glob import glob
import pytest
from griffe.docstrings.dataclasses import DocstringSectionExamples, DocstringSectionKind
from mkdocstrings_handlers.python.handler import CollectionError, PythonHandler, get_handler
def test_collect_missing_module():
"""Assert error is raised for missing modules."""
handler = get_handler(theme="material")
with pytest.raises(CollectionError):
handler.collect("aaaaaaaa", {})
def test_collect_missing_module_item():
"""Assert error is raised for missing items within existing modules."""
handler = get_handler(theme="material")
with pytest.raises(CollectionError):
handler.collect("mkdocstrings.aaaaaaaa", {})
def test_collect_module():
"""Assert existing module can be collected."""
handler = get_handler(theme="material")
assert handler.collect("mkdocstrings", {})
def test_collect_with_null_parser():
"""Assert we can pass `None` as parser when collecting."""
handler = get_handler(theme="material")
assert handler.collect("mkdocstrings", {"docstring_style": None})
@pytest.mark.parametrize(
"handler",
[
{"theme": "mkdocs"},
{"theme": "readthedocs"},
{"theme": {"name": "material"}},
],
indirect=["handler"],
)
def test_render_docstring_examples_section(handler):
"""Assert docstrings' examples section can be rendered.
Parameters:
handler: A handler instance (parametrized).
"""
section = DocstringSectionExamples(
value=[
(DocstringSectionKind.text, "This is an example."),
(DocstringSectionKind.examples, ">>> print('Hello')\nHello"),
],
)
template = handler.env.get_template("docstring/examples.html")
rendered = template.render(section=section)
assert "<p>This is an example.</p>" in rendered
assert "print" in rendered
assert "Hello" in rendered
def test_expand_globs(tmp_path):
"""Assert globs are correctly expanded.
Parameters:
tmp_path: Pytext fixture that creates a temporary directory.
"""
globbed_names = (
"expanded_a",
"expanded_b",
"other_expanded_c",
"other_expanded_d",
)
globbed_paths = [tmp_path.joinpath(globbed_name) for globbed_name in globbed_names]
for path in globbed_paths:
path.touch()
handler = PythonHandler(
handler="python",
theme="material",
config_file_path=tmp_path / "mkdocs.yml",
paths=["*exp*"],
)
for path in globbed_paths: # noqa: WPS440
assert str(path) in handler._paths # noqa: WPS437
def test_expand_globs_without_changing_directory():
"""Assert globs are correctly expanded when we are already in the right directory."""
handler = PythonHandler(
handler="python",
theme="material",
config_file_path="mkdocs.yml",
paths=["*.md"],
)
for path in list(glob(os.path.abspath(".") + "/*.md")):
assert path in handler._paths # noqa: WPS437