Files
anki/tools/tests/test_mintlify_hooks.py
Luc Mcgrady e9ac48cac2 Docs: Set up Prettier for formatting Mintlify website (#5020)
<!--
Title (for the Pull Request title field at the top):
Use a short prefix so the change type is obvious. You do not need to
repeat it in the body below.

Examples:
- fix: — bugfix
- feat: — feature
- refactor: — internal change without user-facing feature
- docs: — documentation only
- chore: — tooling, CI, deps, build housekeeping
- test: — tests only
-->

## Linked issue (required)

closes #5018
<!-- Fixes #123 / Closes #123 / Refs #123 -->

## Summary / motivation (required)

This prevents large diffs with prettier being used with the mintlify
editor

A caveat of this is that the docs generated by cog now have to be
prettier compatible. Also for some reason prettier has problems with the
{/* */} multi-line comment format so we have to use <!-- --> instead.

Sadly I don't have a good way to check that the Prettier config does not
differ between this PR and the editor.

---------

Co-authored-by: Abdo <abdo@abdnh.net>
2026-06-17 15:54:11 +03:00

60 lines
1.6 KiB
Python

# Copyright: Ankitects Pty Ltd and contributors
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
from __future__ import annotations
from types import SimpleNamespace
from tools.mintlify_hooks import OBSOLETE_TEXT, render_hook, safe, signature
def test_signature_includes_arguments_and_return_type() -> None:
hook = SimpleNamespace(
args=("text: str", "count: int"),
return_type="str",
)
assert (
signature(hook)
== "**Args:** <code>text: str</code>, <code>count: int</code>\\\n**Returns:** <code>str</code>"
)
def test_render_hook_marks_deprecated_docstring() -> None:
hook = SimpleNamespace(
name="old_hook",
args=(),
return_type=None,
doc="Deprecated. Use new_hook instead.\nCalled after work finishes.",
)
assert render_hook(hook) == "\n".join(
[
"### `old_hook` _(Deprecated)_",
"",
"No arguments.",
"",
"<Warning>",
" Deprecated. Use `new_hook` instead.",
"</Warning>",
"",
"Called after work finishes.",
]
)
def test_render_hook_marks_obsolete_docstring() -> None:
hook = SimpleNamespace(
name="old_hook",
args=(),
return_type=None,
doc="Obsolete, do not use.",
)
assert OBSOLETE_TEXT in render_hook(hook)
def test_safe_escapes_mdx_sensitive_text() -> None:
assert safe("{{filters:..}}\n<show both sides>") == (
"`{{filters:..}}`\n&lt;show both sides&gt;"
)