| 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 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 setUp(self): |
| 26 super(LocalGitParsersTest, self).setUp() |
| 27 self.blame_parser = local_git_parsers.GitBlameParser() |
| 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 +0000 |
| 37 committer test@google.com |
| 38 committer-mail <test@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> |
| 39 committer-time 1363032816 |
| 40 committer-tz +0000 |
| 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 revision_hash 29 29 2 |
| 51 * blabla line 4 |
| 52 """ |
| 53 ) |
| 54 |
| 55 expected_regions = [blame.Region(18, 3, 'revision_hash', 'test@google.com', |
| 56 'test@google.com', |
| 57 datetime(2013, 03, 11, 17, 13, 36)), |
| 58 blame.Region(29, 2, 'revision_hash', 'test@google.com', |
| 59 'test@google.com', |
| 60 datetime(2013, 03, 11, 17, 13, 36))] |
| 61 expected_blame = blame.Blame('src/core/SkFont.h', 'rev') |
| 62 # TODO(crbug.com/663445): Add methods in blame for this. |
| 63 for expected_region in expected_regions: |
| 64 expected_blame.AddRegion(expected_region) |
| 65 |
| 66 blame_result = self.blame_parser(output, 'src/core/SkFont.h', 'rev') |
| 67 self.assertTrue(blame_result.revision, expected_blame.revision) |
| 68 self.assertTrue(blame_result.path, expected_blame.path) |
| 69 for region, expected_region in zip(blame_result, expected_blame): |
| 70 self.assertTrue(region.ToDict(), expected_region.ToDict()) |
| 71 |
| 72 def testGitBlameParserEmptyOutput(self): |
| 73 blame_result = self.blame_parser('', 'src/core/SkFont.h', 'rev') |
| 74 self.assertIsNone(blame_result) |
| 75 |
| 76 def testGitBlameParserDummyOutput(self): |
| 77 blame_result = self.blame_parser('Dummy', |
| 78 'src/core/SkFont.h', |
| 79 'rev') |
| 80 self.assertIsNone(blame_result) |
| 81 |
| 82 def testGetFileChangeInfo(self): |
| 83 self.assertIsNone(local_git_parsers.GetFileChangeInfo('change type', |
| 84 None, None)) |
| 85 |
| 86 def testGitChangeLogParser(self): |
| 87 output = textwrap.dedent( |
| 88 """ |
| 89 commit revision |
| 90 tree tree_revision |
| 91 parents parent_revision |
| 92 |
| 93 author Test |
| 94 author-mail test@google.com |
| 95 author-time 2016-07-13 20:37:06 |
| 96 |
| 97 committer Test |
| 98 committer-mail test@google.com |
| 99 committer-time 2016-07-13 20:37:06 |
| 100 |
| 101 --Message start-- |
| 102 Revert commit messages... |
| 103 > Committed: https://c.com/+/c9cc182781484f9010f062859cda048afefefefe |
| 104 Review-Url: https://codereview.chromium.org/2391763002 |
| 105 Cr-Commit-Position: refs/heads/master@{#425880} |
| 106 --Message end-- |
| 107 |
| 108 :100644 100644 25f95f c766f1 M src/a/b.py |
| 109 """ |
| 110 ) |
| 111 |
| 112 message = ('Revert commit messages...\n' |
| 113 '> Committed: https://c.com/+/' |
| 114 'c9cc182781484f9010f062859cda048afefefefe\n' |
| 115 'Review-Url: https://codereview.chromium.org/2391763002\n' |
| 116 'Cr-Commit-Position: refs/heads/master@{#425880}') |
| 117 |
| 118 expected_changelog = change_log.ChangeLog( |
| 119 'Test', 'test@google.com', datetime(2016, 7, 13, 20, 37, 6), |
| 120 'Test', 'test@google.com', datetime(2016, 7, 13, 20, 37, 6), |
| 121 'revision', 425880, message, [change_log.FileChangeInfo( |
| 122 'modify', 'src/a/b.py', 'src/a/b.py')], |
| 123 'https://repo/+/revision', |
| 124 'https://codereview.chromium.org/2391763002', |
| 125 'c9cc182781484f9010f062859cda048afefefefe') |
| 126 |
| 127 changelog = local_git_parsers.GitChangeLogParser()(output, 'https://repo') |
| 128 self.assertTrue(expected_changelog.ToDict(), changelog.ToDict()) |
| 129 |
| 130 def testGitChangeLogParserParseEmptyOutput(self): |
| 131 self.assertIsNone(local_git_parsers.GitChangeLogParser()(None, 'repo')) |
| 132 |
| 133 def testGitChangeLogsParser(self): |
| 134 output = textwrap.dedent( |
| 135 """ |
| 136 **Changelog start** |
| 137 commit rev1 |
| 138 tree 27b0421273ed4aea25e497c6d26d9c7db6481852 |
| 139 parents rev22c9e |
| 140 |
| 141 author author1 |
| 142 author-mail author1@chromium.org |
| 143 author-time 2016-06-02 10:55:38 |
| 144 |
| 145 committer Commit bot |
| 146 committer-mail commit-bot@chromium.org |
| 147 committer-time 2016-06-02 10:57:13 |
| 148 |
| 149 --Message start-- |
| 150 Message 1 |
| 151 --Message end-- |
| 152 |
| 153 :100644 100644 28e117 f12d3 D a/b.py |
| 154 |
| 155 |
| 156 **Changelog start** |
| 157 commit rev2 |
| 158 tree d22d3786e135b83183cfeba5f3d8913959f56299 |
| 159 parents ac7ee4ce7b8d39b22a710c58d110e0039c11cf9a |
| 160 |
| 161 author author2 |
| 162 author-mail author2@chromium.org |
| 163 author-time 2016-06-02 10:53:03 |
| 164 |
| 165 committer Commit bot |
| 166 committer-mail commit-bot@chromium.org |
| 167 committer-time 2016-06-02 10:54:14 |
| 168 |
| 169 --Message start-- |
| 170 Message 2 |
| 171 --Message end-- |
| 172 |
| 173 :100644 100644 7280f df186 A b/c.py |
| 174 |
| 175 **Changelog start** |
| 176 commit rev3 |
| 177 tree d22d3786e135b83183cfeba5f3d8913959f56299 |
| 178 parents ac7ee4ce7b8d39b22a710c58d110e0039c11cf9a |
| 179 |
| 180 author author3 |
| 181 author-mail author3@chromium.org |
| 182 author-time 2016-06-02 10:53:03 |
| 183 |
| 184 committer Commit bot |
| 185 committer-mail commit-bot@chromium.org |
| 186 committer-time 2016-06-02 10:54:14 |
| 187 |
| 188 --Message start-- |
| 189 Message 3 |
| 190 --Message end-- |
| 191 |
| 192 :100644 100644 3f2e 20a5 R078 b/c.py b/cc.py |
| 193 """ |
| 194 ) |
| 195 |
| 196 expected_changelogs = [ |
| 197 change_log.ChangeLog('author1', |
| 198 'author1@chromium.org', |
| 199 datetime(2016, 6, 2, 10, 55, 38), |
| 200 'Commit bot', |
| 201 'commit-bot@chromium.org', |
| 202 datetime(2016, 6, 2, 10, 57, 13), |
| 203 'rev1', None, |
| 204 'Message 1', [change_log.FileChangeInfo( |
| 205 'delete', 'a/b.py', None)], |
| 206 'http://repo/+/rev1', None, None), |
| 207 change_log.ChangeLog('author2', |
| 208 'author2@chromium.org', |
| 209 datetime(2016, 6, 2, 10, 53, 3), |
| 210 'Commit bot', |
| 211 'commit-bot@chromium.org', |
| 212 datetime(2016, 6, 2, 10, 54, 14), |
| 213 'rev2', None, |
| 214 'Message 2', [change_log.FileChangeInfo( |
| 215 'add', None, 'b/c.py')], |
| 216 'http://repo/+/rev2', None, None), |
| 217 change_log.ChangeLog('author3', |
| 218 'author3@chromium.org', |
| 219 datetime(2016, 6, 2, 10, 53, 3), |
| 220 'Commit bot', |
| 221 'commit-bot@chromium.org', |
| 222 datetime(2016, 6, 2, 10, 54, 14), |
| 223 'rev3', None, |
| 224 'Message 3', [change_log.FileChangeInfo( |
| 225 'rename', 'b/c.py', 'b/cc.py')], |
| 226 'http://repo/+/rev3', None, None), |
| 227 ] |
| 228 |
| 229 changelogs = local_git_parsers.GitChangeLogsParser()(output, 'http://repo') |
| 230 for changelog, expected_changelog in zip(changelogs, expected_changelogs): |
| 231 self.assertEqual(changelog.ToDict(), expected_changelog.ToDict()) |
| 232 |
| 233 |
| 234 def testGitChangeLogsParserParseEmptyOutput(self): |
| 235 self.assertIsNone(local_git_parsers.GitChangeLogsParser()(None, 'repo')) |
| 236 |
| 237 def testGitChangeLogsParserWithEmptyChangelog(self): |
| 238 output = '**Changelog start**\nblablabla' |
| 239 self.assertEqual(local_git_parsers.GitChangeLogsParser()(output, |
| 240 'http://repo'), []) |
| 241 |
| 242 def testGitDiffParser(self): |
| 243 self.assertEqual('output', local_git_parsers.GitDiffParser()('output')) |
| 244 |
| 245 |
| 246 if __name__ == '__main__': |
| 247 unittest.main() |
| OLD | NEW |