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

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

Issue 25958: Implicit ABCs have no means of "anti-registration"
Patch Set: Created 4 years, 4 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
OLDNEW
1 # Test properties of bool promised by PEP 285 1 # Test properties of bool promised by PEP 285
2 2
3 import unittest 3 import unittest
4 from test import support 4 from test import support
5 5
6 import os 6 import os
7 7
8 class BoolTest(unittest.TestCase): 8 class BoolTest(unittest.TestCase):
9 9
10 def test_subclass(self): 10 def test_subclass(self):
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 def __len__(self): 322 def __len__(self):
323 return badval 323 return badval
324 try: 324 try:
325 bool(A()) 325 bool(A())
326 except (Exception) as e_bool: 326 except (Exception) as e_bool:
327 try: 327 try:
328 len(A()) 328 len(A())
329 except (Exception) as e_len: 329 except (Exception) as e_len:
330 self.assertEqual(str(e_bool), str(e_len)) 330 self.assertEqual(str(e_bool), str(e_len))
331 331
332 def test_blocked(self):
333 class A:
334 __bool__ = None
335 self.assertRaises(TypeError, bool, A())
336
337 class B:
338 def __len__(self):
339 return 10
340 __bool__ = None
341 self.assertRaises(TypeError, bool, B())
342
332 def test_real_and_imag(self): 343 def test_real_and_imag(self):
333 self.assertEqual(True.real, 1) 344 self.assertEqual(True.real, 1)
334 self.assertEqual(True.imag, 0) 345 self.assertEqual(True.imag, 0)
335 self.assertIs(type(True.real), int) 346 self.assertIs(type(True.real), int)
336 self.assertIs(type(True.imag), int) 347 self.assertIs(type(True.imag), int)
337 self.assertEqual(False.real, 0) 348 self.assertEqual(False.real, 0)
338 self.assertEqual(False.imag, 0) 349 self.assertEqual(False.imag, 0)
339 self.assertIs(type(False.real), int) 350 self.assertIs(type(False.real), int)
340 self.assertIs(type(False.imag), int) 351 self.assertIs(type(False.imag), int)
341 352
342 def test_main(): 353 def test_main():
343 support.run_unittest(BoolTest) 354 support.run_unittest(BoolTest)
344 355
345 if __name__ == "__main__": 356 if __name__ == "__main__":
346 test_main() 357 test_main()
OLDNEW

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