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

Side by Side Diff: appengine/findit/util_scripts/git_checkout/test/local_git_parsers_test.py

Issue 2435863003: [Findit] Add local git parsers. (Closed)
Patch Set: Fix nits. Created 4 years, 1 month 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
(Empty)
1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 from datetime import datetime
6 from datetime import timedelta
7 import os
8 import sys
9 import textwrap
10 import unittest
11
12 _SCRIPT_DIR = os.path.join(os.path.dirname(__file__),
13 os.path.pardir, os.path.pardir)
14 sys.path.insert(1, _SCRIPT_DIR)
15 import script_util
16 script_util.SetUpSystemPaths()
17
18 from git_checkout import local_git_parsers
19 from lib.gitiles import blame
20 from lib.gitiles import change_log
21
22
23 class LocalGitParsersTest(unittest.TestCase):
24
25 def testGitBlameParser(self):
26 output = textwrap.dedent(
27 """
28 revision_hash 18 18 3
29 author test@google.com
30 author-mail <test@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
31 author-time 1363032816
32 author-tz +0000
33 committer test@google.com
34 committer-mail <test@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
35 committer-time 1363032816
36 committer-tz +0000
37 summary add (mac) test for ttcindex in SkFontStream
38 previous fe7533eebe777cc66c7f8fa7a03f00572755c5b4 src/core/SkFont.h
39 filename src/core/SkFont.h
40 * blabla line 1
41 revision_hash 19 19
42 * blabla line 2
43 revision_hash 20 20
44 * blabla line 3
45
46 revision_hash 29 29 2
47 * blabla line 4
48 """
49 )
50
51 expected_regions = [blame.Region(18, 3, 'revision_hash', 'test@google.com',
52 'test@google.com',
53 datetime(2013, 03, 11, 17, 13, 36)),
54 blame.Region(29, 2, 'revision_hash', 'test@google.com',
55 'test@google.com',
56 datetime(2013, 03, 11, 17, 13, 36))]
57 expected_blame = blame.Blame('src/core/SkFont.h', 'rev')
58 for expected_region in expected_regions:
59 expected_blame.AddRegion(expected_region)
wrengr 2016/11/08 19:05:16 Can you add a TODO(crbug.com/663445)? resolving th
Sharu Jiang 2016/11/10 22:28:37 Done.
60
61 blame_result = local_git_parsers.GitBlameParser()(output,
wrengr 2016/11/08 19:05:16 should prolly cache the local_git_parsers.GitBlame
Sharu Jiang 2016/11/10 22:28:37 Done.
62 'src/core/SkFont.h',
63 'rev')
64 self.assertTrue(blame_result.revision, expected_blame.revision)
65 self.assertTrue(blame_result.path, expected_blame.path)
66 for region, expected_region in zip(blame_result, expected_blame):
67 self.assertTrue(region.ToDict(), expected_region.ToDict())
68
69 def testGitBlameParserEmptyOutput(self):
70 output = ''
wrengr 2016/11/08 19:05:16 since output and blame_result are only used once (
Sharu Jiang 2016/11/10 22:28:37 Done.
71 blame_result = local_git_parsers.GitBlameParser()(output,
72 'src/core/SkFont.h',
73 'rev')
74 self.assertIsNone(blame_result)
75
76 def testGitBlameParserDummyOutput(self):
77 output = 'Dummy'
wrengr 2016/11/08 19:05:16 ditto
Sharu Jiang 2016/11/10 22:28:37 Done.
78 blame_result = local_git_parsers.GitBlameParser()(output,
79 'src/core/SkFont.h',
80 'rev')
81 self.assertIsNone(blame_result)
82
83 def testGetFileChangeInfo(self):
84 self.assertIsNone(local_git_parsers.GetFileChangeInfo('change type',
85 None, None))
86
87 def testGitChangeLogParser(self):
88 output = textwrap.dedent(
89 """
90 commit revision
91 tree tree_revision
92 parents parent_revision
93
94 author Test
95 author-mail test@google.com
96 author-time 2016-07-13 20:37:06
97
98 committer Test
99 committer-mail test@google.com
100 committer-time 2016-07-13 20:37:06
101
102 --Message start--
103 Revert commit messages...
104 > Committed: https://c.com/+/c9cc182781484f9010f062859cda048afefefefe
105 Review-Url: https://codereview.chromium.org/2391763002
106 Cr-Commit-Position: refs/heads/master@{#425880}
107 --Message end--
108
109 :100644 100644 25f95f c766f1 M src/a/b.py
110 """
111 )
112
113 message = ('Revert commit messages...\n'
114 '> Committed: https://c.com/+/'
115 'c9cc182781484f9010f062859cda048afefefefe\n'
116 'Review-Url: https://codereview.chromium.org/2391763002\n'
117 'Cr-Commit-Position: refs/heads/master@{#425880}')
118
119 expected_changelog = change_log.ChangeLog(
120 'Test', 'test@google.com', datetime(2016, 7, 13, 20, 37, 6),
121 'Test', 'test@google.com', datetime(2016, 7, 13, 20, 37, 6),
122 'revision', 425880, message, [change_log.FileChangeInfo(
123 'modify', 'src/a/b.py', 'src/a/b.py')],
124 'https://repo/+/revision',
125 'https://codereview.chromium.org/2391763002',
126 'c9cc182781484f9010f062859cda048afefefefe')
127
128 changelog = local_git_parsers.GitChangeLogParser()(output, 'https://repo')
129 self.assertTrue(expected_changelog.ToDict(), changelog.ToDict())
130
131 def testGitChangeLogParserParseEmptyOutput(self):
132 output = None
wrengr 2016/11/08 19:05:16 ditto
Sharu Jiang 2016/11/10 22:28:37 Done.
133 self.assertIsNone(local_git_parsers.GitChangeLogParser()(output, 'repo'))
134
135 def testGitChangeLogsParser(self):
136 output = textwrap.dedent(
137 """
138 **Changelog start**
139 commit rev1
140 tree 27b0421273ed4aea25e497c6d26d9c7db6481852
141 parents rev22c9e
142
143 author author1
144 author-mail author1@chromium.org
145 author-time 2016-06-02 10:55:38
146
147 committer Commit bot
148 committer-mail commit-bot@chromium.org
149 committer-time 2016-06-02 10:57:13
150
151 --Message start--
152 Message 1
153 --Message end--
154
155 :100644 100644 28e117 f12d3 D a/b.py
156
157
158 **Changelog start**
159 commit rev2
160 tree d22d3786e135b83183cfeba5f3d8913959f56299
161 parents ac7ee4ce7b8d39b22a710c58d110e0039c11cf9a
162
163 author author2
164 author-mail author2@chromium.org
165 author-time 2016-06-02 10:53:03
166
167 committer Commit bot
168 committer-mail commit-bot@chromium.org
169 committer-time 2016-06-02 10:54:14
170
171 --Message start--
172 Message 2
173 --Message end--
174
175 :100644 100644 7280f df186 A b/c.py
176
177 **Changelog start**
178 commit rev3
179 tree d22d3786e135b83183cfeba5f3d8913959f56299
180 parents ac7ee4ce7b8d39b22a710c58d110e0039c11cf9a
181
182 author author3
183 author-mail author3@chromium.org
184 author-time 2016-06-02 10:53:03
185
186 committer Commit bot
187 committer-mail commit-bot@chromium.org
188 committer-time 2016-06-02 10:54:14
189
190 --Message start--
191 Message 3
192 --Message end--
193
194 :100644 100644 3f2e 20a5 R078 b/c.py b/cc.py
195 """
196 )
197
198 expected_changelogs = [
199 change_log.ChangeLog('author1',
200 'author1@chromium.org',
201 datetime(2016, 6, 2, 10, 55, 38),
202 'Commit bot',
203 'commit-bot@chromium.org',
204 datetime(2016, 6, 2, 10, 57, 13),
205 'rev1', None,
206 'Message 1', [change_log.FileChangeInfo(
207 'delete', 'a/b.py', None)],
208 'http://repo/+/rev1', None, None),
209 change_log.ChangeLog('author2',
210 'author2@chromium.org',
211 datetime(2016, 6, 2, 10, 53, 3),
212 'Commit bot',
213 'commit-bot@chromium.org',
214 datetime(2016, 6, 2, 10, 54, 14),
215 'rev2', None,
216 'Message 2', [change_log.FileChangeInfo(
217 'add', None, 'b/c.py')],
218 'http://repo/+/rev2', None, None),
219 change_log.ChangeLog('author3',
220 'author3@chromium.org',
221 datetime(2016, 6, 2, 10, 53, 3),
222 'Commit bot',
223 'commit-bot@chromium.org',
224 datetime(2016, 6, 2, 10, 54, 14),
225 'rev3', None,
226 'Message 3', [change_log.FileChangeInfo(
227 'rename', 'b/c.py', 'b/cc.py')],
228 'http://repo/+/rev3', None, None),
229 ]
230
231 changelogs = local_git_parsers.GitChangeLogsParser()(output, 'http://repo')
232 for changelog, expected_changelog in zip(changelogs, expected_changelogs):
233 self.assertEqual(changelog.ToDict(), expected_changelog.ToDict())
234
235
236 def testGitChangeLogsParserParseEmptyOutput(self):
237 output = None
wrengr 2016/11/08 19:05:16 ditto
Sharu Jiang 2016/11/10 22:28:37 Done.
238 self.assertIsNone(local_git_parsers.GitChangeLogsParser()(output, 'repo'))
239
240 def testGitChangeLogsParserWithEmptyChangelog(self):
241 output = '**Changelog start**\nblablabla'
242 self.assertEqual(local_git_parsers.GitChangeLogsParser()(output,
243 'http://repo'), [])
244
245 def testGitDiffParser(self):
246 output = 'output'
wrengr 2016/11/08 19:05:16 ditto
Sharu Jiang 2016/11/10 22:28:38 Done.
247 self.assertEqual(output, local_git_parsers.GitDiffParser()(output))
248
249 def testGitSourceParser(self):
250 output = 'output'
wrengr 2016/11/08 19:05:16 ditto
Sharu Jiang 2016/11/10 22:28:37 Done.
251 self.assertEqual(output, local_git_parsers.GitSourceParser()(output))
252
253
254 if __name__ == '__main__':
255 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698