Browse Source

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: Anthony Polito <apolito@google.com>
Edward Lemur 5 years ago
parent
commit
5da394f8e1
2 changed files with 17 additions and 16 deletions
  1. 1 1
      git_footers.py
  2. 16 15
      tests/git_footers_test.py

+ 1 - 1
git_footers.py

@@ -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:

+ 16 - 15
tests/git_footers_test.py

@@ -1,21 +1,24 @@
-#!/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.
         '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))