Beispiel #1
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)
Beispiel #2
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)
Beispiel #3
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)
Beispiel #4
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)
Beispiel #5
0
class TestWarningFilterWithWhitelist(unittest.TestCase):

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

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

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

    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))

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

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

    def test_should_ignore_comments_in_whitelist(self):
        whitelist = Whitelist('foo  #,bar\ni#,bar')
        warnings = list(whitelist.filter(self.WARNINGS))
        self.assertEqual(1, len(warnings))
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)
Beispiel #7
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)
Beispiel #8
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()
Beispiel #9
0
 def setUp(self):
     StreamStdoutTestCase.setUp(self)
     self.extensions = get_extensions([])
     self.scheme = OutputScheme(self.extensions)
     self.foo = FunctionInfo("foo", 'FILENAME', 100)
Beispiel #10
0
 def setUp(self):
     StreamStdoutTestCase.setUp(self)
     self.foo = FunctionInfo("foo", 'FILENAME', 100)
Beispiel #11
0
 def test_FunctionInfo_ShouldBePicklable(self):
     import pickle
     pickle.dumps(FunctionInfo("a", '', 1))
Beispiel #12
0
 def test_should_work_with_class_member(self):
     warnings = whitelist_filter([FunctionInfo("class::foo", 'filename')],
                                 'class::foo')
     self.assertEqual(0, len(list(warnings)))
Beispiel #13
0
 def setUp(self):
     self.func = FunctionInfo("foo", 'FILENAME', 100)
     self.file_info = FileInformation("filename", 10, [self.func])
Beispiel #14
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])
Beispiel #15
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))