Example #1
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)
Example #2
0
 def test_should_use_clang_format_for_warning(self):
     fun = FunctionInfo("foo", 100)
     fun.cyclomatic_complexity = 16
     fileStat = FileInformation("FILENAME", 1, [fun])
     option = Mock(CCN=15)
     print_warnings(option, [fileStat])
     self.assertIn("FILENAME:100: warning: foo has 16 CCN and 0 params (0 NLOC, 0 tokens)\n", sys.stdout.stream)
Example #3
0
 def test_print_fileinfo(self):
     fun = FunctionInfo("foo", 100)
     fun.end_line = 100
     fun.cyclomatic_complexity = 16
     fileStat = FileInformation("FILENAME", 1, [fun])
     print_and_save_detail_information([fileStat], self.options)
     self.assertEquals("       0     16      1      0 foo@100-100@FILENAME", sys.stdout.stream.splitlines()[3])
Example #4
0
 def test_sort_warning(self):
     self.option.sorting = ['cyclomatic_complexity']
     self.foo.cyclomatic_complexity = 10
     bar = FunctionInfo("bar", '', 100)
     bar.cyclomatic_complexity = 15
     print_warnings(self.option, self.scheme, [self.foo, bar])
     self.assertEqual('bar', self.scheme.function_info.call_args_list[0][0][0].name)
Example #5
0
class TestWarningFilterWithWhitelist(unittest.TestCase):

    WARNINGS = [
        FunctionInfo("foo", 'filename'),
        FunctionInfo("bar", 'filename'),
        FunctionInfo("foo", 'anotherfile')
    ]

    def test_should_filter_out_the_whitelist(self):
        warnings = whitelist_filter(self.WARNINGS, "foo")
        self.assertEqual(1, len(list(warnings)))

    def test_should_filter_function_in_the_right_file_when_specified(self):
        warnings = whitelist_filter(self.WARNINGS, 'filename:foo')
        self.assertEqual(2, len(list(warnings)))

    def test_should_work_with_class_member(self):
        warnings = whitelist_filter([FunctionInfo("class::foo", 'filename')],
                                    'class::foo')
        self.assertEqual(0, len(list(warnings)))

    def test_should_filter_mutiple_functions_defined_on_one_line(self):
        warnings = whitelist_filter(self.WARNINGS, 'foo, bar')
        self.assertEqual(0, len(list(warnings)))

    def test_should_filter_mutiple_lines_of_whitelist(self):
        warnings = whitelist_filter(self.WARNINGS, 'foo\n bar')
        self.assertEqual(0, len(list(warnings)))

    def test_should_ignore_comments_in_whitelist(self):
        warnings = whitelist_filter(self.WARNINGS, 'foo  #,bar\ni#,bar')
        self.assertEqual(1, len(list(warnings)))
Example #6
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)
Example #7
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)
Example #8
0
 def test_sort_warning(self):
     self.option.sorting = ['cyclomatic_complexity']
     self.foo.cyclomatic_complexity = 30
     bar = FunctionInfo("bar", '', 100)
     bar.cyclomatic_complexity = 40
     fileSummary = FileInformation("FILENAME", 123, [self.foo, bar])
     warnings = get_warnings([fileSummary], self.option)
     self.assertEqual('bar', warnings[0].name)
Example #9
0
 def test_sort_warning(self):
     self.option.sorting = ['cyclomatic_complexity']
     self.foo.cyclomatic_complexity = 30
     bar = FunctionInfo("bar", '', 100)
     bar.cyclomatic_complexity = 40
     fileSummary = FileInformation("FILENAME", 123, [self.foo, bar])
     warnings = get_warnings([fileSummary], self.option)
     self.assertEqual('bar', warnings[0].name)
Example #10
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)
Example #11
0
 def setUp(self):
     StreamStdoutTestCase.setUp(self)
     self.option = parse_args("app")
     self.foo = FunctionInfo("foo", 'FILENAME', 100)
     self.fileSummary = FileInformation("FILENAME", 123, [self.foo])
     self.extensions = get_extensions([])
     self.scheme = OutputScheme(self.extensions)
