68
68
import unittest
69
69
70
70
71
- # See localtz.patch
72
- try :
73
- datetime .fromtimestamp (0 )
74
- LOCALTZ = True
75
- except NotImplementedError :
76
- LOCALTZ = False
77
-
78
-
79
71
if hasattr (datetime , "EPOCH" ):
80
72
EPOCH = datetime .EPOCH
81
73
else :
@@ -1619,11 +1611,8 @@ def test___init__24(self):
1619
1611
def test_fromtimestamp00 (self ):
1620
1612
with LocalTz ("Europe/Rome" ):
1621
1613
ts = 1012499103.001234
1622
- if LOCALTZ :
1623
- dt = datetime .fromtimestamp (ts )
1624
- self .assertEqual (dt , d1t1 )
1625
- else :
1626
- self .assertRaises (NotImplementedError , datetime .fromtimestamp , ts )
1614
+ dt = datetime .fromtimestamp (ts )
1615
+ self .assertEqual (dt , d1t1 )
1627
1616
1628
1617
def test_fromtimestamp01 (self ):
1629
1618
ts = 1012506303.001234
@@ -1642,48 +1631,35 @@ def test_fromtimestamp04(self):
1642
1631
dt = datetime (2010 , 10 , 31 , 0 , 30 , tzinfo = timezone .utc )
1643
1632
ts = (dt - EPOCH ).total_seconds ()
1644
1633
dt = dt .replace (tzinfo = None ) + 2 * td1h
1645
- if LOCALTZ :
1646
- ds = datetime .fromtimestamp (ts )
1647
- self .assertEqual (ds , dt )
1648
- self .assertFalse (ds .fold )
1649
- else :
1650
- self .assertRaises (NotImplementedError , datetime .fromtimestamp , ts )
1634
+ ds = datetime .fromtimestamp (ts )
1635
+ self .assertEqual (ds , dt )
1636
+ self .assertFalse (ds .fold )
1651
1637
1652
1638
def test_fromtimestamp05 (self ):
1653
1639
with LocalTz ("Europe/Rome" ):
1654
1640
dt = datetime (2010 , 10 , 31 , 1 , 30 , tzinfo = timezone .utc )
1655
1641
ts = (dt - EPOCH ).total_seconds ()
1656
1642
dt = dt .replace (tzinfo = None ) + 1 * td1h
1657
- if LOCALTZ :
1658
- ds = datetime .fromtimestamp (ts )
1659
- self .assertEqual (ds , dt )
1660
- self .assertTrue (ds .fold )
1661
- else :
1662
- self .assertRaises (NotImplementedError , datetime .fromtimestamp , ts )
1643
+ ds = datetime .fromtimestamp (ts )
1644
+ self .assertEqual (ds , dt )
1645
+ self .assertTrue (ds .fold )
1663
1646
1664
1647
def test_fromtimestamp06 (self ):
1665
1648
with LocalTz ("US/Eastern" ):
1666
1649
dt = datetime (2020 , 11 , 1 , 5 , 30 , tzinfo = timezone .utc )
1667
1650
ts = (dt - EPOCH ).total_seconds ()
1668
1651
dt = dt .replace (tzinfo = None ) - 4 * td1h
1669
- if LOCALTZ :
1670
- ds = datetime .fromtimestamp (ts )
1671
- self .assertEqual (ds , dt )
1672
- else :
1673
- self .assertRaises (NotImplementedError , datetime .fromtimestamp , ts )
1652
+ ds = datetime .fromtimestamp (ts )
1653
+ self .assertEqual (ds , dt )
1674
1654
1675
1655
def test_fromtimestamp07 (self ):
1676
1656
with LocalTz ("US/Eastern" ):
1677
1657
dt = datetime (2020 , 11 , 1 , 7 , 30 , tzinfo = timezone .utc )
1678
1658
ts = (dt - EPOCH ).total_seconds ()
1679
1659
dt = dt .replace (tzinfo = None ) - 5 * td1h
1680
- if LOCALTZ :
1681
- ds = datetime .fromtimestamp (ts )
1682
- self .assertEqual (ds , dt )
1683
- else :
1684
- self .assertRaises (NotImplementedError , datetime .fromtimestamp , ts )
1660
+ ds = datetime .fromtimestamp (ts )
1661
+ self .assertEqual (ds , dt )
1685
1662
1686
- @unittest .skipIf (not LOCALTZ , "naive datetime not supported" )
1687
1663
def test_now00 (self ):
1688
1664
tm = datetime (* mod_time .localtime ()[:6 ])
1689
1665
dt = datetime .now ()
@@ -2004,46 +1980,31 @@ def test_astimezone04(self):
2004
1980
with LocalTz ("Europe/Rome" ):
2005
1981
dt1 = dt27tz2
2006
1982
dt2 = dt1 .replace (tzinfo = None )
2007
- if LOCALTZ :
2008
- self .assertEqual (dt1 , dt2 .astimezone (tz2 ))
2009
- else :
2010
- self .assertRaises (NotImplementedError , dt2 .astimezone , tz2 )
1983
+ self .assertEqual (dt1 , dt2 .astimezone (tz2 ))
2011
1984
2012
1985
def test_astimezone05 (self ):
2013
1986
with LocalTz ("Europe/Rome" ):
2014
1987
dt1 = dt28tz2
2015
1988
dt2 = dt1 .replace (tzinfo = None )
2016
- if LOCALTZ :
2017
- self .assertEqual (dt1 , dt2 .astimezone (tz2 ))
2018
- else :
2019
- self .assertRaises (NotImplementedError , dt2 .astimezone , tz2 )
1989
+ self .assertEqual (dt1 , dt2 .astimezone (tz2 ))
2020
1990
2021
1991
def test_astimezone06 (self ):
2022
1992
with LocalTz ("Europe/Rome" ):
2023
1993
dt1 = dt30tz2
2024
1994
dt2 = dt1 .replace (tzinfo = None )
2025
- if LOCALTZ :
2026
- self .assertEqual (dt1 , dt2 .astimezone (tz2 ))
2027
- else :
2028
- self .assertRaises (NotImplementedError , dt2 .astimezone , tz2 )
1995
+ self .assertEqual (dt1 , dt2 .astimezone (tz2 ))
2029
1996
2030
1997
def test_astimezone07 (self ):
2031
1998
with LocalTz ("Europe/Rome" ):
2032
1999
dt1 = dt31tz2
2033
2000
dt2 = dt1 .replace (tzinfo = None )
2034
- if LOCALTZ :
2035
- self .assertEqual (dt1 , dt2 .astimezone (tz2 ))
2036
- else :
2037
- self .assertRaises (NotImplementedError , dt2 .astimezone , tz2 )
2001
+ self .assertEqual (dt1 , dt2 .astimezone (tz2 ))
2038
2002
2039
2003
def test_astimezone08 (self ):
2040
2004
with LocalTz ("Europe/Rome" ):
2041
2005
dt1 = dt3
2042
2006
dt2 = dt1 .replace (tzinfo = None )
2043
- if LOCALTZ :
2044
- self .assertEqual (dt1 , dt2 .astimezone (tz2 ))
2045
- else :
2046
- self .assertRaises (NotImplementedError , dt2 .astimezone , tz2 )
2007
+ self .assertEqual (dt1 , dt2 .astimezone (tz2 ))
2047
2008
2048
2009
def test_utcoffset00 (self ):
2049
2010
self .assertEqual (dt1 .utcoffset (), None )
@@ -2123,77 +2084,50 @@ def test_weekday00(self):
2123
2084
2124
2085
def test_timestamp00 (self ):
2125
2086
with LocalTz ("Europe/Rome" ):
2126
- if LOCALTZ :
2127
- self .assertEqual (d1t1 .timestamp (), 1012499103.001234 )
2128
- else :
2129
- self .assertRaises (NotImplementedError , d1t1 .timestamp )
2087
+ self .assertEqual (d1t1 .timestamp (), 1012499103.001234 )
2130
2088
2131
2089
def test_timestamp01 (self ):
2132
2090
self .assertEqual (d1t1z .timestamp (), 1012506303.001234 )
2133
2091
2134
2092
def test_timestamp02 (self ):
2135
2093
with LocalTz ("Europe/Rome" ):
2136
2094
dt = datetime (2010 , 3 , 28 , 2 , 30 ) # doens't exist
2137
- if LOCALTZ :
2138
- self .assertEqual (dt .timestamp (), 1269739800.0 )
2139
- else :
2140
- self .assertRaises (NotImplementedError , dt .timestamp )
2095
+ self .assertEqual (dt .timestamp (), 1269739800.0 )
2141
2096
2142
2097
def test_timestamp03 (self ):
2143
2098
with LocalTz ("Europe/Rome" ):
2144
2099
dt = datetime (2010 , 8 , 10 , 2 , 30 )
2145
- if LOCALTZ :
2146
- self .assertEqual (dt .timestamp (), 1281400200.0 )
2147
- else :
2148
- self .assertRaises (NotImplementedError , dt .timestamp )
2100
+ self .assertEqual (dt .timestamp (), 1281400200.0 )
2149
2101
2150
2102
def test_timestamp04 (self ):
2151
2103
with LocalTz ("Europe/Rome" ):
2152
2104
dt = datetime (2010 , 10 , 31 , 2 , 30 , fold = 0 )
2153
- if LOCALTZ :
2154
- self .assertEqual (dt .timestamp (), 1288485000.0 )
2155
- else :
2156
- self .assertRaises (NotImplementedError , dt .timestamp )
2105
+ self .assertEqual (dt .timestamp (), 1288485000.0 )
2157
2106
2158
2107
def test_timestamp05 (self ):
2159
2108
with LocalTz ("Europe/Rome" ):
2160
2109
dt = datetime (2010 , 10 , 31 , 2 , 30 , fold = 1 )
2161
- if LOCALTZ :
2162
- self .assertEqual (dt .timestamp (), 1288488600.0 )
2163
- else :
2164
- self .assertRaises (NotImplementedError , dt .timestamp )
2110
+ self .assertEqual (dt .timestamp (), 1288488600.0 )
2165
2111
2166
2112
def test_timestamp06 (self ):
2167
2113
with LocalTz ("US/Eastern" ):
2168
2114
dt = datetime (2020 , 3 , 8 , 2 , 30 ) # doens't exist
2169
- if LOCALTZ :
2170
- self .assertEqual (dt .timestamp (), 1583652600.0 )
2171
- else :
2172
- self .assertRaises (NotImplementedError , dt .timestamp )
2115
+ self .assertEqual (dt .timestamp (), 1583652600.0 )
2173
2116
2174
2117
def test_timestamp07 (self ):
2175
2118
with LocalTz ("US/Eastern" ):
2176
2119
dt = datetime (2020 , 8 , 10 , 2 , 30 )
2177
- if LOCALTZ :
2178
- self .assertEqual (dt .timestamp (), 1597041000.0 )
2179
- else :
2180
- self .assertRaises (NotImplementedError , dt .timestamp )
2120
+ self .assertEqual (dt .timestamp (), 1597041000.0 )
2181
2121
2182
2122
def test_timestamp08 (self ):
2183
2123
with LocalTz ("US/Eastern" ):
2184
2124
dt = datetime (2020 , 11 , 1 , 2 , 30 , fold = 0 )
2185
- if LOCALTZ :
2186
- self .assertEqual (dt .timestamp (), 1604215800.0 )
2187
- else :
2188
- self .assertRaises (NotImplementedError , dt .timestamp )
2125
+ self .assertEqual (dt .timestamp (), 1604215800.0 )
2189
2126
2190
2127
def test_timestamp09 (self ):
2191
2128
with LocalTz ("US/Eastern" ):
2192
2129
dt = datetime (2020 , 11 , 1 , 2 , 30 , fold = 1 )
2193
- if LOCALTZ :
2194
- self .assertEqual (dt .timestamp (), 1604215800.0 )
2195
- else :
2196
- self .assertRaises (NotImplementedError , dt .timestamp )
2130
+ self .assertEqual (dt .timestamp (), 1604215800.0 )
2197
2131
2198
2132
def test_isoweekday00 (self ):
2199
2133
self .assertEqual (dt1 .isoweekday (), d1 .isoweekday ())
0 commit comments