From 9cf81ea67aec2adc7b68cb95d723e708ccbfa54f Mon Sep 17 00:00:00 2001 From: Jeremiah Leary Date: Tue, 28 Jul 2020 07:32:10 -0500 Subject: [PATCH] Updates for issue #402: Mocking the number of rules ran to make tests more robust. --- vsg/rule_list.py | 5 ++- .../severity/output_w_config.architecture.txt | 2 +- vsg/tests/severity/output_w_config.txt | 2 +- .../output_w_config_fixed.architecture.txt | 2 +- vsg/tests/severity/output_w_config_fixed.txt | 2 +- .../output_wo_config.architecture.txt | 2 +- vsg/tests/severity/output_wo_config.txt | 2 +- vsg/tests/severity/test_main.py | 32 ++++++++++++++----- 8 files changed, 34 insertions(+), 15 deletions(-) diff --git a/vsg/rule_list.py b/vsg/rule_list.py index f84a49ad..eb85d317 100644 --- a/vsg/rule_list.py +++ b/vsg/rule_list.py @@ -233,7 +233,7 @@ class rule_list(): dRunInfo['violations'].extend(lViolations) dRunInfo['stopPhase'] = self.lastPhaseRan - dRunInfo['num_rules_checked'] = self.iNumberRulesRan + dRunInfo['num_rules_checked'] = self.get_number_of_rules_ran() dRunInfo['total_violations'] = len(dRunInfo['violations']) dRunInfo['maxSeverityNameLength'] = self.oSeverityList.iMaxNameLength dRunInfo['severities'] = {} @@ -328,6 +328,9 @@ class rule_list(): for oRule in self.rules: oRule.clear_violations() + def get_number_of_rules_ran(self): + return self.iNumberRulesRan + def filter_out_disabled_rules(lRules): ''' diff --git a/vsg/tests/severity/output_w_config.architecture.txt b/vsg/tests/severity/output_w_config.architecture.txt index 47b837c1..2b668f73 100644 --- a/vsg/tests/severity/output_w_config.architecture.txt +++ b/vsg/tests/severity/output_w_config.architecture.txt @@ -2,7 +2,7 @@ File: architecture.vhd ================================================================================ Phase 3 of 7... Reporting -Total Rules Checked: 201 +Total Rules Checked: 200 Total Violations: 2 Error : 1 Warning : 1 diff --git a/vsg/tests/severity/output_w_config.txt b/vsg/tests/severity/output_w_config.txt index 40ca1008..72ac046c 100644 --- a/vsg/tests/severity/output_w_config.txt +++ b/vsg/tests/severity/output_w_config.txt @@ -2,7 +2,7 @@ File: entity.vhd ================================================================================ Phase 2 of 7... Reporting -Total Rules Checked: 154 +Total Rules Checked: 200 Total Violations: 5 Error : 4 Warning : 0 diff --git a/vsg/tests/severity/output_w_config_fixed.architecture.txt b/vsg/tests/severity/output_w_config_fixed.architecture.txt index c2edcd87..4c08f908 100644 --- a/vsg/tests/severity/output_w_config_fixed.architecture.txt +++ b/vsg/tests/severity/output_w_config_fixed.architecture.txt @@ -2,7 +2,7 @@ File: architecture.vhd ================================================================================ Phase 7 of 7... Reporting -Total Rules Checked: 389 +Total Rules Checked: 200 Total Violations: 1 Error : 0 Warning : 1 diff --git a/vsg/tests/severity/output_w_config_fixed.txt b/vsg/tests/severity/output_w_config_fixed.txt index 93417e5b..19e9e65f 100644 --- a/vsg/tests/severity/output_w_config_fixed.txt +++ b/vsg/tests/severity/output_w_config_fixed.txt @@ -2,7 +2,7 @@ File: entity.vhd ================================================================================ Phase 7 of 7... Reporting -Total Rules Checked: 389 +Total Rules Checked: 200 Total Violations: 1 Error : 0 Warning : 0 diff --git a/vsg/tests/severity/output_wo_config.architecture.txt b/vsg/tests/severity/output_wo_config.architecture.txt index dc495217..dcdb416a 100644 --- a/vsg/tests/severity/output_wo_config.architecture.txt +++ b/vsg/tests/severity/output_wo_config.architecture.txt @@ -2,7 +2,7 @@ File: architecture.vhd ================================================================================ Phase 1 of 7... Reporting -Total Rules Checked: 64 +Total Rules Checked: 200 Total Violations: 1 Error : 1 Warning : 0 diff --git a/vsg/tests/severity/output_wo_config.txt b/vsg/tests/severity/output_wo_config.txt index 262bf6a4..ed4806c3 100644 --- a/vsg/tests/severity/output_wo_config.txt +++ b/vsg/tests/severity/output_wo_config.txt @@ -2,7 +2,7 @@ File: entity.vhd ================================================================================ Phase 1 of 7... Reporting -Total Rules Checked: 64 +Total Rules Checked: 200 Total Violations: 1 Error : 1 Warning : 0 diff --git a/vsg/tests/severity/test_main.py b/vsg/tests/severity/test_main.py index 874acf57..a81330b1 100644 --- a/vsg/tests/severity/test_main.py +++ b/vsg/tests/severity/test_main.py @@ -44,7 +44,9 @@ class test_severity_using_main(unittest.TestCase): os.remove(sJUnitFileName) @mock.patch('sys.stdout') - def test_entity_without_configuration(self, mock_stdout): + @mock.patch('vsg.__main__.rule_list.rule_list.get_number_of_rules_ran') + def test_entity_without_configuration(self, mock_rule_ran, mock_stdout): + mock_rule_ran.return_value = 200 try: sys.argv = ['vsg', '-f', sEntityFileName] __main__.main() @@ -62,7 +64,9 @@ class test_severity_using_main(unittest.TestCase): mock_stdout.write.assert_has_calls(lExpected) @mock.patch('sys.stdout') - def test_entity_with_configuration(self, mock_stdout): + @mock.patch('vsg.__main__.rule_list.rule_list.get_number_of_rules_ran') + def test_entity_with_configuration(self, mock_rule_ran, mock_stdout): + mock_rule_ran.return_value = 200 try: sys.argv = ['vsg', '-f', sEntityFileName, '-c', sConfigFile] __main__.main() @@ -80,7 +84,9 @@ class test_severity_using_main(unittest.TestCase): mock_stdout.write.assert_has_calls(lExpected) @mock.patch('sys.stdout') - def test_entity_with_configuration_and_fixed(self, mock_stdout): + @mock.patch('vsg.__main__.rule_list.rule_list.get_number_of_rules_ran') + def test_entity_with_configuration_and_fixed(self, mock_rule_ran, mock_stdout): + mock_rule_ran.return_value = 200 try: sys.argv = ['vsg', '-f', sEntityFileName, '-c', sConfigFile, '--fix'] __main__.main() @@ -98,7 +104,9 @@ class test_severity_using_main(unittest.TestCase): mock_stdout.write.assert_has_calls(lExpected) @mock.patch('sys.stdout') - def test_architecture_without_configuration(self, mock_stdout): + @mock.patch('vsg.__main__.rule_list.rule_list.get_number_of_rules_ran') + def test_architecture_without_configuration(self, mock_rule_ran, mock_stdout): + mock_rule_ran.return_value = 200 try: sys.argv = ['vsg', '-f', sArchitectureFileName] __main__.main() @@ -116,7 +124,9 @@ class test_severity_using_main(unittest.TestCase): mock_stdout.write.assert_has_calls(lExpected) @mock.patch('sys.stdout') - def test_architecture_with_configuration(self, mock_stdout): + @mock.patch('vsg.__main__.rule_list.rule_list.get_number_of_rules_ran') + def test_architecture_with_configuration(self, mock_rule_ran, mock_stdout): + mock_rule_ran.return_value = 200 try: sys.argv = ['vsg', '-f', sArchitectureFileName, '-c', sConfigFile] __main__.main() @@ -134,7 +144,9 @@ class test_severity_using_main(unittest.TestCase): mock_stdout.write.assert_has_calls(lExpected) @mock.patch('sys.stdout') - def test_architecture_with_configuration_and_fixed(self, mock_stdout): + @mock.patch('vsg.__main__.rule_list.rule_list.get_number_of_rules_ran') + def test_architecture_with_configuration_and_fixed(self, mock_rule_ran, mock_stdout): + mock_rule_ran.return_value = 200 try: sys.argv = ['vsg', '-f', sArchitectureFileName, '-c', sConfigFile, '--fix'] __main__.main() @@ -152,7 +164,9 @@ class test_severity_using_main(unittest.TestCase): mock_stdout.write.assert_has_calls(lExpected) @mock.patch('sys.stdout') - def test_both_with_configuration(self, mock_stdout): + @mock.patch('vsg.__main__.rule_list.rule_list.get_number_of_rules_ran') + def test_both_with_configuration(self, mock_rule_ran, mock_stdout): + mock_rule_ran.return_value = 200 try: sys.argv = ['vsg', '-f', sEntityFileName, sArchitectureFileName, '-c', sConfigFile] __main__.main() @@ -172,7 +186,9 @@ class test_severity_using_main(unittest.TestCase): mock_stdout.write.assert_has_calls(lExpected) @mock.patch('sys.stdout') - def test_both_with_configuration_and_fixed(self, mock_stdout): + @mock.patch('vsg.__main__.rule_list.rule_list.get_number_of_rules_ran') + def test_both_with_configuration_and_fixed(self, mock_rule_ran, mock_stdout): + mock_rule_ran.return_value = 200 try: sys.argv = ['vsg', '-f', sEntityFileName, sArchitectureFileName, '-c', sConfigFile, '--fix'] __main__.main()