def test_ne(self): """Test __ne__ method.""" # By default, __ne__ always returns true on different objects. # Thus, just check the distinguishing case to verify that the # code defines __ne__. # # Also, see the notes at the top of this module about testing # __eq__() and __ne__(). self.assertFalse(FilterConfiguration().__ne__(FilterConfiguration()))
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_path_rules_specifier(self): for _, path_rules in PATH_RULES_SPECIFIER: validate_filter_rules(path_rules, self._all_categories()) config = FilterConfiguration(path_specific=PATH_RULES_SPECIFIER) def assert_check(path, category): """Assert that the given category should be checked.""" self.assertTrue(config.should_check(category, path)) def assert_no_check(path, category): """Assert that the given category should not be checked.""" message = ('Should not check category "%s" for path "%s".' % (category, path)) self.assertFalse(config.should_check(category, path), message) assert_check("random_path.cpp", "build/include") assert_check("random_path.cpp", "readability/naming") # Third-party Python code: blinkpy/third_party path = "tools/blinkpy/third_party/mock.py" assert_no_check(path, "build/include") assert_no_check(path, "pep8/E401") # A random pep8 category. assert_check(path, "pep8/W191") assert_check(path, "pep8/W291") assert_check(path, "whitespace/carriage_return")
def test_default_arguments(self): # Test that the attributes are getting set correctly to the defaults. config = FilterConfiguration() self.assertEqual([], config._base_rules) self.assertEqual([], config._path_specific) self.assertEqual([], config._user_rules)
def _style_checker_configuration(self, output_format="vs7"): """Return a StyleProcessorConfiguration instance for testing.""" base_rules = ["-whitespace", "+whitespace/tab"] filter_configuration = FilterConfiguration(base_rules=base_rules) return StyleProcessorConfiguration( filter_configuration=filter_configuration, max_reports_per_category={"whitespace/newline": 1}, min_confidence=3, output_format=output_format, stderr_write=self._mock_stderr_write)
def test_eq(self): """Test __eq__ method.""" # See the notes at the top of this module about testing # __eq__() and __ne__(). self.assertTrue(FilterConfiguration().__eq__(FilterConfiguration())) # Verify that a difference in any argument causes equality to fail. config = FilterConfiguration() # These parameter values are different from the defaults. base_rules = ["-"] path_specific = [(["path"], ["+a"])] user_rules = ["+"] self.assertFalse( config.__eq__(FilterConfiguration(base_rules=base_rules))) self.assertFalse( config.__eq__(FilterConfiguration(path_specific=path_specific))) self.assertFalse( config.__eq__(FilterConfiguration(user_rules=user_rules)))
def _style_checker_configuration(self): """Return a StyleProcessorConfiguration instance for testing.""" base_rules = ['-whitespace', '+whitespace/tab'] filter_configuration = FilterConfiguration(base_rules=base_rules) return StyleProcessorConfiguration( filter_configuration=filter_configuration, max_reports_per_category={'whitespace/tab': 2}, min_confidence=3, output_format='vs7', stderr_write=self._mock_stderr_write)
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 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 check_webkit_style_configuration(options): """Return a StyleProcessorConfiguration instance for check_blink_style.py. Args: options: A CommandOptionValues instance. """ filter_configuration = FilterConfiguration( base_rules=_BASE_FILTER_RULES, path_specific=_PATH_RULES_SPECIFIER, user_rules=options.filter_rules) return StyleProcessorConfiguration(filter_configuration=filter_configuration, max_reports_per_category=_MAX_REPORTS_PER_CATEGORY, min_confidence=options.min_confidence, output_format=options.output_format, stderr_write=sys.stderr.write)
def _config(self, base_rules, path_specific, user_rules): """Return a FilterConfiguration instance.""" return FilterConfiguration(base_rules=base_rules, path_specific=path_specific, user_rules=user_rules)