Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(152)

Side by Side Diff: third_party/WebKit/Tools/Scripts/webkitpy/style/patchreader_unittest.py

Issue 2742453003: webkitpy: Simplify DiffParser, removing support for SVN patches. (Closed)
Patch Set: Re-add accidentally-removed baseline Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Tools/Scripts/webkitpy/style/patchreader.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (C) 2010 Google Inc. All rights reserved. 1 # Copyright (C) 2010 Google Inc. All rights reserved.
2 # Copyright (C) 2009 Torch Mobile Inc. 2 # Copyright (C) 2009 Torch Mobile Inc.
3 # Copyright (C) 2009 Apple Inc. All rights reserved. 3 # Copyright (C) 2009 Apple Inc. All rights reserved.
4 # Copyright (C) 2010 Chris Jerdonek (chris.jerdonek@gmail.com) 4 # Copyright (C) 2010 Chris Jerdonek (chris.jerdonek@gmail.com)
5 # 5 #
6 # Redistribution and use in source and binary forms, with or without 6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are 7 # modification, are permitted provided that the following conditions are
8 # met: 8 # met:
9 # 9 #
10 # * Redistributions of source code must retain the above copyright 10 # * Redistributions of source code must retain the above copyright
(...skipping 13 matching lines...) Expand all
24 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 31
32 import unittest 32 import unittest
33 33
34 from webkitpy.common.system.filesystem_mock import MockFileSystem
35 from webkitpy.style.patchreader import PatchReader 34 from webkitpy.style.patchreader import PatchReader
36 35
37 36
38 class PatchReaderTest(unittest.TestCase): 37 class PatchReaderTest(unittest.TestCase):
39 38
40 """Test the PatchReader class."""
41
42 class MockTextFileReader(object): 39 class MockTextFileReader(object):
43 40
44 def __init__(self): 41 def __init__(self):
45 self.passed_to_process_file = [] 42 self.passed_to_process_file = [] # A list of (file_path, line_numbe rs) pairs.
46 """A list of (file_path, line_numbers) pairs.""" 43 self.delete_only_file_count = 0 # A number of times count_delete_on ly_file() called.
47 self.delete_only_file_count = 0
48 """A number of times count_delete_only_file() called"""
49 44
50 def process_file(self, file_path, line_numbers): 45 def process_file(self, file_path, line_numbers):
51 self.passed_to_process_file.append((file_path, line_numbers)) 46 self.passed_to_process_file.append((file_path, line_numbers))
52 47
53 def count_delete_only_file(self): 48 def count_delete_only_file(self):
54 self.delete_only_file_count += 1 49 self.delete_only_file_count += 1
55 50
56 def setUp(self): 51 def setUp(self):
57 file_reader = self.MockTextFileReader() 52 self._file_reader = self.MockTextFileReader()
58 self._file_reader = file_reader
59 self._patch_checker = PatchReader(file_reader)
60
61 def _call_check_patch(self, patch_string):
62 self._patch_checker.check(patch_string)
63 53
64 def _assert_checked(self, passed_to_process_file, delete_only_file_count): 54 def _assert_checked(self, passed_to_process_file, delete_only_file_count):
65 self.assertEqual(self._file_reader.passed_to_process_file, 55 self.assertEqual(self._file_reader.passed_to_process_file, passed_to_pro cess_file)
66 passed_to_process_file) 56 self.assertEqual(self._file_reader.delete_only_file_count, delete_only_f ile_count)
67 self.assertEqual(self._file_reader.delete_only_file_count,
68 delete_only_file_count)
69 57
70 def test_check_patch(self): 58 def test_check_patch(self):
71 # The modified line_numbers array for this patch is: [2]. 59 PatchReader(self._file_reader).check(
72 self._call_check_patch("""diff --git a/__init__.py b/__init__.py 60 'diff --git a/__init__.py b/__init__.py\n'
73 index ef65bee..e3db70e 100644 61 'index ef65bee..e3db70e 100644\n'
74 --- a/__init__.py 62 '--- a/__init__.py\n'
75 +++ b/__init__.py 63 '+++ b/__init__.py\n'
76 @@ -1,1 +1,2 @@ 64 '@@ -1,1 +1,2 @@\n'
77 # Required for Python to search this directory for module files 65 ' # Required for Python to search this directory for module files\n'
78 +# New line 66 '+# New line\n')
79 """) 67 self._assert_checked(
80 self._assert_checked([("__init__.py", [2])], 0) 68 passed_to_process_file=[('__init__.py', [2])],
69 delete_only_file_count=0)
81 70
82 def test_check_patch_with_deletion(self): 71 def test_check_patch_with_deletion(self):
83 self._call_check_patch("""Index: __init__.py 72 PatchReader(self._file_reader).check(
84 =================================================================== 73 'diff --git a/__init__.py b/__init.py\n'
85 --- __init__.py (revision 3593) 74 'deleted file mode 100644\n'
86 +++ __init__.py (working copy) 75 'index ef65bee..0000000\n'
87 @@ -1 +0,0 @@ 76 '--- a/__init__.py\n'
88 -foobar 77 '+++ /dev/null\n'
89 """) 78 '@@ -1 +0,0 @@\n'
90 # _mock_check_file should not be called for the deletion patch. 79 '-foobar\n')
91 self._assert_checked([], 1) 80 # The deleted file isn't be processed.
81 self._assert_checked(passed_to_process_file=[], delete_only_file_count=1 )
92 82
93 def test_check_patch_with_png_deletion(self): 83 def test_check_patch_with_png_deletion(self):
94 fs = MockFileSystem() 84 PatchReader(self._file_reader).check(
95 diff_text = """Index: LayoutTests/platform/mac/foo-expected.png 85 'diff --git a/foo-expected.png b/foo-expected.png\n'
96 =================================================================== 86 'deleted file mode 100644\n'
97 Cannot display: file marked as a binary type. 87 'index ef65bee..0000000\n'
98 svn:mime-type = image/png 88 'Binary files a/foo-expected.png and /dev/null differ\n')
99 """ 89 self._assert_checked(passed_to_process_file=[], delete_only_file_count=1 )
100 self._patch_checker.check(diff_text, fs)
101 self._assert_checked([], 1)
OLDNEW
« no previous file with comments | « third_party/WebKit/Tools/Scripts/webkitpy/style/patchreader.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698