Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(27957)

Delta Between Two Patch Sets: Lib/test/test_pep247.py

Issue 16510: Using appropriate checks in tests
Left Patch Set: Created 5 years, 10 months ago
Right Patch Set: Created 5 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/test/test_peepholer.py ('k') | Lib/test/test_pep3120.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 """ 1 """
2 Test suite to check compilance with PEP 247, the standard API 2 Test suite to check compilance with PEP 247, the standard API
3 for hashing algorithms 3 for hashing algorithms
4 """ 4 """
5 5
6 import hmac 6 import hmac
7 import unittest 7 import unittest
8 from hashlib import md5, sha1, sha224, sha256, sha384, sha512 8 from hashlib import md5, sha1, sha224, sha256, sha384, sha512
9 from test import support 9 from test import support
10 10
11 class Pep247Test(unittest.TestCase): 11 class Pep247Test(unittest.TestCase):
12 12
13 def check_module(self, module, key=None): 13 def check_module(self, module, key=None):
14 self.assertTrue(hasattr(module, 'digest_size')) 14 self.assertTrue(hasattr(module, 'digest_size'))
15 if module.digest_size is not None: 15 if module.digest_size is not None:
16 self.assertGreater(module.digest_size, 0) 16 self.assertGreater(module.digest_size, 0)
17 self.check_object(module.new, module.digest_size, key) 17 self.check_object(module.new, module.digest_size, key)
18 18
19 def check_object(self, cls, digest_size, key): 19 def check_object(self, cls, digest_size, key, digestmod=None):
20 if key is not None: 20 if key is not None:
21 obj1 = cls(key) 21 if digestmod is None:
22 obj2 = cls(key, b'string') 22 digestmod = md5
23 h1 = cls(key, b'string').digest() 23 obj1 = cls(key, digestmod=digestmod)
24 obj3 = cls(key) 24 obj2 = cls(key, b'string', digestmod=digestmod)
25 h1 = cls(key, b'string', digestmod=digestmod).digest()
26 obj3 = cls(key, digestmod=digestmod)
25 obj3.update(b'string') 27 obj3.update(b'string')
26 h2 = obj3.digest() 28 h2 = obj3.digest()
27 else: 29 else:
28 obj1 = cls() 30 obj1 = cls()
29 obj2 = cls(b'string') 31 obj2 = cls(b'string')
30 h1 = cls(b'string').digest() 32 h1 = cls(b'string').digest()
31 obj3 = cls() 33 obj3 = cls()
32 obj3.update(b'string') 34 obj3.update(b'string')
33 h2 = obj3.digest() 35 h2 = obj3.digest()
34 self.assertEqual(h1, h2) 36 self.assertEqual(h1, h2)
(...skipping 25 matching lines...) Expand all
60 self.check_object(sha512, None, None) 62 self.check_object(sha512, None, None)
61 63
62 def test_hmac(self): 64 def test_hmac(self):
63 self.check_module(hmac, key=b'abc') 65 self.check_module(hmac, key=b'abc')
64 66
65 def test_main(): 67 def test_main():
66 support.run_unittest(Pep247Test) 68 support.run_unittest(Pep247Test)
67 69
68 if __name__ == '__main__': 70 if __name__ == '__main__':
69 test_main() 71 test_main()
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+