Coverage for tests/test_exit_errors.py: 100%

36 statements  

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

1import errno 1iabcdefgh

2 

3import typer 1iabcdefgh

4import typer.completion 1iabcdefgh

5from typer.testing import CliRunner 1iabcdefgh

6 

7runner = CliRunner() 1iabcdefgh

8 

9 

10def test_eoferror(): 1iabcdefgh

11 # Mainly for coverage/completeness 

12 app = typer.Typer() 1iabcdefgh

13 

14 @app.command() 1iabcdefgh

15 def main(): 1abcdefgh

16 raise EOFError() 1iabcdefgh

17 

18 result = runner.invoke(app) 1iabcdefgh

19 assert result.exit_code == 1 1iabcdefgh

20 

21 

22def test_keyboardinterrupt(): 1iabcdefgh

23 # Mainly for coverage/completeness 

24 app = typer.Typer() 1iabcdefgh

25 

26 @app.command() 1iabcdefgh

27 def main(): 1abcdefgh

28 raise KeyboardInterrupt() 1iabcdefgh

29 

30 result = runner.invoke(app) 1iabcdefgh

31 assert result.exit_code == 130 1iabcdefgh

32 assert result.stdout == "" 1iabcdefgh

33 

34 

35def test_oserror(): 1iabcdefgh

36 # Mainly for coverage/completeness 

37 app = typer.Typer() 1iabcdefgh

38 

39 @app.command() 1iabcdefgh

40 def main(): 1abcdefgh

41 e = OSError() 1iabcdefgh

42 e.errno = errno.EPIPE 1iabcdefgh

43 raise e 1iabcdefgh

44 

45 result = runner.invoke(app) 1iabcdefgh

46 assert result.exit_code == 1 1iabcdefgh

47 

48 

49def test_oserror_no_epipe(): 1iabcdefgh

50 # Mainly for coverage/completeness 

51 app = typer.Typer() 1iabcdefgh

52 

53 @app.command() 1iabcdefgh

54 def main(): 1abcdefgh

55 raise OSError() 1iabcdefgh

56 

57 result = runner.invoke(app) 1iabcdefgh

58 assert result.exit_code == 1 1iabcdefgh