2002-05-17 21:25:10 -03:00
|
|
|
import unittest
|
2002-07-23 16:04:11 -03:00
|
|
|
from test import test_support
|
2002-05-17 21:25:10 -03:00
|
|
|
import base64
|
|
|
|
from binascii import Error as binascii_error
|
|
|
|
|
|
|
|
class Base64TestCase(unittest.TestCase):
|
|
|
|
def test_encode_string(self):
|
|
|
|
"""Testing encode string"""
|
2002-05-23 12:15:30 -03:00
|
|
|
test_support.verify(base64.encodestring("www.python.org") ==
|
|
|
|
"d3d3LnB5dGhvbi5vcmc=\n",
|
2002-05-17 21:25:10 -03:00
|
|
|
reason="www.python.org encodestring failed")
|
2002-05-23 12:15:30 -03:00
|
|
|
test_support.verify(base64.encodestring("a") ==
|
|
|
|
"YQ==\n",
|
2002-05-17 21:25:10 -03:00
|
|
|
reason="a encodestring failed")
|
2002-05-23 12:15:30 -03:00
|
|
|
test_support.verify(base64.encodestring("ab") ==
|
|
|
|
"YWI=\n",
|
2002-05-17 21:25:10 -03:00
|
|
|
reason="ab encodestring failed")
|
2002-05-23 12:15:30 -03:00
|
|
|
test_support.verify(base64.encodestring("abc") ==
|
|
|
|
"YWJj\n",
|
2002-05-17 21:25:10 -03:00
|
|
|
reason="abc encodestring failed")
|
2002-05-23 12:15:30 -03:00
|
|
|
test_support.verify(base64.encodestring("") ==
|
|
|
|
"",
|
2002-05-17 21:25:10 -03:00
|
|
|
reason="null encodestring failed")
|
|
|
|
test_support.verify(base64.encodestring(
|
|
|
|
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#0^&*();:<>,. []{}") ==
|
|
|
|
"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0\nNTY3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==\n",
|
|
|
|
reason = "long encodestring failed")
|
|
|
|
|
|
|
|
def test_decode_string(self):
|
|
|
|
"""Testing decode string"""
|
|
|
|
test_support.verify(base64.decodestring("d3d3LnB5dGhvbi5vcmc=\n") ==
|
2002-05-23 12:15:30 -03:00
|
|
|
"www.python.org",
|
2002-05-17 21:25:10 -03:00
|
|
|
reason="www.python.org decodestring failed")
|
|
|
|
test_support.verify(base64.decodestring("YQ==\n") ==
|
2002-05-23 12:15:30 -03:00
|
|
|
"a",
|
2002-05-17 21:25:10 -03:00
|
|
|
reason="a decodestring failed")
|
|
|
|
test_support.verify(base64.decodestring("YWI=\n") ==
|
2002-05-23 12:15:30 -03:00
|
|
|
"ab",
|
2002-05-17 21:25:10 -03:00
|
|
|
reason="ab decodestring failed")
|
|
|
|
test_support.verify(base64.decodestring("YWJj\n") ==
|
2002-05-23 12:15:30 -03:00
|
|
|
"abc",
|
2002-05-17 21:25:10 -03:00
|
|
|
reason="abc decodestring failed")
|
|
|
|
test_support.verify(base64.decodestring(
|
|
|
|
"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0\nNTY3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==\n") ==
|
|
|
|
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#0^&*();:<>,. []{}",
|
|
|
|
reason = "long decodestring failed")
|
2002-08-15 19:14:24 -03:00
|
|
|
test_support.verify(base64.decodestring('') == '')
|
2002-05-23 12:15:30 -03:00
|
|
|
|
2002-05-17 21:25:10 -03:00
|
|
|
def test_main():
|
|
|
|
test_support.run_unittest(Base64TestCase)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
test_main()
|