Esempio n. 1
0
    def test_checker(self):
        """Test for errors"""

        errors_found = set()

        def error_handler_for_test(line_number, category, confidence, message):
            errors_found.add((line_number, category, confidence, message))

        messages_in_checker = MessagesInChecker('foo.messages.in', error_handler_for_test)
        lines = self.test_file_content.split('\n')
        messages_in_checker.check(lines)
        self.assertEqual(self.expected_errors, errors_found)
Esempio n. 2
0
    def test_init(self):

        def error_handler_for_test(line_number, category, confidence, message):
            pass

        checker = MessagesInChecker('foo.messages.in', error_handler_for_test)
        self.assertEqual(checker.file_path, 'foo.messages.in')
        self.assertEqual(checker.handle_style_error, error_handler_for_test)
Esempio n. 3
0
    def _create_checker(self, file_type, file_path, handle_style_error,
                        min_confidence, commit_queue):
        """Instantiate and return a style checker based on file type."""
        if file_type == FileType.NONE:
            checker = None
        elif file_type == FileType.CHANGELOG:
            should_line_be_checked = None
            if handle_style_error:
                should_line_be_checked = handle_style_error.should_line_be_checked
            checker = ChangeLogChecker(file_path, handle_style_error,
                                       should_line_be_checked)
        elif file_type == FileType.CPP:
            file_extension = self._file_extension(file_path)
            checker = CppChecker(file_path, file_extension, handle_style_error,
                                 min_confidence)
        elif file_type == FileType.JS:
            basename = os.path.basename(file_path)
            # Do not attempt to check non-Inspector or 3rd-party JavaScript files as JS.
            if os.path.join('WebInspectorUI',
                            'UserInterface') in file_path and (not 'External'
                                                               in file_path):
                checker = JSChecker(file_path, handle_style_error)
            elif basename in _NEVER_SKIPPED_JS_FILES:
                checker = JSTestChecker(file_path, handle_style_error)
            else:
                checker = TextChecker(file_path, handle_style_error)
        elif file_type == FileType.JSON:
            basename = os.path.basename(file_path)
            if basename == 'contributors.json':
                if commit_queue:
                    checker = JSONContributorsChecker(file_path,
                                                      handle_style_error)
                else:
                    checker = ContributorsChecker(file_path,
                                                  handle_style_error)
            elif basename == 'features.json':
                checker = JSONFeaturesChecker(file_path, handle_style_error)
            elif basename == 'CSSProperties.json':
                checker = JSONCSSPropertiesChecker(file_path,
                                                   handle_style_error)
            else:
                checker = JSONChecker(file_path, handle_style_error)
        elif file_type == FileType.PYTHON:
            python3_paths = ['Tools/resultsdbpy']
            for partial in python3_paths:
                if file_path.startswith(partial):
                    return Python3Checker(file_path, handle_style_error)
            if apple_additions():
                checker = apple_additions().python_checker(
                    file_path, handle_style_error)
            else:
                checker = PythonChecker(file_path, handle_style_error)
        elif file_type == FileType.XML:
            checker = XMLChecker(file_path, handle_style_error)
        elif file_type == FileType.XCODEPROJ:
            checker = XcodeProjectFileChecker(file_path, handle_style_error)
        elif file_type == FileType.PNG:
            checker = PNGChecker(file_path, handle_style_error)
        elif file_type == FileType.CMAKE:
            checker = CMakeChecker(file_path, handle_style_error)
        elif file_type == FileType.TEXT:
            basename = os.path.basename(file_path)
            if basename == 'TestExpectations':
                checker = TestExpectationsChecker(file_path,
                                                  handle_style_error)
            elif file_path.endswith('.messages.in'):
                checker = MessagesInChecker(file_path, handle_style_error)
            else:
                checker = TextChecker(file_path, handle_style_error)
        elif file_type == FileType.WATCHLIST:
            checker = WatchListChecker(file_path, handle_style_error)
        elif file_type == FileType.FEATUREDEFINES:
            checker = FeatureDefinesChecker(file_path, handle_style_error)
        elif file_type == FileType.SDKVARIANT:
            checker = SDKVariantChecker(file_path, handle_style_error)
        else:
            raise ValueError(
                'Invalid file type "%(file_type)s": the only valid file types '
                "are %(NONE)s, %(CPP)s, and %(TEXT)s." % {
                    "file_type": file_type,
                    "NONE": FileType.NONE,
                    "CPP": FileType.CPP,
                    "TEXT": FileType.TEXT
                })

        return checker