Issue #24279: Update test_base64 to use test.support.script_helper.

Initial patch by Christie.
This commit is contained in:
Berker Peksag 2015-07-25 14:14:24 +03:00
parent a1bddadddd
commit 00f8197540
1 changed files with 9 additions and 17 deletions

View File

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