File: test_argv_args.py

package info (click to toggle)
clikit 0.6.2-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 984 kB
  • sloc: python: 9,575; sh: 6; makefile: 3
file content (77 lines) | stat: -rw-r--r-- 2,061 bytes parent folder | download | duplicates (3)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import sys

import pytest

from clikit.args import ArgvArgs


@pytest.fixture()
def argv():
    original_argv = sys.argv

    yield

    sys.argv = original_argv


def test_create(argv):
    sys.argv = ("console", "server", "add", "--port", "80", "localhost")
    args = ArgvArgs()

    assert args.script_name == "console"
    assert ["server", "add", "--port", "80", "localhost"] == args.tokens


def test_create_with_custom_tokens(argv):
    sys.argv = ("console", "server", "add", "localhost")
    args = ArgvArgs(["console", "server", "add", "--port", "80", "localhost"])

    assert args.script_name == "console"
    assert ["server", "add", "--port", "80", "localhost"] == args.tokens


def test_has_token():
    args = ArgvArgs(["console", "server", "add", "--port", "80", "localhost"])

    assert args.has_token("server")
    assert args.has_token("add")
    assert args.has_token("--port")
    assert args.has_token("80")
    assert args.has_token("localhost")
    assert not args.has_token("console")
    assert not args.has_token("foo")


def test_has_option_token():
    args = ArgvArgs(
        [
            "console",
            "server",
            "add",
            "--port",
            "80",
            "localhost",
            "--",
            "-h",
            "--test",
            "remainder",
        ]
    )

    assert args.has_option_token("server")
    assert args.has_option_token("add")
    assert args.has_option_token("--port")
    assert args.has_option_token("80")
    assert args.has_option_token("localhost")
    assert not args.has_option_token("console")
    assert not args.has_option_token("-h")
    assert not args.has_option_token("--test")
    assert not args.has_option_token("remainder")


def test_to_string():
    args = ArgvArgs(["console", "server", "add", "--port", "80", "localhost"])

    assert "console server add --port 80 localhost" == args.to_string()
    assert "console server add --port 80 localhost" == args.to_string(True)
    assert "server add --port 80 localhost" == args.to_string(False)