Changeset 57467 in webkit
- Timestamp:
- Apr 11, 2010 8:52:58 PM (14 years ago)
- Location:
- trunk/WebKitTools
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebKitTools/ChangeLog
r57466 r57467 1 2010-04-11 Chris Jerdonek <cjerdonek@webkit.org> 2 3 Reviewed by Shinichiro Hamaji. 4 5 Refactored check-webkit-style so that the StyleChecker class 6 has no dependencies on patch-related concepts. 7 8 https://bugs.webkit.org/show_bug.cgi?id=37065 9 10 This patch is an intermediate step towards making the StyleChecker 11 class a generalized file processor that can do arbitary operations 12 on the files corresponding to a list of paths. This patch 13 also simplifies the unit-testing of patch-checking code. 14 15 * Scripts/check-webkit-style: 16 - Updated to use the new PatchChecker class. 17 18 * Scripts/webkitpy/style/checker.py: 19 - Refactored the StyleChecker.check_patch() method into the 20 check() method of a new PatchChecker class. 21 22 * Scripts/webkitpy/style/checker_unittest.py: 23 - Refactored the unit tests as necessary, changing the 24 StyleCheckerCheckPatchTest class to a PatchCheckerTest class. 25 1 26 2010-04-11 Adam Barth <abarth@webkit.org> 2 27 -
trunk/WebKitTools/Scripts/check-webkit-style
r57056 r57467 50 50 51 51 from webkitpy.style_references import detect_checkout 52 import webkitpy.style.checker as checker 53 from webkitpy.style.checker import PatchChecker 52 54 from webkitpy.style.main import change_directory 53 import webkitpy.style.checker as checker54 55 55 56 _log = logging.getLogger("check-webkit-style") … … 114 115 else: 115 116 patch = checkout.create_patch() 116 style_checker.check_patch(patch) 117 patch_checker = PatchChecker(style_checker) 118 patch_checker.check(patch) 117 119 118 120 error_count = style_checker.error_count -
trunk/WebKitTools/Scripts/webkitpy/style/checker.py
r57119 r57467 708 708 process_file(processor, file_path, handle_style_error) 709 709 710 # FIXME: Eliminate this method and move its logic to style/main.py. 711 # Calls to check_patch() can be replaced by appropriate calls 712 # to check_file() using the optional line_numbers parameter. 713 def check_patch(self, patch_string, mock_check_file=None): 714 """Check style in the given patch. 710 711 class PatchChecker(object): 712 713 """Supports checking style in patches.""" 714 715 def __init__(self, style_checker): 716 """Create a PatchChecker instance. 715 717 716 718 Args: 717 patch_string: A string that is a patch string.719 style_checker: A StyleChecker instance. 718 720 719 721 """ 720 check_file = (self.check_file if mock_check_file is None else 721 mock_check_file) 722 722 self._file_checker = style_checker 723 724 def check(self, patch_string): 725 """Check style in the given patch.""" 723 726 patch_files = parse_patch(patch_string) 724 727 725 728 # The diff variable is a DiffFile instance. 726 for file_path, diff in patch_files.iteritems():729 for path, diff in patch_files.iteritems(): 727 730 line_numbers = set() 728 731 for line in diff.lines: … … 732 735 line_numbers.add(line[1]) 733 736 734 _log.debug('Found %s modified lines in patch for: %s' 735 % (len(line_numbers), file_path)) 736 737 check_file(file_path=file_path, line_numbers=line_numbers) 737 _log.debug('Found %s new or modified lines in: %s' 738 % (len(line_numbers), path)) 739 740 self._file_checker.check_file(file_path=path, 741 line_numbers=line_numbers) -
trunk/WebKitTools/Scripts/webkitpy/style/checker_unittest.py
r57119 r57467 51 51 from checker import configure_logging 52 52 from checker import ProcessorDispatcher 53 from checker import PatchChecker 53 54 from checker import StyleChecker 54 55 from checker import StyleCheckerConfiguration … … 699 700 700 701 701 class StyleCheckerCheckPatchTest(StyleCheckerCheckFileBase):702 703 """Test the check_patch() method of the StyleChecker class.704 705 Internally, the check_patch() method calls StyleChecker.check_file() for706 each file that appears in the patch string. This class passes a mock707 check_file() method to check_patch() to facilitate unit-testing. The708 "got_*" attributes of this class are the parameters that check_patch()709 passed to check_file(). (We test only a single call.) These attributes710 let us check that check_patch() is calling check_file() correctly.711 712 Attributes:713 got_file_path: The value that check_patch() passed as the file_path714 parameter to the mock_check_file() function.715 got_line_numbers: The value that check_patch() passed as the line_numbers716 parameter to the mock_check_file() function.717 718 """719 720 _file_path = "__init__.py"721 722 # The modified line_numbers array for this patch is: [2].723 _patch_string = """diff --git a/__init__.py b/__init__.py724 index ef65bee..e3db70e 100644725 --- a/__init__.py726 +++ b/__init__.py727 @@ -1,1 +1,2 @@728 # Required for Python to search this directory for module files729 +# New line730 """731 732 def setUp(self):733 StyleCheckerCheckFileBase.setUp(self)734 self._got_file_path = None735 self._got_line_numbers = None736 737 def _mock_check_file(self, file_path, line_numbers):738 self._got_file_path = file_path739 self._got_line_numbers = line_numbers740 741 def test_check_patch(self):742 patch_files = parse_patch(self._patch_string)743 diff = patch_files[self._file_path]744 745 configuration = self._style_checker_configuration()746 747 style_checker = StyleChecker(configuration)748 749 style_checker.check_patch(patch_string=self._patch_string,750 mock_check_file=self._mock_check_file)751 752 self.assertEquals(self._got_file_path, "__init__.py")753 self.assertEquals(self._got_line_numbers, set([2]))754 755 756 702 class StyleCheckerCheckPathsTest(unittest.TestCase): 757 703 … … 800 746 os.path.join("dir_path1", "file2"), 801 747 os.path.join("dir_path2", "file3")]) 748 749 750 class PatchCheckerTest(unittest.TestCase): 751 752 """Test the PatchChecker class.""" 753 754 class MockStyleChecker(object): 755 756 def __init__(self): 757 self.checked_files = [] 758 """A list of (file_path, line_numbers) pairs.""" 759 760 def check_file(self, file_path, line_numbers): 761 self.checked_files.append((file_path, line_numbers)) 762 763 def setUp(self): 764 style_checker = self.MockStyleChecker() 765 self._style_checker = style_checker 766 self._patch_checker = PatchChecker(style_checker) 767 768 def _call_check_patch(self, patch_string): 769 self._patch_checker.check(patch_string) 770 771 def _assert_checked(self, checked_files): 772 self.assertEquals(self._style_checker.checked_files, checked_files) 773 774 def test_check_patch(self): 775 # The modified line_numbers array for this patch is: [2]. 776 self._call_check_patch("""diff --git a/__init__.py b/__init__.py 777 index ef65bee..e3db70e 100644 778 --- a/__init__.py 779 +++ b/__init__.py 780 @@ -1,1 +1,2 @@ 781 # Required for Python to search this directory for module files 782 +# New line 783 """) 784 self._assert_checked([("__init__.py", set([2]))])
Note: See TracChangeset
for help on using the changeset viewer.