diff --git a/.copier-answers.yml b/.copier-answers.yml
index f2e7c7ac..97027f2b 100644
--- a/.copier-answers.yml
+++ b/.copier-answers.yml
@@ -1,5 +1,5 @@
# Changes here will be overwritten by Copier
-_commit: 0.9.0
+_commit: 0.9.7
_src_path: gh:pawamoy/copier-pdm
author_email: pawamoy@pm.me
author_fullname: Timothée Mazzucotelli
diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml
index c71a8d4e..cf5764f4 100644
--- a/.github/FUNDING.yml
+++ b/.github/FUNDING.yml
@@ -1,7 +1,4 @@
github:
- - pawamoy
-ko_fi: pawamoy
-liberapay: pawamoy
-patreon: pawamoy
+- pawamoy
custom:
- - https://www.paypal.me/pawamoy
+- https://www.paypal.me/pawamoy
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index a9b12e44..201e8d52 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -28,7 +28,7 @@ jobs:
uses: actions/checkout@v2
- name: Set up PDM
- uses: pdm-project/setup-pdm@v2.5
+ uses: pdm-project/setup-pdm@v2.6
with:
python-version: "3.8"
@@ -86,7 +86,7 @@ jobs:
uses: actions/checkout@v2
- name: Set up PDM
- uses: pdm-project/setup-pdm@v2.5
+ uses: pdm-project/setup-pdm@v2.6
with:
python-version: ${{ matrix.python-version }}
@@ -105,7 +105,7 @@ jobs:
key: tests-cache-${{ runner.os }}-${{ matrix.python-version }}
- name: Install dependencies
- run: pdm install -G duty -G tests
+ run: pdm install --no-editable -G duty -G tests
- name: Run the test suite
run: pdm run duty test
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ea3c8079..a13eb8dd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,34 @@ 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.7.0](https://github.com/mkdocstrings/python/releases/tag/0.7.0) - 2022-05-28
+
+[Compare with 0.6.6](https://github.com/mkdocstrings/python/compare/0.6.6...0.7.0)
+
+### Packaging / Dependencies
+- Depend on mkdocstrings 0.19 ([b6a9a47](https://github.com/mkdocstrings/python/commit/b6a9a4799980c4590a7ce2838e12653f40e43be3) by Timothée Mazzucotelli).
+
+### Features
+- Add config option for annotations paths verbosity ([b6c9893](https://github.com/mkdocstrings/python/commit/b6c989315fb028813a919319ad1818b0b1f597ac) by Timothée Mazzucotelli).
+- Use sections titles in SpaCy-styled docstrings ([fe16b54](https://github.com/mkdocstrings/python/commit/fe16b54aea60473575343e3a3c428567b701bd7d) by Timothée Mazzucotelli).
+- Wrap objects names in spans to allow custom styling ([0822ff9](https://github.com/mkdocstrings/python/commit/0822ff9d3ffd3fb71fb619a8b557160661eff9c3) by Timothée Mazzucotelli). [Issue mkdocstrings/mkdocstrings#240](https://github.com/mkdocstrings/mkdocstrings/issues/240)
+- Add Jinja blocks around docstring section styles ([aaa79ee](https://github.com/mkdocstrings/python/commit/aaa79eea40d49a64a69badbe732bf5211fbf055a) by Timothée Mazzucotelli).
+- Add members and filters options ([24a6136](https://github.com/mkdocstrings/python/commit/24a6136ee6c04a6a49ee74b20e65177868a10ea7) by Timothée Mazzucotelli).
+- Add paths option ([dd41182](https://github.com/mkdocstrings/python/commit/dd41182c210f0bb2675ead162adaa01dbbb1949f) by Timothée Mazzucotelli). [Issue mkdocstrings/mkdocstrings#311](https://github.com/mkdocstrings/mkdocstrings/issues/311), [PR #20](https://github.com/mkdocstrings/python/issues/20)
+
+### Bug Fixes
+- Fix CSS class on labels ([312a709](https://github.com/mkdocstrings/python/commit/312a7092394aab968032cf08195af7445a85052f) by Timothée Mazzucotelli).
+- Fix categories rendering ([6407cf4](https://github.com/mkdocstrings/python/commit/6407cf4f2375c894e0c528e932e9b76774a6455e) by Timothée Mazzucotelli). [Issue #14](https://github.com/mkdocstrings/python/issues/14)
+
+### Code Refactoring
+- Disable `show_submodules` by default ([480d0c3](https://github.com/mkdocstrings/python/commit/480d0c373904713313ec76b6e2570dbc35eb527b) by Timothée Mazzucotelli).
+- Merge default configuration options in handler ([347ce76](https://github.com/mkdocstrings/python/commit/347ce76d074c0e3841df2d5162b54d3938d00453) by Timothée Mazzucotelli).
+- Reduce number of template debug logs ([8fed314](https://github.com/mkdocstrings/python/commit/8fed314243e3981fc7b527c69cee628e87b10220) by Timothée Mazzucotelli).
+- Respect `show_root_full_path` for ToC entries (hidden headings) ([8f4c853](https://github.com/mkdocstrings/python/commit/8f4c85328e8b4a45db77f9fc3e536a5008686f37) by Timothée Mazzucotelli).
+- Bring consistency on headings style ([59104c4](https://github.com/mkdocstrings/python/commit/59104c4c51c86c774eed76d8508f9f4d3db5463f) by Timothée Mazzucotelli).
+- Stop using deprecated base classes ([d5ea1c5](https://github.com/mkdocstrings/python/commit/d5ea1c5cf7884d8c019145f73685a84218e69840) by Timothée Mazzucotelli).
+
+
## [0.6.6](https://github.com/mkdocstrings/python/releases/tag/0.6.6) - 2022-03-06
[Compare with 0.6.5](https://github.com/mkdocstrings/python/compare/0.6.5...0.6.6)
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 734eb110..ba0c5d2b 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -14,21 +14,21 @@ cd python
make setup
```
-!!! note
- If it fails for some reason,
- you'll need to install
- [PDM](https://github.com/pdm-project/pdm)
- manually.
-
- You can install it with:
-
- ```bash
- python3 -m pip install --user pipx
- pipx install pdm
- ```
-
- Now you can try running `make setup` again,
- or simply `pdm install`.
+> NOTE:
+> If it fails for some reason,
+> you'll need to install
+> [PDM](https://github.com/pdm-project/pdm)
+> manually.
+>
+> You can install it with:
+>
+> ```bash
+> python3 -m pip install --user pipx
+> pipx install pdm
+> ```
+>
+> Now you can try running `make setup` again,
+> or simply `pdm install`.
You now have the dependencies installed.
@@ -57,17 +57,14 @@ As usual:
1. create a new branch: `git checkout -b feature-or-bugfix-name`
1. edit the code and/or the documentation
-If you updated the documentation or the project dependencies:
-
-1. run `make docs-regen`
-1. run `make docs-serve`,
- go to http://localhost:8000 and check that everything looks good
-
**Before committing:**
1. run `make format` to auto-format the code
1. run `make check` to check everything (fix any warning)
1. run `make test` to run the tests (fix any issue)
+1. if you updated the documentation or the project dependencies:
+ 1. run `make docs-serve`
+ 1. go to http://localhost:8000 and check that everything looks good
1. follow our [commit message convention](#commit-message-convention)
If you are unsure about how to fix or ignore a warning,
diff --git a/README.md b/README.md
index 3cdd2c6d..f446ee8a 100644
--- a/README.md
+++ b/README.md
@@ -1,45 +1,34 @@
-# mkdocstrings-python
-
-[](https://github.com/mkdocstrings/python/actions?query=workflow%3Aci)
-[](https://mkdocstrings.github.io/python/)
-[](https://pypi.org/project/python/)
-[](https://gitpod.io/#https://github.com/mkdocstrings/python)
-[](https://gitter.im/mkdocstrings/python)
-
-A Python handler for [mkdocstrings](https://github.com/mkdocstrings/mkdocstrings).
-
-
-
-
-## Requirements
-
-mkdocstrings-python requires Python 3.7 or above.
-
-To install Python 3.7, I recommend using
-
-```bash
-# install pyenv
-git clone https://github.com/pyenv/pyenv ~/.pyenv
-
-# setup pyenv (you should also put these three lines in .bashrc or similar)
-export PATH="${HOME}/.pyenv/bin:${PATH}"
-export PYENV_ROOT="${HOME}/.pyenv"
-eval "$(pyenv init -)"
-
-# install Python 3.7
-pyenv install 3.7.12
-
-# make it available globally
-pyenv global system 3.7.12
-```
-pyenv.
A Python handler for mkdocstrings.
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

{text}"
- return Markup(text).format(**variables)
-
-
-@lru_cache(maxsize=1)
-def _get_black_formatter():
- try:
- from black import Mode, format_str
- except ModuleNotFoundError:
- logger.warning("Formatting signatures requires Black to be installed.")
- return lambda text, _: text
-
- def formatter(code, line_length): # noqa: WPS430
- mode = Mode(line_length=line_length)
- return format_str(code, mode=mode)
-
- return formatter
diff --git a/src/mkdocstrings_handlers/python/rendering.py b/src/mkdocstrings_handlers/python/rendering.py
new file mode 100644
index 00000000..8e5f7d85
--- /dev/null
+++ b/src/mkdocstrings_handlers/python/rendering.py
@@ -0,0 +1,209 @@
+"""This module implements rendering utilities."""
+
+from __future__ import annotations
+
+import enum
+import re
+import sys
+from functools import lru_cache
+from typing import Any, Pattern, Sequence
+
+from griffe.dataclasses import Alias, Object
+from markupsafe import Markup
+from mkdocstrings.handlers.base import CollectorItem
+from mkdocstrings.loggers import get_logger
+
+logger = get_logger(__name__)
+
+
+class Order(enum.Enum):
+ """Enumeration for the possible members ordering."""
+
+ alphabetical = "alphabetical"
+ source = "source"
+
+
+def _sort_key_alphabetical(item: CollectorItem) -> Any:
+ # chr(sys.maxunicode) is a string that contains the final unicode
+ # character, so if 'name' isn't found on the object, the item will go to
+ # the end of the list.
+ return item.name or chr(sys.maxunicode)
+
+
+def _sort_key_source(item: CollectorItem) -> Any:
+ # if 'lineno' is none, the item will go to the start of the list.
+ return item.lineno if item.lineno is not None else -1
+
+
+order_map = {
+ Order.alphabetical: _sort_key_alphabetical,
+ Order.source: _sort_key_source,
+}
+
+
+def do_format_code(code: str, line_length: int) -> str:
+ """Format code using Black.
+
+ Parameters:
+ code: The code to format.
+ line_length: The line length to give to Black.
+
+ Returns:
+ The same code, formatted.
+ """
+ code = code.strip()
+ if len(code) < line_length:
+ return code
+ formatter = _get_black_formatter()
+ return formatter(code, line_length)
+
+
+def do_format_signature(signature: str, line_length: int) -> str:
+ """Format a signature using Black.
+
+ Parameters:
+ signature: The signature to format.
+ line_length: The line length to give to Black.
+
+ Returns:
+ The same code, formatted.
+ """
+ code = signature.strip()
+ if len(code) < line_length:
+ return code
+ formatter = _get_black_formatter()
+ formatted = formatter(f"def {code}: pass", line_length)
+ # remove starting `def ` and trailing `: pass`
+ return formatted[4:-5].strip()[:-1]
+
+
+def do_order_members(
+ members: Sequence[Object | Alias],
+ order: Order,
+ members_list: list[str] | None,
+) -> Sequence[Object | Alias]:
+ """Order members given an ordering method.
+
+ Parameters:
+ members: The members to order.
+ order: The ordering method.
+ members_list: An optional member list (manual ordering).
+
+ Returns:
+ The same members, ordered.
+ """
+ if members_list:
+ sorted_members = []
+ members_dict = {member.name: member for member in members}
+ for name in members_list:
+ if name in members_dict:
+ sorted_members.append(members_dict[name])
+ return sorted_members
+ return sorted(members, key=order_map[order])
+
+
+def do_crossref(path: str, brief: bool = True) -> Markup:
+ """Filter to create cross-references.
+
+ Parameters:
+ path: The path to link to.
+ brief: Show only the last part of the path, add full path as hover.
+
+ Returns:
+ Markup text.
+ """
+ full_path = path
+ if brief:
+ path = full_path.split(".")[-1]
+ return Markup("{path}").format(full_path=full_path, path=path)
+
+
+def do_multi_crossref(text: str, code: bool = True) -> Markup:
+ """Filter to create cross-references.
+
+ Parameters:
+ text: The text to scan.
+ code: Whether to wrap the result in a code tag.
+
+ Returns:
+ Markup text.
+ """
+ group_number = 0
+ variables = {}
+
+ def repl(match): # noqa: WPS430
+ nonlocal group_number # noqa: WPS420
+ group_number += 1
+ path = match.group()
+ path_var = f"path{group_number}"
+ variables[path_var] = path
+ return f"{{{path_var}}}"
+
+ text = re.sub(r"([\w.]+)", repl, text)
+ if code:
+ text = f"{text}"
+ return Markup(text).format(**variables)
+
+
+def _keep_object(name, filters):
+ keep = None
+ rules = set()
+ for regex, exclude in filters:
+ rules.add(exclude)
+ if regex.search(name):
+ keep = not exclude
+ if keep is None:
+ if rules == {False}: # noqa: WPS531
+ # only included stuff, no match = reject
+ return False
+ # only excluded stuff, or included and excluded stuff, no match = keep
+ return True
+ return keep
+
+
+def do_filter_objects(
+ objects_dictionary: dict[str, Object | Alias],
+ filters: list[tuple[bool, Pattern]] | None = None,
+ members_list: list[str] | None = None,
+ keep_no_docstrings: bool = True,
+) -> list[Object | Alias]:
+ """Filter a dictionary of objects based on their docstrings.
+
+ Parameters:
+ objects_dictionary: The dictionary of objects.
+ filters: Filters to apply, based on members' names.
+ Each element is a tuple: a pattern, and a boolean indicating whether
+ to reject the object if the pattern matches.
+ members_list: An optional, explicit list of members to keep.
+ When given and empty, return an empty list.
+ When given and not empty, ignore filters and docstrings presence/absence.
+ keep_no_docstrings: Whether to keep objects with no/empty docstrings (recursive check).
+
+ Returns:
+ A list of objects.
+ """
+ if members_list is not None:
+ if not members_list:
+ return []
+ return [obj for obj in objects_dictionary.values() if obj.name in set(members_list)]
+ objects = list(objects_dictionary.values())
+ if filters:
+ objects = [obj for obj in objects if _keep_object(obj.name, filters)]
+ if keep_no_docstrings:
+ return objects
+ return [obj for obj in objects if obj.has_docstrings]
+
+
+@lru_cache(maxsize=1)
+def _get_black_formatter():
+ try:
+ from black import Mode, format_str
+ except ModuleNotFoundError:
+ logger.warning("Formatting signatures requires Black to be installed.")
+ return lambda text, _: text
+
+ def formatter(code, line_length): # noqa: WPS430
+ mode = Mode(line_length=line_length)
+ return format_str(code, mode=mode)
+
+ return formatter
diff --git a/src/mkdocstrings_handlers/python/templates/material/_base/attribute.html b/src/mkdocstrings_handlers/python/templates/material/_base/attribute.html
index 527c38fd..019e7fae 100644
--- a/src/mkdocstrings_handlers/python/templates/material/_base/attribute.html
+++ b/src/mkdocstrings_handlers/python/templates/material/_base/attribute.html
@@ -1,72 +1,69 @@
{{ log.debug("Rendering " + attribute.path) }}
-{% if config.show_if_no_docstring or attribute.has_docstrings %}
- {% if show_full_path %}{{ class.path }}{% else %}{{ class.name }}{% endif %}
{% endif %}
- {% filter heading(heading_level,
- role="class",
- id=html_id,
- class="doc doc-heading",
- toc_label=class.name) %}
+ {% with labels = class.labels %}
+ {% include "labels.html" with context %}
+ {% endwith %}
- {% if config.separate_signature %}
- {% if show_full_path %}{{ class.path }}{% else %}{{ class.name }}{% endif %}
- {% elif config.merge_init_into_class and "__init__" in class.members -%}
- {%- with function = class.members["__init__"] -%}
- {%- filter highlight(language="python", inline=True) -%}
- {% if show_full_path %}{{ class.path }}{% else %}{{ class.name }}{% endif %}
- {%- include "signature.html" with context -%}
- {%- endfilter -%}
- {%- endwith -%}
- {% else %}
- {% if show_full_path %}{{ class.path }}{% else %}{{ class.name }}{% endif %}
- {% endif %}
+ {% endfilter %}
- {% with labels = class.labels %}
- {% include "labels.html" with context %}
+ {% if config.separate_signature and config.merge_init_into_class %}
+ {% if "__init__" in class.members %}
+ {% with function = class.members["__init__"] %}
+ {% filter highlight(language="python", inline=False) %}
+ {% filter format_signature(config.line_length) %}
+ {% if show_full_path %}{{ class.path }}{% else %}{{ class.name }}{% endif %}
+ {% include "signature.html" with context %}
+ {% endfilter %}
+ {% endfilter %}
{% endwith %}
+ {% endif %}
+ {% endif %}
+ {% else %}
+ {% if config.show_root_toc_entry %}
+ {% filter heading(heading_level,
+ role="class",
+ id=html_id,
+ toc_label=class.path if config.show_root_full_path else class.name,
+ hidden=True) %}
{% endfilter %}
+ {% endif %}
+ {% set heading_level = heading_level - 1 %}
+ {% endif %}
+
+
+ Bases: {% for expression in class.bases -%}
+ {% include "expression.html" with context %}{% if not loop.last %}, {% endif %}
+ {% endfor -%}
+
- Bases: {% for expression in class.bases -%}
- {% include "expression.html" with context %}{% if not loop.last %}, {% endif %}
- {% endfor -%}
-
{{ class.relative_filepath }}{{ class.relative_filepath }}{{ class.relative_filepath }}{{ section.title or "Attributes:" }}
{{ section.title or "Attributes:" }}
| ATTRIBUTE | +{{ (section.title or "ATTRIBUTE").rstrip(":").upper() }} | DESCRIPTION |
|---|
{{ section.title or "Other Parameters:" }}
{{ section.title or "Other Parameters:" }}
| PARAMETER | +{{ (section.title or "PARAMETER").rstrip(":").upper() }} | DESCRIPTION |
|---|
{{ section.title or "Parameters:" }}
{{ section.title or "Parameters:" }}
| PARAMETER | +{{ (section.title or "PARAMETER").rstrip(":").upper() }} | DESCRIPTION |
|---|
{{ section.title or "Raises:" }}
{{ section.title or "Raises:" }}
| RAISES | +{{ (section.title or "RAISES").rstrip(":").upper() }} | DESCRIPTION |
|---|
{{ section.title or "Receives:" }}
{{ section.title or "Receives:" }}
| RECEIVES | +{{ (section.title or "RECEIVES").rstrip(":").upper() }} | DESCRIPTION |
|---|
{{ section.title or "Returns:" }}
{{ section.title or "Returns:" }}
| RETURNS | +{{ (section.title or "RETURNS").rstrip(":").upper() }} | DESCRIPTION |
|---|
{{ section.title or "Warns:" }}
{{ section.title or "Warns:" }}
| WARNS | +{{ (section.title or "WARNS").rstrip(":").upper() }} | DESCRIPTION |
|---|
{{ section.title or "Yields:" }}
{{ section.title or "Yields:" }}
| YIELDS | +{{ (section.title or "YIELDS").rstrip(":").upper() }} | DESCRIPTION |
|---|
{{ function.relative_filepath }}{{ function.relative_filepath }}{{ label }}
{% endfor %}
diff --git a/src/mkdocstrings_handlers/python/templates/material/_base/module.html b/src/mkdocstrings_handlers/python/templates/material/_base/module.html
index 54e4d4e4..8e14d354 100644
--- a/src/mkdocstrings_handlers/python/templates/material/_base/module.html
+++ b/src/mkdocstrings_handlers/python/templates/material/_base/module.html
@@ -1,60 +1,63 @@
{{ log.debug("Rendering " + module.path) }}
-{% if config.show_if_no_docstring or module.has_docstrings %}
- {{ module_name }}
+ {% endif %}
+ {% endwith %}
- {% if not root or config.show_root_heading %}
+ {% with labels = module.labels %}
+ {% include "labels.html" with context %}
+ {% endwith %}
- {% if root %}
- {% set show_full_path = config.show_root_full_path %}
- {% set root_members = True %}
- {% elif root_members %}
- {% set show_full_path = config.show_root_members_full_path or config.show_object_full_path %}
- {% set root_members = False %}
- {% else %}
- {% set show_full_path = config.show_object_full_path %}
- {% endif %}
+ {% endfilter %}
+ {% else %}
+ {% if config.show_root_toc_entry %}
{% filter heading(heading_level,
role="module",
id=html_id,
- class="doc doc-heading",
- toc_label=module.name) %}
-
- {% if show_full_path %}{{ module.path }}{% else %}{{ module.name }}{% endif %}
-
- {% with labels = module.labels %}
- {% include "labels.html" with context %}
- {% endwith %}
-
+ toc_label=module.path if config.show_root_full_path else module.name,
+ hidden=True) %}
{% endfilter %}
-
- {% else %}
- {% if config.show_root_toc_entry %}
- {% filter heading(heading_level,
- role="module",
- id=html_id,
- toc_label=module.path,
- hidden=True) %}
- {% endfilter %}
- {% endif %}
- {% set heading_level = heading_level - 1 %}
{% endif %}
-
- This is an example.
" in rendered + assert "print" in rendered + assert "Hello" in rendered diff --git a/tests/test_renderer.py b/tests/test_renderer.py deleted file mode 100644 index 31232e12..00000000 --- a/tests/test_renderer.py +++ /dev/null @@ -1,45 +0,0 @@ -"""Tests for the `renderer` module.""" - -import pytest -from griffe.docstrings.dataclasses import DocstringSection, DocstringSectionKind - - -@pytest.mark.parametrize( - "renderer", - [ - {"theme": "mkdocs"}, - {"theme": "readthedocs"}, - {"theme": {"name": "material"}}, - ], - indirect=["renderer"], -) -def test_render_docstring_examples_section(renderer): - """Assert docstrings' examples section can be rendered. - - Parameters: - renderer: A renderer instance (parametrized). - """ - section = DocstringSection( - DocstringSectionKind.examples, - value=[ - (DocstringSectionKind.text, "This is an example."), - (DocstringSectionKind.examples, ">>> print('Hello')\nHello"), - ], - ) - template = renderer.env.get_template("docstring/examples.html") - rendered = template.render(section=section) - assert "This is an example.
" in rendered - assert "print" in rendered - assert "Hello" in rendered - - -def test_format_code_and_signature(renderer): - """Assert code and signatures can be Black-formatted. - - Parameters: - renderer: A renderer instance (parametrized). - """ - assert renderer.do_format_code("print('Hello')", 100) - assert renderer.do_format_code('print("Hello")', 100) - assert renderer.do_format_signature("(param: str = 'hello') -> 'Class'", 100) - assert renderer.do_format_signature('(param: str = "hello") -> "Class"', 100) diff --git a/tests/test_rendering.py b/tests/test_rendering.py new file mode 100644 index 00000000..533eaf34 --- /dev/null +++ b/tests/test_rendering.py @@ -0,0 +1,42 @@ +"""Tests for the `rendering` module.""" + +import re +from dataclasses import dataclass + +import pytest + +from mkdocstrings_handlers.python import rendering + + +def test_format_code_and_signature(): + """Assert code and signatures can be Black-formatted.""" + assert rendering.do_format_code("print('Hello')", 100) + assert rendering.do_format_code('print("Hello")', 100) + assert rendering.do_format_signature("(param: str = 'hello') -> 'Class'", 100) + assert rendering.do_format_signature('(param: str = "hello") -> "Class"', 100) + + +@dataclass +class _FakeObject: + name: str + + +@pytest.mark.parametrize( + ("names", "filter_params", "expected_names"), + [ + (["aa", "ab", "ac", "da"], {"filters": [(re.compile("^a[^b]"), True)]}, {"ab", "da"}), + (["aa", "ab", "ac", "da"], {"members_list": ["aa", "ab"]}, {"aa", "ab"}), + ], +) +def test_filter_objects(names, filter_params, expected_names): + """Assert the objects filter works correctly. + + Parameters: + names: Names of the objects. + filter_params: Parameters passed to the filter function. + expected_names: Names expected to be kept. + """ + objects = {name: _FakeObject(name) for name in names} + filtered = rendering.do_filter_objects(objects, **filter_params) + filtered_names = {obj.name for obj in filtered} + assert set(filtered_names) == set(expected_names) diff --git a/tests/test_themes.py b/tests/test_themes.py index 44426fb6..b1e7d5d5 100644 --- a/tests/test_themes.py +++ b/tests/test_themes.py @@ -35,6 +35,6 @@ def test_render_themes_templates_python(module, plugin): plugin: Pytest fixture: [tests.conftest.fixture_plugin][]. """ handler = plugin.handlers.get_handler("python") - handler.renderer._update_env(plugin.md, plugin.handlers._config) # noqa: WPS437 - data = handler.collector.collect(module, {}) - handler.renderer.render(data, {}) + handler._update_env(plugin.md, plugin.handlers._config) # noqa: WPS437 + data = handler.collect(module, {}) + handler.render(data, {})