summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/output/test_md59
-rw-r--r--Lib/test/test_md5.py64
-rw-r--r--Lib/test/test_weakref.py8
3 files changed, 54 insertions, 27 deletions
diff --git a/Lib/test/output/test_md5 b/Lib/test/output/test_md5
deleted file mode 100644
index c21f8e3..0000000
--- a/Lib/test/output/test_md5
+++ /dev/null
@@ -1,9 +0,0 @@
-test_md5
-MD5 test suite:
-MD5 ("") = d41d8cd98f00b204e9800998ecf8427e
-MD5 ("a") = 0cc175b9c0f1b6a831c399e269772661
-MD5 ("abc") = 900150983cd24fb0d6963f7d28e17f72
-MD5 ("message digest") = f96b697d7cb7938d525a2f31aaf161d0
-MD5 ("abcdefghijklmnopqrstuvwxyz") = c3fcd3d76192e4007dfb496cca67e13b
-MD5 ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") = d174ab98d277d9f5a5611c2c9f419d9f
-MD5 ("12345678901234567890123456789012345678901234567890123456789012345678901234567890") = 57edf4a22be3c955ac49da2e2107b67a
diff --git a/Lib/test/test_md5.py b/Lib/test/test_md5.py
index 92cd568..bd0fb2e 100644
--- a/Lib/test/test_md5.py
+++ b/Lib/test/test_md5.py
@@ -1,9 +1,11 @@
# Testing md5 module
-import string
+import unittest
from md5 import md5
+from test import test_support
def hexstr(s):
+ import string
h = string.hexdigits
r = ''
for c in s:
@@ -11,20 +13,46 @@ def hexstr(s):
r = r + h[(i >> 4) & 0xF] + h[i & 0xF]
return r
-def md5test(s):
- return 'MD5 ("' + s + '") = ' + hexstr(md5(s).digest())
-
-print 'MD5 test suite:'
-print md5test('')
-print md5test('a')
-print md5test('abc')
-print md5test('message digest')
-print md5test('abcdefghijklmnopqrstuvwxyz')
-print md5test('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789')
-print md5test('12345678901234567890123456789012345678901234567890123456789012345678901234567890')
-
-# hexdigest is new with Python 2.0
-m = md5('testing the hexdigest method')
-h = m.hexdigest()
-if hexstr(m.digest()) != h:
- print 'hexdigest() failed'
+class MD5_Test(unittest.TestCase):
+
+ def md5test(self, s, expected):
+ self.assertEqual(hexstr(md5(s).digest()), expected)
+ self.assertEqual(md5(s).hexdigest(), expected)
+
+ def test_basics(self):
+ eq = self.md5test
+ eq('', 'd41d8cd98f00b204e9800998ecf8427e')
+ eq('a', '0cc175b9c0f1b6a831c399e269772661')
+ eq('abc', '900150983cd24fb0d6963f7d28e17f72')
+ eq('message digest', 'f96b697d7cb7938d525a2f31aaf161d0')
+ eq('abcdefghijklmnopqrstuvwxyz', 'c3fcd3d76192e4007dfb496cca67e13b')
+ eq('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',
+ 'd174ab98d277d9f5a5611c2c9f419d9f')
+ eq('12345678901234567890123456789012345678901234567890123456789012345678901234567890',
+ '57edf4a22be3c955ac49da2e2107b67a')
+
+ def test_hexdigest(self):
+ # hexdigest is new with Python 2.0
+ m = md5('testing the hexdigest method')
+ h = m.hexdigest()
+ self.assertEqual(hexstr(m.digest()), h)
+
+ def test_large_update(self):
+ aas = 'a' * 64
+ bees = 'b' * 64
+ cees = 'c' * 64
+
+ m1 = md5()
+ m1.update(aas)
+ m1.update(bees)
+ m1.update(cees)
+
+ m2 = md5()
+ m2.update(aas + bees + cees)
+ self.assertEqual(m1.digest(), m2.digest())
+
+def test_main():
+ test_support.run_unittest(MD5_Test)
+
+if __name__ == '__main__':
+ test_main()
diff --git a/Lib/test/test_weakref.py b/Lib/test/test_weakref.py
index 34831f1..d42922a 100644
--- a/Lib/test/test_weakref.py
+++ b/Lib/test/test_weakref.py
@@ -249,6 +249,10 @@ class ReferencesTestCase(TestBase):
self.assert_(weakref.getweakrefcount(o) == 4,
"got wrong number of weak reference objects")
+ # assumes ints do not support weakrefs
+ self.assert_(weakref.getweakrefcount(1) == 0,
+ "got wrong number of weak reference objects for int")
+
def test_getweakrefs(self):
o = C()
ref1 = weakref.ref(o, self.callback)
@@ -264,6 +268,10 @@ class ReferencesTestCase(TestBase):
self.assert_(weakref.getweakrefs(o) == [ref1],
"list of refs does not match")
+ # assumes ints do not support weakrefs
+ self.assert_(weakref.getweakrefs(1) == [],
+ "list of refs does not match for int")
+
def test_newstyle_number_ops(self):
class F(float):
pass