summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2008-03-18 20:47:14 (GMT)
committerNeal Norwitz <nnorwitz@gmail.com>2008-03-18 20:47:14 (GMT)
commitc598b6fdb7f04a3206e4bb1a877dcfcf14b863b7 (patch)
treecee81b745b4963ff996dcc1c928a10ae3d9ef5b1
parent40a088dc27865eb1236d6c728d2880ecd0022a65 (diff)
downloadcpython-c598b6fdb7f04a3206e4bb1a877dcfcf14b863b7.zip
cpython-c598b6fdb7f04a3206e4bb1a877dcfcf14b863b7.tar.gz
cpython-c598b6fdb7f04a3206e4bb1a877dcfcf14b863b7.tar.bz2
Get this test to work (it was skipped previously):
* Remove warnings and import the proper modules * Use bytes appropriately * Test the proper sha* objects on hashlib
-rw-r--r--Lib/test/test_pep247.py51
1 files changed, 26 insertions, 25 deletions
diff --git a/Lib/test/test_pep247.py b/Lib/test/test_pep247.py
index fb59d6a..9478969 100644
--- a/Lib/test/test_pep247.py
+++ b/Lib/test/test_pep247.py
@@ -3,15 +3,9 @@ Test suite to check compilance with PEP 247, the standard API
for hashing algorithms
"""
-import warnings
-warnings.filterwarnings('ignore', 'the md5 module is deprecated.*',
- DeprecationWarning)
-warnings.filterwarnings('ignore', 'the sha module is deprecated.*',
- DeprecationWarning)
import hmac
-import md5
-import sha
import unittest
+from hashlib import md5, sha1, sha224, sha256, sha384, sha512
from test import test_support
class Pep247Test(unittest.TestCase):
@@ -19,28 +13,31 @@ class Pep247Test(unittest.TestCase):
def check_module(self, module, key=None):
self.assert_(hasattr(module, 'digest_size'))
self.assert_(module.digest_size is None or module.digest_size > 0)
- if not key is None:
- obj1 = module.new(key)
- obj2 = module.new(key, 'string')
- h1 = module.new(key, 'string').digest()
- obj3 = module.new(key)
- obj3.update('string')
+ self.check_object(module.new, module.digest_size, key)
+
+ def check_object(self, cls, digest_size, key):
+ if key is not None:
+ obj1 = cls(key)
+ obj2 = cls(key, b'string')
+ h1 = cls(key, b'string').digest()
+ obj3 = cls(key)
+ obj3.update(b'string')
h2 = obj3.digest()
else:
- obj1 = module.new()
- obj2 = module.new('string')
- h1 = module.new('string').digest()
- obj3 = module.new()
- obj3.update('string')
+ obj1 = cls()
+ obj2 = cls(b'string')
+ h1 = cls(b'string').digest()
+ obj3 = cls()
+ obj3.update(b'string')
h2 = obj3.digest()
self.assertEquals(h1, h2)
self.assert_(hasattr(obj1, 'digest_size'))
- if not module.digest_size is None:
- self.assertEquals(obj1.digest_size, module.digest_size)
+ if digest_size is not None:
+ self.assertEquals(obj1.digest_size, digest_size)
self.assertEquals(obj1.digest_size, len(h1))
- obj1.update('string')
+ obj1.update(b'string')
obj_copy = obj1.copy()
self.assertEquals(obj1.digest(), obj_copy.digest())
self.assertEquals(obj1.hexdigest(), obj_copy.hexdigest())
@@ -48,17 +45,21 @@ class Pep247Test(unittest.TestCase):
digest, hexdigest = obj1.digest(), obj1.hexdigest()
hd2 = ""
for byte in digest:
- hd2 += '%02x' % ord(byte)
+ hd2 += '%02x' % byte
self.assertEquals(hd2, hexdigest)
def test_md5(self):
- self.check_module(md5)
+ self.check_object(md5, None, None)
def test_sha(self):
- self.check_module(sha)
+ self.check_object(sha1, None, None)
+ self.check_object(sha224, None, None)
+ self.check_object(sha256, None, None)
+ self.check_object(sha384, None, None)
+ self.check_object(sha512, None, None)
def test_hmac(self):
- self.check_module(hmac, key='abc')
+ self.check_module(hmac, key=b'abc')
def test_main():
test_support.run_unittest(Pep247Test)