| OLD | NEW |
| (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 2013-03-11 17:13:36 |
| 25 committer test@google.com |
| 26 committer-mail <test@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> |
| 27 committer-time 2013-03-11 17:13:36 |
| 28 summary add (mac) test for ttcindex in SkFontStream |
| 29 previous fe7533eebe777cc66c7f8fa7a03f00572755c5b4 src/core/SkFont.h |
| 30 filename src/core/SkFont.h |
| 31 * blabla line 1 |
| 32 revision_hash 19 19 |
| 33 * blabla line 2 |
| 34 revision_hash 20 20 |
| 35 * blabla line 3 |
| 36 """ |
| 37 ) |
| 38 |
| 39 expected_regions = [blame.Region(18, 3, 'revision_hash', 'test@google.com', |
| 40 'test@google.com', |
| 41 datetime(2013, 03, 11, 17, 13, 36))] |
| 42 expected_blame = blame.Blame('src/core/SkFont.h', 'rev') |
| 43 for expected_region in expected_regions: |
| 44 expected_blame.AddRegion(expected_region) |
| 45 |
| 46 blame_result = local_git_parsers.GitBlameParser()(output, |
| 47 'src/core/SkFont.h', |
| 48 'rev') |
| 49 self.assertTrue(blame_result.revision, expected_blame.revision) |
| 50 self.assertTrue(blame_result.path, expected_blame.path) |
| 51 for region, expected_region in zip(blame_result, expected_blame): |
| 52 self.assertTrue(region.ToDict(), expected_region.ToDict()) |
| 53 |
| 54 def testGetFileChangeInfo(self): |
| 55 self.assertIsNone(local_git_parsers.GetFileChangeInfo('change type', |
| 56 None, None)) |
| 57 |
| 58 def testGitChangeLogParser(self): |
| 59 output = textwrap.dedent( |
| 60 """ |
| 61 commit revision |
| 62 tree tree_revision |
| 63 parents parent_revision |
| 64 |
| 65 author Test |
| 66 author-mail test@google.com |
| 67 author-time 2016-07-13 20:37:06 |
| 68 |
| 69 committer Test |
| 70 committer-mail test@google.com |
| 71 committer-time 2016-07-13 20:37:06 |
| 72 |
| 73 --Message start-- |
| 74 Revert commit messages... |
| 75 > Committed: https://c.com/+/c9cc182781484f9010f062859cda048afefefefe |
| 76 Review-Url: https://codereview.chromium.org/2391763002 |
| 77 Cr-Commit-Position: refs/heads/master@{#425880} |
| 78 --Message end-- |
| 79 |
| 80 :100644 100644 25f95f c766f1 M src/a/b.py |
| 81 """ |
| 82 ) |
| 83 |
| 84 message = ('Revert commit messages...\n' |
| 85 '> Committed: https://c.com/+/' |
| 86 'c9cc182781484f9010f062859cda048afefefefe\n' |
| 87 'Review-Url: https://codereview.chromium.org/2391763002\n' |
| 88 'Cr-Commit-Position: refs/heads/master@{#425880}') |
| 89 |
| 90 expected_changelog = change_log.ChangeLog( |
| 91 'Test', 'test@google.com', datetime(2016, 7, 13, 20, 37, 6), |
| 92 'Test', 'test@google.com', datetime(2016, 7, 13, 20, 37, 6), |
| 93 'revision', 425880, message, [change_log.FileChangeInfo( |
| 94 'modify', 'src/a/b.py', 'src/a/b.py')], |
| 95 'https://repo/+/revision', |
| 96 'https://codereview.chromium.org/2391763002', |
| 97 'c9cc182781484f9010f062859cda048afefefefe') |
| 98 |
| 99 changelog = local_git_parsers.GitChangeLogParser()(output, 'https://repo') |
| 100 self.assertTrue(expected_changelog.ToDict(), changelog.ToDict()) |
| 101 |
| 102 def testGitChangeLogsParser(self): |
| 103 output = textwrap.dedent( |
| 104 """ |
| 105 **Changelog start** |
| 106 commit rev1 |
| 107 tree 27b0421273ed4aea25e497c6d26d9c7db6481852 |
| 108 parents rev22c9e |
| 109 |
| 110 author author1 |
| 111 author-mail author1@chromium.org |
| 112 author-time 2016-06-02 10:55:38 |
| 113 |
| 114 committer Commit bot |
| 115 committer-mail commit-bot@chromium.org |
| 116 committer-time 2016-06-02 10:57:13 |
| 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 rev2 |
| 127 tree d22d3786e135b83183cfeba5f3d8913959f56299 |
| 128 parents ac7ee4ce7b8d39b22a710c58d110e0039c11cf9a |
| 129 |
| 130 author author2 |
| 131 author-mail author2@chromium.org |
| 132 author-time 2016-06-02 10:53:03 |
| 133 |
| 134 committer Commit bot |
| 135 committer-mail commit-bot@chromium.org |
| 136 committer-time 2016-06-02 10:54:14 |
| 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 rev3 |
| 146 tree d22d3786e135b83183cfeba5f3d8913959f56299 |
| 147 parents ac7ee4ce7b8d39b22a710c58d110e0039c11cf9a |
| 148 |
| 149 author author3 |
| 150 author-mail author3@chromium.org |
| 151 author-time 2016-06-02 10:53:03 |
| 152 |
| 153 committer Commit bot |
| 154 committer-mail commit-bot@chromium.org |
| 155 committer-time 2016-06-02 10:54:14 |
| 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('author1', |
| 167 'author1@chromium.org', |
| 168 datetime(2016, 6, 2, 10, 55, 38), |
| 169 'Commit bot', |
| 170 'commit-bot@chromium.org', |
| 171 datetime(2016, 6, 2, 10, 57, 13), |
| 172 'rev1', None, |
| 173 'Message 1', [change_log.FileChangeInfo( |
| 174 'delete', 'a/b.py', None)], |
| 175 'http://repo/+/rev1', None, None), |
| 176 change_log.ChangeLog('author2', |
| 177 'author2@chromium.org', |
| 178 datetime(2016, 6, 2, 10, 53, 3), |
| 179 'Commit bot', |
| 180 'commit-bot@chromium.org', |
| 181 datetime(2016, 6, 2, 10, 54, 14), |
| 182 'rev2', None, |
| 183 'Message 2', [change_log.FileChangeInfo( |
| 184 'add', None, 'b/c.py')], |
| 185 'http://repo/+/rev2', None, None), |
| 186 change_log.ChangeLog('author3', |
| 187 'author3@chromium.org', |
| 188 datetime(2016, 6, 2, 10, 53, 3), |
| 189 'Commit bot', |
| 190 'commit-bot@chromium.org', |
| 191 datetime(2016, 6, 2, 10, 54, 14), |
| 192 'rev3', None, |
| 193 'Message 3', [change_log.FileChangeInfo( |
| 194 'rename', 'b/c.py', 'b/cc.py')], |
| 195 'http://repo/+/rev3', None, None), |
| 196 ] |
| 197 |
| 198 changelogs = local_git_parsers.GitChangeLogsParser()(output, 'http://repo') |
| 199 for changelog, expected_changelog in zip(changelogs, expected_changelogs): |
| 200 self.assertEqual(changelog.ToDict(), expected_changelog.ToDict()) |
| 201 |
| 202 def testGitChangeLogsParserWithEmptyChangelog(self): |
| 203 output = '**Changelog start**\nblablabla' |
| 204 self.assertEqual(local_git_parsers.GitChangeLogsParser()(output, |
| 205 'http://repo'), []) |
| 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)) |
| OLD | NEW |