From 9d8a14b49ab53549c928895e2922221bcd0482cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Thu, 23 Sep 2021 20:19:31 +0200 Subject: [PATCH 1/4] tests: Move fixtures to conftest --- tests/conftest.py | 57 +++++++++++++++++++++++++++++++++++++++++ tests/test_extension.py | 39 ---------------------------- 2 files changed, 57 insertions(+), 39 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 3be27baf..7025b8fd 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1 +1,58 @@ """Configuration for the pytest test suite.""" + +from collections import ChainMap + +import pytest +from markdown.core import Markdown +from mkdocs import config + +try: + from mkdocs.config.defaults import get_schema +except ImportError: + + def get_schema(): # noqa: WPS440 + """Fallback for old versions of MkDocs.""" + return config.DEFAULT_SCHEMA + + +@pytest.fixture(name="mkdocs_conf") +def fixture_mkdocs_conf(request, tmp_path): + """Yield a MkDocs configuration object.""" + conf = config.Config(schema=get_schema()) + while hasattr(request, "_parent_request") and hasattr(request._parent_request, "_parent_request"): # noqa: WPS437 + request = request._parent_request # noqa: WPS437 + + conf_dict = { + "site_name": "foo", + "site_url": "https://example.org/", + "site_dir": str(tmp_path), + "plugins": [{"mkdocstrings": {"default_handler": "python"}}], + **getattr(request, "param", {}), + } + # Re-create it manually as a workaround for https://github.com/mkdocs/mkdocs/issues/2289 + mdx_configs = dict(ChainMap(*conf_dict.get("markdown_extensions", []))) + + conf.load_dict(conf_dict) + assert conf.validate() == ([], []) + + conf["mdx_configs"] = mdx_configs + conf["markdown_extensions"].insert(0, "toc") # Guaranteed to be added by MkDocs. + + conf = conf["plugins"]["mkdocstrings"].on_config(conf) + conf = conf["plugins"]["autorefs"].on_config(conf) + yield conf + conf["plugins"]["mkdocstrings"].on_post_build(conf) + + +@pytest.fixture(name="plugin") +def fixture_plugin(mkdocs_conf): + """Return a plugin instance.""" + plugin = mkdocs_conf["plugins"]["mkdocstrings"] + plugin.md = Markdown(extensions=mkdocs_conf["markdown_extensions"], extension_configs=mkdocs_conf["mdx_configs"]) + return plugin + + +@pytest.fixture(name="ext_markdown") +def fixture_ext_markdown(plugin): + """Return a Markdown instance with MkdocstringsExtension.""" + return plugin.md diff --git a/tests/test_extension.py b/tests/test_extension.py index 3d4a5294..db407233 100644 --- a/tests/test_extension.py +++ b/tests/test_extension.py @@ -1,48 +1,9 @@ """Tests for the extension module.""" import re import sys -from collections import ChainMap from textwrap import dedent import pytest -from markdown import Markdown -from mkdocs import config - -try: - from mkdocs.config.defaults import get_schema -except ImportError: - - def get_schema(): # noqa: WPS440 - """Fallback for old versions of MkDocs.""" - return config.DEFAULT_SCHEMA - - -@pytest.fixture(name="ext_markdown") -def fixture_ext_markdown(request, tmp_path): - """Yield a Markdown instance with MkdocstringsExtension, with config adjustments.""" - conf = config.Config(schema=get_schema()) - - conf_dict = { - "site_name": "foo", - "site_url": "https://example.org/", - "site_dir": str(tmp_path), - "plugins": [{"mkdocstrings": {"default_handler": "python"}}], - **getattr(request, "param", {}), - } - # Re-create it manually as a workaround for https://github.com/mkdocs/mkdocs/issues/2289 - mdx_configs = dict(ChainMap(*conf_dict.get("markdown_extensions", []))) - - conf.load_dict(conf_dict) - assert conf.validate() == ([], []) - - conf["mdx_configs"] = mdx_configs - conf["markdown_extensions"].insert(0, "toc") # Guaranteed to be added by MkDocs. - - conf = conf["plugins"]["mkdocstrings"].on_config(conf) - conf = conf["plugins"]["autorefs"].on_config(conf) - md = Markdown(extensions=conf["markdown_extensions"], extension_configs=conf["mdx_configs"]) - yield md - conf["plugins"]["mkdocstrings"].on_post_build(conf) def test_render_html_escaped_sequences(ext_markdown): From 598621bff29d2aeda0e14f350cda36c1a1f418d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Thu, 23 Sep 2021 20:20:07 +0200 Subject: [PATCH 2/4] fix: Fix ReadTheDocs "return" template --- .../templates/python/readthedocs/return.html | 2 +- tests/test_themes.py | 33 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 tests/test_themes.py diff --git a/src/mkdocstrings/templates/python/readthedocs/return.html b/src/mkdocstrings/templates/python/readthedocs/return.html index 7e45ecaf..74bf65bb 100644 --- a/src/mkdocstrings/templates/python/readthedocs/return.html +++ b/src/mkdocstrings/templates/python/readthedocs/return.html @@ -9,7 +9,7 @@ Returns: diff --git a/tests/test_themes.py b/tests/test_themes.py new file mode 100644 index 00000000..c3396ad9 --- /dev/null +++ b/tests/test_themes.py @@ -0,0 +1,33 @@ +"""Tests for the different themes we claim to support.""" + +import sys + +import pytest + + +@pytest.mark.parametrize( + "plugin", + [ + {"theme": "mkdocs"}, + {"theme": "readthedocs"}, + {"theme": {"name": "material"}}, + ], + indirect=["plugin"], +) +@pytest.mark.skipif(sys.version_info < (3, 7), reason="material is not installed on Python 3.6") +def test_render_themes_templates_python(plugin): + """Test rendering of a given theme's templates.""" + modules = { + "mkdocstrings.extension", + "mkdocstrings.inventory", + "mkdocstrings.loggers", + "mkdocstrings.plugin", + "mkdocstrings.handlers.base", + "mkdocstrings.handlers.python", + "mkdocstrings.handlers.rendering", + } + handler = plugin.handlers.get_handler("python") + handler.renderer._update_env(plugin.md, plugin.handlers._config) # noqa: WPS437 + for identifier in modules: + data = handler.collector.collect(identifier, {}) + handler.renderer.render(data, {}) From 4c47ddea0725ce6a10563decd8db192abbbd465e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Thu, 23 Sep 2021 20:20:32 +0200 Subject: [PATCH 3/4] ci: Use a template linter --- duties.py | 1 + pyproject.toml | 1 + src/mkdocstrings/templates/python/mkdocs/exceptions.html | 2 +- src/mkdocstrings/templates/python/mkdocs/parameters.html | 2 +- src/mkdocstrings/templates/python/mkdocs/return.html | 2 +- 5 files changed, 5 insertions(+), 3 deletions(-) diff --git a/duties.py b/duties.py index 284c97ce..2dcc706c 100644 --- a/duties.py +++ b/duties.py @@ -121,6 +121,7 @@ def check_code_quality(ctx, files=PY_SRC): files: The files to check. """ ctx.run(f"flake8 --config=config/flake8.ini {files}", title="Checking code quality", pty=PTY) + ctx.run("curlylint src/mkdocstrings/templates", title="Checking templates quality", pty=PTY) @duty diff --git a/pyproject.toml b/pyproject.toml index c517aa90..4f806842 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -79,6 +79,7 @@ quality = [ "flake8-variables-names~=0.0", "pep8-naming~=0.11", "wps-light~=0.15", + "curlylint~=0.13", ] tests = [ "pygments~=2.10", # python 3.6 diff --git a/src/mkdocstrings/templates/python/mkdocs/exceptions.html b/src/mkdocstrings/templates/python/mkdocs/exceptions.html index f5b592f5..677c867b 100644 --- a/src/mkdocstrings/templates/python/mkdocs/exceptions.html +++ b/src/mkdocstrings/templates/python/mkdocs/exceptions.html @@ -1,6 +1,6 @@ {{ log.debug() }}
-
Exceptions: +
Exceptions:
{% for exception in exceptions %}
{{ ("`" + exception.annotation + "`: " + exception.description)|convert_markdown(heading_level, html_id) }}
{% endfor %} diff --git a/src/mkdocstrings/templates/python/mkdocs/parameters.html b/src/mkdocstrings/templates/python/mkdocs/parameters.html index 39db7ea3..3eca4c14 100644 --- a/src/mkdocstrings/templates/python/mkdocs/parameters.html +++ b/src/mkdocstrings/templates/python/mkdocs/parameters.html @@ -1,6 +1,6 @@ {{ log.debug() }}
-
Parameters: +
Parameters:
{% for parameter in parameters %}
{{ ("**" + parameter.name + ":** " + ("`" + parameter.annotation + "` – " if parameter.annotation else "") + parameter.description)|convert_markdown(heading_level, html_id) }}
{% endfor %} diff --git a/src/mkdocstrings/templates/python/mkdocs/return.html b/src/mkdocstrings/templates/python/mkdocs/return.html index 270823c4..b38d61d1 100644 --- a/src/mkdocstrings/templates/python/mkdocs/return.html +++ b/src/mkdocstrings/templates/python/mkdocs/return.html @@ -1,5 +1,5 @@ {{ log.debug() }}
-
Returns: +
Returns:
{{ (("`" + return.annotation + "` – " if return.annotation else "") + return.description)|convert_markdown(heading_level, html_id) }}
From 0f32b701f6911af1745ccc88ff4312d734e282eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Thu, 23 Sep 2021 21:04:04 +0200 Subject: [PATCH 4/4] chore: Prepare release 0.16.1 --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ef6d4eac..557f070d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [0.16.1](https://github.com/mkdocstrings/mkdocstrings/releases/tag/0.16.1) - 2021-09-23 + +[Compare with 0.16.0](https://github.com/mkdocstrings/mkdocstrings/compare/0.16.0...0.16.1) + +### Bug Fixes +- Fix ReadTheDocs "return" template ([598621b](https://github.com/mkdocstrings/mkdocstrings/commit/598621bff29d2aeda0e14f350cda36c1a1f418d5) by Timothée Mazzucotelli). + + ## [0.16.0](https://github.com/mkdocstrings/mkdocstrings/releases/tag/0.16.0) - 2021-09-20 [Compare with 0.15.0](https://github.com/mkdocstrings/mkdocstrings/compare/0.15.0...0.16.0)