[Python-checkins] cpython (merge 3.5 -> default): Issue #24279: Update test_base64 to use test.support.script_helper.

berker.peksag python-checkins at python.org
Sat Jul 25 13:15:18 CEST 2015


https://hg.python.org/cpython/rev/472f354c70b8
changeset:   97059:472f354c70b8
parent:      97057:5fb7d3238248
parent:      97058:8e1291cc8b69
user:        Berker Peksag <berker.peksag at gmail.com>
date:        Sat Jul 25 14:14:50 2015 +0300
summary:
  Issue #24279: Update test_base64 to use test.support.script_helper.

Initial patch by Christie.

files:
  Lib/test/test_base64.py |  26 +++++++++-----------------
  1 files changed, 9 insertions(+), 17 deletions(-)


diff --git a/Lib/test/test_base64.py b/Lib/test/test_base64.py
--- a/Lib/test/test_base64.py
+++ b/Lib/test/test_base64.py
@@ -3,10 +3,8 @@
 import base64
 import binascii
 import os
-import sys
-import subprocess
-import struct
 from array import array
+from test.support import script_helper
 
 
 class LegacyBase64TestCase(unittest.TestCase):
@@ -622,15 +620,13 @@
         self.assertTrue(issubclass(binascii.Error, ValueError))
 
 
-
 class TestMain(unittest.TestCase):
     def tearDown(self):
         if os.path.exists(support.TESTFN):
             os.unlink(support.TESTFN)
 
-    def get_output(self, *args, **options):
-        args = (sys.executable, '-m', 'base64') + args
-        return subprocess.check_output(args, **options)
+    def get_output(self, *args):
+        return script_helper.assert_python_ok('-m', 'base64', *args).out
 
     def test_encode_decode(self):
         output = self.get_output('-t')
@@ -643,13 +639,14 @@
     def test_encode_file(self):
         with open(support.TESTFN, 'wb') as fp:
             fp.write(b'a\xffb\n')
-
         output = self.get_output('-e', support.TESTFN)
         self.assertEqual(output.rstrip(), b'Yf9iCg==')
 
-        with open(support.TESTFN, 'rb') as fp:
-            output = self.get_output('-e', stdin=fp)
-        self.assertEqual(output.rstrip(), b'Yf9iCg==')
+    def test_encode_from_stdin(self):
+        with script_helper.spawn_python('-m', 'base64', '-e') as proc:
+            out, err = proc.communicate(b'a\xffb\n')
+        self.assertEqual(out.rstrip(), b'Yf9iCg==')
+        self.assertIsNone(err)
 
     def test_decode(self):
         with open(support.TESTFN, 'wb') as fp:
@@ -657,10 +654,5 @@
         output = self.get_output('-d', support.TESTFN)
         self.assertEqual(output.rstrip(), b'a\xffb')
 
-
-
-def test_main():
-    support.run_unittest(__name__)
-
 if __name__ == '__main__':
-    test_main()
+    unittest.main()

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list