From 960cfea3ff78c2757efbd13aa38d3e7972e334db Mon Sep 17 00:00:00 2001 From: daizutabi Date: Sun, 11 Feb 2024 16:01:18 +0900 Subject: [PATCH] Add test for convert_source --- .github/workflows/ci.yml | 4 +++- pyproject.toml | 4 +++- src/mkapi/pages.py | 2 +- src/mkapi/plugins.py | 3 +-- tests/test_globals.py | 1 - tests/test_pages.py | 14 +++++++++++--- 6 files changed, 19 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ce03f0bb..092d16d9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,7 +31,9 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install Hatch run: pip install --upgrade hatch - - name: Run tests + - name: Check format + run: hatch fmt --check + - name: Run test run: hatch run test - name: Upload Codecov Results if: success() diff --git a/pyproject.toml b/pyproject.toml index 7b75d07c..2b28a782 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -83,20 +83,22 @@ ignore = [ "COM812", "D105", "D406", - "G004", "D407", "EM102", "ERA001", "FIX002", "FIX003", + "G004", "ISC001", "N812", "PGH003", "PLR2004", + "PT001", "RET504", "TD", "TRY003", ] +exclude = ["google.py", 'numpy.py'] [tool.ruff.extend-per-file-ignores] "tests/*.py" = ["ANN", "D", "S101", "INP001", "T201", "PLR2004", "PGH003"] diff --git a/src/mkapi/pages.py b/src/mkapi/pages.py index 53711aab..1ee2ae7b 100644 --- a/src/mkapi/pages.py +++ b/src/mkapi/pages.py @@ -9,7 +9,7 @@ import mkapi.renderers from mkapi.globals import resolve_with_attribute from mkapi.importlib import get_object, load_module -from mkapi.objects import Module, is_empty, iter_objects_with_depth +from mkapi.objects import is_empty, iter_objects_with_depth from mkapi.renderers import get_object_filter_for_source from mkapi.utils import is_module_cache_dirty, split_filters diff --git a/src/mkapi/plugins.py b/src/mkapi/plugins.py index 2d28e056..27d31d7d 100644 --- a/src/mkapi/plugins.py +++ b/src/mkapi/plugins.py @@ -16,7 +16,6 @@ from halo import Halo from mkdocs.config import Config, config_options -from mkdocs.config.defaults import MkDocsConfig from mkdocs.plugins import BasePlugin, get_plugin_logger from mkdocs.structure.files import File, InclusionLevel, get_files from tqdm.std import tqdm @@ -32,7 +31,7 @@ from collections.abc import Callable from mkdocs.config.defaults import MkDocsConfig - from mkdocs.structure.files import File, Files + from mkdocs.structure.files import Files from mkdocs.structure.pages import Page as MkDocsPage from mkdocs.structure.toc import AnchorLink, TableOfContents diff --git a/tests/test_globals.py b/tests/test_globals.py index 1782e22e..e127a48c 100644 --- a/tests/test_globals.py +++ b/tests/test_globals.py @@ -8,7 +8,6 @@ _iter_imports_from_import_from, _iter_objects_from_all, get_all, - get_all_from_ast, get_all_from_importlib, get_fullname, get_globals, diff --git a/tests/test_pages.py b/tests/test_pages.py index 8043ed8c..0232601a 100644 --- a/tests/test_pages.py +++ b/tests/test_pages.py @@ -95,7 +95,7 @@ def test_create_source_markdown_failure(tmpdir: Path): assert "!!! failure" in m -@pytest.fixture() +@pytest.fixture def prepare(tmpdir: Path): api = Path(tmpdir) / "api/a.md" src = Path(tmpdir) / "src/b.md" @@ -108,12 +108,12 @@ def prepare(tmpdir: Path): return page, obj, src -@pytest.fixture() +@pytest.fixture def page(prepare): return prepare[0] -@pytest.fixture() +@pytest.fixture def src(prepare): return prepare[2] @@ -161,3 +161,11 @@ def test_convert_source(src, page): assert '[[A]](../../api/a.md#mkapi.objects' in m assert "``` {.python .mkapi-source}" in m assert "class Attribute(Member):## __mkapi__.mkapi.objects.Attribute" in m + + es = ["admonition", "attr_list", "md_in_html", "pymdownx.superfences"] + h = markdown.markdown(m, extensions=es) + assert '

' in h + + h = convert_source(h, page, "AAA") + assert "mkapi-dummy-heading" not in h + assert '[AAA]' in h