| Index: appengine/findit/common/test/local_git_repository_test.py
|
| diff --git a/appengine/findit/common/test/local_git_parsers_test.py b/appengine/findit/common/test/local_git_repository_test.py
|
| similarity index 51%
|
| copy from appengine/findit/common/test/local_git_parsers_test.py
|
| copy to appengine/findit/common/test/local_git_repository_test.py
|
| index d72899534e07f4de5d921d2c22318968130b9339..aa776c58769b582f3a1a7f053d745b16a02ce480 100644
|
| --- a/appengine/findit/common/test/local_git_parsers_test.py
|
| +++ b/appengine/findit/common/test/local_git_repository_test.py
|
| @@ -3,60 +3,84 @@
|
| # found in the LICENSE file.
|
|
|
| from datetime import datetime
|
| -from datetime import timedelta
|
| +import pytz
|
| +import os
|
| +import subprocess
|
| import textwrap
|
|
|
| from testing_utils import testing
|
|
|
| -from common import local_git_parsers
|
| from common import blame
|
| from common import change_log
|
| +from common import repo_util
|
| +from common.local_git_repository import LocalGitRepository
|
|
|
| +CHECKOUT_ROOT_DIR = os.path.join(os.path.expanduser('~'), '.local_checkouts')
|
|
|
| -class LocalGitParsersTest(testing.AppengineTestCase):
|
|
|
| - def testGitBlameParser(self):
|
| - output = textwrap.dedent(
|
| - """
|
| - revision_hash 18 18 3
|
| - author test@google.com
|
| - author-mail <test@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
|
| - author-time 1363032816
|
| - author-tz +0300
|
| - committer test@google.com
|
| - committer-mail <test@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
|
| - committer-time 1363032816
|
| - committer-tz +0300
|
| - summary add (mac) test for ttcindex in SkFontStream
|
| - previous fe7533eebe777cc66c7f8fa7a03f00572755c5b4 src/core/SkFont.h
|
| - filename src/core/SkFont.h
|
| - * blabla line 1
|
| - revision_hash 19 19
|
| - * blabla line 2
|
| - revision_hash 20 20
|
| - * blabla line 3
|
| - """
|
| - )
|
| +class LocalGitRepositoryTest(testing.AppengineTestCase):
|
|
|
| - expected_regions = [blame.Region(18, 3, 'revision_hash', 'test@google.com',
|
| - 'test@google.com',
|
| - datetime(2013, 03, 11, 17, 13, 36))]
|
| - expected_blames = [blame.Blame('revision_hash',
|
| - 'src/core/SkFont.h',
|
| - regions=expected_regions)]
|
| + def setUp(self):
|
| + super(LocalGitRepositoryTest, self).setUp()
|
| + def _MockProcessCall(*_, **kwargs): # pylint: disable=W
|
| + return
|
|
|
| - blames = local_git_parsers.GitBlameParser()(output)
|
| - for blame_result, expected_blame in zip(blames, expected_blames):
|
| - self.assertTrue(blame_result.revision, expected_blame.revision)
|
| - self.assertTrue(blame_result.path, expected_blame.path)
|
| - for region, expected_region in zip(blame_result, expected_blame):
|
| - self.assertTrue(region.ToDict(), expected_region.ToDict())
|
| + self.mock(subprocess, 'call', _MockProcessCall)
|
| + self.mock(subprocess, 'check_call', _MockProcessCall)
|
| + self.local_repo = LocalGitRepository(
|
| + 'https://chromium.googlesource.com/repo/path')
|
| +
|
| + def testCloneOrUpdateRepoIfNeeded(self):
|
| + self.local_repo._CloneOrUpdateRepoIfNeeded()
|
| + self.assertTrue(self.local_repo.repo_url in
|
| + LocalGitRepository.updated_repos)
|
| +
|
| + LocalGitRepository.updated_repos.remove(self.local_repo.repo_url)
|
| + self.mock(os.path, 'exists', lambda path: True)
|
| + self.local_repo._CloneOrUpdateRepoIfNeeded()
|
| + self.assertTrue(self.local_repo.repo_url in
|
| + LocalGitRepository.updated_repos)
|
| +
|
| + self.local_repo._CloneOrUpdateRepoIfNeeded()
|
| + self.assertTrue(self.local_repo.repo_url in
|
| + LocalGitRepository.updated_repos)
|
| +
|
| + def testRepoUrlSetter(self):
|
| + def _MockCloneOrUpdateRepoIfNeeded(*_):
|
| + if not hasattr(_MockCloneOrUpdateRepoIfNeeded, 'clone_or_update_count'):
|
| + _MockCloneOrUpdateRepoIfNeeded.clone_or_update_count = 0
|
| + _MockCloneOrUpdateRepoIfNeeded.clone_or_update_count += 1
|
| +
|
| + repo = LocalGitRepository()
|
| + self.mock(repo, '_CloneOrUpdateRepoIfNeeded',
|
| + _MockCloneOrUpdateRepoIfNeeded)
|
| +
|
| + repo.repo_url = 'https://chromium.googlesource.com/repo/path'
|
| + self.assertEqual(_MockCloneOrUpdateRepoIfNeeded.clone_or_update_count, 1)
|
| +
|
| + repo.repo_url = 'https://chromium.googlesource.com/repo/path'
|
| + self.assertEqual(_MockCloneOrUpdateRepoIfNeeded.clone_or_update_count, 1)
|
| +
|
| + repo.repo_url = 'https://chromium.googlesource.com/repo/path2'
|
| + self.assertEqual(_MockCloneOrUpdateRepoIfNeeded.clone_or_update_count, 2)
|
|
|
| - def testGetFileChangeInfo(self):
|
| - self.assertIsNone(local_git_parsers.GetFileChangeInfo('change type',
|
| - None, None))
|
| + def testGetLocalGitCommandOutput(self):
|
| + class _MockProcess(object):
|
| + def __init__(self, command, *_):
|
| + self.command = command
|
|
|
| - def testGitChangeLogParser(self):
|
| + def communicate(self, *_):
|
| + return self.command, 'dummy'
|
| +
|
| + def _MockPopen(command, **_):
|
| + return _MockProcess(command)
|
| +
|
| + self.mock(subprocess, 'Popen', _MockPopen)
|
| + output = self.local_repo._GetLocalGitCommandOutput('command')
|
| + self.assertEqual(output,
|
| + 'cd %s/repo/path; command' % CHECKOUT_ROOT_DIR)
|
| +
|
| + def testGetChangeLog(self):
|
| output = textwrap.dedent(
|
| """
|
| commit revision
|
| @@ -72,38 +96,34 @@ class LocalGitParsersTest(testing.AppengineTestCase):
|
| committer-time 1468442226
|
|
|
| --Message start--
|
| - Revert commit messages...
|
| - > Committed: https://c.com/+/c9cc182781484f9010f062859cda048afefefefe
|
| - Review-Url: https://codereview.chromium.org/2391763002
|
| - Cr-Commit-Position: refs/heads/master@{#425880}
|
| + blabla
|
| --Message end--
|
|
|
| :100644 100644 25f95f c766f1 M src/a/b.py
|
| """
|
| )
|
|
|
| - message = ('Revert commit messages...\n'
|
| - '> Committed: https://c.com/+/'
|
| - 'c9cc182781484f9010f062859cda048afefefefe\n'
|
| - 'Review-Url: https://codereview.chromium.org/2391763002\n'
|
| - 'Cr-Commit-Position: refs/heads/master@{#425880}')
|
| + def _MockGetLocalGitCommandOutput(*_):
|
| + return output
|
|
|
| expected_changelog = change_log.ChangeLog(
|
| 'Test', 'test@google.com', datetime(2016, 7, 13, 20, 37, 6),
|
| 'Test', 'test@google.com', datetime(2016, 7, 13, 20, 37, 6),
|
| - 'revision', 425880, message, [change_log.FileChangeInfo(
|
| + 'revision', message='blabla', touched_files=[change_log.FileChangeInfo(
|
| 'modify', 'src/a/b.py', 'src/a/b.py')],
|
| - code_review_url='https://codereview.chromium.org/2391763002',
|
| - reverted_revision='c9cc182781484f9010f062859cda048afefefefe')
|
| + commit_url='https://chromium.googlesource.com/repo/path/+/revision')
|
| +
|
| + self.mock(self.local_repo, '_GetLocalGitCommandOutput',
|
| + _MockGetLocalGitCommandOutput)
|
|
|
| - changelog = local_git_parsers.GitChangeLogParser()(output)
|
| - self.assertTrue(expected_changelog.ToDict(), changelog.ToDict())
|
| + self.assertEqual(self.local_repo.GetChangeLog('revision').ToDict(),
|
| + expected_changelog.ToDict())
|
|
|
| - def testGitChangeLogsParser(self):
|
| + def testGetChangeLogs(self):
|
| output = textwrap.dedent(
|
| """
|
| **Changelog start**
|
| - commit 9af040a364c15bdc2adeea794e173a2c529a
|
| + commit rev1
|
| tree 27b0421273ed4aea25e497c6d26d9c7db6481852
|
| parents c39b0cc8a516de1fa57d032dc0135a4eadfe2c9e
|
|
|
| @@ -123,7 +143,7 @@ class LocalGitParsersTest(testing.AppengineTestCase):
|
|
|
|
|
| **Changelog start**
|
| - commit c39b0cc8a516de1fa57d032dc0135a4eadfe
|
| + commit rev2
|
| tree d22d3786e135b83183cfeba5f3d8913959f56299
|
| parents ac7ee4ce7b8d39b22a710c58d110e0039c11cf9a
|
|
|
| @@ -140,25 +160,6 @@ class LocalGitParsersTest(testing.AppengineTestCase):
|
| --Message end--
|
|
|
| :100644 100644 7280f df186 A b/c.py
|
| -
|
| - **Changelog start**
|
| - commit c39b0cc8a516de1fa57d032dc0135a4eadfed
|
| - tree d22d3786e135b83183cfeba5f3d8913959f56299
|
| - parents ac7ee4ce7b8d39b22a710c58d110e0039c11cf9a
|
| -
|
| - author author3
|
| - author-mail author3@chromium.org
|
| - author-time 1464864783
|
| -
|
| - committer Commit bot
|
| - committer-mail commit-bot@chromium.org
|
| - committer-time 1464864854
|
| -
|
| - --Message start--
|
| - Message 3
|
| - --Message end--
|
| -
|
| - :100644 100644 3f2e 20a5 R078 b/c.py b/cc.py
|
| """
|
| )
|
|
|
| @@ -170,7 +171,7 @@ class LocalGitParsersTest(testing.AppengineTestCase):
|
| committer_email='commit-bot@chromium.org',
|
| committer_time=datetime(2016, 6, 2, 10, 57, 13),
|
| message='Message 1',
|
| - revision='9af040a364c15bdc2adeea794e173a2c529a',
|
| + revision='rev1',
|
| touched_files=[change_log.FileChangeInfo(
|
| 'delete', 'a/b.py', None)]),
|
| change_log.ChangeLog(author_name='author2',
|
| @@ -180,34 +181,81 @@ class LocalGitParsersTest(testing.AppengineTestCase):
|
| committer_email='commit-bot@chromium.org',
|
| committer_time=datetime(2016, 6, 2, 10, 54, 14),
|
| message='Message 2',
|
| - revision='c39b0cc8a516de1fa57d032dc0135a4eadfe',
|
| + revision='rev2',
|
| touched_files=[change_log.FileChangeInfo(
|
| 'add', None, 'b/c.py')]),
|
| - change_log.ChangeLog(author_name='author3',
|
| - author_email='author3@chromium.org',
|
| - author_time=datetime(2016, 6, 2, 10, 53, 3),
|
| - committer_name='Commit bot',
|
| - committer_email='commit-bot@chromium.org',
|
| - committer_time=datetime(2016, 6, 2, 10, 54, 14),
|
| - message='Message 3',
|
| - revision='c39b0cc8a516de1fa57d032dc0135a4eadfed',
|
| - touched_files=[change_log.FileChangeInfo(
|
| - 'rename', 'b/c.py', 'b/cc.py')]),
|
| -
|
| ]
|
|
|
| - changelogs = local_git_parsers.GitChangeLogsParser()(output)
|
| +
|
| + def _MockGetLocalGitCommandOutput(*_):
|
| + return output
|
| +
|
| + self.mock(self.local_repo, '_GetLocalGitCommandOutput',
|
| + _MockGetLocalGitCommandOutput)
|
| +
|
| + changelogs = self.local_repo.GetChangeLogs('rev0', 'rev2')
|
| for changelog, expected_changelog in zip(changelogs, expected_changelogs):
|
| self.assertEqual(changelog.ToDict(), expected_changelog.ToDict())
|
|
|
| - def testGitChangeLogsParserWithEmptyChangelog(self):
|
| - output = '**Changelog start**\nblablabla'
|
| - self.assertEqual(local_git_parsers.GitChangeLogsParser()(output), [])
|
| + def testGetChangeDiff(self):
|
| + def _MockGetLocalGitCommandOutput(*_):
|
| + return 'diff'
|
| +
|
| + self.mock(self.local_repo, '_GetLocalGitCommandOutput',
|
| + _MockGetLocalGitCommandOutput)
|
| + self.assertEqual(self.local_repo.GetChangeDiff('rev'), 'diff')
|
| + self.assertEqual(self.local_repo.GetChangeDiff('rev', 'file_path'), 'diff')
|
| +
|
| + def testGetBlame(self):
|
| + output = textwrap.dedent(
|
| + """
|
| + revision_hash 18 18 3
|
| + author test@google.com
|
| + author-mail <test@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
|
| + author-time 1363032816
|
| + author-tz +0300
|
| + committer test@google.com
|
| + committer-mail <test@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
|
| + committer-time 1363032816
|
| + committer-tz +0300
|
| + summary add (mac) test for ttcindex in SkFontStream
|
| + previous fe7533eebe777cc66c7f8fa7a03f00572755c5b4 src/core/SkFont.h
|
| + filename src/core/SkFont.h
|
| + * blabla line 1
|
| + revision_hash 19 19
|
| + * blabla line 2
|
| + revision_hash 20 20
|
| + * blabla line 3
|
| + """
|
| + )
|
| +
|
| + expected_regions = [blame.Region(18, 3, 'revision_hash', 'test@google.com',
|
| + 'test@google.com',
|
| + datetime(2013, 03, 11, 17, 13, 36,
|
| + tzinfo=pytz.utc))]
|
| + expected_blames = [blame.Blame('revision_hash',
|
| + 'src/core/SkFont.h',
|
| + regions=expected_regions)]
|
| +
|
| + def _MockGetLocalGitCommandOutput(*_):
|
| + return output
|
| +
|
| + self.mock(self.local_repo, '_GetLocalGitCommandOutput',
|
| + _MockGetLocalGitCommandOutput)
|
| +
|
| + blames = self.local_repo.GetBlame('path', 'revision')
|
| + for blame_result, expected_blame in zip(blames, expected_blames):
|
| + self.assertTrue(blame_result.revision, expected_blame.revision)
|
| + self.assertTrue(blame_result.path, expected_blame.path)
|
| + for region, expected_region in zip(blame_result, expected_blame):
|
| + self.assertTrue(region.ToDict(), expected_region.ToDict())
|
|
|
| - def testGitDiffParser(self):
|
| - output = 'output'
|
| - self.assertEqual(output, local_git_parsers.GitDiffParser()(output))
|
| + def testGetSource(self):
|
| + def _MockGetLocalGitCommandOutput(*_):
|
| + return 'source'
|
|
|
| - def testGitSourceParser(self):
|
| - output = 'output'
|
| - self.assertEqual(output, local_git_parsers.GitSourceParser()(output))
|
| + self.mock(self.local_repo, '_GetLocalGitCommandOutput',
|
| + _MockGetLocalGitCommandOutput)
|
| + self.assertIsNone(self.local_repo.GetSource('file_path', 'rev'))
|
| + self.mock(os.path, 'isfile', lambda path: True)
|
| + self.assertEqual(self.local_repo.GetSource('file_path', 'rev'), 'source')
|
|
|