diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2010-05-25 21:12:34 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2010-05-25 21:12:34 (GMT) |
commit | 479736b31c2500bc12d09c3ff766de6a2ec68ac0 (patch) | |
tree | 27bfaf3fc19f10f085c0606a5c0381133aff5726 /Lib/test | |
parent | 0b2f5180d73f9239ae621014d0af478ac1887155 (diff) | |
download | cpython-479736b31c2500bc12d09c3ff766de6a2ec68ac0.zip cpython-479736b31c2500bc12d09c3ff766de6a2ec68ac0.tar.gz cpython-479736b31c2500bc12d09c3ff766de6a2ec68ac0.tar.bz2 |
Issue #4769: Fix main() function of the base64 module, use sys.stdin.buffer and
sys.stdout.buffer (instead of sys.stdin and sys.stdout) to use the bytes API
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_base64.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/Lib/test/test_base64.py b/Lib/test/test_base64.py index fadee6d..7ff0db5 100644 --- a/Lib/test/test_base64.py +++ b/Lib/test/test_base64.py @@ -2,6 +2,8 @@ import unittest from test import support import base64 import binascii +import sys +import subprocess @@ -208,6 +210,38 @@ class BaseXYTestCase(unittest.TestCase): +class TestMain(unittest.TestCase): + def get_output(self, *args, **options): + args = (sys.executable, '-m', 'base64') + args + return subprocess.check_output(args, **options) + + def test_encode_decode(self): + output = self.get_output('-t') + self.assertSequenceEqual(output.splitlines(), ( + b"b'Aladdin:open sesame'", + br"b'QWxhZGRpbjpvcGVuIHNlc2FtZQ==\n'", + b"b'Aladdin:open sesame'", + )) + + 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.assertEquals(output.rstrip(), b'Yf9iCg==') + + with open(support.TESTFN, 'rb') as fp: + output = self.get_output('-e', stdin=fp) + self.assertEquals(output.rstrip(), b'Yf9iCg==') + + def test_decode(self): + with open(support.TESTFN, 'wb') as fp: + fp.write(b'Yf9iCg==') + output = self.get_output('-d', support.TESTFN) + self.assertEquals(output, b'a\xffb\n') + + + def test_main(): support.run_unittest(__name__) |