示例#1
0
 def test_fail_to_open_file_should_be_allowed(self, mock_open, mock_os_walk):
     mock_os_walk.return_value = (['.',
                                   None,
                                   ['f1.cpp', 'f2.cpp']],)
     file_handle = mock_open.side_effect = IOError
     files = get_all_source_files(["dir"], [], [])
     self.assertEqual(['./f1.cpp', './f2.cpp'], list(files))
示例#2
0
 def test_duplicates(self, mock_open, mock_os_walk):
     mock_os_walk.return_value = (['.',
                                   None,
                                   ['f1.cpp', 'f2.cpp']],)
     file_handle = mock_open.return_value.__enter__.return_value
     file_handle.read.return_value = "int foo(){haha();\n}"
     files = get_all_source_files(["dir"], [], [])
     self.assertEqual(['./f1.cpp'], list(files))
示例#3
0
 def test_exclude_file_name(self, mock_os_walk, md5):
     mock_os_walk.return_value = (['.', None, ['temp.c', 'useful.cpp']], )
     files = get_all_source_files(["dir"], ["*.c"], [])
     if which_system() == "Windows":
         file_names = [".\\useful.cpp"]
     else:
         file_names = ["./useful.cpp"]
     self.assertEqual(file_names, list(files))
示例#4
0
 def test_nonduplicates(self, mock_open, mock_os_walk):
     mock_os_walk.return_value = (['.',
                                   None,
                                   ['f1.cpp', 'f2.cpp']],)
     file_handle = mock_open.return_value.__enter__.return_value
     outs = ["int foo(){{haha({param});\n}}".format(param=i) for i in range(2)]
     file_handle.read.side_effect = lambda: outs.pop()
     files = get_all_source_files(["dir"], [], [])
     self.assertEqual(["./f1.cpp", "./f2.cpp"], list(files))
示例#5
0
 def test_nonduplicates(self, mock_open, mock_os_walk):
     mock_os_walk.return_value = (['.', None, ['f1.cpp', 'f2.cpp']], )
     file_handle = mock_open.return_value.__enter__.return_value
     outs = [
         "int foo(){{haha({param});\n}}".format(param=i) for i in range(2)
     ]
     file_handle.read.side_effect = lambda: outs.pop()
     files = get_all_source_files(["dir"], [], [])
     self.assertEqual(["./f1.cpp", "./f2.cpp"], list(files))
示例#6
0
 def test_assigned_lanagues(self, mock_os_walk, md5):
     mock_os_walk.return_value = ([
         '.', None, ['temp.c', 'useful.cpp', 'x.java', 'x.js']
     ], )
     md5.side_effect = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
     files = list(get_all_source_files(["dir"], [], ['cpp', 'java']))
     self.assertIn("./temp.c", files)
     self.assertIn("./useful.cpp", files)
     self.assertIn("./x.java", files)
     self.assertNotIn("./x.js", files)
示例#7
0
 def test_exclude_file_name(self, mock_os_walk, md5):
     mock_os_walk.return_value = (['.',
                                   None,
                                   ['temp.c', 'useful.cpp']],)
     files = get_all_source_files(["dir"], ["*.c"], [])
     if which_system() == "Windows":
         file_names = [".\\useful.cpp"]
     else:
         file_names = ["./useful.cpp"]
     self.assertEqual(file_names, list(files))
示例#8
0
 def test_fail_to_open_file_should_be_allowed(self, mock_open,
                                              mock_os_walk):
     mock_os_walk.return_value = (['.', None, ['f1.cpp', 'f2.cpp']], )
     file_handle = mock_open.side_effect = IOError
     files = get_all_source_files(["dir"], [], [])
     if which_system() == "Windows":
         file_names = [".\\f1.cpp", ".\\f2.cpp"]
     else:
         file_names = ["./f1.cpp", "./f2.cpp"]
     self.assertEqual(file_names, list(files))
