예제 #1
0
 def test_print_file_summary_only_once(self):
     scheme = OutputScheme([])
     print_and_save_modules([
         FileInformation("FILENAME1", 123, []),
         FileInformation("FILENAME2", 123, [])
     ], scheme)
     self.assertEqual(1, sys.stdout.stream.count("FILENAME1"))
예제 #2
0
 def test_print_result(self):
     file_infos = [
         FileInformation('f1.c', 1, []),
         FileInformation('f2.c', 1, [])
     ]
     option = Mock(CCN=15,
                   thresholds={},
                   number=0,
                   extensions=[],
                   whitelist='')
     self.assertEqual(0, print_result_with_scheme(file_infos, option))
예제 #3
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])
예제 #4
0
 def test_print_and_save_detail_information(self):
     scheme = OutputScheme([])
     fileSummary = FileInformation("FILENAME", 123, [])
     print_and_save_modules([fileSummary], scheme)
     self.assertIn(
         "    123       0.0     0.0        0.0         0     FILENAME\n",
         sys.stdout.stream)
예제 #5
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)
예제 #6
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)
예제 #7
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)
예제 #8
0
 def test_print_fileinfo(self):
     self.foo.end_line = 100
     self.foo.cyclomatic_complexity = 16
     fileStat = FileInformation("FILENAME", 1, [self.foo])
     print_and_save_modules([fileStat], self.scheme)
     self.assertEqual(
         "       1     16      1      0       0 foo@100-100@FILENAME",
         sys.stdout.stream.splitlines()[3])
예제 #9
0
 def test_should_use_clang_format_for_warning(self):
     self.foo.cyclomatic_complexity = 30
     self.foo.max_nesting_depth = 10
     fileSummary = FileInformation("FILENAME", 123, [self.foo])
     scheme = OutputScheme([Ext()])
     count = print_clang_style_warning([fileSummary], self.option, scheme)
     self.assertIn("FILENAME:100: warning: foo has 1 NLOC, 30 CCN, 1 token, 0 PARAM, 0 length, 10 ND\n", sys.stdout.stream)
     self.assertEqual(1, count)
예제 #10
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)
예제 #11
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)
예제 #12
0
    def test_print_fileinfo(self):
        self.foo.end_line = 100
        self.foo.cyclomatic_complexity = 16
        fileStat = FileInformation("FILENAME", 1, [self.foo])

        csv_output(AllResult([fileStat]), True)

        self.assertEqual(
            '1,16,1,0,0,"foo@100-100@FILENAME","FILENAME","foo","foo",100,100',
            sys.stdout.stream.splitlines()[1])
예제 #13
0
파일: testOutput.py 프로젝트: KenLau/lizard
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)
예제 #14
0
 def check_whitelist(self, script, mock_open, mock_isfile):
     mock_isfile.return_value = True
     mock_open.return_value.read.return_value = script
     file_infos = [FileInformation('f1.c', 1, [self.foo])]
     option = Mock(thresholds={
         'cyclomatic_complexity': 15,
         'length': 1000
     },
                   CCN=15,
                   number=0,
                   arguments=100,
                   length=1000,
                   extensions=[])
     return print_result_with_scheme(file_infos, option)
예제 #15
0
    def test_print_extension(self):
        options_mock = Mock()
        options_mock.verbose = True
        options_mock.extensions = []

        self.foo.end_line = 100
        self.foo.cyclomatic_complexity = 16
        fileStat = FileInformation("FILENAME", 1, [self.foo])

        csv_output(AllResult([fileStat]), options_mock)

        self.assertEqual(
            '1,16,1,0,0,"foo@100-100@FILENAME","FILENAME","foo","foo",100,100',
            sys.stdout.stream.splitlines()[1])
예제 #16
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)
예제 #17
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)
예제 #18
0
 def setUp(self):
     self.func = FunctionInfo("foo", 'FILENAME', 100)
     self.file_info = FileInformation("filename", 10, [self.func])
예제 #19
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)
예제 #20
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"))
예제 #21
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)
예제 #22
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)
예제 #23
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()