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

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

Issue 16510: Using appropriate checks in tests
Patch Set: Created 5 years, 6 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_gzip.py ('k') | Lib/test/test_inspect.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 import functools 1 import functools
2 import hmac 2 import hmac
3 import hashlib 3 import hashlib
4 import unittest 4 import unittest
5 import warnings 5 import warnings
6 from test import support 6 from test import support
7 7
8 8
9 def ignore_warning(func): 9 def ignore_warning(func):
10 @functools.wraps(func) 10 @functools.wraps(func)
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 h2 = h.copy() 350 h2 = h.copy()
351 except Exception: 351 except Exception:
352 self.fail("Exception raised during normal usage of HMAC class.") 352 self.fail("Exception raised during normal usage of HMAC class.")
353 353
354 class CopyTestCase(unittest.TestCase): 354 class CopyTestCase(unittest.TestCase):
355 355
356 def test_attributes(self): 356 def test_attributes(self):
357 # Testing if attributes are of same type. 357 # Testing if attributes are of same type.
358 h1 = hmac.HMAC(b"key", digestmod="md5") 358 h1 = hmac.HMAC(b"key", digestmod="md5")
359 h2 = h1.copy() 359 h2 = h1.copy()
360 self.assertTrue(h1.digest_cons == h2.digest_cons, 360 self.assertEqual(h1.digest_cons, h2.digest_cons,
361 "digest constructors don't match.") 361 "digest constructors don't match.")
362 self.assertEqual(type(h1.inner), type(h2.inner), 362 self.assertEqual(type(h1.inner), type(h2.inner),
363 "Types of inner don't match.") 363 "Types of inner don't match.")
364 self.assertEqual(type(h1.outer), type(h2.outer), 364 self.assertEqual(type(h1.outer), type(h2.outer),
365 "Types of outer don't match.") 365 "Types of outer don't match.")
366 366
367 def test_realcopy(self): 367 def test_realcopy(self):
368 # Testing if the copy method created a real copy. 368 # Testing if the copy method created a real copy.
369 h1 = hmac.HMAC(b"key", digestmod="md5") 369 h1 = hmac.HMAC(b"key", digestmod="md5")
370 h2 = h1.copy() 370 h2 = h1.copy()
371 # Using id() in case somebody has overridden __eq__/__ne__. 371 # Using "is" in case somebody has overridden __eq__/__ne__.
372 self.assertTrue(id(h1) != id(h2), "No real copy of the HMAC instance.") 372 self.assertIsNot(h1, h2, "No real copy of the HMAC instance.")
373 self.assertTrue(id(h1.inner) != id(h2.inner), 373 self.assertIsNot(h1.inner, h2.inner,
374 "No real copy of the attribute 'inner'.") 374 "No real copy of the attribute 'inner'.")
375 self.assertTrue(id(h1.outer) != id(h2.outer), 375 self.assertIsNot(h1.outer, h2.outer,
376 "No real copy of the attribute 'outer'.") 376 "No real copy of the attribute 'outer'.")
377 377
378 def test_equality(self): 378 def test_equality(self):
379 # Testing if the copy has the same digests. 379 # Testing if the copy has the same digests.
380 h1 = hmac.HMAC(b"key", digestmod="md5") 380 h1 = hmac.HMAC(b"key", digestmod="md5")
381 h1.update(b"some random text") 381 h1.update(b"some random text")
382 h2 = h1.copy() 382 h2 = h1.copy()
383 self.assertEqual(h1.digest(), h2.digest(), 383 self.assertEqual(h1.digest(), h2.digest(),
384 "Digest of copy doesn't match original digest.") 384 "Digest of copy doesn't match original digest.")
385 self.assertEqual(h1.hexdigest(), h2.hexdigest(), 385 self.assertEqual(h1.hexdigest(), h2.hexdigest(),
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 support.run_unittest( 497 support.run_unittest(
498 TestVectorsTestCase, 498 TestVectorsTestCase,
499 ConstructorTestCase, 499 ConstructorTestCase,
500 SanityTestCase, 500 SanityTestCase,
501 CopyTestCase, 501 CopyTestCase,
502 CompareDigestTestCase 502 CompareDigestTestCase
503 ) 503 )
504 504
505 if __name__ == "__main__": 505 if __name__ == "__main__":
506 test_main() 506 test_main()
OLDNEW
« no previous file with comments | « Lib/test/test_gzip.py ('k') | Lib/test/test_inspect.py » ('j') | no next file with comments »

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