Passed
Branch master (53139b)
by Matěj
02:05
created

test_matches_platform.test_typo()   A

Complexity

Conditions 2

Size

Total Lines 5
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

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