Coverage for tests/test_future_annotations.py: 100%

18 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2025-04-14 00:18 +0000

1from __future__ import annotations 1abcdefghi

2 

3import typer 1abcdefghi

4from typer.testing import CliRunner 1abcdefghi

5from typing_extensions import Annotated 1abcdefghi

6 

7runner = CliRunner() 1abcdefghi

8 

9 

10def test_annotated(): 1abcdefghi

11 app = typer.Typer() 1abcdefghi

12 

13 @app.command() 1abcdefghi

14 def cmd(force: Annotated[bool, typer.Option("--force")] = False): 1abcdefghi

15 if force: 1abcdefghi

16 print("Forcing operation") 1abcdefghi

17 else: 

18 print("Not forcing") 1abcdefghi

19 

20 result = runner.invoke(app) 1abcdefghi

21 assert result.exit_code == 0, result.output 1abcdefghi

22 assert "Not forcing" in result.output 1abcdefghi

23 

24 result = runner.invoke(app, ["--force"]) 1abcdefghi

25 assert result.exit_code == 0, result.output 1abcdefghi

26 assert "Forcing operation" in result.output 1abcdefghi