-
Notifications
You must be signed in to change notification settings - Fork 126
/
Copy pathtest_veristat_compare.py
75 lines (64 loc) · 2.46 KB
/
test_veristat_compare.py
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
#!/usr/bin/env python3
import unittest
from typing import Iterable, List
from ..veristat_compare import parse_table, VeristatFields
def gen_csv_table(records: Iterable[str]) -> List[str]:
return [
",".join(VeristatFields.headers()),
*records,
]
class TestVeristatCompare(unittest.TestCase):
def test_parse_table_ignore_new_prog(self):
table = gen_csv_table(
[
"prog_file.bpf.o,prog_name,N/A,success,N/A,N/A,1,N/A",
]
)
veristat_info = parse_table(table)
self.assertEqual(veristat_info.table, [])
self.assertFalse(veristat_info.changes)
self.assertFalse(veristat_info.new_failures)
def test_parse_table_ignore_removed_prog(self):
table = gen_csv_table(
[
"prog_file.bpf.o,prog_name,success,N/A,N/A,1,N/A,N/A",
]
)
veristat_info = parse_table(table)
self.assertEqual(veristat_info.table, [])
self.assertFalse(veristat_info.changes)
self.assertFalse(veristat_info.new_failures)
def test_parse_table_new_failure(self):
table = gen_csv_table(
[
"prog_file.bpf.o,prog_name,success,failure,MISMATCH,1,1,+0 (+0.00%)",
]
)
veristat_info = parse_table(table)
self.assertEqual(
veristat_info.table,
[["prog_file.bpf.o", "prog_name", "success -> failure (!!)", "+0.00 %"]],
)
self.assertTrue(veristat_info.changes)
self.assertTrue(veristat_info.new_failures)
def test_parse_table_new_changes(self):
table = gen_csv_table(
[
"prog_file.bpf.o,prog_name,failure,success,MISMATCH,0,0,+0 (+0.00%)",
"prog_file.bpf.o,prog_name_increase,failure,failure,MATCH,1,2,+1 (+100.00%)",
"prog_file.bpf.o,prog_name_decrease,success,success,MATCH,1,1,-1 (-100.00%)",
]
)
veristat_info = parse_table(table)
self.assertEqual(
veristat_info.table,
[
["prog_file.bpf.o", "prog_name", "failure -> success", "+0.00 %"],
["prog_file.bpf.o", "prog_name_increase", "failure", "+100.00 %"],
["prog_file.bpf.o", "prog_name_decrease", "success", "-100.00 %"],
],
)
self.assertTrue(veristat_info.changes)
self.assertFalse(veristat_info.new_failures)
if __name__ == "__main__":
unittest.main()