File tree Expand file tree Collapse file tree 4 files changed +51
-3
lines changed
src/mkdocstrings_handlers/python/templates/material/_base/docstring Expand file tree Collapse file tree 4 files changed +51
-3
lines changed Original file line number Diff line number Diff line change 1
1
{{ log.debug("Rendering examples section") }}
2
2
< p > < strong > {{ section.title or "Examples:" }}</ strong > </ p >
3
3
{% for section_type, sub_section in section.value %}
4
- {% if section_type == "markdown " %}
4
+ {% if section_type.value == "text " %}
5
5
{{ sub_section|convert_markdown(heading_level, html_id) }}
6
- {% elif section_type == "examples" %}
6
+ {% elif section_type.value == "examples" %}
7
7
{{ sub_section|highlight(language="python", linenums=False) }}
8
8
{% endif %}
9
9
{% endfor %}
Original file line number Diff line number Diff line change @@ -84,3 +84,18 @@ def fixture_ext_markdown(plugin):
84
84
A Markdown instance.
85
85
"""
86
86
return plugin .md
87
+
88
+
89
+ @pytest .fixture (name = "renderer" )
90
+ def fixture_renderer (plugin ):
91
+ """Return a PythonRenderer instance.
92
+
93
+ Parameters:
94
+ plugin: Pytest fixture: [tests.conftest.fixture_plugin][].
95
+
96
+ Returns:
97
+ A renderer instance.
98
+ """
99
+ handler = plugin .handlers .get_handler ("python" )
100
+ handler .renderer ._update_env (plugin .md , plugin .handlers ._config ) # noqa: WPS437
101
+ return handler .renderer
Original file line number Diff line number Diff line change 1
- """Tests for the handlers.python module."""
1
+ """Tests for the `collector` module."""
2
2
3
3
import pytest
4
4
Original file line number Diff line number Diff line change
1
+ """Tests for the `renderer` module."""
2
+
3
+ import pytest
4
+ from griffe .docstrings .dataclasses import DocstringSection , DocstringSectionKind
5
+
6
+
7
+ @pytest .mark .parametrize (
8
+ "renderer" ,
9
+ [
10
+ {"theme" : "mkdocs" },
11
+ {"theme" : "readthedocs" },
12
+ {"theme" : {"name" : "material" }},
13
+ ],
14
+ indirect = ["renderer" ],
15
+ )
16
+ def test_render_docstring_examples_section (renderer ):
17
+ """Assert docstrings' examples section can be rendered.
18
+
19
+ Parameters:
20
+ renderer: A renderer instance (parametrized).
21
+ """
22
+ section = DocstringSection (
23
+ DocstringSectionKind .examples ,
24
+ value = [
25
+ (DocstringSectionKind .text , "This is an example." ),
26
+ (DocstringSectionKind .examples , ">>> print('Hello')\n Hello" ),
27
+ ],
28
+ )
29
+ template = renderer .env .get_template ("docstring/examples.html" )
30
+ rendered = template .render (section = section )
31
+ assert "<p>This is an example.</p>" in rendered
32
+ assert "print" in rendered
33
+ assert "Hello" in rendered
You can’t perform that action at this time.
0 commit comments