File: test_cmds.py

package info (click to toggle)
python-dcos 0.2.0-10
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,440 kB
  • sloc: python: 8,196; sh: 194; makefile: 36
file content (99 lines) | stat: -rw-r--r-- 2,181 bytes parent folder | download | duplicates (4)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
from dcos import cmds

import pytest


@pytest.fixture
def args():
    return {
        'cmd-a': True,
        'cmd-b': True,
        'cmd-c': False,
        'arg-1': 'arg-1',
        'arg-2': 'arg-2',
        'arg-0': 'arg-0',
    }


def test_single_cmd(args):
    commands = [
        cmds.Command(
            hierarchy=['cmd-a', 'cmd-b'],
            arg_keys=['arg-0', 'arg-1', 'arg-2'],
            function=function),
    ]

    assert cmds.execute(commands, args) == 1


def test_multiple_cmd(args):
    commands = [
        cmds.Command(
            hierarchy=['cmd-c'],
            arg_keys=['arg-0', 'arg-1', 'arg-2'],
            function=pytest.fail),
        cmds.Command(
            hierarchy=['cmd-a', 'cmd-b'],
            arg_keys=['arg-0', 'arg-1', 'arg-2'],
            function=function),
    ]

    assert cmds.execute(commands, args) == 1


def test_no_matching_cmd(args):
    commands = [
        cmds.Command(
            hierarchy=['cmd-c'],
            arg_keys=['arg-0', 'arg-1', 'arg-2'],
            function=pytest.fail),
    ]

    with pytest.raises(Exception):
        cmds.execute(commands, args)


def test_similar_cmds(args):
    commands = [
        cmds.Command(
            hierarchy=['cmd-a', 'cmd-b'],
            arg_keys=['arg-0', 'arg-1', 'arg-2'],
            function=function),
        cmds.Command(
            hierarchy=['cmd-a'],
            arg_keys=['arg-0', 'arg-1', 'arg-2'],
            function=pytest.fail),
    ]

    assert cmds.execute(commands, args) == 1


def test_missing_cmd(args):
    commands = [
        cmds.Command(
            hierarchy=['cmd-d'],
            arg_keys=['arg-0', 'arg-1', 'arg-2'],
            function=pytest.fail),
    ]

    with pytest.raises(KeyError):
        returncode, err = cmds.execute(commands, args)


def test_missing_arg(args):
    commands = [
        cmds.Command(
            hierarchy=['cmd-a'],
            arg_keys=['arg-3'],
            function=pytest.fail),
    ]

    with pytest.raises(KeyError):
        returncode, err = cmds.execute(commands, args)


def function(*args):
    for i in range(len(args)):
        assert args[i] == 'arg-{}'.format(i)

    return 1