示例#9
0
 def test_duplicates(self, mock_open, mock_os_walk):
     mock_os_walk.return_value = (['.', None, ['f1.cpp', 'f2.cpp']], )
     file_handle = mock_open.return_value.__enter__.return_value
     file_handle.read.return_value = "int foo(){haha();\n}"
     files = get_all_source_files(["dir"], [], [])
     if which_system() == "Windows":
         file_names = [".\\f1.cpp"]
     else:
         file_names = ["./f1.cpp"]
     self.assertEqual(file_names, list(files))
示例#10
0
 def test_assigned_lanagues(self, mock_os_walk, md5):
     mock_os_walk.return_value = (['.', 
                                   None,
                                   ['temp.c', 'useful.cpp', 'x.java', 'x.js']],)
     md5.side_effect = [1,2,3,4,5,6,7,8,9,0]
     files = list(get_all_source_files(["dir"], [], ['cpp', 'java']))
     self.assertIn("./temp.c", files)
     self.assertIn("./useful.cpp", files)
     self.assertIn("./x.java", files)
     self.assertNotIn("./x.js", files)
示例#11
0
 def test_fail_to_open_file_should_be_allowed(self, mock_open, mock_os_walk):
     mock_os_walk.return_value = (['.',
                                   None,
                                   ['f1.cpp', 'f2.cpp']],)
     file_handle = mock_open.side_effect = IOError
     files = get_all_source_files(["dir"], [], [])
     if which_system() == "Windows":
         file_names = [".\\f1.cpp", ".\\f2.cpp"]
     else:
         file_names = ["./f1.cpp", "./f2.cpp"]
     self.assertEqual(file_names, list(files))
示例#12
0
 def test_duplicates(self, mock_open, mock_os_walk):
     mock_os_walk.return_value = (['.',
                                   None,
                                   ['f1.cpp', 'f2.cpp']],)
     file_handle = mock_open.return_value.__enter__.return_value
     file_handle.read.return_value = "int foo(){haha();\n}"
     files = get_all_source_files(["dir"], [], [])
     if which_system() == "Windows":
         file_names = [".\\f1.cpp"]
     else:
         file_names = ["./f1.cpp"]
     self.assertEqual(file_names, list(files))
示例#13
0
 def test_assigned_lanagues(self, mock_os_walk, md5):
     mock_os_walk.return_value = (['.',
                                   None,
                                   ['temp.c', 'useful.cpp', 'x.java', 'x.js']],)
     md5.side_effect = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
     files = list(get_all_source_files(["dir"], [], ['cpp', 'java']))
     if which_system() == "Windows":
         file_names = [".\\temp.c", ".\\useful.cpp", ".\\x.java", ".\\x.js"]
     else:
         file_names = ["./temp.c", "./useful.cpp", "./x.java", "./x.js"]
     self.assertIn(file_names[0], files)
     self.assertIn(file_names[1], files)
     self.assertIn(file_names[2], files)
     self.assertNotIn(file_names[3], files)
示例#14
0
 def test_assigned_lanagues(self, mock_os_walk, md5):
     mock_os_walk.return_value = ([
         '.', None, ['temp.c', 'useful.cpp', 'x.java', 'x.js']
     ], )
     md5.side_effect = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
     files = list(get_all_source_files(["dir"], [], ['cpp', 'java']))
     if which_system() == "Windows":
         file_names = [".\\temp.c", ".\\useful.cpp", ".\\x.java", ".\\x.js"]
     else:
         file_names = ["./temp.c", "./useful.cpp", "./x.java", "./x.js"]
     self.assertIn(file_names[0], files)
     self.assertIn(file_names[1], files)
     self.assertIn(file_names[2], files)
     self.assertNotIn(file_names[3], files)
示例#15
0
 def test_duplicates(self, mock_open, mock_os_walk):
     mock_os_walk.return_value = (['.', None, ['f1.cpp', 'f2.cpp']], )
     file_handle = mock_open.return_value.__enter__.return_value
     file_handle.read.return_value = "int foo(){haha();\n}"
     files = get_all_source_files(["dir"], [], [])
     self.assertEqual(['./f1.cpp'], list(files))
