| 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 from datetime import timedelta |
| 7 import os | 7 import os |
| 8 import sys | 8 import sys |
| 9 import textwrap | 9 import textwrap |
| 10 import unittest | 10 import unittest |
| 11 | 11 |
| 12 _SCRIPT_DIR = os.path.join(os.path.dirname(__file__), | 12 _SCRIPT_DIR = os.path.join(os.path.dirname(__file__), |
| 13 os.path.pardir, os.path.pardir) | 13 os.path.pardir, os.path.pardir) |
| 14 sys.path.insert(1, _SCRIPT_DIR) | 14 sys.path.insert(1, _SCRIPT_DIR) |
| 15 import script_util | 15 import script_util |
| 16 script_util.SetUpSystemPaths() | 16 script_util.SetUpSystemPaths() |
| 17 | 17 |
| 18 from git_checkout import local_git_parsers | 18 from git_checkout import local_git_parsers |
| 19 from libs.gitiles import blame | 19 from libs.gitiles.blame import Blame |
| 20 from libs.gitiles.blame import Region |
| 20 from libs.gitiles import change_log | 21 from libs.gitiles import change_log |
| 21 | 22 |
| 22 | 23 |
| 23 class LocalGitParsersTest(unittest.TestCase): | 24 class LocalGitParsersTest(unittest.TestCase): |
| 24 | 25 |
| 25 def setUp(self): | 26 def setUp(self): |
| 26 super(LocalGitParsersTest, self).setUp() | 27 super(LocalGitParsersTest, self).setUp() |
| 27 self.blame_parser = local_git_parsers.GitBlameParser() | 28 self.blame_parser = local_git_parsers.GitBlameParser() |
| 28 | 29 |
| 29 def testGitBlameParser(self): | 30 def testGitBlameParser(self): |
| (...skipping 15 matching lines...) Expand all Loading... |
| 45 revision_hash 19 19 | 46 revision_hash 19 19 |
| 46 * blabla line 2 | 47 * blabla line 2 |
| 47 revision_hash 20 20 | 48 revision_hash 20 20 |
| 48 * blabla line 3 | 49 * blabla line 3 |
| 49 | 50 |
| 50 revision_hash 29 29 2 | 51 revision_hash 29 29 2 |
| 51 * blabla line 4 | 52 * blabla line 4 |
| 52 """ | 53 """ |
| 53 ) | 54 ) |
| 54 | 55 |
| 55 expected_regions = [blame.Region(18, 3, 'revision_hash', 'test@google.com', | 56 expected_blame = Blame('src/core/SkFont.h', 'rev') |
| 56 'test@google.com', | 57 mock_email = 'test@google.com' |
| 57 datetime(2013, 03, 11, 17, 13, 36)), | 58 author_time = datetime(2013, 03, 11, 17, 13, 36) |
| 58 blame.Region(29, 2, 'revision_hash', 'test@google.com', | 59 expected_blame.AddRegions([ |
| 59 'test@google.com', | 60 Region(18, 3, 'revision_hash', mock_email, mock_email, author_time), |
| 60 datetime(2013, 03, 11, 17, 13, 36))] | 61 Region(29, 2, 'revision_hash', mock_email, mock_email, author_time)]) |
| 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 | 62 |
| 66 blame_result = self.blame_parser(output, 'src/core/SkFont.h', 'rev') | 63 blame_result = self.blame_parser(output, 'src/core/SkFont.h', 'rev') |
| 67 self.assertTrue(blame_result.revision, expected_blame.revision) | 64 self.assertTrue(blame_result.revision, expected_blame.revision) |
| 68 self.assertTrue(blame_result.path, expected_blame.path) | 65 self.assertTrue(blame_result.path, expected_blame.path) |
| 69 for region, expected_region in zip(blame_result, expected_blame): | 66 for region, expected_region in zip(blame_result, expected_blame): |
| 70 self.assertTrue(region.ToDict(), expected_region.ToDict()) | 67 self.assertTrue(region.ToDict(), expected_region.ToDict()) |
| 71 | 68 |
| 72 def testGitBlameParserEmptyOutput(self): | 69 def testGitBlameParserEmptyOutput(self): |
| 73 blame_result = self.blame_parser('', 'src/core/SkFont.h', 'rev') | 70 blame_result = self.blame_parser('', 'src/core/SkFont.h', 'rev') |
| 74 self.assertIsNone(blame_result) | 71 self.assertIsNone(blame_result) |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 output = '**Changelog start**\nblablabla' | 234 output = '**Changelog start**\nblablabla' |
| 238 self.assertEqual(local_git_parsers.GitChangeLogsParser()(output, | 235 self.assertEqual(local_git_parsers.GitChangeLogsParser()(output, |
| 239 'http://repo'), []) | 236 'http://repo'), []) |
| 240 | 237 |
| 241 def testGitDiffParser(self): | 238 def testGitDiffParser(self): |
| 242 self.assertEqual('output', local_git_parsers.GitDiffParser()('output')) | 239 self.assertEqual('output', local_git_parsers.GitDiffParser()('output')) |
| 243 | 240 |
| 244 | 241 |
| 245 if __name__ == '__main__': | 242 if __name__ == '__main__': |
| 246 unittest.main() | 243 unittest.main() |
| OLD | NEW |