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

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

Issue 637503004: [webkitpy] Refactor diff_parser.py (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 2 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 import diff_parser 30 from diff_parser import DiffParser
31 import re 31 import re
32 import unittest 32 import unittest
33 33
34 from webkitpy.common.checkout.diff_test_data import DIFF_TEST_DATA 34 from webkitpy.common.checkout.diff_test_data import DIFF_TEST_DATA
35 35
36 class DiffParserTest(unittest.TestCase): 36 class DiffParserTest(unittest.TestCase):
37 maxDiff = None 37 maxDiff = None
38 38
39 def test_diff_parser(self, parser = None): 39 def test_diff_parser(self, parser = None):
40 if not parser: 40 if not parser:
41 parser = diff_parser.DiffParser(DIFF_TEST_DATA.splitlines()) 41 parser = DiffParser(DIFF_TEST_DATA.splitlines())
42 self.assertEqual(3, len(parser.files)) 42 self.assertEqual(3, len(parser.files))
43 43
44 self.assertTrue('WebCore/rendering/style/StyleFlexibleBoxData.h' in pars er.files) 44 self.assertTrue('WebCore/rendering/style/StyleFlexibleBoxData.h' in pars er.files)
45 diff = parser.files['WebCore/rendering/style/StyleFlexibleBoxData.h'] 45 diff = parser.files['WebCore/rendering/style/StyleFlexibleBoxData.h']
46 self.assertEqual(7, len(diff.lines)) 46 self.assertEqual(7, len(diff.lines))
47 # The first two unchaged lines. 47 # The first two unchaged lines.
48 self.assertEqual((47, 47), diff.lines[0][0:2]) 48 self.assertEqual((47, 47), diff.lines[0][0:2])
49 self.assertEqual('', diff.lines[0][2]) 49 self.assertEqual('', diff.lines[0][2])
50 self.assertEqual((48, 48), diff.lines[1][0:2]) 50 self.assertEqual((48, 48), diff.lines[1][0:2])
51 self.assertEqual(' unsigned align : 3; // EBoxAlignment', diff.lines[ 1][2]) 51 self.assertEqual(' unsigned align : 3; // EBoxAlignment', diff.lines[ 1][2])
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 "Subversion Revision 289799\n", 92 "Subversion Revision 289799\n",
93 ] 93 ]
94 94
95 svn_diff_lines = [ 95 svn_diff_lines = [
96 "Index: Tools/Scripts/webkitpy/common/checkout/diff_parser.py\n", 96 "Index: Tools/Scripts/webkitpy/common/checkout/diff_parser.py\n",
97 "=================================================================== \n", 97 "=================================================================== \n",
98 "--- Tools/Scripts/webkitpy/common/checkout/diff_parser.py\n", 98 "--- Tools/Scripts/webkitpy/common/checkout/diff_parser.py\n",
99 "+++ Tools/Scripts/webkitpy/common/checkout/diff_parser.py\n", 99 "+++ Tools/Scripts/webkitpy/common/checkout/diff_parser.py\n",
100 "@@ -59,6 +59,7 @@ def git_diff_to_svn_diff(line):\n", 100 "@@ -59,6 +59,7 @@ def git_diff_to_svn_diff(line):\n",
101 ] 101 ]
102 self.assertEqual(diff_parser.get_diff_converter(svn_diff_lines), diff_pa rser.svn_diff_to_svn_diff) 102 self.assertEqual(DiffParser.get_diff_converter(svn_diff_lines), DiffPars er.svn_diff_to_svn_diff)
103 self.assertEqual(diff_parser.get_diff_converter(comment_lines + svn_diff _lines), diff_parser.svn_diff_to_svn_diff) 103 self.assertEqual(DiffParser.get_diff_converter(comment_lines + svn_diff_ lines), DiffParser.svn_diff_to_svn_diff)
104 self.assertEqual(diff_parser.get_diff_converter(revision_lines + svn_dif f_lines), diff_parser.svn_diff_to_svn_diff) 104 self.assertEqual(DiffParser.get_diff_converter(revision_lines + svn_diff _lines), DiffParser.svn_diff_to_svn_diff)
105 105
106 git_diff_lines = [ 106 git_diff_lines = [
107 "diff --git a/Tools/Scripts/webkitpy/common/checkout/diff_parser.py b/Tools/Scripts/webkitpy/common/checkout/diff_parser.py\n", 107 "diff --git a/Tools/Scripts/webkitpy/common/checkout/diff_parser.py b/Tools/Scripts/webkitpy/common/checkout/diff_parser.py\n",
108 "index 3c5b45b..0197ead 100644\n", 108 "index 3c5b45b..0197ead 100644\n",
109 "--- a/Tools/Scripts/webkitpy/common/checkout/diff_parser.py\n", 109 "--- a/Tools/Scripts/webkitpy/common/checkout/diff_parser.py\n",
110 "+++ b/Tools/Scripts/webkitpy/common/checkout/diff_parser.py\n", 110 "+++ b/Tools/Scripts/webkitpy/common/checkout/diff_parser.py\n",
111 "@@ -59,6 +59,7 @@ def git_diff_to_svn_diff(line):\n", 111 "@@ -59,6 +59,7 @@ def git_diff_to_svn_diff(line):\n",
112 ] 112 ]
113 self.assertEqual(diff_parser.get_diff_converter(git_diff_lines), diff_pa rser.git_diff_to_svn_diff) 113 self.assertEqual(DiffParser.get_diff_converter(git_diff_lines), DiffPars er.git_diff_to_svn_diff)
114 self.assertEqual(diff_parser.get_diff_converter(comment_lines + git_diff _lines), diff_parser.git_diff_to_svn_diff) 114 self.assertEqual(DiffParser.get_diff_converter(comment_lines + git_diff_ lines), DiffParser.git_diff_to_svn_diff)
115 self.assertEqual(diff_parser.get_diff_converter(revision_lines + git_dif f_lines), diff_parser.git_diff_to_svn_diff) 115 self.assertEqual(DiffParser.get_diff_converter(revision_lines + git_diff _lines), DiffParser.git_diff_to_svn_diff)
116 116
117 def test_git_mnemonicprefix(self): 117 def test_git_mnemonicprefix(self):
118 p = re.compile(r' ([a|b])/') 118 p = re.compile(r' ([a|b])/')
119 119
120 prefixes = [ 120 prefixes = [
121 { 'a' : 'i', 'b' : 'w' }, # git-diff (compares the (i)ndex and the ( w)ork tree) 121 { 'a' : 'i', 'b' : 'w' }, # git-diff (compares the (i)ndex and the ( w)ork tree)
122 { 'a' : 'c', 'b' : 'w' }, # git-diff HEAD (compares a (c)ommit and t he (w)ork tree) 122 { 'a' : 'c', 'b' : 'w' }, # git-diff HEAD (compares a (c)ommit and t he (w)ork tree)
123 { 'a' : 'c', 'b' : 'i' }, # git diff --cached (compares a (c)ommit a nd the (i)ndex) 123 { 'a' : 'c', 'b' : 'i' }, # git diff --cached (compares a (c)ommit a nd the (i)ndex)
124 { 'a' : 'o', 'b' : 'w' }, # git-diff HEAD:file1 file2 (compares an ( o)bject and a (w)ork tree entity) 124 { 'a' : 'o', 'b' : 'w' }, # git-diff HEAD:file1 file2 (compares an ( o)bject and a (w)ork tree entity)
125 { 'a' : '1', 'b' : '2' }, # git diff --no-index a b (compares two no n-git things (1) and (2)) 125 { 'a' : '1', 'b' : '2' }, # git diff --no-index a b (compares two no n-git things (1) and (2))
126 ] 126 ]
127 127
128 for prefix in prefixes: 128 for prefix in prefixes:
129 patch = p.sub(lambda x: " %s/" % prefix[x.group(1)], DIFF_TEST_DATA) 129 patch = p.sub(lambda x: " %s/" % prefix[x.group(1)], DIFF_TEST_DATA)
130 self.test_diff_parser(diff_parser.DiffParser(patch.splitlines())) 130 self.test_diff_parser(DiffParser(patch.splitlines()))
131 131
132 def test_git_diff_to_svn_diff(self): 132 def test_git_diff_to_svn_diff(self):
133 output = """\ 133 output = """\
134 Index: Tools/Scripts/webkitpy/common/checkout/diff_parser.py 134 Index: Tools/Scripts/webkitpy/common/checkout/diff_parser.py
135 =================================================================== 135 ===================================================================
136 --- Tools/Scripts/webkitpy/common/checkout/diff_parser.py 136 --- Tools/Scripts/webkitpy/common/checkout/diff_parser.py
137 +++ Tools/Scripts/webkitpy/common/checkout/diff_parser.py 137 +++ Tools/Scripts/webkitpy/common/checkout/diff_parser.py
138 @@ -59,6 +59,7 @@ def git_diff_to_svn_diff(line): 138 @@ -59,6 +59,7 @@ def git_diff_to_svn_diff(line):
139 A 139 A
140 B 140 B
(...skipping 23 matching lines...) Expand all
164 +++ b/Tools/Scripts/webkitpy/common/checkout/diff_parser.py 164 +++ b/Tools/Scripts/webkitpy/common/checkout/diff_parser.py
165 @@ -59,6 +59,7 @@ def git_diff_to_svn_diff(line): 165 @@ -59,6 +59,7 @@ def git_diff_to_svn_diff(line):
166 A 166 A
167 B 167 B
168 C 168 C
169 +D 169 +D
170 E 170 E
171 F 171 F
172 """) 172 """)
173 173
174 self.assertMultiLineEqual(output, ''.join(diff_parser.git_diff_to_svn_di ff(x) for x in shortfmt.readlines())) 174 self.assertMultiLineEqual(output, ''.join(DiffParser.git_diff_to_svn_dif f(x) for x in shortfmt.readlines()))
175 self.assertMultiLineEqual(output, ''.join(diff_parser.git_diff_to_svn_di ff(x) for x in inputfmt.readlines())) 175 self.assertMultiLineEqual(output, ''.join(DiffParser.git_diff_to_svn_dif f(x) for x in inputfmt.readlines()))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698