@@ -369,12 +369,14 @@ def __trunc__(self):
369
369
class JustTrunc (base ):
370
370
def __trunc__ (self ):
371
371
return 42
372
- self .assertEqual (int (JustTrunc ()), 42 )
372
+ with self .assertWarns (DeprecationWarning ):
373
+ self .assertEqual (int (JustTrunc ()), 42 )
373
374
374
375
class ExceptionalTrunc (base ):
375
376
def __trunc__ (self ):
376
377
1 / 0
377
- with self .assertRaises (ZeroDivisionError ):
378
+ with self .assertRaises (ZeroDivisionError ), \
379
+ self .assertWarns (DeprecationWarning ):
378
380
int (ExceptionalTrunc ())
379
381
380
382
for trunc_result_base in (object , Classic ):
@@ -385,7 +387,8 @@ def __index__(self):
385
387
class TruncReturnsNonInt (base ):
386
388
def __trunc__ (self ):
387
389
return Index ()
388
- self .assertEqual (int (TruncReturnsNonInt ()), 42 )
390
+ with self .assertWarns (DeprecationWarning ):
391
+ self .assertEqual (int (TruncReturnsNonInt ()), 42 )
389
392
390
393
class Intable (trunc_result_base ):
391
394
def __int__ (self ):
@@ -394,7 +397,8 @@ def __int__(self):
394
397
class TruncReturnsNonIndex (base ):
395
398
def __trunc__ (self ):
396
399
return Intable ()
397
- self .assertEqual (int (TruncReturnsNonInt ()), 42 )
400
+ with self .assertWarns (DeprecationWarning ):
401
+ self .assertEqual (int (TruncReturnsNonInt ()), 42 )
398
402
399
403
class NonIntegral (trunc_result_base ):
400
404
def __trunc__ (self ):
@@ -405,7 +409,8 @@ class TruncReturnsNonIntegral(base):
405
409
def __trunc__ (self ):
406
410
return NonIntegral ()
407
411
try :
408
- int (TruncReturnsNonIntegral ())
412
+ with self .assertWarns (DeprecationWarning ):
413
+ int (TruncReturnsNonIntegral ())
409
414
except TypeError as e :
410
415
self .assertEqual (str (e ),
411
416
"__trunc__ returned non-Integral"
@@ -423,7 +428,8 @@ class TruncReturnsBadInt(base):
423
428
def __trunc__ (self ):
424
429
return BadInt ()
425
430
426
- with self .assertRaises (TypeError ):
431
+ with self .assertRaises (TypeError ), \
432
+ self .assertWarns (DeprecationWarning ):
427
433
int (TruncReturnsBadInt ())
428
434
429
435
def test_int_subclass_with_index (self ):
@@ -458,8 +464,6 @@ def __int__(self):
458
464
self .assertEqual (my_int , 7 )
459
465
self .assertRaises (TypeError , int , my_int )
460
466
461
- # TODO: RUSTPYTHON
462
- @unittest .expectedFailure
463
467
def test_int_returns_int_subclass (self ):
464
468
class BadIndex :
465
469
def __index__ (self ):
@@ -519,13 +523,16 @@ def __trunc__(self):
519
523
self .assertIs (type (n ), int )
520
524
521
525
bad_int = TruncReturnsBadInt ()
522
- self .assertRaises (TypeError , int , bad_int )
526
+ with self .assertWarns (DeprecationWarning ):
527
+ self .assertRaises (TypeError , int , bad_int )
523
528
524
529
good_int = TruncReturnsIntSubclass ()
525
- n = int (good_int )
530
+ with self .assertWarns (DeprecationWarning ):
531
+ n = int (good_int )
526
532
self .assertEqual (n , 1 )
527
533
self .assertIs (type (n ), int )
528
- n = IntSubclass (good_int )
534
+ with self .assertWarns (DeprecationWarning ):
535
+ n = IntSubclass (good_int )
529
536
self .assertEqual (n , 1 )
530
537
self .assertIs (type (n ), IntSubclass )
531
538
0 commit comments