Coverage for tests/test_future_annotations.py: 100%

18 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-09-09 18:26 +0000

1from __future__ import annotations 1abcdefgh

2 

3import typer 1abcdefgh

4from typer.testing import CliRunner 1abcdefgh

5from typing_extensions import Annotated 1abcdefgh

6 

7runner = CliRunner() 1abcdefgh

8 

9 

10def test_annotated(): 1abcdefgh

11 app = typer.Typer() 1abcdefgh

12 

13 @app.command() 1abcdefgh

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

15 if force: 1abcdefgh

16 print("Forcing operation") 1abcdefgh

17 else: 

18 print("Not forcing") 1abcdefgh

19 

20 result = runner.invoke(app) 1abcdefgh

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

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

23 

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

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

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