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

Side by Side Diff: Lib/test/test_pep247.py

Issue 16510: Using appropriate checks in tests
Patch Set: Created 5 years, 10 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:
View unified diff | Download patch
« no previous file with comments | « Lib/test/test_peepholer.py ('k') | Lib/test/test_pep3120.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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): 19 def check_object(self, cls, digest_size, key):
19 if key is not None: 20 if key is not None:
20 obj1 = cls(key) 21 obj1 = cls(key)
21 obj2 = cls(key, b'string') 22 obj2 = cls(key, b'string')
22 h1 = cls(key, b'string').digest() 23 h1 = cls(key, b'string').digest()
23 obj3 = cls(key) 24 obj3 = cls(key)
24 obj3.update(b'string') 25 obj3.update(b'string')
25 h2 = obj3.digest() 26 h2 = obj3.digest()
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 self.check_object(sha512, None, None) 60 self.check_object(sha512, None, None)
60 61
61 def test_hmac(self): 62 def test_hmac(self):
62 self.check_module(hmac, key=b'abc') 63 self.check_module(hmac, key=b'abc')
63 64
64 def test_main(): 65 def test_main():
65 support.run_unittest(Pep247Test) 66 support.run_unittest(Pep247Test)
66 67
67 if __name__ == '__main__': 68 if __name__ == '__main__':
68 test_main() 69 test_main()
OLDNEW
« no previous file with comments | « Lib/test/test_peepholer.py ('k') | Lib/test/test_pep3120.py » ('j') | no next file with comments »

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