Coverage for tests / test_exit_errors.py: 100%

36 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-11-18 11:12 +0000

1import errno 1abcdefghij

2 

3import typer 1abcdefghij

4import typer.completion 1abcdefghij

5from typer.testing import CliRunner 1abcdefghij

6 

7runner = CliRunner() 1abcdefghij

8 

9 

10def test_eoferror(): 1abcdefghij

11 # Mainly for coverage/completeness 

12 app = typer.Typer() 1abcdefghij

13 

14 @app.command() 1abcdefghij

15 def main(): 1abcdefghij

16 raise EOFError() 1abcdefghij

17 

18 result = runner.invoke(app) 1abcdefghij

19 assert result.exit_code == 1 1abcdefghij

20 

21 

22def test_keyboardinterrupt(): 1abcdefghij

23 # Mainly for coverage/completeness 

24 app = typer.Typer() 1abcdefghij

25 

26 @app.command() 1abcdefghij

27 def main(): 1abcdefghij

28 raise KeyboardInterrupt() 1abcdefghij

29 

30 result = runner.invoke(app) 1abcdefghij

31 assert result.exit_code == 130 1abcdefghij

32 assert result.stdout == "" 1abcdefghij

33 

34 

35def test_oserror(): 1abcdefghij

36 # Mainly for coverage/completeness 

37 app = typer.Typer() 1abcdefghij

38 

39 @app.command() 1abcdefghij

40 def main(): 1abcdefghij

41 e = OSError() 1abcdefghij

42 e.errno = errno.EPIPE 1abcdefghij

43 raise e 1abcdefghij

44 

45 result = runner.invoke(app) 1abcdefghij

46 assert result.exit_code == 1 1abcdefghij

47 

48 

49def test_oserror_no_epipe(): 1abcdefghij

50 # Mainly for coverage/completeness 

51 app = typer.Typer() 1abcdefghij

52 

53 @app.command() 1abcdefghij

54 def main(): 1abcdefghij

55 raise OSError() 1abcdefghij

56 

57 result = runner.invoke(app) 1abcdefghij

58 assert result.exit_code == 1 1abcdefghij