Skip to content

Commit 0b6317a

Browse files
committed
up
1 parent 467d3d9 commit 0b6317a

3 files changed

Lines changed: 58 additions & 2 deletions

File tree

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ path = "nonebot_plugin_picmenu_next/__init__.py"
4747

4848
[tool.poe.tasks]
4949
gen-defs.shell = "uv run scripts/gen_defs.py && pnpx prettier -cw defs"
50-
test.cmd = "pytest"
51-
coverage.cmd = "pytest --cov=nonebot_plugin_picmenu_next --cov-branch --cov-report=term-missing"
50+
test.cmd = "uv run pytest"
51+
coverage.cmd = "uv run pytest --cov=nonebot_plugin_picmenu_next --cov-branch --cov-report=term-missing"
5252

5353
[tool.pytest.ini_options]
5454
asyncio_mode = "auto"

tests_nbp_picmenu_next/__main__/test_help_interception.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,36 @@ async def no_view(*_args: object, **kwargs: object) -> object:
106106
assert attempts == [False, True]
107107

108108

109+
async def test_help_interception_leaves_ineligible_outputs_to_alconna(
110+
picmenu_plugin: object,
111+
monkeypatch: "pytest.MonkeyPatch",
112+
) -> None:
113+
"""Only owned Help output enters the PicMenu interception pipeline."""
114+
from nonebot_plugin_picmenu_next import __main__ as main
115+
116+
async def unexpected_pipeline_call(*_args: object, **_kwargs: object) -> None:
117+
raise AssertionError("ineligible output entered the interception pipeline")
118+
119+
ext = main.PMNHelpExtension()
120+
monkeypatch.setattr(ext, "inject", unexpected_pipeline_call)
121+
monkeypatch.setattr(main, "render_menu", unexpected_pipeline_call)
122+
123+
ext.command = _owned_command("not-help-picmenu", "not_help_plugin")
124+
assert (
125+
await ext.output_converter("error", "Alconna error")
126+
).extract_plain_text() == "Alconna error"
127+
128+
ext.command = None
129+
assert (
130+
await ext.output_converter("help", "Uninitialized fallback")
131+
).extract_plain_text() == "Uninitialized fallback"
132+
133+
ext.command = Alconna("unowned-picmenu")
134+
assert (
135+
await ext.output_converter("help", "Unowned fallback")
136+
).extract_plain_text() == "Unowned fallback"
137+
138+
109139
async def test_help_interception_uses_hidden_snapshot_for_adapter_hidden_plugin(
110140
picmenu_plugin: object,
111141
monkeypatch: "pytest.MonkeyPatch",

tests_nbp_picmenu_next/data_source/alconna/test_markdown_formatter.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,32 @@ def test_markdown_formatter_formats_subcommands_arguments_and_options(
6262
assert "Create a user." in nested
6363

6464

65+
def test_markdown_formatter_hides_ignored_nested_options(
66+
picmenu_plugin: object,
67+
) -> None:
68+
"""Ignored options remain hidden when a subcommand expands in Markdown Help."""
69+
from nonebot_plugin_picmenu_next.data_source.alconna import (
70+
PMNMarkdownTextFormatter,
71+
)
72+
73+
command = Alconna(
74+
"ignored-option-picmenu",
75+
Subcommand(
76+
"group",
77+
Option("--visible", help_text="Visible nested option."),
78+
Option("--ignored", help_text="Ignored nested option."),
79+
),
80+
)
81+
formatter = PMNMarkdownTextFormatter().add(command)
82+
formatter.ignore_names.add("--ignored")
83+
trace = next(iter(formatter.data.values()))
84+
85+
rendered = formatter.format(trace)
86+
87+
assert "Visible nested option." in rendered
88+
assert "Ignored nested option." not in rendered
89+
90+
6591
def test_markdown_formatter_accepts_root_prefixed_help_parts(
6692
picmenu_plugin: object,
6793
) -> None:

0 commit comments

Comments
 (0)