def runApplicationWithArgv(self, argv, print_result, os_walk, mock_open): def store_result(result, options): self.fileInfos = list(result) os_walk.return_value = [('.', [], ['a.cpp'])] mock_open.return_value.__enter__.return_value.read.return_value = self.source_code print_result.side_effect = store_result lizard_main(argv)
def run_with_mocks(self, argv, src, print_result, mock_open): def store_result(result, options): self.fileInfos = list(result) mock_open.return_value.read.return_value = src print_result.side_effect = store_result lizard_main(argv) return self.fileInfos
def testEmptyResult(self, print_result, os_walk, mock_open, _): def check_empty_result(result, options, scheme): self.assertEqual([], list(result)) return 0 os_walk.return_value = [('.', [], [])] print_result.side_effect = check_empty_result lizard_main(['lizard'])
def run_with_mocks(self, argv, src, print_result, mock_open): def store_result(result, options, scheme): self.fileInfos = list(result) return self.returned_warning_count mock_open.return_value = src print_result.side_effect = store_result lizard_main(argv) return self.fileInfos
def testEmptyResult(self, print_result, os_walk, mock_open, _): def check_empty_result(result, options): self.assertEqual([], list(result)) os_walk.return_value = [('.', [], [])] print_result.side_effect = check_empty_result lizard_main(['lizard'])
def testMutipleFilesInArgv(self, print_result, os_walk, mock_open): def check_result(result, options): fileInfos = list(result) self.assertEqual(1, len(fileInfos)) self.assertEqual('foo', fileInfos[0].function_list[0].name) os_walk.return_value = [('.', [], ['a.cpp'])] mock_open.return_value.__enter__.return_value.read.return_value = "void foo(){}" print_result.side_effect = check_result lizard_main(['lizard'])
def testFilesWithFunction(self, print_result, os_walk, mock_open, _): def check_result(result, options, scheme): fileInfos = list(result) self.assertEqual(1, len(fileInfos)) self.assertEqual('foo', fileInfos[0].function_list[0].name) return 0 os_walk.return_value = [('.', [], ['a.cpp'])] mock_open.return_value.read.return_value = "void foo(){}" print_result.side_effect = check_result lizard_main(['lizard'])
def testFilesWithFunction(self, print_result, os_walk, mock_open, _): def check_result(result, options, scheme): fileInfos = list(result) self.assertEqual(1, len(fileInfos)) self.assertEqual('foo', fileInfos[0].function_list[0].name) return 0 os_walk.return_value = [('.', [], ['a.cpp'])] mock_open.return_value = "void foo(){}" print_result.side_effect = check_result lizard_main(['lizard'])
def testGetCurrentFolderByDefault(self, print_result, os_walk, mock_open): print_result.side_effect = self.exhaust_result lizard_main(['lizard']) os_walk.assert_called_once_with('.', topdown=False)
from lizard import lizard_main import cProfile, pstats, StringIO import sys if __name__ == "__main__": pr = cProfile.Profile() pr.enable() lizard_main(sys.argv) pr.disable() s = StringIO.StringIO() sortby = 'tottime' ps = pstats.Stats(pr, stream=s).sort_stats(sortby) ps.print_stats() print s.getvalue()
def testEmptyResult(self, print_result, os_walk, mock_open): os_walk.return_value = [('.', [], [])] print_result.side_effect = self.check_empty_result lizard_main(['lizard'])