From 065c890beba3091724d16bbbbfff85c4343d8a79 Mon Sep 17 00:00:00 2001 From: Oleh Prypin Date: Sat, 14 Oct 2023 04:53:52 +0200 Subject: [PATCH] Refactor to use new static type checking features (#180) * Use new static type checking features * Use class-based config and attributes from MkDocs 1.4 * Use dataclass from Python 3.8 * Refactor: put runtime attributes onto the plugin rather than onto the config - also statically typed Extra: actually depend on MkDocs, it is a dependency --- README.md | 4 +- locale/es/README.md | 4 +- locale/es/README.md.po | 9 +- locale/fr/README.md | 4 +- locale/fr/README.md.po | 9 +- pyproject.toml | 5 +- src/mkdocs_include_markdown_plugin/config.py | 85 +++---------- .../directive.py | 39 +++--- src/mkdocs_include_markdown_plugin/event.py | 116 +++++++----------- src/mkdocs_include_markdown_plugin/plugin.py | 81 ++++++------ src/mkdocs_include_markdown_plugin/process.py | 2 +- tests/conftest.py | 11 ++ .../test_cache_integration.py | 2 + tests/test_unit/test_arguments.py | 65 ++++++++-- tests/test_unit/test_config.py | 16 +-- tests/test_unit/test_encoding.py | 9 +- tests/test_unit/test_exclude.py | 2 + tests/test_unit/test_glob_include.py | 7 +- tests/test_unit/test_include.py | 3 +- tests/test_unit/test_include_markdown.py | 8 +- tests/test_unit/test_logging.py | 3 +- tests/test_unit/test_nested_includes.py | 6 +- 22 files changed, 242 insertions(+), 248 deletions(-) diff --git a/README.md b/README.md index ee959a5..e03d046 100644 --- a/README.md +++ b/README.md @@ -277,8 +277,8 @@ Includes the content of a file or a group of files. [license-image]: https://img.shields.io/pypi/l/mkdocs-include-markdown-plugin?color=light-green&logo=apache&logoColor=white [license-link]: https://github.com/mondeja/mkdocs-include-markdown-plugin/blob/master/LICENSE [platformdirs]: https://pypi.org/project/platformdirs/ -[cibuildwheel-470]: https://github.com/joerick/cibuildwheel/issues/470 -[cibuildwheel-repo-link]: https://github.com/joerick/cibuildwheel +[cibuildwheel-470]: https://github.com/pypa/cibuildwheel/issues/470 +[cibuildwheel-repo-link]: https://github.com/pypa/cibuildwheel [es-readme-link]: https://github.com/mondeja/mkdocs-include-markdown-plugin/blob/master/locale/es/README.md [fr-readme-link]: https://github.com/mondeja/mkdocs-include-markdown-plugin/blob/master/locale/fr/README.md [Bash wildcard globs]: https://facelessuser.github.io/wcmatch/glob/#syntax diff --git a/locale/es/README.md b/locale/es/README.md index 71e6460..d6e6970 100644 --- a/locale/es/README.md +++ b/locale/es/README.md @@ -266,8 +266,8 @@ separar este plugin de la documentación de [license-image]: https://img.shields.io/pypi/l/mkdocs-include-markdown-plugin?color=light-green&logo=apache&logoColor=white [license-link]: https://github.com/mondeja/mkdocs-include-markdown-plugin/blob/master/LICENSE [platformdirs]: https://pypi.org/project/platformdirs/ -[cibuildwheel-470]: https://github.com/joerick/cibuildwheel/issues/470 -[cibuildwheel-repo-link]: https://github.com/joerick/cibuildwheel +[cibuildwheel-470]: https://github.com/pypa/cibuildwheel/issues/470 +[cibuildwheel-repo-link]: https://github.com/pypa/cibuildwheel [es-readme-link]: https://github.com/mondeja/mkdocs-include-markdown-plugin/blob/master/locale/es/README.md [fr-readme-link]: https://github.com/mondeja/mkdocs-include-markdown-plugin/blob/master/locale/fr/README.md [Bash wildcard globs]: https://facelessuser.github.io/wcmatch/glob/#syntax diff --git a/locale/es/README.md.po b/locale/es/README.md.po index 8aead37..91d6bf7 100644 --- a/locale/es/README.md.po +++ b/locale/es/README.md.po @@ -56,12 +56,11 @@ msgstr "" "[tests-link]: https://github.com/mondeja/mkdocs-include-markdown-" "plugin/actions?query=workflow%3ACI" -msgid "[cibuildwheel-470]: https://github.com/joerick/cibuildwheel/issues/470" -msgstr "" -"[cibuildwheel-470]: https://github.com/joerick/cibuildwheel/issues/470" +msgid "[cibuildwheel-470]: https://github.com/pypa/cibuildwheel/issues/470" +msgstr "[cibuildwheel-470]: https://github.com/pypa/cibuildwheel/issues/470" -msgid "[cibuildwheel-repo-link]: https://github.com/joerick/cibuildwheel" -msgstr "[cibuildwheel-repo-link]: https://github.com/joerick/cibuildwheel" +msgid "[cibuildwheel-repo-link]: https://github.com/pypa/cibuildwheel" +msgstr "[cibuildwheel-repo-link]: https://github.com/pypa/cibuildwheel" msgid "Read this document in other languages:" msgstr "Lee este documento en otros idiomas:" diff --git a/locale/fr/README.md b/locale/fr/README.md index d9fba28..967ea62 100644 --- a/locale/fr/README.md +++ b/locale/fr/README.md @@ -263,8 +263,8 @@ autorisations][cibuildwheel-470] pour séparer ce plugin de la documentation de [license-image]: https://img.shields.io/pypi/l/mkdocs-include-markdown-plugin?color=light-green&logo=apache&logoColor=white [license-link]: https://github.com/mondeja/mkdocs-include-markdown-plugin/blob/master/LICENSE [platformdirs]: https://pypi.org/project/platformdirs/ -[cibuildwheel-470]: https://github.com/joerick/cibuildwheel/issues/470 -[cibuildwheel-repo-link]: https://github.com/joerick/cibuildwheel +[cibuildwheel-470]: https://github.com/pypa/cibuildwheel/issues/470 +[cibuildwheel-repo-link]: https://github.com/pypa/cibuildwheel [es-readme-link]: https://github.com/mondeja/mkdocs-include-markdown-plugin/blob/master/locale/es/README.md [fr-readme-link]: https://github.com/mondeja/mkdocs-include-markdown-plugin/blob/master/locale/fr/README.md [Bash wildcard globs]: https://facelessuser.github.io/wcmatch/glob/#syntax diff --git a/locale/fr/README.md.po b/locale/fr/README.md.po index 7752807..5717d02 100644 --- a/locale/fr/README.md.po +++ b/locale/fr/README.md.po @@ -69,12 +69,11 @@ msgstr "" "[tests-link]: https://github.com/mondeja/mkdocs-include-markdown-" "plugin/actions?query=workflow%3ACI" -msgid "[cibuildwheel-470]: https://github.com/joerick/cibuildwheel/issues/470" -msgstr "" -"[cibuildwheel-470]: https://github.com/joerick/cibuildwheel/issues/470" +msgid "[cibuildwheel-470]: https://github.com/pypa/cibuildwheel/issues/470" +msgstr "[cibuildwheel-470]: https://github.com/pypa/cibuildwheel/issues/470" -msgid "[cibuildwheel-repo-link]: https://github.com/joerick/cibuildwheel" -msgstr "[cibuildwheel-repo-link]: https://github.com/joerick/cibuildwheel" +msgid "[cibuildwheel-repo-link]: https://github.com/pypa/cibuildwheel" +msgstr "[cibuildwheel-repo-link]: https://github.com/pypa/cibuildwheel" msgid "" "[es-readme-link]: https://github.com/mondeja/mkdocs-include-markdown-" diff --git a/pyproject.toml b/pyproject.toml index 9dc10b0..1a02bb8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,7 +22,10 @@ classifiers = [ "Programming Language :: Python :: 3.12" ] keywords = ["markdown", "mkdocs", "includer", "plugin"] -dependencies = ["wcmatch>=8,<9"] +dependencies = [ + "mkdocs>=1.4", + "wcmatch>=8,<9" +] [[project.authors]] name = "Joe Rickerby" diff --git a/src/mkdocs_include_markdown_plugin/config.py b/src/mkdocs_include_markdown_plugin/config.py index 6bd5d58..251f55c 100644 --- a/src/mkdocs_include_markdown_plugin/config.py +++ b/src/mkdocs_include_markdown_plugin/config.py @@ -2,6 +2,7 @@ from __future__ import annotations +from mkdocs.config.base import Config from mkdocs.config.config_options import ( ListOfItems, Optional, @@ -9,73 +10,17 @@ ) -CONFIG_DEFAULTS = { - 'opening-tag': '{%', - 'closing-tag': '%}', - 'encoding': 'utf-8', - 'preserve-includer-indent': True, - 'dedent': False, - 'trailing-newlines': True, - 'comments': True, - 'rewrite-relative-urls': True, - 'heading-offset': 0, - 'start': None, - 'end': None, - 'exclude': None, - 'cache': 0, -} - -CONFIG_SCHEME = ( - ( - 'opening_tag', - MkType(str, default=CONFIG_DEFAULTS['opening-tag']), - ), - ( - 'closing_tag', - MkType(str, default=CONFIG_DEFAULTS['closing-tag']), - ), - ( - 'encoding', - MkType(str, default=CONFIG_DEFAULTS['encoding']), - ), - ( - 'preserve_includer_indent', - MkType(bool, default=CONFIG_DEFAULTS['preserve-includer-indent']), - ), - ( - 'dedent', - MkType(bool, default=CONFIG_DEFAULTS['dedent']), - ), - ( - 'trailing_newlines', - MkType(bool, default=CONFIG_DEFAULTS['trailing-newlines']), - ), - ( - 'comments', - MkType(bool, default=CONFIG_DEFAULTS['comments']), - ), - ( - 'rewrite_relative_urls', - MkType(bool, default=CONFIG_DEFAULTS['rewrite-relative-urls']), - ), - ( - 'heading_offset', - MkType(int, default=CONFIG_DEFAULTS['heading-offset']), - ), - ( - 'start', - MkType(str, default=CONFIG_DEFAULTS['start']), - ), - ( - 'end', - MkType(str, default=CONFIG_DEFAULTS['end']), - ), - ( - 'exclude', - Optional(ListOfItems(MkType(str))), - ), - ( - 'cache', - MkType(int, default=CONFIG_DEFAULTS['cache']), - ), -) +class PluginConfig(Config): # noqa: D101 + opening_tag = MkType(str, default='{%') + closing_tag = MkType(str, default='%}') + encoding = MkType(str, default='utf-8') + preserve_includer_indent = MkType(bool, default=True) + dedent = MkType(bool, default=False) + trailing_newlines = MkType(bool, default=True) + comments = MkType(bool, default=True) + rewrite_relative_urls = MkType(bool, default=True) + heading_offset = MkType(int, default=0) + start = Optional(MkType(str)) + end = Optional(MkType(str)) + exclude = ListOfItems(MkType(str), default=[]) + cache = MkType(int, default=0) diff --git a/src/mkdocs_include_markdown_plugin/directive.py b/src/mkdocs_include_markdown_plugin/directive.py index f14ec7a..c1efaba 100644 --- a/src/mkdocs_include_markdown_plugin/directive.py +++ b/src/mkdocs_include_markdown_plugin/directive.py @@ -5,6 +5,7 @@ import os import re import string +from dataclasses import dataclass from typing import TYPE_CHECKING from wcmatch import glob @@ -12,13 +13,15 @@ from mkdocs_include_markdown_plugin import process +@dataclass +class DirectiveBoolArgument: # noqa: D101 + value: bool + regex: re.Pattern[str] + + if TYPE_CHECKING: from typing import TypedDict - class DirectiveBoolArgument(TypedDict): # noqa: D101 - value: bool - regex: re.Pattern[str] - DirectiveBoolArgumentsDict = dict[str, DirectiveBoolArgument] DefaultValues = TypedDict( @@ -30,8 +33,8 @@ class DirectiveBoolArgument(TypedDict): # noqa: D101 'comments': bool, 'rewrite-relative-urls': bool, 'heading-offset': int, - 'start': str, - 'end': str, + 'start': str | None, + 'end': str | None, }, ) @@ -102,9 +105,9 @@ def parse_filename_argument( match: re.Match[str], ) -> tuple[str | None, str | None]: """Return filename argument matched by ``match``.""" - raw_filename = match.group('double_quoted_filename') + raw_filename = match['double_quoted_filename'] if raw_filename is None: - raw_filename = match.group('single_quoted_filename') + raw_filename = match['single_quoted_filename'] if raw_filename is None: filename = None else: @@ -116,9 +119,9 @@ def parse_filename_argument( def parse_string_argument(match: re.Match[str]) -> str | None: """Return the string argument matched by ``match``.""" - value = match.group(1) + value = match[1] if value is None: - value = match.group(3) + value = match[3] if value is not None: value = value.replace("\\'", "'") else: @@ -152,20 +155,18 @@ def parse_bool_options( bool_options: dict[str, DirectiveBoolArgument] = {} for option_name in option_names: - bool_options[option_name] = { - 'value': defaults[option_name], # type: ignore - 'regex': ARGUMENT_REGEXES[option_name], - } + bool_options[option_name] = DirectiveBoolArgument( + value=defaults[option_name], # type: ignore + regex=ARGUMENT_REGEXES[option_name], + ) for arg_name, arg in bool_options.items(): - bool_arg_match = arg['regex'].search(arguments_string) + bool_arg_match = arg.regex.search(arguments_string) if bool_arg_match is None: continue try: - bool_options[arg_name]['value'] = TRUE_FALSE_STR_BOOL[ - bool_arg_match.group( - 1, - ) or TRUE_FALSE_BOOL_STR[arg['value']] + bool_options[arg_name].value = TRUE_FALSE_STR_BOOL[ + bool_arg_match[1] or TRUE_FALSE_BOOL_STR[arg.value] ] except KeyError: invalid_args.append(arg_name) diff --git a/src/mkdocs_include_markdown_plugin/event.py b/src/mkdocs_include_markdown_plugin/event.py index 99b19fd..0867642 100644 --- a/src/mkdocs_include_markdown_plugin/event.py +++ b/src/mkdocs_include_markdown_plugin/event.py @@ -7,19 +7,17 @@ import os import re import textwrap -from collections.abc import MutableMapping -from typing import TYPE_CHECKING, Any +from dataclasses import dataclass +from typing import TYPE_CHECKING from mkdocs.exceptions import PluginError from wcmatch import glob from mkdocs_include_markdown_plugin import process from mkdocs_include_markdown_plugin.cache import Cache -from mkdocs_include_markdown_plugin.config import CONFIG_DEFAULTS from mkdocs_include_markdown_plugin.directive import ( ARGUMENT_REGEXES, GLOB_FLAGS, - create_include_tag, parse_bool_options, parse_filename_argument, parse_string_argument, @@ -35,6 +33,7 @@ from mkdocs.structure.pages import Page from mkdocs_include_markdown_plugin.directive import DefaultValues + from mkdocs_include_markdown_plugin.plugin import IncludeMarkdownPlugin IncludeTags = TypedDict( 'IncludeTags', { @@ -43,8 +42,10 @@ }, ) - class Settings(TypedDict): # noqa: D101 - exclude: list[str] | None + +@dataclass +class Settings: # noqa: D101 + exclude: list[str] | None logger = logging.getLogger('mkdocs.plugins.mkdocs_include_markdown_plugin') @@ -72,7 +73,7 @@ def found_include_tag( # noqa: PLR0912, PLR0915 ) -> str: directive_match_start = match.start() - includer_indent = match.group('_includer_indent') + includer_indent = match['_includer_indent'] filename, raw_filename = parse_filename_argument(match) if filename is None: @@ -86,17 +87,17 @@ def found_include_tag( # noqa: PLR0912, PLR0915 f':{lineno}', ) - arguments_string = match.group('arguments') + arguments_string = match['arguments'] exclude_match = ARGUMENT_REGEXES['exclude'].search(arguments_string) ignore_paths = [] - if settings['exclude'] is not None: + if settings.exclude: ignore_paths.extend( glob.glob( [ os.path.join(docs_dir, fp) if not os.path.isabs(fp) - else fp for fp in settings['exclude'] + else fp for fp in settings.exclude ], flags=GLOB_FLAGS, root_dir=docs_dir, @@ -240,16 +241,16 @@ def found_include_tag( # noqa: PLR0912, PLR0915 ) # trailing newlines right stripping - if not bool_options['trailing-newlines']['value']: + if not bool_options['trailing-newlines'].value: new_text_to_include = process.rstrip_trailing_newlines( new_text_to_include, ) - if bool_options['dedent']['value']: + if bool_options['dedent'].value: new_text_to_include = textwrap.dedent(new_text_to_include) # includer indentation preservation - if bool_options['preserve-includer-indent']['value']: + if bool_options['preserve-includer-indent'].value: new_text_to_include = ''.join( includer_indent + line for line in ( @@ -304,7 +305,7 @@ def found_include_markdown_tag( # noqa: PLR0912, PLR0915 ) -> str: directive_match_start = match.start() - includer_indent = match.group('_includer_indent') + includer_indent = match['_includer_indent'] empty_includer_indent = ' ' * len(includer_indent) filename, raw_filename = parse_filename_argument(match) @@ -319,17 +320,17 @@ def found_include_markdown_tag( # noqa: PLR0912, PLR0915 f':{lineno}', ) - arguments_string = match.group('arguments') + arguments_string = match['arguments'] exclude_match = ARGUMENT_REGEXES['exclude'].search(arguments_string) ignore_paths = [] - if settings['exclude'] is not None: + if settings.exclude is not None: ignore_paths.extend( glob.glob( [ os.path.join(docs_dir, fp) if not os.path.isabs(fp) - else fp for fp in settings['exclude'] + else fp for fp in settings.exclude ], flags=GLOB_FLAGS, root_dir=docs_dir, @@ -452,7 +453,7 @@ def found_include_markdown_tag( # noqa: PLR0912, PLR0915 arguments_string, ) if offset_match: - offset = offset_match.group(1) + offset = offset_match[1] if offset == '': lineno = lineno_from_content_start( markdown, @@ -478,7 +479,7 @@ def found_include_markdown_tag( # noqa: PLR0912, PLR0915 else: offset = defaults['heading-offset'] - separator = '\n' if bool_options['trailing-newlines']['value'] else '' + separator = '\n' if bool_options['trailing-newlines'].value else '' if not start and not end: start_end_part = '' else: @@ -524,13 +525,13 @@ def found_include_markdown_tag( # noqa: PLR0912, PLR0915 ) # trailing newlines right stripping - if not bool_options['trailing-newlines']['value']: + if not bool_options['trailing-newlines'].value: new_text_to_include = process.rstrip_trailing_newlines( new_text_to_include, ) # relative URLs rewriting - if bool_options['rewrite-relative-urls']['value']: + if bool_options['rewrite-relative-urls'].value: new_text_to_include = process.rewrite_relative_urls( new_text_to_include, source_path=file_path, @@ -538,7 +539,7 @@ def found_include_markdown_tag( # noqa: PLR0912, PLR0915 ) # comments - if bool_options['comments']['value']: + if bool_options['comments'].value: new_text_to_include = ( f'{includer_indent}' f' @@ -75,6 +83,7 @@ def test_start_end_mixed_quotes(directive, page, caplog, tmp_path): %}}''', page(tmp_path / 'includer.md'), tmp_path, + plugin, ) assert result == '\nContent to include\n' @@ -89,6 +98,7 @@ def test_invalid_start_end_arguments( page, caplog, tmp_path, + plugin, ): page_to_include_filepath = tmp_path / 'included.md' included_content = '''Content that should be ignored @@ -109,6 +119,7 @@ def test_invalid_start_end_arguments( %}}''', page(tmp_path / 'includer.md'), tmp_path, + plugin, ) assert str(exc.value) == ( f"Invalid empty '{argument}' argument in '{directive}'" @@ -120,7 +131,7 @@ def test_invalid_start_end_arguments( @unix_only @parametrize_directives -def test_exclude_double_quote_escapes(directive, page, tmp_path): +def test_exclude_double_quote_escapes(directive, page, tmp_path, plugin): drectory_to_include = tmp_path / 'exclude_double_quote_escapes' drectory_to_include.mkdir() @@ -142,13 +153,14 @@ def test_exclude_double_quote_escapes(directive, page, tmp_path): %}}''', page(tmp_path / 'includer.md'), tmp_path, + plugin, ) assert result == 'Content that should be included\n' @unix_only @parametrize_directives -def test_invalid_exclude_argument(directive, page, tmp_path, caplog): +def test_invalid_exclude_argument(directive, page, tmp_path, caplog, plugin): drectory_to_include = tmp_path / 'exclude_double_quote_escapes' drectory_to_include.mkdir() @@ -168,6 +180,7 @@ def test_invalid_exclude_argument(directive, page, tmp_path, caplog): %}}''', page(tmp_path / 'includer.md'), tmp_path, + plugin, ) assert len(caplog.records) == 0 @@ -178,7 +191,7 @@ def test_invalid_exclude_argument(directive, page, tmp_path, caplog): @parametrize_directives -def test_empty_encoding_argument(directive, page, tmp_path, caplog): +def test_empty_encoding_argument(directive, page, tmp_path, plugin, caplog): page_to_include_filepath = tmp_path / 'included.md' page_to_include_filepath.write_text('Content to include') @@ -191,6 +204,7 @@ def test_empty_encoding_argument(directive, page, tmp_path, caplog): %}}''', page(tmp_path / 'includer.md'), tmp_path, + plugin, ) assert len(caplog.records) == 0 @@ -224,6 +238,7 @@ def test_invalid_heading_offset_arguments( exception_message, page, tmp_path, + plugin, caplog, ): page_to_include_filepath = tmp_path / 'included.md' @@ -238,6 +253,7 @@ def test_invalid_heading_offset_arguments( %}}''', page(tmp_path / 'includer.md'), tmp_path, + plugin, ) assert len(caplog.records) == 0 @@ -256,7 +272,7 @@ class TestFilename: @parametrize_directives @pytest.mark.parametrize('filename', double_quoted_filenames) def test_not_escaped_double_quotes( - self, directive, filename, page, tmp_path, caplog, + self, directive, filename, page, tmp_path, plugin, caplog, ): page_to_include_filepath = tmp_path / filename page_to_include_filepath.write_text('Foo\n') @@ -266,6 +282,7 @@ def test_not_escaped_double_quotes( f'{{% {directive} "{page_to_include_filepath}" %}}', page(tmp_path / 'includer.md'), tmp_path, + plugin, ) assert len(caplog.records) == 0 @@ -278,7 +295,7 @@ def test_not_escaped_double_quotes( @parametrize_directives @pytest.mark.parametrize('filename', double_quoted_filenames) def test_escaped_double_quotes( - self, directive, filename, page, tmp_path, + self, directive, filename, page, tmp_path, plugin, ): included_content = 'Foo\n' page_to_include_filepath = tmp_path / filename @@ -295,13 +312,14 @@ def test_escaped_double_quotes( %}}''', page(tmp_path / 'includer.md'), tmp_path, + plugin, ) assert result == included_content @parametrize_directives @pytest.mark.parametrize('filename', single_quoted_filenames) def test_escaped_single_quotes( - self, filename, directive, page, tmp_path, + self, filename, directive, page, tmp_path, plugin, ): included_content = 'Foo\n' page_to_include_filepath = tmp_path / filename @@ -318,6 +336,7 @@ def test_escaped_single_quotes( %}}''', page(tmp_path / 'includer.md'), tmp_path, + plugin, ) assert result == included_content @@ -325,7 +344,7 @@ def test_escaped_single_quotes( @parametrize_directives @pytest.mark.parametrize('filename', double_quoted_filenames) def test_unescaped_double_quotes( - self, filename, directive, page, tmp_path, + self, filename, directive, page, tmp_path, plugin, ): included_content = 'Foo\n' page_to_include_filepath = tmp_path / filename @@ -338,13 +357,14 @@ def test_unescaped_double_quotes( %}}''', page(tmp_path / 'includer.md'), tmp_path, + plugin, ) assert result == included_content @parametrize_directives @pytest.mark.parametrize('filename', single_quoted_filenames) def test_unescaped_single_quotes( - self, filename, directive, page, tmp_path, + self, filename, directive, page, tmp_path, plugin, ): included_content = 'Foo\n' page_to_include_filepath = tmp_path / filename @@ -357,6 +377,7 @@ def test_unescaped_single_quotes( %}}''', page(tmp_path / 'includer.md'), tmp_path, + plugin, ) assert result == included_content @@ -372,7 +393,15 @@ def test_unescaped_single_quotes( 'escape', (True, False), ids=('escape=True', 'escape=False'), ) def test_mixed_quotes( - self, filename, quote, escape, directive, page, tmp_path, caplog, + self, + filename, + quote, + escape, + directive, + page, + tmp_path, + plugin, + caplog, ): included_content = 'Foo\n' page_to_include_filepath = tmp_path / filename @@ -395,6 +424,7 @@ def test_mixed_quotes( markdown, page(tmp_path / 'includer.md'), tmp_path, + plugin, ) if escape: @@ -409,7 +439,7 @@ def test_mixed_quotes( assert len(caplog.records) == 0 @parametrize_directives - def test_no_filename(self, directive, page, tmp_path, caplog): + def test_no_filename(self, directive, page, tmp_path, plugin, caplog): filename = 'includer.md' with pytest.raises(PluginError) as exc: @@ -417,6 +447,7 @@ def test_no_filename(self, directive, page, tmp_path, caplog): f'\n\n{{% {directive} %}}', page(tmp_path / filename), tmp_path, + plugin, ) assert str(exc.value) == ( @@ -426,7 +457,14 @@ def test_no_filename(self, directive, page, tmp_path, caplog): assert len(caplog.records) == 0 @parametrize_directives - def test_non_existent_filename(self, directive, page, tmp_path, caplog): + def test_non_existent_filename( + self, + directive, + page, + tmp_path, + plugin, + caplog, + ): page_content = f'''{{% {directive} "/path/to/file/that/does/not/exists" start="" @@ -441,6 +479,7 @@ def test_non_existent_filename(self, directive, page, tmp_path, caplog): page_content, page(page_filepath), tmp_path, + plugin, ) assert len(caplog.records) == 0 diff --git a/tests/test_unit/test_config.py b/tests/test_unit/test_config.py index 54e7079..b93bca7 100644 --- a/tests/test_unit/test_config.py +++ b/tests/test_unit/test_config.py @@ -9,7 +9,7 @@ 'includer_schema', 'content_to_include', 'expected_result', - 'config', + 'plugin', ) @@ -17,7 +17,7 @@ def _run_test( includer_schema, content_to_include, expected_result, - config, + plugin, page, caplog, tmp_path, @@ -47,7 +47,7 @@ def _run_test( page_content, page(includer_file), tmp_path, - config, + plugin, ) == expected_result ) @@ -152,12 +152,13 @@ def _run_test( id='custom-comments', ), ), + indirect=['plugin'], ) def test_config_options( includer_schema, content_to_include, expected_result, - config, + plugin, page, caplog, tmp_path, @@ -166,7 +167,7 @@ def test_config_options( includer_schema, content_to_include, expected_result, - config, + plugin, page, caplog, tmp_path, @@ -193,12 +194,13 @@ def test_config_options( id='custom-encoding', ), ), + indirect=['plugin'], ) def test_config_encoding_option( includer_schema, content_to_include, expected_result, - config, + plugin, page, caplog, tmp_path, @@ -207,7 +209,7 @@ def test_config_encoding_option( includer_schema, content_to_include, expected_result, - config, + plugin, page, caplog, tmp_path, diff --git a/tests/test_unit/test_encoding.py b/tests/test_unit/test_encoding.py index 932c4a9..65c4e52 100644 --- a/tests/test_unit/test_encoding.py +++ b/tests/test_unit/test_encoding.py @@ -4,7 +4,7 @@ @parametrize_directives -def test_encoding(directive, page, tmp_path): +def test_encoding(directive, page, tmp_path, plugin): page_to_include_file = tmp_path / 'included.md' page_to_include_file.write_text('''Á @@ -24,12 +24,13 @@ def test_encoding(directive, page, tmp_path): %}}''', page(tmp_path / 'includer.md'), tmp_path, + plugin, ) @unix_only @parametrize_directives -def test_default_encoding(directive, page, tmp_path): +def test_default_encoding(directive, page, tmp_path, plugin): page_to_include_file = tmp_path / 'included.md' page_to_include_file.write_text('''Á @@ -47,13 +48,14 @@ def test_default_encoding(directive, page, tmp_path): %}}''', page(tmp_path / 'includer.md'), tmp_path, + plugin, ) assert result == '\nContent to include\n' @unix_only @parametrize_directives -def test_explicit_default_encoding(directive, page, tmp_path): +def test_explicit_default_encoding(directive, page, tmp_path, plugin): page_to_include_file = tmp_path / 'included.md' page_to_include_file.write_text('''Á @@ -72,5 +74,6 @@ def test_explicit_default_encoding(directive, page, tmp_path): %}}''', page(tmp_path / 'includer.md'), tmp_path, + plugin, ) assert result == '\nContent to include\n' diff --git a/tests/test_unit/test_exclude.py b/tests/test_unit/test_exclude.py index 398d2ee..8117588 100644 --- a/tests/test_unit/test_exclude.py +++ b/tests/test_unit/test_exclude.py @@ -62,6 +62,7 @@ def test_exclude( page, tmp_path, + plugin, caplog, directive, filenames, @@ -95,6 +96,7 @@ def test_exclude( includer_file_content, page(includer_file), includer_folder, + plugin, ) if expected_result is None: diff --git a/tests/test_unit/test_glob_include.py b/tests/test_unit/test_glob_include.py index c6299d2..11aecc9 100644 --- a/tests/test_unit/test_glob_include.py +++ b/tests/test_unit/test_glob_include.py @@ -8,7 +8,7 @@ @unix_only -def test_glob_include_absolute(page, tmp_path): +def test_glob_include_absolute(page, tmp_path, plugin): includer_file = tmp_path / 'includer.txt' included_01_file = tmp_path / 'included_01.txt' included_02_file = tmp_path / 'included_02.txt' @@ -41,7 +41,7 @@ def test_glob_include_absolute(page, tmp_path): ''' assert on_page_markdown( - includer_file_content, page(includer_file), tmp_path, + includer_file_content, page(includer_file), tmp_path, plugin, ) == expected_result @@ -150,6 +150,7 @@ def test_glob_include( page, caplog, tmp_path, + plugin, ): includer_file = tmp_path / 'includer.txt' included_01_file = tmp_path / 'included_01.txt' @@ -178,7 +179,7 @@ def test_glob_include( included_02_file.write_text(included_02_content) on_page_markdown( - includer_file_content, page(includer_file), tmp_path, + includer_file_content, page(includer_file), tmp_path, plugin, ) # assert warnings diff --git a/tests/test_unit/test_include.py b/tests/test_unit/test_include.py index ce69ae0..b77ad27 100644 --- a/tests/test_unit/test_include.py +++ b/tests/test_unit/test_include.py @@ -371,6 +371,7 @@ def test_include( page, caplog, tmp_path, + plugin, ): included_file = tmp_path / 'included.md' includer_file = tmp_path / 'includer.md' @@ -387,7 +388,7 @@ def test_include( includer_file.write_text(page_content) assert on_page_markdown( - page_content, page(includer_file), tmp_path, + page_content, page(includer_file), tmp_path, plugin, ) == expected_result # assert warnings diff --git a/tests/test_unit/test_include_markdown.py b/tests/test_unit/test_include_markdown.py index 3302878..5b5e305 100644 --- a/tests/test_unit/test_include_markdown.py +++ b/tests/test_unit/test_include_markdown.py @@ -772,6 +772,7 @@ def test_include_markdown( page, caplog, tmp_path, + plugin, ): included_file = tmp_path / 'included.md' includer_file = tmp_path / 'includer.md' @@ -796,6 +797,7 @@ def test_include_markdown( page_content, page(includer_file), tmp_path, + plugin, ) == expected_result # assert warnings @@ -823,6 +825,7 @@ def test_include_markdown( def test_include_markdown_relative_rewrite( page, tmp_path, + plugin, rewrite_relative_urls, ): option_value = '' if rewrite_relative_urls is None else ( @@ -864,6 +867,7 @@ def test_include_markdown_relative_rewrite( includer_path.read_text(), page(str(includer_path)), docs_dir, + plugin, ) if rewrite_relative_urls in ['true', None]: @@ -897,7 +901,7 @@ def test_include_markdown_relative_rewrite( ''' -def test_multiple_includes(page, tmp_path): +def test_multiple_includes(page, tmp_path, plugin): snippet_filepath = tmp_path / 'snippet.md' another_filepath = tmp_path / 'another.md' includer_file = tmp_path / 'includer.md' @@ -940,5 +944,5 @@ def test_multiple_includes(page, tmp_path): Another ''' assert on_page_markdown( - includer_content, page(includer_file), tmp_path, + includer_content, page(includer_file), tmp_path, plugin, ) == expected_result diff --git a/tests/test_unit/test_logging.py b/tests/test_unit/test_logging.py index 297acd0..85249f3 100644 --- a/tests/test_unit/test_logging.py +++ b/tests/test_unit/test_logging.py @@ -12,6 +12,7 @@ def test_start_end_arguments_not_found( missing_argument, page, tmp_path, + plugin, caplog, ): included_file_name = 'included.md' @@ -42,7 +43,7 @@ def test_start_end_arguments_not_found( ''' assert on_page_markdown( - includer_content, page(includer_file), tmp_path, + includer_content, page(includer_file), tmp_path, plugin, ) == expected_result rec = caplog.records[0] diff --git a/tests/test_unit/test_nested_includes.py b/tests/test_unit/test_nested_includes.py index eac0af0..1da91f5 100644 --- a/tests/test_unit/test_nested_includes.py +++ b/tests/test_unit/test_nested_includes.py @@ -248,6 +248,7 @@ def test_nested_include( page, caplog, tmp_path, + plugin, ): first_includer_file = tmp_path / 'first-includer.txt' second_includer_file = tmp_path / 'second-includer.txt' @@ -266,7 +267,7 @@ def test_nested_include( # assert content assert on_page_markdown( - first_includer_content, page(first_includer_file), tmp_path, + first_includer_content, page(first_includer_file), tmp_path, plugin, ) == expected_result # assert warnings @@ -292,7 +293,7 @@ def test_nested_include( assert len(expected_warnings_schemas) == len(caplog.records) -def test_nested_include_relpath(page, tmp_path): +def test_nested_include_relpath(page, tmp_path, plugin): docs_dir = tmp_path / 'docs' docs_dir.mkdir() @@ -332,4 +333,5 @@ def test_nested_include_relpath(page, tmp_path): first_includer_content, page(first_includer_file), docs_dir, + plugin, ) == expected_result