Passed
Branch master (53139b)
by Matěj
04:46 queued 02:30
created

test_matches_platform.test_typo()   A

Complexity

Conditions 2

Size

Total Lines 5
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
import pytest
2
3
from ssg_test_suite import common
4
5
6
def test_simple_match():
7
    scenario_platforms = ["Red Hat Enterprise Linux 7"]
8
    benchmark_cpes = {"cpe:/o:redhat:enterprise_linux:7"}
9
    assert common.matches_platform(scenario_platforms, benchmark_cpes) == True
10
11
12
def test_simple_no_match():
13
    scenario_platforms = ["Red Hat Enterprise Linux 7"]
14
    benchmark_cpes = {"cpe:/o:redhat:enterprise_linux:6"}
15
    assert common.matches_platform(scenario_platforms, benchmark_cpes) == False
16
17
18
def test_multi_platform_all():
19
    scenario_platforms = ["multi_platform_all"]
20
    benchmark_cpes = {"cpe:/o:redhat:enterprise_linux:7"}
21
    assert common.matches_platform(scenario_platforms, benchmark_cpes) == True
22
23
24
def test_multi_platform_match():
25
    scenario_platforms = ["multi_platform_rhel"]
26
    benchmark_cpes = {"cpe:/o:redhat:enterprise_linux:7"}
27
    assert common.matches_platform(scenario_platforms, benchmark_cpes) == True
28
29
30
def test_multi_platform_no_match():
31
    scenario_platforms = ["multi_platform_fedora"]
32
    benchmark_cpes = {"cpe:/o:redhat:enterprise_linux:7"}
33
    assert common.matches_platform(scenario_platforms, benchmark_cpes) == False
34
35
36
def test_list_simple_match_first():
37
    scenario_platforms = ["Red Hat Enterprise Linux 7",
38
                          "Red Hat Enterprise Linux 8"]
39
    benchmark_cpes = {"cpe:/o:redhat:enterprise_linux:7"}
40
    assert common.matches_platform(scenario_platforms, benchmark_cpes) == True
41
42
43
def test_list_simple_match_second():
44
    scenario_platforms = ["Red Hat Enterprise Linux 7",
45
                          "Red Hat Enterprise Linux 8"]
46
    benchmark_cpes = {"cpe:/o:redhat:enterprise_linux:8"}
47
    assert common.matches_platform(scenario_platforms, benchmark_cpes) == True
48
49
50
def test_list_simple_no_match():
51
    scenario_platforms = ["Red Hat Enterprise Linux 7",
52
                          "Red Hat Enterprise Linux 8"]
53
    benchmark_cpes = {"cpe:/o:redhat:enterprise_linux:6"}
54
    assert common.matches_platform(scenario_platforms, benchmark_cpes) == False
55
56
57
def test_list_multi_platform_match_first():
58
    scenario_platforms = ["multi_platform_rhel", "multi_platform_debian"]
59
    benchmark_cpes = {"cpe:/o:redhat:enterprise_linux:6"}
60
    assert common.matches_platform(scenario_platforms, benchmark_cpes) == True
61
62
63
def test_list_multi_platform_match_second():
64
    scenario_platforms = ["multi_platform_rhel", "multi_platform_debian"]
65
    benchmark_cpes = {"cpe:/o:debianproject:debian:8"}
66
    assert common.matches_platform(scenario_platforms, benchmark_cpes) == True
67
68
69
def test_list_multi_platform_no_match():
70
    scenario_platforms = ["multi_platform_debian", "multi_platform_ubuntu"]
71
    benchmark_cpes = {"cpe:/o:redhat:enterprise_linux:6"}
72
    assert common.matches_platform(scenario_platforms, benchmark_cpes) == False
73
74
75
def test_list_combined_match():
76
    scenario_platforms = ["multi_platform_debian", "multi_platform_ubuntu",
77
                          "Red Hat Enterprise Linux 6"]
