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

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

Issue 16510: Using appropriate checks in tests
Left Patch Set: Created 6 years 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:
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
(no file at all)
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 self.assertTrue(module.digest_size is None or module.digest_size > 0) 15 if module.digest_size is not None:
16 self.assertGreater(module.digest_size, 0)
16 self.check_object(module.new, module.digest_size, key) 17 self.check_object(module.new, module.digest_size, key)
17 18
18 def check_object(self, cls, digest_size, key, digestmod=None): 19 def check_object(self, cls, digest_size, key, digestmod=None):
19 if key is not None: 20 if key is not None:
20 if digestmod is None: 21 if digestmod is None:
21 digestmod = md5 22 digestmod = md5
22 obj1 = cls(key, digestmod=digestmod) 23 obj1 = cls(key, digestmod=digestmod)
23 obj2 = cls(key, b'string', digestmod=digestmod) 24 obj2 = cls(key, b'string', digestmod=digestmod)
24 h1 = cls(key, b'string', digestmod=digestmod).digest() 25 h1 = cls(key, b'string', digestmod=digestmod).digest()
25 obj3 = cls(key, digestmod=digestmod) 26 obj3 = cls(key, digestmod=digestmod)
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 self.check_object(sha512, None, None) 62 self.check_object(sha512, None, None)
62 63
63 def test_hmac(self): 64 def test_hmac(self):
64 self.check_module(hmac, key=b'abc') 65 self.check_module(hmac, key=b'abc')
65 66
66 def test_main(): 67 def test_main():
67 support.run_unittest(Pep247Test) 68 support.run_unittest(Pep247Test)
68 69
69 if __name__ == '__main__': 70 if __name__ == '__main__':
70 test_main() 71 test_main()
LEFTRIGHT

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