summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2002-05-18 00:25:10 (GMT)
committerRaymond Hettinger <python@rcn.com>2002-05-18 00:25:10 (GMT)
commit2ae87539aad20670184ff9d30f625dddd6ac2e78 (patch)
treed70dc6c1b62fc5fcde24a565cff12d018c336059 /Lib
parent18ca791028f77722cc7f450a414ab3b73415ea01 (diff)
downloadcpython-2ae87539aad20670184ff9d30f625dddd6ac2e78.zip
cpython-2ae87539aad20670184ff9d30f625dddd6ac2e78.tar.gz
cpython-2ae87539aad20670184ff9d30f625dddd6ac2e78.tar.bz2
Added Mitchell Surface's regression tests for base64. Closes patch #550002.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_base64.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/Lib/test/test_base64.py b/Lib/test/test_base64.py
new file mode 100644
index 0000000..8ee4d2e
--- /dev/null
+++ b/Lib/test/test_base64.py
@@ -0,0 +1,59 @@
+import unittest
+import test_support
+import base64
+from binascii import Error as binascii_error
+
+class Base64TestCase(unittest.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):
+ """Testing decode string"""
+ test_support.verify(base64.decodestring("d3d3LnB5dGhvbi5vcmc=\n") ==
+ "www.python.org",
+ reason="www.python.org decodestring failed")
+ test_support.verify(base64.decodestring("YQ==\n") ==
+ "a",
+ reason="a decodestring failed")
+ test_support.verify(base64.decodestring("YWI=\n") ==
+ "ab",
+ reason="ab decodestring failed")
+ test_support.verify(base64.decodestring("YWJj\n") ==
+ "abc",
+ reason="abc decodestring failed")
+ test_support.verify(base64.decodestring(
+ "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0\nNTY3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==\n") ==
+ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#0^&*();:<>,. []{}",
+ reason = "long decodestring failed")
+ try:
+ base64.decodestring("")
+ except binascii_error:
+ pass
+ else:
+ self.fail("expected a binascii.Error on null decode request")
+
+def test_main():
+ test_support.run_unittest(Base64TestCase)
+
+if __name__ == "__main__":
+ test_main()
+