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

Side by Side Diff: appengine/findit/common/test/local_git_parsers_test.py

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

Powered by Google App Engine
This is Rietveld 408576698