File: test_package.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 (108 lines) | stat: -rw-r--r-- 2,794 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
100
101
102
103
104
105
106
107
108
import collections

from dcos import package
from dcos.errors import DCOSException

import pytest

MergeData = collections.namedtuple(
    'MergeData',
    ['first', 'second', 'expected'])


@pytest.fixture(params=[
    MergeData(
        first={},
        second={'a': 1},
        expected={'a': 1}),
    MergeData(
        first={'a': 'a'},
        second={'a': 1},
        expected={'a': 1}),
    MergeData(
        first={'b': 'b'},
        second={'a': 1},
        expected={'b': 'b', 'a': 1}),
    MergeData(
        first={'b': 'b'},
        second={},
        expected={'b': 'b'}),
    MergeData(
        first={'b': {'a': 'a'}},
        second={'b': {'c': 'c'}},
        expected={'b': {'c': 'c', 'a': 'a'}}),
    ])
def merge_data(request):
    return request.param


def test_option_merge(merge_data):
    assert merge_data.expected == package._merge_options(
        merge_data.first,
        merge_data.second)


DefaultConfigValues = collections.namedtuple(
    'DefaultConfigValue',
    ['schema', 'expected'])


@pytest.fixture(params=[
    DefaultConfigValues(
        schema={
            "type": "object",
            "properties": {
                "foo": {
                    "type": "object",
                    "properties": {
                        "bar": {
                            "type": "string",
                            "description": "A bar name."
                        },
                        "baz": {
                            "type": "integer",
                            "description": "How many times to do baz.",
                            "minimum": 0,
                            "maximum": 16,
                            "required": False,
                            "default": 4
                        }
                    }
                },
                "fiz": {
                    "type": "boolean",
                    "default": True,
                },
                "buz": {
                    "type": "string"
                }
            }
        },
        expected={'foo': {'baz': 4}, 'fiz': True}),
    DefaultConfigValues(
        schema={
            "type": "object",
            "properties": {
                "fiz": {
                    "type": "boolean",
                    "default": True,
                },
                "additionalProperties": False
            }
        },
        expected={'fiz': True}),
    DefaultConfigValues(
        schema={
            "type": "object",
        },
        expected=None)])
def config_value(request):
    return request.param


def test_extract_default_values(config_value):
    try:
        result = package._extract_default_values(config_value.schema)
    except DCOSException as e:
        result = str(e)
    assert result == config_value.expected