78
    benchmark_cpes = {"cpe:/o:redhat:enterprise_linux:6"}
79
    assert common.matches_platform(scenario_platforms, benchmark_cpes) == True
80
81
82
def test_list_combined_match_2():
83
    scenario_platforms = ["Debian 8", "multi_platform_ubuntu", "openSUSE",
84
                          "Red Hat Enterprise Linux 6"]
85
    benchmark_cpes = {"cpe:/o:debianproject:debian:8"}
86
    assert common.matches_platform(scenario_platforms, benchmark_cpes) == True
87
88
89
def test_list_combined_no_match():
90
    scenario_platforms = ["multi_platform_ubuntu", "multi_platform_fedora",
91
                          "Red Hat Enterprise Linux 6", "openSUSE"]
92
    benchmark_cpes = {"cpe:/o:debianproject:debian:8"}
93
    assert common.matches_platform(scenario_platforms, benchmark_cpes) == False
94
95
96
def test_simple_multiple_benchmark_cpes():
97
    scenario_platforms = ["Red Hat Enterprise Linux 7"]
98
    benchmark_cpes = {"cpe:/o:redhat:enterprise_linux:7",
99
                      "cpe:/o:redhat:enterprise_linux:7::client",
100
                      "cpe:/o:redhat:enterprise_linux:7::computenode"}
101
    assert common.matches_platform(scenario_platforms, benchmark_cpes) == True
102
103
104
def test_simple_multiple_unrelated_benchmark_cpes():
105
    scenario_platforms = ["Red Hat Enterprise Linux 7"]
106
    benchmark_cpes = {"cpe:/o:redhat:enterprise_linux:7",
107
                      "cpe:/o:redhat:enterprise_linux:6"
108
                      "cpe:/o:scientificlinux:scientificlinux:6"}
109
    assert common.matches_platform(scenario_platforms, benchmark_cpes) == True
110
111
112
def test_simple_multiple_bogus_benchmark_cpes():
113
    scenario_platforms = ["Red Hat Enterprise Linux 7"]
114
    benchmark_cpes = {"cpe:/o:abcdef:ghijklm:42"
115
                      "cpe:/o:zzzzz:xxxx:77",
116
                      "cpe:/o:redhat:enterprise_linux:7"}
117
    assert common.matches_platform(scenario_platforms, benchmark_cpes) == True
118
119
def test_simple_multiple_bogus_benchmark_cpes_no_match():
120
    scenario_platforms = ["Fedora"]
121
    benchmark_cpes = {"cpe:/o:abcdef:ghijklm:42"
122
                      "cpe:/o:zzzzz:xxxx:77",
123
                      "cpe:/o:redhat:enterprise_linux:7"}
124
    assert common.matches_platform(scenario_platforms, benchmark_cpes) == False
125
126
127
def test_multiple_multiple_bogus_benchmark_cpes_no_match():
128
    scenario_platforms = ["Fedora", "openSUSE"]
129
    benchmark_cpes = {"cpe:/o:abcdef:ghijklm:42"
130
                      "cpe:/o:zzzzz:xxxx:77",
131
                      "cpe:/o:redhat:enterprise_linux:7"}
132
    assert common.matches_platform(scenario_platforms, benchmark_cpes) == False
133
134
135
def test_typo():
136
    scenario_platforms = ["Rrd Hat Enterprise Linux 7"]
137
    benchmark_cpes = {"cpe:/o:redhat:enterprise_linux:7"}
138
    with pytest.raises(ValueError):
139
        common.matches_platform(scenario_platforms, benchmark_cpes)
140
141
142
def test_wrong_multi_platform():
143
    scenario_platforms = ["multi_platform_fidorka"]
144
    benchmark_cpes = {"cpe:/o:fedoraproject:fedora:30"}
145
    with pytest.raises(ValueError):
146
        common.matches_platform(scenario_platforms, benchmark_cpes)
147