Move the sha tests to PyUnit.

This commit is contained in:
Fred Drake 2001-05-22 21:43:17 +00:00
parent 275dfda633
commit cf99225312
2 changed files with 20 additions and 22 deletions

View File

@ -1,4 +0,0 @@
test_sha
test 0 ok
test 1 ok
test 2 ok

View File

@ -1,28 +1,30 @@
# Testing sha module (NIST's Secure Hash Algorithm) # Testing sha module (NIST's Secure Hash Algorithm)
import sha
# use the three examples from Federal Information Processing Standards # use the three examples from Federal Information Processing Standards
# Publication 180-1, Secure Hash Standard, 1995 April 17 # Publication 180-1, Secure Hash Standard, 1995 April 17
# http://www.itl.nist.gov/div897/pubs/fip180-1.htm # http://www.itl.nist.gov/div897/pubs/fip180-1.htm
s = [''] * 3 import sha
d = [''] * 3 import test_support
import unittest
s[0] = 'abc'
d[0] = 'a9993e364706816aba3e25717850c26c9cd0d89d'
s[1] = 'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq' class SHATestCase(unittest.TestCase):
d[1] = '84983e441c3bd26ebaae4aa1f95129e5e54670f1' def check(self, data, digest):
computed = sha.new(data).hexdigest()
self.assert_(computed == digest)
s[2] = 'a' * 1000000 def test_case_1(self):
d[2] = '34aa973cd4c4daa4f61eeb2bdbad27316534016f' self.check("abc",
"a9993e364706816aba3e25717850c26c9cd0d89d")
for i in range(3): def test_case_2(self):
test = sha.new(s[i]).hexdigest() self.check("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
if test == d[i]: "84983e441c3bd26ebaae4aa1f95129e5e54670f1")
print "test %d ok" % i
else: def test_case_3(self):
print "test %d failed" % i self.check("a" * 1000000,
print "expected", d[i] "34aa973cd4c4daa4f61eeb2bdbad27316534016f")
print "computed", test
test_support.run_unittest(SHATestCase)