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

Side by Side Diff: third_party/WebKit/Tools/Scripts/webkitpy/common/checkout/diff_parser_unittest.py

Issue 2248653002: Revert of Fix pylint warnings in webkitpy/common/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Manual Revert (Patch Set 1 causes patch failure in read_checksum_from_png_unittest.py) Created 4 years, 4 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
OLDNEW
1 # Copyright (C) 2009 Google Inc. All rights reserved. 1 # Copyright (C) 2009 Google Inc. All rights reserved.
2 # 2 #
3 # Redistribution and use in source and binary forms, with or without 3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are 4 # modification, are permitted provided that the following conditions are
5 # met: 5 # met:
6 # 6 #
7 # * Redistributions of source code must retain the above copyright 7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer. 8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above 9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer 10 # copyright notice, this list of conditions and the following disclaimer
11 # in the documentation and/or other materials provided with the 11 # in the documentation and/or other materials provided with the
12 # distribution. 12 # distribution.
13 # * Neither the name of Google Inc. nor the names of its 13 # * Neither the name of Google Inc. nor the names of its
14 # contributors may be used to endorse or promote products derived from 14 # contributors may be used to endorse or promote products derived from
15 # this software without specific prior written permission. 15 # this software without specific prior written permission.
16 # 16 #
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 28
29 import cStringIO as StringIO 29 import cStringIO as StringIO
30 30 import diff_parser
31 import re 31 import re
32 import unittest 32 import unittest
33 33
34 from webkitpy.common.checkout import diff_parser
35 from webkitpy.common.checkout.diff_test_data import DIFF_TEST_DATA 34 from webkitpy.common.checkout.diff_test_data import DIFF_TEST_DATA
36 35
37 36
38 class DiffParserTest(unittest.TestCase): 37 class DiffParserTest(unittest.TestCase):
39 maxDiff = None 38 maxDiff = None
40 39
41 def test_diff_parser(self, parser=None): 40 def test_diff_parser(self, parser=None):
42 if not parser: 41 if not parser:
43 parser = diff_parser.DiffParser(DIFF_TEST_DATA.splitlines()) 42 parser = diff_parser.DiffParser(DIFF_TEST_DATA.splitlines())
44 self.assertEqual(3, len(parser.files)) 43 self.assertEqual(3, len(parser.files))
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 "=================================================================== \n", 98 "=================================================================== \n",
100 "--- Tools/Scripts/webkitpy/common/checkout/diff_parser.py\n", 99 "--- Tools/Scripts/webkitpy/common/checkout/diff_parser.py\n",
101 "+++ Tools/Scripts/webkitpy/common/checkout/diff_parser.py\n", 100 "+++ Tools/Scripts/webkitpy/common/checkout/diff_parser.py\n",
102 "@@ -59,6 +59,7 @@ def git_diff_to_svn_diff(line):\n", 101 "@@ -59,6 +59,7 @@ def git_diff_to_svn_diff(line):\n",
103 ] 102 ]
104 self.assertEqual(diff_parser.get_diff_converter(svn_diff_lines), diff_pa rser.svn_diff_to_svn_diff) 103 self.assertEqual(diff_parser.get_diff_converter(svn_diff_lines), diff_pa rser.svn_diff_to_svn_diff)
105 self.assertEqual(diff_parser.get_diff_converter(comment_lines + svn_diff _lines), diff_parser.svn_diff_to_svn_diff) 104 self.assertEqual(diff_parser.get_diff_converter(comment_lines + svn_diff _lines), diff_parser.svn_diff_to_svn_diff)
106 self.assertEqual(diff_parser.get_diff_converter(revision_lines + svn_dif f_lines), diff_parser.svn_diff_to_svn_diff) 105 self.assertEqual(diff_parser.get_diff_converter(revision_lines + svn_dif f_lines), diff_parser.svn_diff_to_svn_diff)
107 106
108 git_diff_lines = [ 107 git_diff_lines = [
109 ("diff --git a/Tools/Scripts/webkitpy/common/checkout/diff_parser.py " 108 "diff --git a/Tools/Scripts/webkitpy/common/checkout/diff_parser.py b/Tools/Scripts/webkitpy/common/checkout/diff_parser.py\n",
110 "b/Tools/Scripts/webkitpy/common/checkout/diff_parser.py\n"),
111 "index 3c5b45b..0197ead 100644\n", 109 "index 3c5b45b..0197ead 100644\n",
112 "--- a/Tools/Scripts/webkitpy/common/checkout/diff_parser.py\n", 110 "--- a/Tools/Scripts/webkitpy/common/checkout/diff_parser.py\n",
113 "+++ b/Tools/Scripts/webkitpy/common/checkout/diff_parser.py\n", 111 "+++ b/Tools/Scripts/webkitpy/common/checkout/diff_parser.py\n",
114 "@@ -59,6 +59,7 @@ def git_diff_to_svn_diff(line):\n", 112 "@@ -59,6 +59,7 @@ def git_diff_to_svn_diff(line):\n",
115 ] 113 ]
116 self.assertEqual(diff_parser.get_diff_converter(git_diff_lines), diff_pa rser.git_diff_to_svn_diff) 114 self.assertEqual(diff_parser.get_diff_converter(git_diff_lines), diff_pa rser.git_diff_to_svn_diff)
117 self.assertEqual(diff_parser.get_diff_converter(comment_lines + git_diff _lines), diff_parser.git_diff_to_svn_diff) 115 self.assertEqual(diff_parser.get_diff_converter(comment_lines + git_diff _lines), diff_parser.git_diff_to_svn_diff)
118 self.assertEqual(diff_parser.get_diff_converter(revision_lines + git_dif f_lines), diff_parser.git_diff_to_svn_diff) 116 self.assertEqual(diff_parser.get_diff_converter(revision_lines + git_dif f_lines), diff_parser.git_diff_to_svn_diff)
119 117
120 def test_git_mnemonic_prefix(self): 118 def test_git_mnemonicprefix(self):
121 pattern = re.compile(r' ([a|b])/') 119 p = re.compile(r' ([a|b])/')
122 120
123 prefixes = [ 121 prefixes = [
124 {'a': 'i', 'b': 'w'}, # git-diff (compares the (i)ndex and the (w)o rk tree) 122 {'a': 'i', 'b': 'w'}, # git-diff (compares the (i)ndex and the (w)o rk tree)
125 {'a': 'c', 'b': 'w'}, # git-diff HEAD (compares a (c)ommit and the (w)ork tree) 123 {'a': 'c', 'b': 'w'}, # git-diff HEAD (compares a (c)ommit and the (w)ork tree)
126 {'a': 'c', 'b': 'i'}, # git diff --cached (compares a (c)ommit and the (i)ndex) 124 {'a': 'c', 'b': 'i'}, # git diff --cached (compares a (c)ommit and the (i)ndex)
127 {'a': 'o', 'b': 'w'}, # git-diff HEAD:file1 file2 (compares an (o)b ject and a (w)ork tree entity) 125 {'a': 'o', 'b': 'w'}, # git-diff HEAD:file1 file2 (compares an (o)b ject and a (w)ork tree entity)
128 {'a': '1', 'b': '2'}, # git diff --no-index a b (compares two non-g it things (1) and (2)) 126 {'a': '1', 'b': '2'}, # git diff --no-index a b (compares two non-g it things (1) and (2))
129 ] 127 ]
130 128
131 def patch(prefix):
132 return pattern.sub(lambda match: " %s/" % prefix[match.group(1)], DI FF_TEST_DATA)
133
134 for prefix in prefixes: 129 for prefix in prefixes:
135 self.test_diff_parser(diff_parser.DiffParser(patch(prefix).splitline s())) 130 patch = p.sub(lambda x: " %s/" % prefix[x.group(1)], DIFF_TEST_DATA)
131 self.test_diff_parser(diff_parser.DiffParser(patch.splitlines()))
136 132
137 def test_git_diff_to_svn_diff(self): 133 def test_git_diff_to_svn_diff(self):
138 output = """\ 134 output = """\
139 Index: Tools/Scripts/webkitpy/common/checkout/diff_parser.py 135 Index: Tools/Scripts/webkitpy/common/checkout/diff_parser.py
140 =================================================================== 136 ===================================================================
141 --- Tools/Scripts/webkitpy/common/checkout/diff_parser.py 137 --- Tools/Scripts/webkitpy/common/checkout/diff_parser.py
142 +++ Tools/Scripts/webkitpy/common/checkout/diff_parser.py 138 +++ Tools/Scripts/webkitpy/common/checkout/diff_parser.py
143 @@ -59,6 +59,7 @@ def git_diff_to_svn_diff(line): 139 @@ -59,6 +59,7 @@ def git_diff_to_svn_diff(line):
144 A 140 A
145 B 141 B
(...skipping 25 matching lines...) Expand all
171 A 167 A
172 B 168 B
173 C 169 C
174 +D 170 +D
175 E 171 E
176 F 172 F
177 """) 173 """)
178 174
179 self.assertMultiLineEqual(output, ''.join(diff_parser.git_diff_to_svn_di ff(x) for x in shortfmt.readlines())) 175 self.assertMultiLineEqual(output, ''.join(diff_parser.git_diff_to_svn_di ff(x) for x in shortfmt.readlines()))
180 self.assertMultiLineEqual(output, ''.join(diff_parser.git_diff_to_svn_di ff(x) for x in inputfmt.readlines())) 176 self.assertMultiLineEqual(output, ''.join(diff_parser.git_diff_to_svn_di ff(x) for x in inputfmt.readlines()))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698