| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 | 2 |
| 3 """Tests for git_footers.""" | 3 """Tests for git_footers.""" |
| 4 | 4 |
| 5 import os | 5 import os |
| 6 import StringIO | 6 import StringIO |
| 7 import sys | 7 import sys |
| 8 import unittest | 8 import unittest |
| 9 | 9 |
| 10 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | 10 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) |
| 11 | 11 |
| 12 from testing_support.auto_stub import TestCase | 12 from testing_support.auto_stub import TestCase |
| 13 | 13 |
| 14 import git_footers | 14 import git_footers |
| 15 | 15 |
| 16 class GitFootersTest(TestCase): | 16 class GitFootersTest(TestCase): |
| 17 _message = """ | 17 _message = """ |
| 18 This is my commit message. There are many like it, but this one is mine. | 18 This is my commit message. There are many like it, but this one is mine. |
| 19 | 19 |
| 20 My commit message is my best friend. It is my life. I must master it. | 20 My commit message is my best friend. It is my life. I must master it. |
| 21 | 21 |
| 22 """ | 22 """ |
| 23 | 23 |
| 24 _position = 'refs/heads/master@{#292272}' | 24 _position = 'refs/heads/master@{#292272}' |
| 25 | 25 |
| 26 _position_footer = 'Cr-Commit-Position: %s\n' % _position | 26 _position_footer = 'Cr-Commit-Position: %s\n' % _position |
| 27 | 27 |
| 28 _git_svn_id = ('svn://svn.chromium.org/chrome/trunk/src@290386' | |
| 29 ' 0039d316-1c4b-4281-b951-d872f2087c98') | |
| 30 | |
| 31 _git_svn_id_footer = 'git-svn-id: %s\n' % _git_svn_id | |
| 32 | |
| 33 _git_svn_id_branch = ( | |
| 34 'svn://svn.chromium.org/chrome/branches/blabble/src@177288') | |
| 35 | |
| 36 _git_svn_id_footer_branch = 'git-svn-id: %s\n' % _git_svn_id_branch | |
| 37 | |
| 38 def testFootersBasic(self): | 28 def testFootersBasic(self): |
| 39 self.assertEqual( | 29 self.assertEqual( |
| 40 git_footers.split_footers('Not-A: footer'), | 30 git_footers.split_footers('Not-A: footer'), |
| 41 (['Not-A: footer'], [], [])) | 31 (['Not-A: footer'], [], [])) |
| 42 self.assertEqual( | 32 self.assertEqual( |
| 43 git_footers.split_footers('Header\n\nActual: footer'), | 33 git_footers.split_footers('Header\n\nActual: footer'), |
| 44 (['Header', ''], ['Actual: footer'], [('Actual', 'footer')])) | 34 (['Header', ''], ['Actual: footer'], [('Actual', 'footer')])) |
| 45 self.assertEqual( | 35 self.assertEqual( |
| 46 git_footers.split_footers('\nActual: footer'), | 36 git_footers.split_footers('\nActual: footer'), |
| 47 ([''], ['Actual: footer'], [('Actual', 'footer')])) | 37 ([''], ['Actual: footer'], [('Actual', 'footer')])) |
| 48 | 38 |
| 49 self.assertEqual( | 39 self.assertEqual( |
| 50 git_footers.parse_footers(self._message), {}) | 40 git_footers.parse_footers(self._message), {}) |
| 51 self.assertEqual( | 41 self.assertEqual( |
| 52 git_footers.parse_footers(self._message + self._position_footer), | 42 git_footers.parse_footers(self._message + self._position_footer), |
| 53 { 'Cr-Commit-Position': [ self._position ] }) | 43 { 'Cr-Commit-Position': [ self._position ] }) |
| 54 self.assertEqual( | 44 self.assertEqual( |
| 55 git_footers.parse_footers(self._message + self._git_svn_id_footer), | |
| 56 { 'Git-Svn-Id': [ self._git_svn_id ] }) | |
| 57 self.assertEqual( | |
| 58 git_footers.parse_footers(self._message + self._position_footer | 45 git_footers.parse_footers(self._message + self._position_footer |
| 59 + self._position_footer), | 46 + self._position_footer), |
| 60 { 'Cr-Commit-Position': [ self._position, self._position ] }) | 47 { 'Cr-Commit-Position': [ self._position, self._position ] }) |
| 61 | 48 |
| 62 def testTrunkHeuristic(self): | |
| 63 footers = git_footers.parse_footers(self._message + self._git_svn_id_footer) | |
| 64 self.assertEqual( | |
| 65 footers, | |
| 66 { 'Git-Svn-Id': [ self._git_svn_id ] }) | |
| 67 self.assertEqual( | |
| 68 git_footers.get_position(footers), | |
| 69 ('refs/heads/master', '290386')) | |
| 70 | |
| 71 def testBranchHeuristic(self): | |
| 72 footers = git_footers.parse_footers(self._message + | |
| 73 self._git_svn_id_footer_branch) | |
| 74 self.assertEqual( | |
| 75 footers, | |
| 76 { 'Git-Svn-Id': [ self._git_svn_id_branch ] }) | |
| 77 self.assertEqual( | |
| 78 git_footers.get_position(footers), | |
| 79 ('refs/branch-heads/blabble', None)) | |
| 80 | |
| 81 def testGetFooterChangeId(self): | 49 def testGetFooterChangeId(self): |
| 82 msg = '\n'.join(['whatever', | 50 msg = '\n'.join(['whatever', |
| 83 '', | 51 '', |
| 84 'Change-Id: ignored', | 52 'Change-Id: ignored', |
| 85 '', # Above is ignored because of this empty line. | 53 '', # Above is ignored because of this empty line. |
| 86 'Change-Id: Ideadbeaf']) | 54 'Change-Id: Ideadbeaf']) |
| 87 self.assertEqual(['Ideadbeaf'], git_footers.get_footer_change_id(msg)) | 55 self.assertEqual(['Ideadbeaf'], git_footers.get_footer_change_id(msg)) |
| 88 self.assertEqual([], git_footers.get_footer_change_id( | 56 self.assertEqual([], git_footers.get_footer_change_id( |
| 89 'desc\nBUG=not-a-valid-footer\nChange-Id: Ixxx')) | 57 'desc\nBUG=not-a-valid-footer\nChange-Id: Ixxx')) |
| 90 self.assertEqual(['Ixxx'], git_footers.get_footer_change_id( | 58 self.assertEqual(['Ixxx'], git_footers.get_footer_change_id( |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 stdout = StringIO.StringIO() | 121 stdout = StringIO.StringIO() |
| 154 self.mock(git_footers.sys, 'stdout', stdout) | 122 self.mock(git_footers.sys, 'stdout', stdout) |
| 155 | 123 |
| 156 self.assertEqual(git_footers.main([]), 0) | 124 self.assertEqual(git_footers.main([]), 0) |
| 157 self.assertEqual(stdout.getvalue(), "Foo: baz\n") | 125 self.assertEqual(stdout.getvalue(), "Foo: baz\n") |
| 158 | 126 |
| 159 | 127 |
| 160 | 128 |
| 161 if __name__ == '__main__': | 129 if __name__ == '__main__': |
| 162 unittest.main() | 130 unittest.main() |
| OLD | NEW |