Exemple #1
0
 def test_sort_warning(self, print_function_info):
     option = Mock(display_fn_end_line = False, extensions = get_extensions([]))
     option.sorting = ['cyclomatic_complexity']
     foo = FunctionInfo("foo", 100)
     foo.cyclomatic_complexity = 10
     bar = FunctionInfo("bar", 100)
     bar.cyclomatic_complexity = 15
     print_warnings(option, [(foo, "FILENAME"),(bar, "FILENAME")])
     self.assertEqual('bar', print_function_info.call_args_list[0][0][0].name)
Exemple #2
0
 def test_whitelist(self, mock_exit):
     fun = FunctionInfo("foo", 100)
     fun.cyclomatic_complexity = 16
     file_infos = [FileInformation('f1.c', 1, [fun])]
     option = Mock(CCN=15, number = 0, extensions=[], whitelist='foo')
     print_result(file_infos, option)
     self.assertEqual(0, mock_exit.call_count)
Exemple #3
0
 def test_exit_with_non_zero_when_more_warning_than_ignored_number(self, mock_exit):
     fun = FunctionInfo("foo", 100)
     fun.cyclomatic_complexity = 16
     file_infos = [FileInformation('f1.c', 1, [fun])]
     option = Mock(CCN=15, number = 0, extensions=[], whitelist='')
     print_result(file_infos, option)
     mock_exit.assert_called_with(1)
Exemple #4
0
 def test_should_use_clang_format_with_function_end_line_number_for_warning(self):
     fun = FunctionInfo("foo", 100)
     fun.end_line = 100
     fun.cyclomatic_complexity = 16
     fileStat = FileInformation("FILENAME", 1, [fun])
     option = Mock(display_fn_end_line = True)
     print_warnings(option, [(fun, "FILENAME")])
     self.assertIn("FILENAME:100-100: warning: foo has 16 CCN and 0 params (0 NLOC, 1 tokens)\n", sys.stdout.stream)
Exemple #5
0
class TestXMLOutput(unittest.TestCase):
    
    fun = FunctionInfo("foo", 100)
    fun.cyclomatic_complexity = 16
    file_infos = [FileInformation('f1.c', 1, [fun])]
    option = Mock(CCN=15, number = 0, extensions=[])
    xml = XMLFormatter().xml_output(file_infos, option)
    
    def test_xml_output(self):
        root = ET.fromstring(self.xml)
        item = root.findall('''./measure[@type="Function"]/item[0]''')[0]
        self.assertEqual('''foo at f1.c:100''', item.get("name"))

    def test_xml_stylesheet(self):
        self.assertIn('''<?xml-stylesheet type="text/xsl" href="https://raw.github.com/terryyin/lizard/master/lizard.xsl"?>''', self.xml)
Exemple #6
0
 def test_print_result(self, mock_exit):
     file_infos = [FileInformation('f1.c', 1, []), FileInformation('f2.c', 1, [])]
     option = Mock(CCN=15, number = 0, extensions=[], whitelist='')
     print_result(file_infos, option)
     self.assertEqual(0, mock_exit.call_count)
Exemple #7
0
 def test_print_extension_results(self):
     file_infos = []
     extension = Mock()
     option = Mock(CCN=15, number = 0, extensions = [extension], whitelist='')
     print_result(file_infos, option)
     self.assertEqual(1, extension.print_result.call_count)
Exemple #8
0
 def test_print_file_summary_only_once(self):
     print_and_save_detail_information(
                         [FileInformation("FILENAME1", 123, []), 
                          FileInformation("FILENAME2", 123, [])], Mock(warnings_only=False, extensions=[]))
     self.assertEqual(1, sys.stdout.stream.count("FILENAME1"))
Exemple #9
0
 def test_print_and_save_detail_information(self):
     fileSummary = FileInformation("FILENAME", 123, [])
     print_and_save_detail_information([fileSummary], Mock(warnings_only=False, extensions=[]))
     self.assertIn("    123      0      0         0         0     FILENAME", sys.stdout.stream)
Exemple #10
0
 def test_should_use_clang_format_for_warning(self):
     option = Mock(display_fn_end_line = False)
     print_warnings(option, [(FunctionInfo("foo", 100), "FILENAME")])
     self.assertIn("FILENAME:100: warning: foo has 1 CCN and 0 params (0 NLOC, 1 tokens)\n", sys.stdout.stream)
Exemple #11
0
 def test_should_not_have_header_when_warning_only_is_on(self):
     option = Mock(warnings_only=True, CCN=15)
     print_warnings(option, [])
     self.assertNotIn("Warnings (CCN > 15)", sys.stdout.stream)
Exemple #12
0
 def test_should_say_no_warning_when_warning_only_is_off(self):
     option = Mock(warnings_only=False, CCN=15)
     print_warnings(option, [])
     self.assertIn("No warning found. Excellent!\n", sys.stdout.stream)
Exemple #13
0
 def test_null_result(self):
     file_infos = [FileInformation('f1.c', 1, []), None]
     option = Mock(CCN=15, number = 0, extensions=[], whitelist='')
     print_result(file_infos, option)
Exemple #14
0
 def test_sort_warning_with_generator(self):
     option = Mock(display_fn_end_line = False, extensions = get_extensions([]))
     option.sorting = ['cyclomatic_complexity']
     print_warnings(option, (x for x in []))
Exemple #15
0
 def test_should_filter_the_warnings(self):
     option = Mock(CCN=15, arguments=10)
     warnings = list(warning_filter(option, [self.fileStat]))
     self.assertEqual(1, len(warnings))
     self.assertEqual("complex", warnings[0][0].name)