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):
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:
......
#!/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))
......
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