File: BenchmarkSettingDefinition.py

package info (click to toggle)
uranium 5.0.0-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,304 kB
  • sloc: python: 31,765; sh: 132; makefile: 12
file content (79 lines) | stat: -rw-r--r-- 2,437 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
# Copyright (c) 2016 Ultimaker B.V.
# Uranium is released under the terms of the LGPLv3 or higher.

import pytest

from UM.Settings.SettingDefinition import SettingDefinition

benchmark_matches_filter_data = [
    ({ "key": "test" }, True),
    ({ "key": "*est" }, True),
    ({ "default_value": 10 }, True),
    ({ "label": "Test*", "description": "Test*"}, True),
    ({ "minimum_value": 5}, False)
]

@pytest.mark.parametrize("filter,matches", benchmark_matches_filter_data)
def benchmark_matchesFilter(benchmark, filter, matches):
    definition = SettingDefinition("test", None)
    definition.deserialize({
        "label": "Test",
        "type": "int",
        "default_value": 10,
        "description": "Test Setting",
        "children": {
            "test_child_1": {
                "label": "Test Child 1",
                "type": "int",
                "default_value": 20,
                "description": "Test Child Setting 1"
            },
            "test_child_2": {
                "label": "Test Child 2",
                "type": "int",
                "default_value": 20,
                "description": "Test Child Setting 2"
            }
        }
    })

    result = benchmark(definition.matchesFilter, **filter)
    assert result == matches


benchmark_matches_filter_data = [
    ({ "key": "test" }, 1),
    ({ "key": "test*" }, 3),
    ({ "default_value": 10 }, 1),
    ({ "default_value": 20 }, 2),
    ({ "label": "Test*", "description": "Test*"}, 3),
    ({ "minimum_value": 5}, 0),
    ({ "key": "nope"}, 0)
]

@pytest.mark.parametrize("filter,match_count", benchmark_matches_filter_data)
def benchmark_findDefinitions(benchmark, filter, match_count):
    definition = SettingDefinition("test", None)
    definition.deserialize({
        "label": "Test",
        "type": "int",
        "default_value": 10,
        "description": "Test Setting",
        "children": {
            "test_child_1": {
                "label": "Test Child 1",
                "type": "int",
                "default_value": 20,
                "description": "Test Child Setting 1"
            },
            "test_child_2": {
                "label": "Test Child 2",
                "type": "int",
                "default_value": 20,
                "description": "Test Child Setting 2"
            }
        }
    })

    result = benchmark(definition.findDefinitions, **filter)
    assert len(result) == match_count