Made it more readable.

This commit is contained in:
Guido van Rossum 2002-08-22 19:18:56 +00:00
parent 373198e751
commit cb682584a3
1 changed files with 30 additions and 46 deletions

View File

@ -1,53 +1,37 @@
import unittest from unittest import TestCase
from test import test_support from test.test_support import vereq, run_unittest
import base64 from base64 import encodestring, decodestring
from binascii import Error as binascii_error
class Base64TestCase(unittest.TestCase): class Base64TestCase(TestCase):
def test_encode_string(self):
"""Testing encode string"""
test_support.verify(base64.encodestring("www.python.org") ==
"d3d3LnB5dGhvbi5vcmc=\n",
reason="www.python.org encodestring failed")
test_support.verify(base64.encodestring("a") ==
"YQ==\n",
reason="a encodestring failed")
test_support.verify(base64.encodestring("ab") ==
"YWI=\n",
reason="ab encodestring failed")
test_support.verify(base64.encodestring("abc") ==
"YWJj\n",
reason="abc encodestring failed")
test_support.verify(base64.encodestring("") ==
"",
reason="null encodestring failed")
test_support.verify(base64.encodestring(
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#0^&*();:<>,. []{}") ==
"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0\nNTY3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==\n",
reason = "long encodestring failed")
def test_decode_string(self): def test_encodestring(self):
"""Testing decode string""" vereq(encodestring("www.python.org"), "d3d3LnB5dGhvbi5vcmc=\n")
test_support.verify(base64.decodestring("d3d3LnB5dGhvbi5vcmc=\n") == vereq(encodestring("a"), "YQ==\n")
"www.python.org", vereq(encodestring("ab"), "YWI=\n")
reason="www.python.org decodestring failed") vereq(encodestring("abc"), "YWJj\n")
test_support.verify(base64.decodestring("YQ==\n") == vereq(encodestring(""), "")
"a", vereq(encodestring("abcdefghijklmnopqrstuvwxyz"
reason="a decodestring failed") "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
test_support.verify(base64.decodestring("YWI=\n") == "0123456789!@#0^&*();:<>,. []{}"),
"ab", "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE"
reason="ab decodestring failed") "RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0\nNT"
test_support.verify(base64.decodestring("YWJj\n") == "Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==\n")
"abc",
reason="abc decodestring failed") def test_decodestring(self):
test_support.verify(base64.decodestring( vereq(decodestring("d3d3LnB5dGhvbi5vcmc=\n"), "www.python.org")
"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0\nNTY3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==\n") == vereq(decodestring("YQ==\n"), "a")
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#0^&*();:<>,. []{}", vereq(decodestring("YWI=\n"), "ab")
reason = "long decodestring failed") vereq(decodestring("YWJj\n"), "abc")
test_support.verify(base64.decodestring('') == '') vereq(decodestring("YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE"
"RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0\nNT"
"Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==\n"),
"abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"0123456789!@#0^&*();:<>,. []{}")
vereq(decodestring(''), '')
def test_main(): def test_main():
test_support.run_unittest(Base64TestCase) run_unittest(Base64TestCase)
if __name__ == "__main__": if __name__ == "__main__":
test_main() test_main()