Skip to content

Commit 8795090

Browse files
committed
tests: Fix tests
1 parent fa91dd1 commit 8795090

File tree

6 files changed

+80
-84
lines changed

6 files changed

+80
-84
lines changed

tests/conftest.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,16 @@ def fixture_ext_markdown(plugin):
8686
return plugin.md
8787

8888

89-
@pytest.fixture(name="renderer")
90-
def fixture_renderer(plugin):
91-
"""Return a PythonRenderer instance.
89+
@pytest.fixture(name="handler")
90+
def fixture_handler(plugin):
91+
"""Return a handler instance.
9292
9393
Parameters:
9494
plugin: Pytest fixture: [tests.conftest.fixture_plugin][].
9595
9696
Returns:
97-
A renderer instance.
97+
A handler instance.
9898
"""
9999
handler = plugin.handlers.get_handler("python")
100-
handler.renderer._update_env(plugin.md, plugin.handlers._config) # noqa: WPS437
101-
return handler.renderer
100+
handler._update_env(plugin.md, plugin.handlers._config) # noqa: WPS437
101+
return handler

tests/test_collector.py

Lines changed: 0 additions & 31 deletions
This file was deleted.

tests/test_handler.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
"""Tests for the `handler` module."""
2+
3+
import pytest
4+
from griffe.docstrings.dataclasses import DocstringSectionExamples, DocstringSectionKind
5+
6+
from mkdocstrings_handlers.python.handler import CollectionError, get_handler
7+
8+
9+
def test_collect_missing_module():
10+
"""Assert error is raised for missing modules."""
11+
handler = get_handler(theme="material")
12+
with pytest.raises(CollectionError):
13+
handler.collect("aaaaaaaa", {})
14+
15+
16+
def test_collect_missing_module_item():
17+
"""Assert error is raised for missing items within existing modules."""
18+
handler = get_handler(theme="material")
19+
with pytest.raises(CollectionError):
20+
handler.collect("mkdocstrings.aaaaaaaa", {})
21+
22+
23+
def test_collect_module():
24+
"""Assert existing module can be collected."""
25+
handler = get_handler(theme="material")
26+
assert handler.collect("mkdocstrings", {})
27+
28+
29+
def test_collect_with_null_parser():
30+
"""Assert we can pass `None` as parser when collecting."""
31+
handler = get_handler(theme="material")
32+
assert handler.collect("mkdocstrings", {"docstring_style": None})
33+
34+
35+
@pytest.mark.parametrize(
36+
"handler",
37+
[
38+
{"theme": "mkdocs"},
39+
{"theme": "readthedocs"},
40+
{"theme": {"name": "material"}},
41+
],
42+
indirect=["handler"],
43+
)
44+
def test_render_docstring_examples_section(handler):
45+
"""Assert docstrings' examples section can be rendered.
46+
47+
Parameters:
48+
handler: A handler instance (parametrized).
49+
"""
50+
section = DocstringSectionExamples(
51+
value=[
52+
(DocstringSectionKind.text, "This is an example."),
53+
(DocstringSectionKind.examples, ">>> print('Hello')\nHello"),
54+
],
55+
)
56+
template = handler.env.get_template("docstring/examples.html")
57+
rendered = template.render(section=section)
58+
assert "<p>This is an example.</p>" in rendered
59+
assert "print" in rendered
60+
assert "Hello" in rendered

tests/test_renderer.py

Lines changed: 0 additions & 44 deletions
This file was deleted.

tests/test_rendering.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"""Tests for the `rendering` module."""
2+
3+
from mkdocstrings_handlers.python import rendering
4+
5+
6+
def test_format_code_and_signature():
7+
"""Assert code and signatures can be Black-formatted."""
8+
assert rendering.do_format_code("print('Hello')", 100)
9+
assert rendering.do_format_code('print("Hello")', 100)
10+
assert rendering.do_format_signature("(param: str = 'hello') -> 'Class'", 100)
11+
assert rendering.do_format_signature('(param: str = "hello") -> "Class"', 100)

tests/test_themes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ def test_render_themes_templates_python(module, plugin):
3535
plugin: Pytest fixture: [tests.conftest.fixture_plugin][].
3636
"""
3737
handler = plugin.handlers.get_handler("python")
38-
handler.renderer._update_env(plugin.md, plugin.handlers._config) # noqa: WPS437
39-
data = handler.collector.collect(module, {})
40-
handler.renderer.render(data, {})
38+
handler._update_env(plugin.md, plugin.handlers._config) # noqa: WPS437
39+
data = handler.collect(module, {})
40+
handler.render(data, {})

0 commit comments

Comments
 (0)