diff --git a/git_footers.py b/git_footers.py index ad091b59d..bfcf07c1a 100755 --- a/git_footers.py +++ b/git_footers.py @@ -86,7 +86,7 @@ def split_footers(message): footer_lines = [] footer_lines.reverse() - footers = filter(None, map(parse_footer, footer_lines)) + footers = [footer for footer in map(parse_footer, footer_lines) if footer] if not footers: return message_lines, [], [] if maybe_footer_lines: diff --git a/tests/git_footers_test.py b/tests/git_footers_test.py index 9734a2a86..e37199d71 100755 --- a/tests/git_footers_test.py +++ b/tests/git_footers_test.py @@ -1,21 +1,24 @@ -#!/usr/bin/env python +#!/usr/bin/env vpython3 """Tests for git_footers.""" import json import os -import StringIO import sys import tempfile import unittest -sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +if sys.version_info.major == 2: + from StringIO import StringIO +else: + from io import StringIO -from testing_support.auto_stub import TestCase +sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from third_party import mock import git_footers -class GitFootersTest(TestCase): +class GitFootersTest(unittest.TestCase): _message = """ This is my commit message. There are many like it, but this one is mine. @@ -237,20 +240,18 @@ My commit message is my best friend. It is my life. I must master it. 'message\n\nSome: footer') + @mock.patch('sys.stdout', StringIO()) + @mock.patch( + 'sys.stdin', + StringIO('line\r\notherline\r\n\r\n\r\nFoo: baz\r\nStill: footer')) def testReadStdin(self): - self.mock(git_footers.sys, 'stdin', StringIO.StringIO( - 'line\r\notherline\r\n\r\n\r\nFoo: baz\r\nStill: footer')) - - stdout = StringIO.StringIO() - self.mock(git_footers.sys, 'stdout', stdout) - self.assertEqual(git_footers.main([]), 0) - self.assertEqual(stdout.getvalue(), 'Still: footer\nFoo: baz\n') + self.assertEqual(sys.stdout.getvalue(), 'Still: footer\nFoo: baz\n') + @mock.patch( + 'sys.stdin', + StringIO('line\r\nany spaces\r\n\r\n\r\nFoo: 1\nBar: 2\nFoo: 3')) def testToJson(self): - self.mock(git_footers.sys, 'stdin', StringIO.StringIO( - 'line\r\nany spaces\r\n\r\n\r\nFoo: 1\nBar: 2\nFoo: 3')) - with tempfile.NamedTemporaryFile() as tmp: self.assertEqual(git_footers.main(['--json', tmp.name]), 0) js = json.load(open(tmp.name))