-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unittests for veristat_compare script
- Rename veristat-compare.py into veristat_compare.py to match python naming convention - Add unittests for parse_tables() method Signed-off-by: Nikolay Yurin <[email protected]>
- Loading branch information
Showing
4 changed files
with
91 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 TestMatrix(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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters