Commit 5da394f8 authored by Edward Lemur's avatar Edward Lemur Committed by Commit Bot

depot_tools: Run git_footers_test on Python 3.

Bug: 1009809
Change-Id: I39bbb288a96bbb349747a3aa080f505d3b3a2cff
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1835041
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
Auto-Submit: Edward Lesmes <ehmaldonado@chromium.org>
Reviewed-by: 's avatarAnthony Polito <apolito@google.com>
parent 12a537f9
...@@ -86,7 +86,7 @@ def split_footers(message): ...@@ -86,7 +86,7 @@ def split_footers(message):
footer_lines = [] footer_lines = []
footer_lines.reverse() 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: if not footers:
return message_lines, [], [] return message_lines, [], []
if maybe_footer_lines: if maybe_footer_lines:
......
#!/usr/bin/env python #!/usr/bin/env vpython3
"""Tests for git_footers.""" """Tests for git_footers."""
import json import json
import os import os
import StringIO
import sys import sys
import tempfile import tempfile
import unittest 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 import git_footers
class GitFootersTest(TestCase): class GitFootersTest(unittest.TestCase):
_message = """ _message = """
This is my commit message. There are many like it, but this one is mine. 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. ...@@ -237,20 +240,18 @@ My commit message is my best friend. It is my life. I must master it.
'message\n\nSome: footer') '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): 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(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): 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: with tempfile.NamedTemporaryFile() as tmp:
self.assertEqual(git_footers.main(['--json', tmp.name]), 0) self.assertEqual(git_footers.main(['--json', tmp.name]), 0)
js = json.load(open(tmp.name)) js = json.load(open(tmp.name))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment