def test_process(self): configuration = StyleProcessorConfiguration( filter_configuration=FilterConfiguration(), max_reports_per_category={}, min_confidence=3, output_format="vs7", stderr_write=self._mock_stderr_write) processor = StyleProcessor(configuration) processor.process(lines=['line1', 'Line with tab:\t'], file_path='foo.txt') self.assertEqual(processor.error_count, 1) expected_messages = ['foo.txt(2): Line contains tab character. ' '[whitespace/tab] [5]\n'] self.assertEqual(self._messages, expected_messages)
def setUp(self): LoggingTestCase.setUp(self) # We can pass an error-message swallower here because error message # output is tested instead in the end-to-end test case above. configuration = StyleProcessorConfiguration( filter_configuration=FilterConfiguration(), max_reports_per_category={"whitespace/newline": 1}, min_confidence=3, output_format="vs7", stderr_write=self._swallow_stderr_message) mock_carriage_checker_class = self._create_carriage_checker_class() mock_dispatcher = self.MockDispatcher() # We do not need to use a real incrementer here because error-count # incrementing is tested instead in the end-to-end test case above. mock_increment_error_count = self._do_nothing processor = StyleProcessor( configuration=configuration, mock_carriage_checker_class=mock_carriage_checker_class, mock_dispatcher=mock_dispatcher, mock_increment_error_count=mock_increment_error_count) self._configuration = configuration self._mock_dispatcher = mock_dispatcher self._processor = processor
def test_init(self): """Test __init__ constructor.""" configuration = StyleProcessorConfiguration( filter_configuration=FilterConfiguration(), max_reports_per_category={}, min_confidence=3, output_format="vs7", stderr_write=self._mock_stderr_write) processor = StyleProcessor(configuration) self.assertEqual(processor.error_count, 0) self.assertEqual(self._messages, [])
def main(self): args = sys.argv[1:] host = Host() stderr = self._engage_awesome_stderr_hacks() # Checking for the verbose flag before calling check_blink_style_parser() # lets us enable verbose logging earlier. is_verbose = '-v' in args or '--verbose' in args checker.configure_logging(stream=stderr, is_verbose=is_verbose) _log.debug('Verbose logging enabled.') parser = checker.check_blink_style_parser() (paths, options) = parser.parse(args) configuration = checker.check_blink_style_configuration(options) paths = change_directory(host.filesystem, checkout_root=host.git().checkout_root, paths=paths) style_processor = StyleProcessor(configuration) file_reader = TextFileReader(host.filesystem, style_processor) if paths and not options.diff_files: file_reader.process_paths(paths) else: changed_files = paths if options.diff_files else None patch = host.git().create_patch(options.git_commit, changed_files=changed_files) patch_checker = PatchReader(file_reader) patch_checker.check(patch) error_count = style_processor.error_count file_count = file_reader.file_count delete_only_file_count = file_reader.delete_only_file_count _log.info('Total errors found: %d in %d files', error_count, file_count) # We fail when style errors are found. return error_count > 0