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