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

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

Issue 16510: Using appropriate checks in tests
Patch Set: Created 6 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_funcattrs.py ('k') | Lib/test/test_gc.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 collections 1 import collections
2 import sys 2 import sys
3 import unittest 3 import unittest
4 from test import support 4 from test import support
5 from weakref import proxy 5 from weakref import proxy
6 import pickle 6 import pickle
7 from random import choice 7 from random import choice
8 8
9 import functools 9 import functools
10 10
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 218
219 partial = staticmethod(PartialSubclass) 219 partial = staticmethod(PartialSubclass)
220 220
221 class TestUpdateWrapper(unittest.TestCase): 221 class TestUpdateWrapper(unittest.TestCase):
222 222
223 def check_wrapper(self, wrapper, wrapped, 223 def check_wrapper(self, wrapper, wrapped,
224 assigned=functools.WRAPPER_ASSIGNMENTS, 224 assigned=functools.WRAPPER_ASSIGNMENTS,
225 updated=functools.WRAPPER_UPDATES): 225 updated=functools.WRAPPER_UPDATES):
226 # Check attributes were assigned 226 # Check attributes were assigned
227 for name in assigned: 227 for name in assigned:
228 self.assertTrue(getattr(wrapper, name) is getattr(wrapped, name)) 228 self.assertIs(getattr(wrapper, name), getattr(wrapped, name))
229 # Check attributes were updated 229 # Check attributes were updated
230 for name in updated: 230 for name in updated:
231 wrapper_attr = getattr(wrapper, name) 231 wrapper_attr = getattr(wrapper, name)
232 wrapped_attr = getattr(wrapped, name) 232 wrapped_attr = getattr(wrapped, name)
233 for key in wrapped_attr: 233 for key in wrapped_attr:
234 self.assertTrue(wrapped_attr[key] is wrapper_attr[key]) 234 self.assertIs(wrapped_attr[key], wrapper_attr[key])
235 235
236 def _default_update(self): 236 def _default_update(self):
237 def f(a:'This is a new annotation'): 237 def f(a:'This is a new annotation'):
238 """This is a test""" 238 """This is a test"""
239 pass 239 pass
240 f.attr = 'This is also a test' 240 f.attr = 'This is also a test'
241 def wrapper(b:'This is the prior annotation'): 241 def wrapper(b:'This is the prior annotation'):
242 pass 242 pass
243 functools.update_wrapper(wrapper, f) 243 functools.update_wrapper(wrapper, f)
244 return wrapper, f 244 return wrapper, f
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 self.assertEqual(hits, 0) 663 self.assertEqual(hits, 0)
664 self.assertEqual(misses, 0) 664 self.assertEqual(misses, 0)
665 665
666 domain = range(5) 666 domain = range(5)
667 for i in range(1000): 667 for i in range(1000):
668 x, y = choice(domain), choice(domain) 668 x, y = choice(domain), choice(domain)
669 actual = f(x, y) 669 actual = f(x, y)
670 expected = orig(x, y) 670 expected = orig(x, y)
671 self.assertEqual(actual, expected) 671 self.assertEqual(actual, expected)
672 hits, misses, maxsize, currsize = f.cache_info() 672 hits, misses, maxsize, currsize = f.cache_info()
673 self.assertTrue(hits > misses) 673 self.assertGreater(hits, misses)
674 self.assertEqual(hits + misses, 1000) 674 self.assertEqual(hits + misses, 1000)
675 self.assertEqual(currsize, 20) 675 self.assertEqual(currsize, 20)
676 676
677 f.cache_clear() # test clearing 677 f.cache_clear() # test clearing
678 hits, misses, maxsize, currsize = f.cache_info() 678 hits, misses, maxsize, currsize = f.cache_info()
679 self.assertEqual(hits, 0) 679 self.assertEqual(hits, 0)
680 self.assertEqual(misses, 0) 680 self.assertEqual(misses, 0)
681 self.assertEqual(currsize, 0) 681 self.assertEqual(currsize, 0)
682 f(x, y) 682 f(x, y)
683 hits, misses, maxsize, currsize = f.cache_info() 683 hits, misses, maxsize, currsize = f.cache_info()
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 import gc 839 import gc
840 counts = [None] * 5 840 counts = [None] * 5
841 for i in range(len(counts)): 841 for i in range(len(counts)):
842 support.run_unittest(*test_classes) 842 support.run_unittest(*test_classes)
843 gc.collect() 843 gc.collect()
844 counts[i] = sys.gettotalrefcount() 844 counts[i] = sys.gettotalrefcount()
845 print(counts) 845 print(counts)
846 846
847 if __name__ == '__main__': 847 if __name__ == '__main__':
848 test_main(verbose=True) 848 test_main(verbose=True)
OLDNEW
« no previous file with comments | « Lib/test/test_funcattrs.py ('k') | Lib/test/test_gc.py » ('j') | no next file with comments »

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