2 Test suite to check compilance with PEP 247, the standard API
7 warnings
.filterwarnings('ignore', 'the md5 module is deprecated.*',
9 warnings
.filterwarnings('ignore', 'the sha module is deprecated.*',
17 from test
import test_support
19 class Pep247Test(unittest
.TestCase
):
21 def check_module(self
, module
, key
=None):
22 self
.assertTrue(hasattr(module
, 'digest_size'))
23 self
.assertTrue(module
.digest_size
is None or module
.digest_size
> 0)
26 obj1
= module
.new(key
)
27 obj2
= module
.new(key
, 'string')
29 h1
= module
.new(key
, 'string').digest()
30 obj3
= module
.new(key
)
35 obj2
= module
.new('string')
37 h1
= module
.new('string').digest()
42 self
.assertEquals(h1
, h2
)
44 self
.assertTrue(hasattr(obj1
, 'digest_size'))
46 if not module
.digest_size
is None:
47 self
.assertEquals(obj1
.digest_size
, module
.digest_size
)
49 self
.assertEquals(obj1
.digest_size
, len(h1
))
51 obj_copy
= obj1
.copy()
52 self
.assertEquals(obj1
.digest(), obj_copy
.digest())
53 self
.assertEquals(obj1
.hexdigest(), obj_copy
.hexdigest())
55 digest
, hexdigest
= obj1
.digest(), obj1
.hexdigest()
58 hd2
+= '%02x' % ord(byte
)
59 self
.assertEquals(hd2
, hexdigest
)
62 self
.check_module(md5
)
65 self
.check_module(sha
)
68 self
.check_module(hmac
, key
='abc')
71 test_support
.run_unittest(Pep247Test
)
73 if __name__
== '__main__':