Home | History | Annotate | Download | only in style

Lines Matching full:self

55     def test_init(self):
59 self.assertEquals(options.extra_flag_values, {})
60 self.assertEquals(options.filter_configuration, FilterConfiguration())
61 self.assertEquals(options.git_commit, None)
62 self.assertEquals(options.max_reports_per_category, {})
63 self.assertEquals(options.output_format, "emacs")
64 self.assertEquals(options.verbosity, 1)
67 self.assertRaises(ValueError, ProcessorOptions, output_format="bad")
70 self.assertRaises(ValueError, ProcessorOptions, verbosity=0)
71 self.assertRaises(ValueError, ProcessorOptions, verbosity=6)
83 self.assertEquals(options.extra_flag_values, {"extra_value" : 2})
84 self.assertEquals(options.filter_configuration, filter_configuration)
85 self.assertEquals(options.git_commit, "commit")
86 self.assertEquals(options.max_reports_per_category, {"category": 3})
87 self.assertEquals(options.output_format, "vs7")
88 self.assertEquals(options.verbosity, 3)
90 def test_eq(self):
93 self.assertTrue(ProcessorOptions() == ProcessorOptions())
103 self.assertFalse(options == ProcessorOptions(extra_flag_values={"extra_value" : 2}))
105 self.assertFalse(options ==
107 self.assertFalse(options == ProcessorOptions(git_commit="commit2"))
108 self.assertFalse(options == ProcessorOptions(max_reports_per_category=
110 self.assertFalse(options == ProcessorOptions(output_format="emacs"))
111 self.assertFalse(options == ProcessorOptions(verbosity=2))
113 def test_ne(self):
119 self.assertFalse(ProcessorOptions() != ProcessorOptions())
121 def test_is_reportable(self):
128 self.assertTrue(options.is_reportable("abc", 3, "foo.h"))
129 self.assertFalse(options.is_reportable("abc", 2, "foo.h"))
132 self.assertTrue(options.is_reportable("xy", 3, "foo.h"))
133 self.assertFalse(options.is_reportable("xyz", 3, "foo.h"))
140 def _all_categories(self):
143 def defaults(self):
146 def test_filter_rules(self):
147 defaults = self.defaults()
150 self._all_categories())
154 self.assertEquals(rule, rule.strip())
157 self.assertTrue(rule.startswith('-'))
159 self.assertFalse(rule in already_seen)
162 def test_defaults(self):
164 defaults = self.defaults()
173 def test_path_rules_specifier(self):
176 self.assertTrue(isinstance(path_rules, tuple),
178 validate_filter_rules(path_rules, self._all_categories())
182 self.assertTrue(config.should_check("xxx_any_category",
184 self.assertTrue(config.should_check("xxx_any_category",
186 self.assertFalse(config.should_check("build/include",
188 self.assertFalse(config.should_check("readability/naming",
191 def test_max_reports_per_category(self):
193 all_categories = self._all_categories()
195 self.assertTrue(category in all_categories,
205 def _create_options(self,
218 def test_to_flag_string(self):
219 options = self._create_options('vs7', 5, ['+foo', '-bar'], 'git',
221 self.assertEquals('--a=0 --filter=+foo,-bar --git-commit=git '
223 self._printer.to_flag_string(options))
227 options = self._create_options()
228 self.assertEquals('--output=emacs --verbose=3',
229 self._printer.to_flag_string(options))
236 def _parse(self):
238 return self._create_parser().parse
240 def _create_defaults(self, default_output_format='vs7',
248 def _create_parser(self, defaults=None):
260 defaults = self._create_defaults()
264 def test_parse_documentation(self):
265 parse = self._parse()
271 self.assertRaises(SystemExit, parse, ['--help'])
273 self.assertRaises(SystemExit, parse, ['--filter='])
275 def test_parse_bad_values(self):
276 parse = self._parse()
279 self.assertRaises(SystemExit, parse, ['--bad'])
281 self.assertRaises(ValueError, parse, ['--verbose=bad'])
282 self.assertRaises(ValueError, parse, ['--verbose=0'])
283 self.assertRaises(ValueError, parse, ['--verbose=6'])
287 self.assertRaises(ValueError, parse, ['--output=bad'])
291 self.assertRaises(ValueError, parse, ['--filter=build'])
294 self.assertRaises(SystemExit, parse, ['--git-commit=', 'file.txt'])
296 self.assertRaises(ValueError, parse, [], ['filter='])
299 self.assertRaises(SystemExit, parse, ['--extratypo='], ['extra='])
301 self.assertRaises(ValueError, parse, [], ['extra=', 'extra='])
304 def test_parse_default_arguments(self):
305 parse = self._parse()
309 self.assertEquals(files, [])
311 self.assertEquals(options.output_format, 'vs7')
312 self.assertEquals(options.verbosity, 3)
313 self.assertEquals(options.filter_configuration,
316 self.assertEquals(options.git_commit, None)
318 def test_parse_explicit_arguments(self):
319 parse = self._parse()
323 self.assertEquals(options.output_format, 'emacs')
325 self.assertEquals(options.verbosity, 4)
327 self.assertEquals(options.git_commit, 'commit')
332 self.assertEquals(options.filter_configuration,
339 self.assertEquals(options.filter_configuration,
346 self.assertEquals(options.extra_flag_values, {'--extra': ''})
348 self.assertEquals(options.extra_flag_values, {'--extra': ''})
350 self.assertEquals(options.extra_flag_values, {'--extra': 'x'})
352 def test_parse_files(self):
353 parse = self._parse()
356 self.assertEquals(files, ['foo.cpp'])
360 self.assertEquals(files, ['foo.cpp', 'bar.cpp'])
367 def test_should_skip_with_warning(self):
372 self.assertFalse(dispatcher.should_skip_with_warning("foo.txt"))
387 self.assertTrue(dispatcher.should_skip_with_warning(path),
390 def test_should_skip_without_warning(self):
395 self.assertFalse(dispatcher.should_skip_without_warning("foo.txt"))
404 self.assertTrue(dispatcher.should_skip_without_warning(path),
412 def mock_handle_style_error(self):
415 def dispatch_processor(self, file_path):
419 self.mock_handle_style_error,
423 def assert_processor_none(self, file_path):
425 processor = self.dispatch_processor(file_path)
426 self.assertTrue(processor is None, 'Checking: "%s"' % file_path)
428 def assert_processor(self, file_path, expected_class):
430 processor = self.dispatch_processor(file_path)
432 self.assertEquals(got_class, expected_class,
439 def assert_processor_cpp(self, file_path):
441 self.assert_processor(file_path, CppProcessor)
443 def assert_processor_text(self, file_path):
445 self.assert_processor(file_path, TextProcessor)
447 def test_cpp_paths(self):
457 self.assert_processor_cpp(path)
463 self.assert_processor_cpp(file_path)
464 processor = self.dispatch_processor(file_path)
465 self.assertEquals(processor.file_extension, file_extension)
466 self.assertEquals(processor.file_path, file_path)
467 self.assertEquals(processor.handle_style_error, self.mock_handle_style_error)
468 self.assertEquals(processor.verbosity, 3)
473 self.assert_processor_cpp(file_path)
474 processor = self.dispatch_processor(file_path)
475 self.assertEquals(processor.file_extension, file_extension)
476 self.assertEquals(processor.file_path, file_path)
478 def test_text_paths(self):
499 self.assert_processor_text(path)
505 self.assert_processor_text(file_path)
506 processor = self.dispatch_processor(file_path)
507 self.assertEquals(processor.file_path, file_path)
508 self.assertEquals(processor.handle_style_error, self.mock_handle_style_error)
510 def test_none_paths(self):
519 self.assert_processor_none(path)
533 def _mock_stderr_write(self, message):
536 def _style_checker(self, options):
537 return StyleChecker(options, self._mock_stderr_write)
539 def test_init(self):
542 style_checker = self._style_checker(options)
544 self.assertEquals(style_checker.error_count, 0)
545 self.assertEquals(style_checker.options, options)
573 def setUp(self):
574 self.got_file_path = None
575 self.got_handle_style_error = None
576 self.got_processor = None
577 self.warning_messages = ""
579 def mock_stderr_write(self, warning_message):
580 self.warning_messages += warning_message
582 def mock_handle_style_error(self):
585 def mock_process_file(self, processor, file_path, handle_style_error):
592 self.got_file_path = file_path
593 self.got_handle_style_error = handle_style_error
594 self.got_processor = processor
596 def assert_attributes(self,
602 self.assertEquals(self.got_file_path, expected_file_path)
603 self.assertEquals(self.got_handle_style_error, expected_handle_style_error)
604 self.assertEquals(self.got_processor, expected_processor)
605 self.assertEquals(self.warning_messages, expected_warning_messages)
607 def call_check_file(self, file_path):
610 self.assert_attributes(None, None, None, "")
620 style_checker = StyleChecker(options, self.mock_stderr_write)
623 self.mock_handle_style_error,
624 self.mock_process_file)
626 def test_check_file_on_skip_without_warning(self):
633 self.assertTrue(dispatcher.should_skip_without_warning(file_path))
636 self.call_check_file(file_path)
637 self.assert_attributes(None, None, None, "")
639 def test_check_file_on_skip_with_warning(self):
646 self.assertTrue(dispatcher.should_skip_with_warning(file_path))
649 self.call_check_file(file_path)
650 self.assert_attributes(None, None, None,
653 def test_check_file_on_non_skipped(self):
664 self.assertEquals(dispatcher._file_type(file_path), style.FileType.CPP)
667 self.call_check_file(file_path)
669 expected_processor = CppProcessor(file_path, file_extension, self.mock_handle_style_error, 3)
671 self.assert_attributes(file_path,
672 self.mock_handle_style_error,