示例#16
0
 def test_exclude_folder_recursively(self, mock_os_walk):
     mock_os_walk.return_value = (['ut/something', 
                                   None,
                                   ['useful.cpp']],)
     files = get_all_source_files(["dir"], ["ut/*"], [])
     self.assertEqual([], list(files))
示例#17
0
 def test_explicit_file_names(self, mock_isfile):
     mock_isfile.return_value = True
     files = get_all_source_files(["dir/file.c"], [], [])
     self.assertEqual(["dir/file.c"], list(files))
示例#18
0
 def test_specific_filenames_should_not_be_excluded(self, mock_isfile):
     mock_isfile.return_value = True
     files = get_all_source_files(["dir/file.log"], [], [])
     self.assertEqual(["dir/file.log"], list(files))
示例#19
0
 def test_fail_to_open_file_should_be_allowed(self, mock_open,
                                              mock_os_walk):
     mock_os_walk.return_value = (['.', None, ['f1.cpp', 'f2.cpp']], )
     file_handle = mock_open.side_effect = IOError
     files = get_all_source_files(["dir"], [], [])
     self.assertEqual(['./f1.cpp', './f2.cpp'], list(files))
示例#20
0
 def test_no_matching(self, mock_os_walk):
     mock_os_walk.return_value = []
     files = get_all_source_files(["dir"], [], [])
     self.assertEqual(0, len(list(files)))
示例#21
0
 def test_explicit_file_names(self, mock_isfile):
     mock_isfile.return_value = True
     files = get_all_source_files(["dir/file.c"], [], [])
     self.assertEqual(["dir/file.c"], list(files))
示例#22
0
 def test_no_matching(self, mock_os_walk):
     mock_os_walk.return_value = []
     files = get_all_source_files(["dir"], [], [])
     self.assertEqual(0, len(list(files)))
示例#23
0
 def test_specific_filenames_should_not_be_excluded(self, mock_isfile):
     mock_isfile.return_value = True
     files = get_all_source_files(["dir/file.log"], [], [])
     self.assertEqual(["dir/file.log"], list(files))
示例#24
0
 def test_exclude_file_name(self, mock_os_walk, md5):
     mock_os_walk.return_value = (['.', 
                                   None,
                                   ['temp.c', 'useful.cpp']],)
     files = get_all_source_files(["dir"], ["*.c"], [])
     self.assertEqual(["./useful.cpp"], list(files))
示例#25
0
 def test_exclude_folder_recursively(self, mock_os_walk):
     mock_os_walk.return_value = (['ut/something', None, ['useful.cpp']], )
     files = get_all_source_files(["dir"], ["ut/*"], [])
     self.assertEqual([], list(files))
示例#26
0
 def test_exclude_none_supported_files(self, mock_os_walk):
     mock_os_walk.return_value = (['.', None, ['useful.txt']], )
     files = get_all_source_files(["dir"], ['exclude_me'], [])
     self.assertEqual([], list(files))
示例#27
0
 def test_exclude_none_supported_files(self, mock_os_walk):
     mock_os_walk.return_value = (['.', 
                                   None,
                                   ['useful.txt']],)
     files = get_all_source_files(["dir"],['exclude_me'], [])
     self.assertEqual([], list(files))
示例#28
0
def main():
    pathName = getArgs()
    srcFiles = lizard.get_all_source_files([pathName], [], [])
    printMetrics(srcFiles, pathName)
示例#29
0
 def test_exclude_file_name(self, mock_os_walk, md5):
     mock_os_walk.return_value = (['.', None, ['temp.c', 'useful.cpp']], )
     files = get_all_source_files(["dir"], ["*.c"], [])
     self.assertEqual(["./useful.cpp"], list(files))