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

Side by Side Diff: Lib/test/test_abc.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/pickletester.py ('k') | Lib/test/test_ast.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 # Copyright 2007 Google, Inc. All Rights Reserved. 1 # Copyright 2007 Google, Inc. All Rights Reserved.
2 # Licensed to PSF under a Contributor Agreement. 2 # Licensed to PSF under a Contributor Agreement.
3 3
4 """Unit tests for abc.py.""" 4 """Unit tests for abc.py."""
5 5
6 import unittest 6 import unittest
7 from test import support 7 from test import support
8 8
9 import abc 9 import abc
10 from inspect import isabstract 10 from inspect import isabstract
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 self.assertIsInstance(c, A) 292 self.assertIsInstance(c, A)
293 self.assertIsInstance(c, (A,)) 293 self.assertIsInstance(c, (A,))
294 self.assertIs(C, A.register(C)) 294 self.assertIs(C, A.register(C))
295 295
296 def test_isinstance_invalidation(self): 296 def test_isinstance_invalidation(self):
297 class A(metaclass=abc.ABCMeta): 297 class A(metaclass=abc.ABCMeta):
298 pass 298 pass
299 class B: 299 class B:
300 pass 300 pass
301 b = B() 301 b = B()
302 self.assertFalse(isinstance(b, A)) 302 self.assertNotIsInstance(b, A)
303 self.assertFalse(isinstance(b, (A,))) 303 self.assertNotIsInstance(b, (A,))
304 token_old = abc.get_cache_token() 304 token_old = abc.get_cache_token()
305 A.register(B) 305 A.register(B)
306 token_new = abc.get_cache_token() 306 token_new = abc.get_cache_token()
307 self.assertNotEqual(token_old, token_new) 307 self.assertNotEqual(token_old, token_new)
308 self.assertTrue(isinstance(b, A)) 308 self.assertIsInstance(b, A)
309 self.assertTrue(isinstance(b, (A,))) 309 self.assertIsInstance(b, (A,))
310 310
311 def test_registration_builtins(self): 311 def test_registration_builtins(self):
312 class A(metaclass=abc.ABCMeta): 312 class A(metaclass=abc.ABCMeta):
313 pass 313 pass
314 A.register(int) 314 A.register(int)
315 self.assertIsInstance(42, A) 315 self.assertIsInstance(42, A)
316 self.assertIsInstance(42, (A,)) 316 self.assertIsInstance(42, (A,))
317 self.assertTrue(issubclass(int, A)) 317 self.assertTrue(issubclass(int, A))
318 self.assertTrue(issubclass(int, (A,))) 318 self.assertTrue(issubclass(int, (A,)))
319 class B(A): 319 class B(A):
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 return super().__new__(cls) 399 return super().__new__(cls)
400 class C(A, B): 400 class C(A, B):
401 pass 401 pass
402 self.assertEqual(B.counter, 0) 402 self.assertEqual(B.counter, 0)
403 C() 403 C()
404 self.assertEqual(B.counter, 1) 404 self.assertEqual(B.counter, 1)
405 405
406 406
407 if __name__ == "__main__": 407 if __name__ == "__main__":
408 unittest.main() 408 unittest.main()
OLDNEW
« no previous file with comments | « Lib/test/pickletester.py ('k') | Lib/test/test_ast.py » ('j') | no next file with comments »

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