Commit abac0a77 authored by Serhiy Storchaka's avatar Serhiy Storchaka

Added base64 module tests for non-binary files.

parent 017523c4
...@@ -45,7 +45,7 @@ class LegacyBase64TestCase(unittest.TestCase): ...@@ -45,7 +45,7 @@ class LegacyBase64TestCase(unittest.TestCase):
def test_encode(self): def test_encode(self):
eq = self.assertEqual eq = self.assertEqual
from io import BytesIO from io import BytesIO, StringIO
infp = BytesIO(b'abcdefghijklmnopqrstuvwxyz' infp = BytesIO(b'abcdefghijklmnopqrstuvwxyz'
b'ABCDEFGHIJKLMNOPQRSTUVWXYZ' b'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
b'0123456789!@#0^&*();:<>,. []{}') b'0123456789!@#0^&*();:<>,. []{}')
...@@ -55,13 +55,21 @@ class LegacyBase64TestCase(unittest.TestCase): ...@@ -55,13 +55,21 @@ class LegacyBase64TestCase(unittest.TestCase):
b'YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE' b'YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE'
b'RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0\nNT' b'RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0\nNT'
b'Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==\n') b'Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==\n')
# Non-binary files
self.assertRaises(TypeError, base64.encode, StringIO('abc'), BytesIO())
self.assertRaises(TypeError, base64.encode, BytesIO(b'abc'), StringIO())
self.assertRaises(TypeError, base64.encode, StringIO('abc'), StringIO())
def test_decode(self): def test_decode(self):
from io import BytesIO from io import BytesIO, StringIO
infp = BytesIO(b'd3d3LnB5dGhvbi5vcmc=') infp = BytesIO(b'd3d3LnB5dGhvbi5vcmc=')
outfp = BytesIO() outfp = BytesIO()
base64.decode(infp, outfp) base64.decode(infp, outfp)
self.assertEqual(outfp.getvalue(), b'www.python.org') self.assertEqual(outfp.getvalue(), b'www.python.org')
# Non-binary files
self.assertRaises(TypeError, base64.encode, StringIO('YWJj\n'), BytesIO())
self.assertRaises(TypeError, base64.encode, BytesIO(b'YWJj\n'), StringIO())
self.assertRaises(TypeError, base64.encode, StringIO('YWJj\n'), StringIO())
class BaseXYTestCase(unittest.TestCase): class BaseXYTestCase(unittest.TestCase):
......
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