|
9 | 9 |
|
10 | 10 | # NOTE: This test file file only works with scripts/ added to PYTHONPATH so pylint can't find the imports |
11 | 11 | # pragma pylint: disable=import-error |
12 | | -from bytecodecompare.prepare_report import CompilerInterface, FileReport, ContractReport, SMTUse |
| 12 | +from bytecodecompare.prepare_report import CompilerInterface, FileReport, ContractReport, SMTUse, Statistics |
13 | 13 | from bytecodecompare.prepare_report import load_source, parse_cli_output, parse_standard_json_output, prepare_compiler_input |
14 | 14 | # pragma pylint: enable=import-error |
15 | 15 |
|
@@ -99,6 +99,58 @@ def test_format_report_should_not_print_anything_if_contract_report_list_is_empt |
99 | 99 |
|
100 | 100 | self.assertEqual(report.format_report(), '') |
101 | 101 |
|
| 102 | +class TestPrepareReport_Statistics(unittest.TestCase): |
| 103 | + def test_initialization(self): |
| 104 | + self.assertEqual(Statistics(), Statistics(0, 0, 0, 0, 0)) |
| 105 | + |
| 106 | + def test_aggregate_bytecode_and_metadata_present(self): |
| 107 | + statistics = Statistics() |
| 108 | + statistics.aggregate(FileReport(file_name=Path('F'), contract_reports=[ContractReport('C', 'c.sol', 'B', 'M')])) |
| 109 | + self.assertEqual(statistics, Statistics(1, 1, 0, 0, 0)) |
| 110 | + |
| 111 | + def test_aggregate_bytecode_missing(self): |
| 112 | + statistics = Statistics() |
| 113 | + statistics.aggregate(FileReport(file_name=Path('F'), contract_reports=[ContractReport('C', 'c.sol', None, 'M')])) |
| 114 | + self.assertEqual(statistics, Statistics(1, 1, 0, 1, 0)) |
| 115 | + |
| 116 | + def test_aggregate_metadata_missing(self): |
| 117 | + statistics = Statistics() |
| 118 | + statistics.aggregate(FileReport(file_name=Path('F'), contract_reports=[ContractReport('C', 'c.sol', 'B', None)])) |
| 119 | + self.assertEqual(statistics, Statistics(1, 1, 0, 0, 1)) |
| 120 | + |
| 121 | + def test_aggregate_no_contract_reports(self): |
| 122 | + statistics = Statistics() |
| 123 | + statistics.aggregate(FileReport(file_name=Path('F'), contract_reports=[])) |
| 124 | + self.assertEqual(statistics, Statistics(1, 0, 0, 0, 0)) |
| 125 | + |
| 126 | + def test_aggregate_missing_contract_report_list(self): |
| 127 | + statistics = Statistics() |
| 128 | + statistics.aggregate(FileReport(file_name=Path('F'), contract_reports=None)) |
| 129 | + self.assertEqual(statistics, Statistics(1, 0, 1, 0, 0)) |
| 130 | + |
| 131 | + def test_aggregate_multiple_contract_reports(self): |
| 132 | + statistics = Statistics() |
| 133 | + statistics.aggregate(FileReport(file_name=Path('F'), contract_reports=[ |
| 134 | + ContractReport('C', 'c.sol', 'B', 'M'), |
| 135 | + ContractReport('C', 'c.sol', None, 'M'), |
| 136 | + ContractReport('C', 'c.sol', 'B', None), |
| 137 | + ContractReport('C', 'c.sol', None, None), |
| 138 | + ])) |
| 139 | + self.assertEqual(statistics, Statistics(1, 4, 0, 2, 2)) |
| 140 | + |
| 141 | + def test_str(self): |
| 142 | + statistics = Statistics() |
| 143 | + statistics.aggregate(FileReport(file_name=Path('F'), contract_reports=[ |
| 144 | + ContractReport('C', 'c.sol', 'B', 'M'), |
| 145 | + ContractReport('C', 'c.sol', None, 'M'), |
| 146 | + ContractReport('C', 'c.sol', 'B', None), |
| 147 | + ContractReport('C', 'c.sol', None, None), |
| 148 | + ])) |
| 149 | + statistics.aggregate(FileReport(file_name=Path('F'), contract_reports=None)) |
| 150 | + |
| 151 | + self.assertEqual(statistics, Statistics(2, 4, 1, 2, 2)) |
| 152 | + self.assertEqual(str(statistics), "test cases: 2, contracts: 4+, errors: 1, missing bytecode: 2, missing metadata: 2") |
| 153 | + |
102 | 154 |
|
103 | 155 | class TestLoadSource(PrepareReportTestBase): |
104 | 156 | def test_load_source_should_strip_smt_pragmas_if_requested(self): |
|
0 commit comments