Coverage for tests/test_rich_markup_mode.py: 100%

25 statements  

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

1import typer 1abcdefgh

2import typer.completion 1abcdefgh

3from typer.testing import CliRunner 1abcdefgh

4 

5runner = CliRunner() 1abcdefgh

6rounded = ["╭", "─", "┬", "╮", "│", "├", "┼", "┤", "╰", "┴", "╯"] 1abcdefgh

7 

8 

9def test_rich_markup_mode_none(): 1abcdefgh

10 app = typer.Typer(rich_markup_mode=None) 1abcdefgh

11 

12 @app.command() 1abcdefgh

13 def main(arg: str): 1abcdefgh

14 """Main function""" 

15 print(f"Hello {arg}") 1abcdefgh

16 

17 assert app.rich_markup_mode is None 1abcdefgh

18 

19 result = runner.invoke(app, ["World"]) 1abcdefgh

20 assert "Hello World" in result.stdout 1abcdefgh

21 

22 result = runner.invoke(app, ["--help"]) 1abcdefgh

23 assert all(c not in result.stdout for c in rounded) 1abcdefgh

24 

25 

26def test_rich_markup_mode_rich(): 1abcdefgh

27 app = typer.Typer(rich_markup_mode="rich") 1abcdefgh

28 

29 @app.command() 1abcdefgh

30 def main(arg: str): 1abcdefgh

31 """Main function""" 

32 print(f"Hello {arg}") 1abcdefgh

33 

34 assert app.rich_markup_mode == "rich" 1abcdefgh

35 

36 result = runner.invoke(app, ["World"]) 1abcdefgh

37 assert "Hello World" in result.stdout 1abcdefgh

38 

39 result = runner.invoke(app, ["--help"]) 1abcdefgh

40 assert any(c in result.stdout for c in rounded) 1abcdefgh