Example #12
0
class TestXMLOutput(unittest.TestCase):
    foo = FunctionInfo("foo", '', 100)
    foo.cyclomatic_complexity = 16
    file_infos = [FileInformation('f1.c', 1, [foo])]
    xml = xml_output(file_infos, True)

    def test_xml_output(self):
        self.assertIn('''foo at f1.c:100''', self.xml)

    def test_xml_stylesheet(self):
        self.assertIn('''<?xml-stylesheet type="text/xsl" href="https://raw.github.com/terryyin/lizard/master/lizard.xsl"?>''', self.xml)
Example #13
0
 def setUp(self):
     complex_fun = FunctionInfo("complex", '', 100)
     complex_fun.cyclomatic_complexity = 16
     simple_fun = FunctionInfo("simple", '', 100)
     simple_fun.cyclomatic_complexity = 15
     self.fileStat = FileInformation("FILENAME", 1,
                                     [complex_fun, simple_fun])
Example #14
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)
Example #15
0
class TestXMLOutput(unittest.TestCase):
    foo = FunctionInfo("foo", '', 100)
    foo.cyclomatic_complexity = 16
    file_infos = [FileInformation('f1.c', 1, [foo])]
    xml = xml_output(file_infos, True)

    def test_xml_output(self):
        self.assertIn('''foo at f1.c:100''', self.xml)

    def test_xml_stylesheet(self):
        self.assertIn('''<?xml-stylesheet type="text/xsl" href="https://raw.githubusercontent.com/terryyin/lizard/master/lizard.xsl"?>''', self.xml)

    def test_xml_output_on_empty_folder(self):
        xml_empty = xml_output([], True)
        self.assertIn('''<sum label="NCSS" value="0"/>''', xml_empty)
        self.assertIn('''<sum label="CCN" value="0"/>''', xml_empty)
        self.assertIn('''<sum label="Functions" value="0"/>''', xml_empty)
Example #16
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)
Example #17
0
 def setUp(self):
     StreamStdoutTestCase.setUp(self)
     self.option = parse_args("app")
     self.foo = FunctionInfo("foo", 'FILENAME', 100)
     fileSummary = FileInformation("FILENAME", 123, [self.foo])
     self.scheme = Mock()
Example #18
0
 def setUp(self):
     StreamStdoutTestCase.setUp(self)
     self.extensions = get_extensions([])
     self.scheme = OutputScheme(self.extensions)
     self.foo = FunctionInfo("foo", 'FILENAME', 100)
Example #19
0
 def setUp(self):
     StreamStdoutTestCase.setUp(self)
     self.foo = FunctionInfo("foo", 'FILENAME', 100)
Example #20
0
 def setUp(self):
     self.func = FunctionInfo("foo", 'FILENAME', 100)
     self.file_info = FileInformation("filename", 10, [self.func])
Example #21
0
 def test_FunctionInfo_ShouldBePicklable(self):
     import pickle
     pickle.dumps(FunctionInfo("a", '', 1))
Example #22
0
 def test_should_work_with_class_member(self):
     warnings = whitelist_filter([FunctionInfo("class::foo", 'filename')],
                                 'class::foo')
     self.assertEqual(0, len(list(warnings)))
Example #23
0
 def setUp(self):
     complex_fun = FunctionInfo("complex", '', 100)
     complex_fun.cyclomatic_complexity = 16
     simple_fun = FunctionInfo("simple", '', 100)
     simple_fun.cyclomatic_complexity = 15
     self.fileStat = FileInformation("FILENAME", 1, [complex_fun, simple_fun])
Example #24
0
 def test_should_work_with_class_member(self):
     whitelist = Whitelist('class::foo')
     warnings = list(
         whitelist.filter([(FunctionInfo("class::foo"), "filename")]))
     self.assertEqual(0, len(warnings))