File: test_exit_errors.py

package info (click to toggle)
typer 0.19.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,688 kB
  • sloc: python: 16,702; javascript: 280; sh: 28; makefile: 27
file content (58 lines) | stat: -rw-r--r-- 1,061 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import errno

import typer
import typer.completion
from typer.testing import CliRunner

runner = CliRunner()


def test_eoferror():
    # Mainly for coverage/completeness
    app = typer.Typer()

    @app.command()
    def main():
        raise EOFError()

    result = runner.invoke(app)
    assert result.exit_code == 1


def test_keyboardinterrupt():
    # Mainly for coverage/completeness
    app = typer.Typer()

    @app.command()
    def main():
        raise KeyboardInterrupt()

    result = runner.invoke(app)
    assert result.exit_code == 130
    assert result.stdout == ""


def test_oserror():
    # Mainly for coverage/completeness
    app = typer.Typer()

    @app.command()
    def main():
        e = OSError()
        e.errno = errno.EPIPE
        raise e

    result = runner.invoke(app)
    assert result.exit_code == 1


def test_oserror_no_epipe():
    # Mainly for coverage/completeness
    app = typer.Typer()

    @app.command()
    def main():
        raise OSError()

    result = runner.invoke(app)
    assert result.exit_code == 1