File: test_callback_warning.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 (44 lines) | stat: -rw-r--r-- 966 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
import pytest
import typer
from typer.testing import CliRunner

runner = CliRunner()


def test_warns_when_callback_is_not_supported():
    app = typer.Typer()

    sub_app = typer.Typer()

    @sub_app.callback()
    def callback():
        """This help text is not used."""

    app.add_typer(sub_app)

    with pytest.warns(
        match="The 'callback' parameter is not supported by Typer when using `add_typer` without a name"
    ):
        try:
            app()
        except SystemExit:
            pass


def test_warns_when_callback_is_not_supported_added_after_add_typer():
    app = typer.Typer()

    sub_app = typer.Typer()
    app.add_typer(sub_app)

    @sub_app.callback()
    def callback():
        """This help text is not used."""

    with pytest.warns(
        match="The 'callback' parameter is not supported by Typer when using `add_typer` without a name"
    ):
        try:
            app()
        except SystemExit:
            pass