Skip to content

Commit 21d89f6

Browse files
committed
Test Typer fallback without dependency
1 parent 994fcc7 commit 21d89f6

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

‎tests/test_typer_cli.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from __future__ import annotations
1111

1212
import importlib
13+
import sys
1314
import types
1415
from pathlib import Path
1516
from unittest.mock import patch
@@ -95,6 +96,25 @@ def test_to_click_command_returns_none_for_non_cli(self):
9596
assert to_click_command(object()) is None
9697
assert to_click_command(None) is None
9798

99+
def test_is_typer_app_false_when_typer_not_installed(self, monkeypatch):
100+
"""Graceful degradation: no Typer installed -> not a Typer app (no raise)."""
101+
from great_docs._typer_cli import is_typer_app
102+
103+
# A None entry in sys.modules makes `import typer` raise ImportError.
104+
monkeypatch.setitem(sys.modules, "typer", None)
105+
106+
assert is_typer_app(object()) is False
107+
108+
def test_to_click_command_returns_none_when_typer_not_installed(self, monkeypatch):
109+
"""A non-Click object cannot be coerced when Typer is unavailable."""
110+
from great_docs._typer_cli import to_click_command
111+
112+
monkeypatch.setitem(sys.modules, "typer", None)
113+
114+
# Click is still importable, so this reaches (and survives) the failed
115+
# Typer import before returning None.
116+
assert to_click_command(object()) is None
117+
98118
def test_is_cli_command(self):
99119
from great_docs._typer_cli import is_cli_command
100120

0 commit comments

Comments
 (0)