Skip to content

Commit

Permalink
Add test for convert_source
Browse files Browse the repository at this point in the history
  • Loading branch information
daizutabi committed Feb 11, 2024
1 parent 42daa6c commit 960cfea
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 9 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion src/mkapi/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions src/mkapi/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
1 change: 0 additions & 1 deletion tests/test_globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 11 additions & 3 deletions tests/test_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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]

Expand Down Expand Up @@ -161,3 +161,11 @@ def test_convert_source(src, page):
assert '<span class="mkapi-docs-link">[[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 '<h2 class="mkapi-dummy-heading" id="mkapi.objects.Object">' in h

h = convert_source(h, page, "AAA")
assert "mkapi-dummy-heading" not in h
assert '<a href="../../../api/a/#mkapi.objects.is_empty">[AAA]</a></span>' in h

0 comments on commit 960cfea

Please sign in to comment.