summaryrefslogtreecommitdiffstats
path: root/WebKitTools/Scripts/webkitpy/style
diff options
context:
space:
mode:
authorSteve Block <steveblock@google.com>2010-05-26 10:11:43 +0100
committerSteve Block <steveblock@google.com>2010-05-27 11:14:42 +0100
commite78cbe89e6f337f2f1fe40315be88f742b547151 (patch)
treed778000b84a04f24bbad50c7fa66244365e960e9 /WebKitTools/Scripts/webkitpy/style
parent7b582e96e4e909ed7dba1e07153d20fbddaec3f7 (diff)
downloadexternal_webkit-e78cbe89e6f337f2f1fe40315be88f742b547151.zip
external_webkit-e78cbe89e6f337f2f1fe40315be88f742b547151.tar.gz
external_webkit-e78cbe89e6f337f2f1fe40315be88f742b547151.tar.bz2
Merge WebKit at r60074: Initial merge by git
Change-Id: I18a2dc5439e36c928351ea829d8fb4e39b062fc7
Diffstat (limited to 'WebKitTools/Scripts/webkitpy/style')
-rw-r--r--WebKitTools/Scripts/webkitpy/style/checker.py40
-rwxr-xr-xWebKitTools/Scripts/webkitpy/style/checker_unittest.py51
-rw-r--r--WebKitTools/Scripts/webkitpy/style/patchreader.py75
-rw-r--r--WebKitTools/Scripts/webkitpy/style/patchreader_unittest.py85
4 files changed, 160 insertions, 91 deletions
diff --git a/WebKitTools/Scripts/webkitpy/style/checker.py b/WebKitTools/Scripts/webkitpy/style/checker.py
index 59a3d39..8fc86c3 100644
--- a/WebKitTools/Scripts/webkitpy/style/checker.py
+++ b/WebKitTools/Scripts/webkitpy/style/checker.py
@@ -43,7 +43,6 @@ from error_handlers import DefaultStyleErrorHandler
from filter import FilterConfiguration
from optparser import ArgumentParser
from optparser import DefaultCommandOptionValues
-from webkitpy.style_references import parse_patch
from webkitpy.style_references import configure_logging as _configure_logging
_log = logging.getLogger("webkitpy.style.checker")
@@ -697,42 +696,3 @@ class StyleProcessor(ProcessorBase):
_log.debug("Using class: " + checker.__class__.__name__)
checker.check(lines)
-
-
-class PatchReader(object):
-
- """Supports checking style in patches."""
-
- def __init__(self, text_file_reader):
- """Create a PatchReader instance.
-
- Args:
- text_file_reader: A TextFileReader instance.
-
- """
- self._text_file_reader = text_file_reader
-
- def check(self, patch_string):
- """Check style in the given patch."""
- patch_files = parse_patch(patch_string)
-
- # The diff variable is a DiffFile instance.
- for path, diff in patch_files.iteritems():
- line_numbers = set()
- for line in diff.lines:
- # When deleted line is not set, it means that
- # the line is newly added (or modified).
- if not line[0]:
- line_numbers.add(line[1])
-
- _log.debug('Found %s new or modified lines in: %s'
- % (len(line_numbers), path))
-
- # If line_numbers is empty, the file has no new or
- # modified lines. In this case, we don't check the file
- # because we'll never output errors for the file.
- # This optimization also prevents the program from exiting
- # due to a deleted file.
- if line_numbers:
- self._text_file_reader.process_file(file_path=path,
- line_numbers=line_numbers)
diff --git a/WebKitTools/Scripts/webkitpy/style/checker_unittest.py b/WebKitTools/Scripts/webkitpy/style/checker_unittest.py
index 6e1eaa2..e99ac68 100755
--- a/WebKitTools/Scripts/webkitpy/style/checker_unittest.py
+++ b/WebKitTools/Scripts/webkitpy/style/checker_unittest.py
@@ -39,7 +39,6 @@ import os
import unittest
import checker as style
-from webkitpy.style_references import parse_patch
from webkitpy.style_references import LogTesting
from webkitpy.style_references import TestLogStream
from checker import _BASE_FILTER_RULES
@@ -50,7 +49,6 @@ from checker import check_webkit_style_configuration
from checker import check_webkit_style_parser
from checker import configure_logging
from checker import CheckerDispatcher
-from checker import PatchReader
from checker import ProcessorBase
from checker import StyleProcessor
from checker import StyleProcessorConfiguration
@@ -769,52 +767,3 @@ class StyleProcessor_CodeCoverageTest(LoggingTestCase):
self.assertRaises(AssertionError, self._processor.process,
lines=['line1', 'line2'], file_path=path,
line_numbers=[100])
-
-
-class PatchReaderTest(unittest.TestCase):
-
- """Test the PatchReader class."""
-
- class MockTextFileReader(object):
-
- def __init__(self):
- self.passed_to_process_file = []
- """A list of (file_path, line_numbers) pairs."""
-
- def process_file(self, file_path, line_numbers):
- self.passed_to_process_file.append((file_path, line_numbers))
-
- def setUp(self):
- file_reader = self.MockTextFileReader()
- self._file_reader = file_reader
- self._patch_checker = PatchReader(file_reader)
-
- def _call_check_patch(self, patch_string):
- self._patch_checker.check(patch_string)
-
- def _assert_checked(self, passed_to_process_file):
- self.assertEquals(self._file_reader.passed_to_process_file,
- passed_to_process_file)
-
- def test_check_patch(self):
- # The modified line_numbers array for this patch is: [2].
- self._call_check_patch("""diff --git a/__init__.py b/__init__.py
-index ef65bee..e3db70e 100644
---- a/__init__.py
-+++ b/__init__.py
-@@ -1,1 +1,2 @@
- # Required for Python to search this directory for module files
-+# New line
-""")
- self._assert_checked([("__init__.py", set([2]))])
-
- def test_check_patch_with_deletion(self):
- self._call_check_patch("""Index: __init__.py
-===================================================================
---- __init__.py (revision 3593)
-+++ __init__.py (working copy)
-@@ -1 +0,0 @@
--foobar
-""")
- # _mock_check_file should not be called for the deletion patch.
- self._assert_checked([])
diff --git a/WebKitTools/Scripts/webkitpy/style/patchreader.py b/WebKitTools/Scripts/webkitpy/style/patchreader.py
new file mode 100644
index 0000000..7ba2b66
--- /dev/null
+++ b/WebKitTools/Scripts/webkitpy/style/patchreader.py
@@ -0,0 +1,75 @@
+# Copyright (C) 2010 Google Inc. All rights reserved.
+# Copyright (C) 2010 Chris Jerdonek (chris.jerdonek@gmail.com)
+# Copyright (C) 2010 ProFUSION embedded systems
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+import logging
+
+from webkitpy.common.checkout.diff_parser import DiffParser
+
+
+_log = logging.getLogger("webkitpy.style.patchreader")
+
+
+class PatchReader(object):
+
+ """Supports checking style in patches."""
+
+ def __init__(self, text_file_reader):
+ """Create a PatchReader instance.
+
+ Args:
+ text_file_reader: A TextFileReader instance.
+
+ """
+ self._text_file_reader = text_file_reader
+
+ def check(self, patch_string):
+ """Check style in the given patch."""
+ patch_files = DiffParser(patch_string.splitlines()).files
+
+ # The diff variable is a DiffFile instance.
+ for path, diff in patch_files.iteritems():
+ line_numbers = set()
+ for line in diff.lines:
+ # When deleted line is not set, it means that
+ # the line is newly added (or modified).
+ if not line[0]:
+ line_numbers.add(line[1])
+
+ _log.debug('Found %s new or modified lines in: %s'
+ % (len(line_numbers), path))
+
+ # If line_numbers is empty, the file has no new or
+ # modified lines. In this case, we don't check the file
+ # because we'll never output errors for the file.
+ # This optimization also prevents the program from exiting
+ # due to a deleted file.
+ if line_numbers:
+ self._text_file_reader.process_file(file_path=path,
+ line_numbers=line_numbers)
diff --git a/WebKitTools/Scripts/webkitpy/style/patchreader_unittest.py b/WebKitTools/Scripts/webkitpy/style/patchreader_unittest.py
new file mode 100644
index 0000000..10791e4
--- /dev/null
+++ b/WebKitTools/Scripts/webkitpy/style/patchreader_unittest.py
@@ -0,0 +1,85 @@
+#!/usr/bin/python
+#
+# Copyright (C) 2010 Google Inc. All rights reserved.
+# Copyright (C) 2009 Torch Mobile Inc.
+# Copyright (C) 2009 Apple Inc. All rights reserved.
+# Copyright (C) 2010 Chris Jerdonek (chris.jerdonek@gmail.com)
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+import unittest
+
+from webkitpy.style.patchreader import PatchReader
+
+
+class PatchReaderTest(unittest.TestCase):
+
+ """Test the PatchReader class."""
+
+ class MockTextFileReader(object):
+
+ def __init__(self):
+ self.passed_to_process_file = []
+ """A list of (file_path, line_numbers) pairs."""
+
+ def process_file(self, file_path, line_numbers):
+ self.passed_to_process_file.append((file_path, line_numbers))
+
+ def setUp(self):
+ file_reader = self.MockTextFileReader()
+ self._file_reader = file_reader
+ self._patch_checker = PatchReader(file_reader)
+
+ def _call_check_patch(self, patch_string):
+ self._patch_checker.check(patch_string)
+
+ def _assert_checked(self, passed_to_process_file):
+ self.assertEquals(self._file_reader.passed_to_process_file,
+ passed_to_process_file)
+
+ def test_check_patch(self):
+ # The modified line_numbers array for this patch is: [2].
+ self._call_check_patch("""diff --git a/__init__.py b/__init__.py
+index ef65bee..e3db70e 100644
+--- a/__init__.py
++++ b/__init__.py
+@@ -1,1 +1,2 @@
+ # Required for Python to search this directory for module files
++# New line
+""")
+ self._assert_checked([("__init__.py", set([2]))])
+
+ def test_check_patch_with_deletion(self):
+ self._call_check_patch("""Index: __init__.py
+===================================================================
+--- __init__.py (revision 3593)
++++ __init__.py (working copy)
+@@ -1 +0,0 @@
+-foobar
+""")
+ # _mock_check_file should not be called for the deletion patch.
+ self._assert_checked([])