WebKitTools/Scripts/webkitpy/style/patchreader_unittest.py
changeset 0 4f2f89ce4247
equal deleted inserted replaced
-1:000000000000 0:4f2f89ce4247
       
     1 #!/usr/bin/python
       
     2 #
       
     3 # Copyright (C) 2010 Google Inc. All rights reserved.
       
     4 # Copyright (C) 2009 Torch Mobile Inc.
       
     5 # Copyright (C) 2009 Apple Inc. All rights reserved.
       
     6 # Copyright (C) 2010 Chris Jerdonek (chris.jerdonek@gmail.com)
       
     7 #
       
     8 # Redistribution and use in source and binary forms, with or without
       
     9 # modification, are permitted provided that the following conditions are
       
    10 # met:
       
    11 #
       
    12 #    * Redistributions of source code must retain the above copyright
       
    13 # notice, this list of conditions and the following disclaimer.
       
    14 #    * Redistributions in binary form must reproduce the above
       
    15 # copyright notice, this list of conditions and the following disclaimer
       
    16 # in the documentation and/or other materials provided with the
       
    17 # distribution.
       
    18 #    * Neither the name of Google Inc. nor the names of its
       
    19 # contributors may be used to endorse or promote products derived from
       
    20 # this software without specific prior written permission.
       
    21 #
       
    22 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
       
    23 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
       
    24 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
       
    25 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
       
    26 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
       
    27 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
       
    28 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
       
    29 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
       
    30 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
       
    31 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
       
    32 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
       
    33 
       
    34 import unittest
       
    35 
       
    36 from webkitpy.style.patchreader import PatchReader
       
    37 
       
    38 
       
    39 class PatchReaderTest(unittest.TestCase):
       
    40 
       
    41     """Test the PatchReader class."""
       
    42 
       
    43     class MockTextFileReader(object):
       
    44 
       
    45         def __init__(self):
       
    46             self.passed_to_process_file = []
       
    47             """A list of (file_path, line_numbers) pairs."""
       
    48 
       
    49         def process_file(self, file_path, line_numbers):
       
    50             self.passed_to_process_file.append((file_path, line_numbers))
       
    51 
       
    52     def setUp(self):
       
    53         file_reader = self.MockTextFileReader()
       
    54         self._file_reader = file_reader
       
    55         self._patch_checker = PatchReader(file_reader)
       
    56 
       
    57     def _call_check_patch(self, patch_string):
       
    58         self._patch_checker.check(patch_string)
       
    59 
       
    60     def _assert_checked(self, passed_to_process_file):
       
    61         self.assertEquals(self._file_reader.passed_to_process_file,
       
    62                           passed_to_process_file)
       
    63 
       
    64     def test_check_patch(self):
       
    65         # The modified line_numbers array for this patch is: [2].
       
    66         self._call_check_patch("""diff --git a/__init__.py b/__init__.py
       
    67 index ef65bee..e3db70e 100644
       
    68 --- a/__init__.py
       
    69 +++ b/__init__.py
       
    70 @@ -1,1 +1,2 @@
       
    71  # Required for Python to search this directory for module files
       
    72 +# New line
       
    73 """)
       
    74         self._assert_checked([("__init__.py", set([2]))])
       
    75 
       
    76     def test_check_patch_with_deletion(self):
       
    77         self._call_check_patch("""Index: __init__.py
       
    78 ===================================================================
       
    79 --- __init__.py  (revision 3593)
       
    80 +++ __init__.py  (working copy)
       
    81 @@ -1 +0,0 @@
       
    82 -foobar
       
    83 """)
       
    84         # _mock_check_file should not be called for the deletion patch.
       
    85         self._assert_checked([])