| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 from datetime import datetime | 5 from datetime import datetime |
| 6 from datetime import timedelta | 6 import pytz |
| 7 import os |
| 8 import subprocess |
| 7 import textwrap | 9 import textwrap |
| 8 | 10 |
| 9 from testing_utils import testing | 11 from testing_utils import testing |
| 10 | 12 |
| 11 from common import local_git_parsers | |
| 12 from common import blame | 13 from common import blame |
| 13 from common import change_log | 14 from common import change_log |
| 15 from common import repo_util |
| 16 from common.local_git_repository import LocalGitRepository |
| 17 |
| 18 CHECKOUT_ROOT_DIR = os.path.join(os.path.expanduser('~'), '.local_checkouts') |
| 14 | 19 |
| 15 | 20 |
| 16 class LocalGitParsersTest(testing.AppengineTestCase): | 21 class LocalGitRepositoryTest(testing.AppengineTestCase): |
| 17 | 22 |
| 18 def testGitBlameParser(self): | 23 def setUp(self): |
| 19 output = textwrap.dedent( | 24 super(LocalGitRepositoryTest, self).setUp() |
| 20 """ | 25 def _MockProcessCall(*_, **kwargs): # pylint: disable=W |
| 21 revision_hash 18 18 3 | 26 return |
| 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 | 27 |
| 39 expected_regions = [blame.Region(18, 3, 'revision_hash', 'test@google.com', | 28 self.mock(subprocess, 'call', _MockProcessCall) |
| 40 'test@google.com', | 29 self.mock(subprocess, 'check_call', _MockProcessCall) |
| 41 datetime(2013, 03, 11, 17, 13, 36))] | 30 self.local_repo = LocalGitRepository( |
| 42 expected_blame = blame.Blame('src/core/SkFont.h', 'rev') | 31 'https://repo/path') |
| 43 for expected_region in expected_regions: | |
| 44 expected_blame.AddRegion(expected_region) | |
| 45 | 32 |
| 46 blame_result = local_git_parsers.GitBlameParser()(output, | 33 def testCloneOrUpdateRepoIfNeeded(self): |
| 47 'src/core/SkFont.h', | 34 self.local_repo._CloneOrUpdateRepoIfNeeded() |
| 48 'rev') | 35 self.assertTrue(self.local_repo.repo_url in |
| 49 self.assertTrue(blame_result.revision, expected_blame.revision) | 36 LocalGitRepository.updated_repos) |
| 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 | 37 |
| 54 def testGetFileChangeInfo(self): | 38 LocalGitRepository.updated_repos.remove(self.local_repo.repo_url) |
| 55 self.assertIsNone(local_git_parsers.GetFileChangeInfo('change type', | 39 self.mock(os.path, 'exists', lambda path: True) |
| 56 None, None)) | 40 self.local_repo._CloneOrUpdateRepoIfNeeded() |
| 41 self.assertTrue(self.local_repo.repo_url in |
| 42 LocalGitRepository.updated_repos) |
| 57 | 43 |
| 58 def testGitChangeLogParser(self): | 44 self.local_repo._CloneOrUpdateRepoIfNeeded() |
| 45 self.assertTrue(self.local_repo.repo_url in |
| 46 LocalGitRepository.updated_repos) |
| 47 |
| 48 def testRepoUrlSetter(self): |
| 49 def _MockCloneOrUpdateRepoIfNeeded(*_): |
| 50 if not hasattr(_MockCloneOrUpdateRepoIfNeeded, 'clone_or_update_count'): |
| 51 _MockCloneOrUpdateRepoIfNeeded.clone_or_update_count = 0 |
| 52 _MockCloneOrUpdateRepoIfNeeded.clone_or_update_count += 1 |
| 53 |
| 54 repo = LocalGitRepository() |
| 55 self.mock(repo, '_CloneOrUpdateRepoIfNeeded', |
| 56 _MockCloneOrUpdateRepoIfNeeded) |
| 57 |
| 58 repo.repo_url = 'https://repo/path' |
| 59 self.assertEqual(_MockCloneOrUpdateRepoIfNeeded.clone_or_update_count, 1) |
| 60 |
| 61 repo.repo_url = 'https://repo/path' |
| 62 self.assertEqual(_MockCloneOrUpdateRepoIfNeeded.clone_or_update_count, 1) |
| 63 |
| 64 repo.repo_url = 'https://repo/path2' |
| 65 self.assertEqual(_MockCloneOrUpdateRepoIfNeeded.clone_or_update_count, 2) |
| 66 |
| 67 |
| 68 def testGetChangeLog(self): |
| 59 output = textwrap.dedent( | 69 output = textwrap.dedent( |
| 60 """ | 70 """ |
| 61 commit revision | 71 commit revision |
| 62 tree tree_revision | 72 tree tree_revision |
| 63 parents parent_revision | 73 parents parent_revision |
| 64 | 74 |
| 65 author Test | 75 author Test |
| 66 author-mail test@google.com | 76 author-mail test@google.com |
| 67 author-time 2016-07-13 20:37:06 | 77 author-time 2016-07-13 20:37:06 |
| 68 | 78 |
| 69 committer Test | 79 committer Test |
| 70 committer-mail test@google.com | 80 committer-mail test@google.com |
| 71 committer-time 2016-07-13 20:37:06 | 81 committer-time 2016-07-13 20:37:06 |
| 72 | 82 |
| 73 --Message start-- | 83 --Message start-- |
| 74 Revert commit messages... | 84 blabla |
| 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-- | 85 --Message end-- |
| 79 | 86 |
| 80 :100644 100644 25f95f c766f1 M src/a/b.py | 87 :100644 100644 25f95f c766f1 M src/a/b.py |
| 81 """ | 88 """ |
| 82 ) | 89 ) |
| 83 | 90 |
| 84 message = ('Revert commit messages...\n' | 91 def _MockGetLocalGitCommandOutput(*_): |
| 85 '> Committed: https://c.com/+/' | 92 return output |
| 86 'c9cc182781484f9010f062859cda048afefefefe\n' | |
| 87 'Review-Url: https://codereview.chromium.org/2391763002\n' | |
| 88 'Cr-Commit-Position: refs/heads/master@{#425880}') | |
| 89 | 93 |
| 90 expected_changelog = change_log.ChangeLog( | 94 expected_changelog = change_log.ChangeLog( |
| 91 'Test', 'test@google.com', datetime(2016, 7, 13, 20, 37, 6), | 95 'Test', 'test@google.com', datetime(2016, 7, 13, 20, 37, 6), |
| 92 'Test', 'test@google.com', datetime(2016, 7, 13, 20, 37, 6), | 96 'Test', 'test@google.com', datetime(2016, 7, 13, 20, 37, 6), |
| 93 'revision', 425880, message, [change_log.FileChangeInfo( | 97 'revision', None, 'blabla', [change_log.FileChangeInfo( |
| 94 'modify', 'src/a/b.py', 'src/a/b.py')], | 98 'modify', 'src/a/b.py', 'src/a/b.py')], |
| 95 'https://repo/+/revision', | 99 'https://repo/path/+/revision', None, None) |
| 96 'https://codereview.chromium.org/2391763002', | 100 self.mock(repo_util, 'GetCommandOutput', |
| 97 'c9cc182781484f9010f062859cda048afefefefe') | 101 _MockGetLocalGitCommandOutput) |
| 98 | 102 |
| 99 changelog = local_git_parsers.GitChangeLogParser()(output, 'https://repo') | 103 print self.local_repo.GetChangeLog('revision').ToDict() |
| 100 self.assertTrue(expected_changelog.ToDict(), changelog.ToDict()) | 104 print expected_changelog.ToDict() |
| 105 self.assertEqual(self.local_repo.GetChangeLog('revision').ToDict(), |
| 106 expected_changelog.ToDict()) |
| 101 | 107 |
| 102 def testGitChangeLogsParser(self): | 108 def testGetChangeLogs(self): |
| 103 output = textwrap.dedent( | 109 output = textwrap.dedent( |
| 104 """ | 110 """ |
| 105 **Changelog start** | 111 **Changelog start** |
| 106 commit rev1 | 112 commit rev1 |
| 107 tree 27b0421273ed4aea25e497c6d26d9c7db6481852 | 113 tree 27b0421273ed4aea25e497c6d26d9c7db6481852 |
| 108 parents rev22c9e | 114 parents rev22c9e |
| 109 | 115 |
| 110 author author1 | 116 author author1 |
| 111 author-mail author1@chromium.org | 117 author-mail author1@chromium.org |
| 112 author-time 2016-06-02 10:55:38 | 118 author-time 2016-06-02 10:55:38 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 133 | 139 |
| 134 committer Commit bot | 140 committer Commit bot |
| 135 committer-mail commit-bot@chromium.org | 141 committer-mail commit-bot@chromium.org |
| 136 committer-time 2016-06-02 10:54:14 | 142 committer-time 2016-06-02 10:54:14 |
| 137 | 143 |
| 138 --Message start-- | 144 --Message start-- |
| 139 Message 2 | 145 Message 2 |
| 140 --Message end-- | 146 --Message end-- |
| 141 | 147 |
| 142 :100644 100644 7280f df186 A b/c.py | 148 :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 """ | 149 """ |
| 163 ) | 150 ) |
| 164 | 151 |
| 165 expected_changelogs = [ | 152 expected_changelogs = [ |
| 166 change_log.ChangeLog('author1', | 153 change_log.ChangeLog('author1', |
| 167 'author1@chromium.org', | 154 'author1@chromium.org', |
| 168 datetime(2016, 6, 2, 10, 55, 38), | 155 datetime(2016, 6, 2, 10, 55, 38), |
| 169 'Commit bot', | 156 'Commit bot', |
| 170 'commit-bot@chromium.org', | 157 'commit-bot@chromium.org', |
| 171 datetime(2016, 6, 2, 10, 57, 13), | 158 datetime(2016, 6, 2, 10, 57, 13), |
| 172 'rev1', None, | 159 'rev1', None, |
| 173 'Message 1', [change_log.FileChangeInfo( | 160 'Message 1', [change_log.FileChangeInfo( |
| 174 'delete', 'a/b.py', None)], | 161 'delete', 'a/b.py', None)], |
| 175 'http://repo/+/rev1', None, None), | 162 'https://repo/path/+/rev1', None, None), |
| 176 change_log.ChangeLog('author2', | 163 change_log.ChangeLog('author2', |
| 177 'author2@chromium.org', | 164 'author2@chromium.org', |
| 178 datetime(2016, 6, 2, 10, 53, 3), | 165 datetime(2016, 6, 2, 10, 53, 3), |
| 179 'Commit bot', | 166 'Commit bot', |
| 180 'commit-bot@chromium.org', | 167 'commit-bot@chromium.org', |
| 181 datetime(2016, 6, 2, 10, 54, 14), | 168 datetime(2016, 6, 2, 10, 54, 14), |
| 182 'rev2', None, | 169 'rev2', None, |
| 183 'Message 2', [change_log.FileChangeInfo( | 170 'Message 2', [change_log.FileChangeInfo( |
| 184 'add', None, 'b/c.py')], | 171 'add', None, 'b/c.py')], |
| 185 'http://repo/+/rev2', None, None), | 172 'https://repo/path/+/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 ] | 173 ] |
| 197 | 174 |
| 198 changelogs = local_git_parsers.GitChangeLogsParser()(output, 'http://repo') | 175 def _MockGetCommandOutput(*_): |
| 176 return output |
| 177 |
| 178 self.mock(repo_util, 'GetCommandOutput', |
| 179 _MockGetCommandOutput) |
| 180 |
| 181 changelogs = self.local_repo.GetChangeLogs('rev0', 'rev2') |
| 199 for changelog, expected_changelog in zip(changelogs, expected_changelogs): | 182 for changelog, expected_changelog in zip(changelogs, expected_changelogs): |
| 200 self.assertEqual(changelog.ToDict(), expected_changelog.ToDict()) | 183 self.assertEqual(changelog.ToDict(), expected_changelog.ToDict()) |
| 201 | 184 |
| 202 def testGitChangeLogsParserWithEmptyChangelog(self): | 185 def testGetChangeDiff(self): |
| 203 output = '**Changelog start**\nblablabla' | 186 def _MockGetCommandOutput(*_): |
| 204 self.assertEqual(local_git_parsers.GitChangeLogsParser()(output, | 187 return 'diff' |
| 205 'http://repo'), []) | |
| 206 | 188 |
| 207 def testGitDiffParser(self): | 189 self.mock(repo_util, 'GetCommandOutput', |
| 208 output = 'output' | 190 _MockGetCommandOutput) |
| 209 self.assertEqual(output, local_git_parsers.GitDiffParser()(output)) | 191 self.assertEqual(self.local_repo.GetChangeDiff('rev'), 'diff') |
| 192 self.assertEqual(self.local_repo.GetChangeDiff('rev', 'file_path'), 'diff') |
| 210 | 193 |
| 211 def testGitSourceParser(self): | 194 def testGetBlame(self): |
| 212 output = 'output' | 195 output = textwrap.dedent( |
| 213 self.assertEqual(output, local_git_parsers.GitSourceParser()(output)) | 196 """ |
| 197 revision_hash 18 18 3 |
| 198 author test@google.com |
| 199 author-mail <test@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> |
| 200 author-time 2013-03-11 17:13:36 |
| 201 committer test@google.com |
| 202 committer-mail <test@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> |
| 203 committer-time 2013-03-11 17:13:36 |
| 204 summary add (mac) test for ttcindex in SkFontStream |
| 205 previous fe7533eebe777cc66c7f8fa7a03f00572755c5b4 src/core/SkFont.h |
| 206 filename src/core/SkFont.h |
| 207 * blabla line 1 |
| 208 revision_hash 19 19 |
| 209 * blabla line 2 |
| 210 revision_hash 20 20 |
| 211 * blabla line 3 |
| 212 """ |
| 213 ) |
| 214 |
| 215 def _MockGetCommandOutput(*_): |
| 216 return output |
| 217 |
| 218 self.mock(repo_util, 'GetCommandOutput', |
| 219 _MockGetCommandOutput) |
| 220 |
| 221 expected_regions = [blame.Region(18, 3, 'revision_hash', 'test@google.com', |
| 222 'test@google.com', |
| 223 datetime(2013, 03, 11, 17, 13, 36))] |
| 224 expected_blame = blame.Blame('src/core/SkFont.h', 'rev') |
| 225 for expected_region in expected_regions: |
| 226 expected_blame.AddRegion(expected_region) |
| 227 |
| 228 blame_result = self.local_repo.GetBlame('src/core/SkFont.h', 'rev') |
| 229 self.assertTrue(blame_result.revision, expected_blame.revision) |
| 230 self.assertTrue(blame_result.path, expected_blame.path) |
| 231 for region, expected_region in zip(blame_result, expected_blame): |
| 232 self.assertTrue(region.ToDict(), expected_region.ToDict()) |
| 233 |
| 234 def testGetSource(self): |
| 235 def _MockGetLocalGitCommandOutput(*_): |
| 236 return 'source' |
| 237 |
| 238 self.mock(repo_util, 'GetCommandOutput', |
| 239 _MockGetLocalGitCommandOutput) |
| 240 self.assertIsNone(self.local_repo.GetSource('file_path', 'rev')) |
| 241 self.mock(os.path, 'isfile', lambda path: True) |
| 242 self.assertEqual(self.local_repo.GetSource('file_path', 'rev'), 'source') |
| OLD | NEW |