6868import unittest
6969
7070
71- # See localtz.patch
72- try :
73- datetime .fromtimestamp (0 )
74- LOCALTZ = True
75- except NotImplementedError :
76- LOCALTZ = False
77-
78-
7971if hasattr (datetime , "EPOCH" ):
8072 EPOCH = datetime .EPOCH
8173else :
@@ -1619,11 +1611,8 @@ def test___init__24(self):
16191611 def test_fromtimestamp00 (self ):
16201612 with LocalTz ("Europe/Rome" ):
16211613 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 )
16271616
16281617 def test_fromtimestamp01 (self ):
16291618 ts = 1012506303.001234
@@ -1642,48 +1631,35 @@ def test_fromtimestamp04(self):
16421631 dt = datetime (2010 , 10 , 31 , 0 , 30 , tzinfo = timezone .utc )
16431632 ts = (dt - EPOCH ).total_seconds ()
16441633 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 )
16511637
16521638 def test_fromtimestamp05 (self ):
16531639 with LocalTz ("Europe/Rome" ):
16541640 dt = datetime (2010 , 10 , 31 , 1 , 30 , tzinfo = timezone .utc )
16551641 ts = (dt - EPOCH ).total_seconds ()
16561642 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 )
16631646
16641647 def test_fromtimestamp06 (self ):
16651648 with LocalTz ("US/Eastern" ):
16661649 dt = datetime (2020 , 11 , 1 , 5 , 30 , tzinfo = timezone .utc )
16671650 ts = (dt - EPOCH ).total_seconds ()
16681651 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 )
16741654
16751655 def test_fromtimestamp07 (self ):
16761656 with LocalTz ("US/Eastern" ):
16771657 dt = datetime (2020 , 11 , 1 , 7 , 30 , tzinfo = timezone .utc )
16781658 ts = (dt - EPOCH ).total_seconds ()
16791659 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 )
16851662
1686- @unittest .skipIf (not LOCALTZ , "naive datetime not supported" )
16871663 def test_now00 (self ):
16881664 tm = datetime (* mod_time .localtime ()[:6 ])
16891665 dt = datetime .now ()
@@ -2004,46 +1980,31 @@ def test_astimezone04(self):
20041980 with LocalTz ("Europe/Rome" ):
20051981 dt1 = dt27tz2
20061982 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 ))
20111984
20121985 def test_astimezone05 (self ):
20131986 with LocalTz ("Europe/Rome" ):
20141987 dt1 = dt28tz2
20151988 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 ))
20201990
20211991 def test_astimezone06 (self ):
20221992 with LocalTz ("Europe/Rome" ):
20231993 dt1 = dt30tz2
20241994 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 ))
20291996
20301997 def test_astimezone07 (self ):
20311998 with LocalTz ("Europe/Rome" ):
20321999 dt1 = dt31tz2
20332000 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 ))
20382002
20392003 def test_astimezone08 (self ):
20402004 with LocalTz ("Europe/Rome" ):
20412005 dt1 = dt3
20422006 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 ))
20472008
20482009 def test_utcoffset00 (self ):
20492010 self .assertEqual (dt1 .utcoffset (), None )
@@ -2123,77 +2084,50 @@ def test_weekday00(self):
21232084
21242085 def test_timestamp00 (self ):
21252086 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 )
21302088
21312089 def test_timestamp01 (self ):
21322090 self .assertEqual (d1t1z .timestamp (), 1012506303.001234 )
21332091
21342092 def test_timestamp02 (self ):
21352093 with LocalTz ("Europe/Rome" ):
21362094 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 )
21412096
21422097 def test_timestamp03 (self ):
21432098 with LocalTz ("Europe/Rome" ):
21442099 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 )
21492101
21502102 def test_timestamp04 (self ):
21512103 with LocalTz ("Europe/Rome" ):
21522104 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 )
21572106
21582107 def test_timestamp05 (self ):
21592108 with LocalTz ("Europe/Rome" ):
21602109 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 )
21652111
21662112 def test_timestamp06 (self ):
21672113 with LocalTz ("US/Eastern" ):
21682114 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 )
21732116
21742117 def test_timestamp07 (self ):
21752118 with LocalTz ("US/Eastern" ):
21762119 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 )
21812121
21822122 def test_timestamp08 (self ):
21832123 with LocalTz ("US/Eastern" ):
21842124 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 )
21892126
21902127 def test_timestamp09 (self ):
21912128 with LocalTz ("US/Eastern" ):
21922129 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 )
21972131
21982132 def test_isoweekday00 (self ):
21992133 self .assertEqual (dt1 .isoweekday (), d1 .isoweekday ())
0 commit comments