| 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 mock |
| 7 import StringIO |
| 6 import sys | 8 import sys |
| 7 import unittest | 9 import unittest |
| 8 | 10 |
| 9 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | 11 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) |
| 10 | 12 |
| 13 from testing_support.auto_stub import TestCase |
| 14 |
| 11 import git_footers | 15 import git_footers |
| 12 | 16 |
| 13 class GitFootersTest(unittest.TestCase): | 17 class GitFootersTest(TestCase): |
| 14 _message = """ | 18 _message = """ |
| 15 This is my commit message. There are many like it, but this one is mine. | 19 This is my commit message. There are many like it, but this one is mine. |
| 16 | 20 |
| 17 My commit message is my best friend. It is my life. I must master it. | 21 My commit message is my best friend. It is my life. I must master it. |
| 18 | 22 |
| 19 """ | 23 """ |
| 20 | 24 |
| 21 _position = 'refs/heads/master@{#292272}' | 25 _position = 'refs/heads/master@{#292272}' |
| 22 | 26 |
| 23 _position_footer = 'Cr-Commit-Position: %s\n' % _position | 27 _position_footer = 'Cr-Commit-Position: %s\n' % _position |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 | 101 |
| 98 self.assertEqual( | 102 self.assertEqual( |
| 99 git_footers.add_footer_change_id('header\n\nBUG: yy\n\nPos: 1', 'Ixxx'), | 103 git_footers.add_footer_change_id('header\n\nBUG: yy\n\nPos: 1', 'Ixxx'), |
| 100 'header\n\nBUG: yy\n\nChange-Id: Ixxx\nPos: 1') | 104 'header\n\nBUG: yy\n\nChange-Id: Ixxx\nPos: 1') |
| 101 | 105 |
| 102 # Special case: first line is never a footer, even if it looks line one. | 106 # Special case: first line is never a footer, even if it looks line one. |
| 103 self.assertEqual( | 107 self.assertEqual( |
| 104 git_footers.add_footer_change_id('header: like footer', 'Ixxx'), | 108 git_footers.add_footer_change_id('header: like footer', 'Ixxx'), |
| 105 'header: like footer\n\nChange-Id: Ixxx') | 109 'header: like footer\n\nChange-Id: Ixxx') |
| 106 | 110 |
| 111 def testReadStdin(self): |
| 112 self.mock(git_footers.sys, 'stdin', StringIO.StringIO( |
| 113 'line\r\notherline\r\n\r\n\r\nFoo: baz')) |
| 114 |
| 115 stdout = StringIO.StringIO() |
| 116 self.mock(git_footers.sys, 'stdout', stdout) |
| 117 |
| 118 self.assertEqual(git_footers.main([]), 0) |
| 119 self.assertEqual(stdout.getvalue(), "Foo: ['baz']\n") |
| 120 |
| 121 |
| 107 | 122 |
| 108 if __name__ == '__main__': | 123 if __name__ == '__main__': |
| 109 unittest.main() | 124 unittest.main() |
| OLD | NEW |