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

Side by Side Diff: appengine/findit/lib/gitiles/test/local_git_parsers_test.py

Issue 2435863003: [Findit] Add local git parsers. (Closed)
Patch Set: Rebase 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 textwrap
8
9 from testing_utils import testing
10
11 from lib.gitiles import local_git_parsers
12 from lib.gitiles import blame
13 from lib.gitiles import change_log
14
15
16 class LocalGitParsersTest(testing.AppengineTestCase):
17
18 def testGitBlameParser(self):
19 output = textwrap.dedent(
20 """
21 revision_hash 18 18 3
22 author test@google.com
23 author-mail <test@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
24 author-time 1363032816
25 author-tz +0000
26 committer test@google.com
27 committer-mail <test@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
28 committer-time 1363032816
29 committer-tz +0000
30 summary add (mac) test for ttcindex in SkFontStream
31 previous fe7533eebe777cc66c7f8fa7a03f00572755c5b4 src/core/SkFont.h
32 filename src/core/SkFont.h
33 * blabla line 1
34 revision_hash 19 19
35 * blabla line 2
36 revision_hash 20 20
37 * blabla line 3
38
39 revision_hash 29 29 2
40 * blabla line 4
41 """
42 )
43
44 expected_regions = [blame.Region(18, 3, 'revision_hash', 'test@google.com',
45 'test@google.com',
46 datetime(2013, 03, 11, 17, 13, 36)),
47 blame.Region(29, 2, 'revision_hash', 'test@google.com',
48 'test@google.com',
49 datetime(2013, 03, 11, 17, 13, 36))]
50 expected_blame = blame.Blame('src/core/SkFont.h', 'rev')
51 for expected_region in expected_regions:
52 expected_blame.AddRegion(expected_region)
53
54 blame_result = local_git_parsers.GitBlameParser()(output,
55 'src/core/SkFont.h',
56 'rev')
57 self.assertTrue(blame_result.revision, expected_blame.revision)
58 self.assertTrue(blame_result.path, expected_blame.path)
59 for region, expected_region in zip(blame_result, expected_blame):
60 self.assertTrue(region.ToDict(), expected_region.ToDict())
61
62 def testGitBlameParserEmptyOutput(self):
63 output = ''
64 blame_result = local_git_parsers.GitBlameParser()(output,
65 'src/core/SkFont.h',
66 'rev')
67 self.assertEqual(len(blame_result), 0)
68
69 def testGetFileChangeInfo(self):
70 self.assertIsNone(local_git_parsers.GetFileChangeInfo('change type',
71 None, None))
72
73 def testGitChangeLogParser(self):
74 output = textwrap.dedent(
75 """
76 commit revision
77 tree tree_revision
78 parents parent_revision
79
80 author Test
81 author-mail test@google.com
82 author-time 2016-07-13 20:37:06
83
84 committer Test
85 committer-mail test@google.com
86 committer-time 2016-07-13 20:37:06
87
88 --Message start--
89 Revert commit messages...
90 > Committed: https://c.com/+/c9cc182781484f9010f062859cda048afefefefe
91 Review-Url: https://codereview.chromium.org/2391763002
92 Cr-Commit-Position: refs/heads/master@{#425880}
93 --Message end--
94
95 :100644 100644 25f95f c766f1 M src/a/b.py
96 """
97 )
98
99 message = ('Revert commit messages...\n'
100 '> Committed: https://c.com/+/'
101 'c9cc182781484f9010f062859cda048afefefefe\n'
102 'Review-Url: https://codereview.chromium.org/2391763002\n'
103 'Cr-Commit-Position: refs/heads/master@{#425880}')
104
105 expected_changelog = change_log.ChangeLog(
106 'Test', 'test@google.com', datetime(2016, 7, 13, 20, 37, 6),
107 'Test', 'test@google.com', datetime(2016, 7, 13, 20, 37, 6),
108 'revision', 425880, message, [change_log.FileChangeInfo(
109 'modify', 'src/a/b.py', 'src/a/b.py')],
110 'https://repo/+/revision',
111 'https://codereview.chromium.org/2391763002',
112 'c9cc182781484f9010f062859cda048afefefefe')
113
114 changelog = local_git_parsers.GitChangeLogParser()(output, 'https://repo')
115 self.assertTrue(expected_changelog.ToDict(), changelog.ToDict())
116
117 def testGitChangeLogsParser(self):
118 output = textwrap.dedent(
119 """
120 **Changelog start**
121 commit rev1
122 tree 27b0421273ed4aea25e497c6d26d9c7db6481852
123 parents rev22c9e
124
125 author author1
126 author-mail author1@chromium.org
127 author-time 2016-06-02 10:55:38
128
129 committer Commit bot
130 committer-mail commit-bot@chromium.org
131 committer-time 2016-06-02 10:57:13
132
133 --Message start--
134 Message 1
135 --Message end--
136
137 :100644 100644 28e117 f12d3 D a/b.py
138
139
140 **Changelog start**
141 commit rev2
142 tree d22d3786e135b83183cfeba5f3d8913959f56299
143 parents ac7ee4ce7b8d39b22a710c58d110e0039c11cf9a
144
145 author author2
146 author-mail author2@chromium.org
147 author-time 2016-06-02 10:53:03
148
149 committer Commit bot
150 committer-mail commit-bot@chromium.org
151 committer-time 2016-06-02 10:54:14
152
153 --Message start--
154 Message 2
155 --Message end--
156
157 :100644 100644 7280f df186 A b/c.py
158
159 **Changelog start**
160 commit rev3
161 tree d22d3786e135b83183cfeba5f3d8913959f56299
162 parents ac7ee4ce7b8d39b22a710c58d110e0039c11cf9a
163
164 author author3
165 author-mail author3@chromium.org
166 author-time 2016-06-02 10:53:03
167
168 committer Commit bot
169 committer-mail commit-bot@chromium.org
170 committer-time 2016-06-02 10:54:14
171
172 --Message start--
173 Message 3
174 --Message end--
175
176 :100644 100644 3f2e 20a5 R078 b/c.py b/cc.py
177 """
178 )
179
180 expected_changelogs = [
181 change_log.ChangeLog('author1',
182 'author1@chromium.org',
183 datetime(2016, 6, 2, 10, 55, 38),
184 'Commit bot',
185 'commit-bot@chromium.org',
186 datetime(2016, 6, 2, 10, 57, 13),
187 'rev1', None,
188 'Message 1', [change_log.FileChangeInfo(
189 'delete', 'a/b.py', None)],
190 'http://repo/+/rev1', None, None),
191 change_log.ChangeLog('author2',
192 'author2@chromium.org',
193 datetime(2016, 6, 2, 10, 53, 3),
194 'Commit bot',
195 'commit-bot@chromium.org',
196 datetime(2016, 6, 2, 10, 54, 14),
197 'rev2', None,
198 'Message 2', [change_log.FileChangeInfo(
199 'add', None, 'b/c.py')],
200 'http://repo/+/rev2', None, None),
201 change_log.ChangeLog('author3',
202 'author3@chromium.org',
203 datetime(2016, 6, 2, 10, 53, 3),
204 'Commit bot',
205 'commit-bot@chromium.org',
206 datetime(2016, 6, 2, 10, 54, 14),
207 'rev3', None,
208 'Message 3', [change_log.FileChangeInfo(
209 'rename', 'b/c.py', 'b/cc.py')],
210 'http://repo/+/rev3', None, None),
211 ]
212
213 changelogs = local_git_parsers.GitChangeLogsParser()(output, 'http://repo')
214 for changelog, expected_changelog in zip(changelogs, expected_changelogs):
215 self.assertEqual(changelog.ToDict(), expected_changelog.ToDict())
216
217 def testGitChangeLogsParserWithEmptyChangelog(self):
218 output = '**Changelog start**\nblablabla'
219 self.assertEqual(local_git_parsers.GitChangeLogsParser()(output,
220 'http://repo'), [])
221
222 def testGitDiffParser(self):
223 output = 'output'
224 self.assertEqual(output, local_git_parsers.GitDiffParser()(output))
225
226 def testGitSourceParser(self):
227 output = 'output'
228 self.assertEqual(output, local_git_parsers.GitSourceParser()(output))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698