14
14
import re
15
15
import struct
16
16
import unittest
17
+ import warnings
17
18
18
19
from array import array
19
20
51
52
# mixed-type comparisons.
52
53
OTHERSTUFF = (10 , 34.5 , "abc" , {}, [], ())
53
54
54
-
55
55
# XXX Copied from test_float.
56
56
INF = float ("inf" )
57
57
NAN = float ("nan" )
@@ -2649,9 +2649,10 @@ def test_utcfromtimestamp_limits(self):
2649
2649
for test_name , ts in test_cases :
2650
2650
with self .subTest (test_name , ts = ts ):
2651
2651
with self .assertRaises ((ValueError , OverflowError )):
2652
- # converting a Python int to C time_t can raise a
2653
- # OverflowError, especially on 32-bit platforms.
2654
- self .theclass .utcfromtimestamp (ts )
2652
+ with self .assertWarns (DeprecationWarning ):
2653
+ # converting a Python int to C time_t can raise a
2654
+ # OverflowError, especially on 32-bit platforms.
2655
+ self .theclass .utcfromtimestamp (ts )
2655
2656
2656
2657
def test_insane_fromtimestamp (self ):
2657
2658
# It's possible that some platform maps time_t to double,
@@ -2668,8 +2669,9 @@ def test_insane_utcfromtimestamp(self):
2668
2669
# exempt such platforms (provided they return reasonable
2669
2670
# results!).
2670
2671
for insane in - 1e200 , 1e200 :
2671
- self .assertRaises (OverflowError , self .theclass .utcfromtimestamp ,
2672
- insane )
2672
+ with self .assertWarns (DeprecationWarning ):
2673
+ self .assertRaises (OverflowError , self .theclass .utcfromtimestamp ,
2674
+ insane )
2673
2675
2674
2676
@unittest .skipIf (sys .platform == "win32" , "Windows doesn't accept negative timestamps" )
2675
2677
def test_negative_float_fromtimestamp (self ):
@@ -3028,7 +3030,7 @@ def __new__(cls, *args, **kwargs):
3028
3030
for name , meth_name , kwargs in test_cases :
3029
3031
with self .subTest (name ):
3030
3032
constr = getattr (DateTimeSubclass , meth_name )
3031
- if constr == "utcnow" :
3033
+ if meth_name == "utcnow" :
3032
3034
with self .assertWarns (DeprecationWarning ):
3033
3035
dt = constr (** kwargs )
3034
3036
else :
@@ -4756,8 +4758,10 @@ def test_tzinfo_utcfromtimestamp(self):
4756
4758
# Try with and without naming the keyword; for whatever reason,
4757
4759
# utcfromtimestamp() doesn't accept a tzinfo argument.
4758
4760
off42 = FixedOffset (42 , "42" )
4759
- self .assertRaises (TypeError , meth , ts , off42 )
4760
- self .assertRaises (TypeError , meth , ts , tzinfo = off42 )
4761
+ with warnings .catch_warnings (category = DeprecationWarning ):
4762
+ warnings .simplefilter ("ignore" , category = DeprecationWarning )
4763
+ self .assertRaises (TypeError , meth , ts , off42 )
4764
+ self .assertRaises (TypeError , meth , ts , tzinfo = off42 )
4761
4765
4762
4766
def test_tzinfo_timetuple (self ):
4763
4767
# TestDateTime tested most of this. datetime adds a twist to the
0 commit comments