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

Delta Between Two Patch Sets: Lib/test/test_bool.py

Issue 25958: Implicit ABCs have no means of "anti-registration"
Left Patch Set: Created 4 years, 1 month ago
Right Patch Set: Created 3 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/test/test_binop.py ('k') | Lib/test/test_bytes.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 class Spam(int): 307 class Spam(int):
308 def __bool__(self): 308 def __bool__(self):
309 return 1 309 return 1
310 check(Spam()) 310 check(Spam())
311 311
312 class Eggs: 312 class Eggs:
313 def __len__(self): 313 def __len__(self):
314 return -1 314 return -1
315 self.assertRaises(ValueError, bool, Eggs()) 315 self.assertRaises(ValueError, bool, Eggs())
316 316
317 def test_from_bytes(self):
318 self.assertIs(bool.from_bytes(b'\x00'*8, 'big'), False)
319 self.assertIs(bool.from_bytes(b'abcd', 'little'), True)
320
317 def test_sane_len(self): 321 def test_sane_len(self):
318 # this test just tests our assumptions about __len__ 322 # this test just tests our assumptions about __len__
319 # this will start failing if __len__ changes assertions 323 # this will start failing if __len__ changes assertions
320 for badval in ['illegal', -1, 1 << 32]: 324 for badval in ['illegal', -1, 1 << 32]:
321 class A: 325 class A:
322 def __len__(self): 326 def __len__(self):
323 return badval 327 return badval
324 try: 328 try:
325 bool(A()) 329 bool(A())
326 except (Exception) as e_bool: 330 except (Exception) as e_bool:
327 try: 331 try:
328 len(A()) 332 len(A())
329 except (Exception) as e_len: 333 except (Exception) as e_len:
330 self.assertEqual(str(e_bool), str(e_len)) 334 self.assertEqual(str(e_bool), str(e_len))
331 335
332 def test_blocked(self): 336 def test_blocked(self):
333 class A: 337 class A:
334 __bool__ = None 338 __bool__ = None
335 self.assertRaises(TypeError, bool, A()) 339 self.assertRaises(TypeError, bool, A())
336 340
337 class B: 341 class B:
338 def __len__(self): 342 def __len__(self):
339 return 10 343 return 10
340 __bool__ = None 344 __bool__ = None
341 self.assertRaises(TypeError, bool, B()) 345 self.assertRaises(TypeError, bool, B())
342 346
343 def test_real_and_imag(self): 347 def test_real_and_imag(self):
344 self.assertEqual(True.real, 1) 348 self.assertEqual(True.real, 1)
345 self.assertEqual(True.imag, 0) 349 self.assertEqual(True.imag, 0)
346 self.assertIs(type(True.real), int) 350 self.assertIs(type(True.real), int)
347 self.assertIs(type(True.imag), int) 351 self.assertIs(type(True.imag), int)
348 self.assertEqual(False.real, 0) 352 self.assertEqual(False.real, 0)
349 self.assertEqual(False.imag, 0) 353 self.assertEqual(False.imag, 0)
350 self.assertIs(type(False.real), int) 354 self.assertIs(type(False.real), int)
351 self.assertIs(type(False.imag), int) 355 self.assertIs(type(False.imag), int)
352 356
353 def test_main(): 357 def test_main():
354 support.run_unittest(BoolTest) 358 support.run_unittest(BoolTest)
355 359
356 if __name__ == "__main__": 360 if __name__ == "__main__":
357 test_main() 361 test_main()
LEFTRIGHT

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