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: webkitpy/thirdparty
        path = "Tools/Scripts/webkitpy/thirdparty/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)
Beispiel #5
0
    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",
            commit_queue=False)
    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)
Beispiel #7
0
    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)
Beispiel #8
0
    def test_init(self):
        """Test __init__ constructor."""
        configuration = StyleProcessorConfiguration(
                            filter_configuration=FilterConfiguration(),
                            max_reports_per_category={},
                            min_confidence=3,
                            output_format="vs7",
                            commit_queue=False)
        processor = StyleProcessor(configuration)

        self.assertEqual(processor.error_count, 0)
    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, [])
Beispiel #10
0
    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)
Beispiel #11
0
def check_webkit_style_configuration(options):
    """Return a StyleProcessorConfiguration instance for check-webkit-style.

    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)
Beispiel #12
0
    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)))
Beispiel #13
0
 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)
Beispiel #14
0
    def test_path_rules_specifier(self):
        all_categories = self._all_categories()
        for (sub_paths, path_rules) in PATH_RULES_SPECIFIER:
            validate_filter_rules(path_rules, self._all_categories())

        config = FilterConfiguration(path_specific=PATH_RULES_SPECIFIER)

        def assertCheck(path, category):
            """Assert that the given category should be checked."""
            message = ('Should check category "%s" for path "%s".'
                       % (category, path))
            self.assertTrue(config.should_check(category, path))

        def assertNoCheck(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)

        assertCheck("random_path.cpp",
                    "build/include")
        assertNoCheck(os.path.join('Tools', 'DumpRenderTree', 'TestNetscapePlugIn', 'main.cpp'),
                      "build/include")
        assertNoCheck(os.path.join('Tools', 'DumpRenderTree', 'TestNetscapePlugIn', 'main.cpp'),
                      "readability/naming")
        assertCheck(os.path.join('Tools', 'TestWebKitAPI', 'Tests', 'WTF', 'RefLogger.cpp'),
                      "build/include")
        assertNoCheck(os.path.join('Tools', 'TestWebKitAPI', 'Tests', 'mac', 'WillSendSubmitEvent.mm'),
                      "readability/naming")
        assertCheck("random_path.cpp",
                    "readability/naming")
        assertNoCheck(os.path.join('Source', 'WebCore', 'css', 'CSSParser.cpp'),
                      "readability/naming")

        assertNoCheck(os.path.join('Source', 'WebCore', 'ForwardingHeaders', 'debugger', 'Debugger.h'),
                      "build/header_guard")

        assertNoCheck(os.path.join('Source', 'WebCore', 'platform', 'graphics', 'gstreamer', 'VideoSinkGStreamer.cpp'),
                      "readability/naming")

        # Third-party Python code: webkitpy/thirdparty
        path = os.path.join('Tools', 'Scripts', 'webkitpy', 'thirdparty', 'mock.py')
        assertNoCheck(path, "build/include")
        assertNoCheck(path, "pep8/E401")  # A random pep8 category.
        assertCheck(path, "pep8/W191")
        assertCheck(path, "pep8/W291")
        assertCheck(path, "whitespace/carriage_return")

        # Test if the exception for GDBInterface.cpp is in place.
        assertNoCheck(os.path.join('Source', 'JavaScriptCore', 'jit', 'GDBInterface.cpp'),
                      "readability/naming")

        # Javascript keywords.
        assertCheck(os.path.join('Source', 'JavaScriptCore', 'parser', 'Keywords.table'), "whitespace/carriage_return")

        # Test if the exception for DataDetectorsCoreSPI.h is in place.
        assertNoCheck(os.path.join('Source', 'WebCore', 'PAL', 'pal', 'spi', 'cocoa', 'DataDetectorsCoreSPI.h'),
                      "runtime/enum_bitfields")

        # Test if the exception for PassKitSPI.h is in place.
        assertNoCheck(os.path.join('Source', 'WebCore', 'PAL', 'pal', 'spi', 'cocoa', 'PassKitSPI.h'),
                      "build/include")

        # Test if the exception for pal/spi is in place.
        assertNoCheck(os.path.join('Source', 'WebCore', 'PAL', 'pal', 'spi'),
                      "readability/naming/underscores")