@@ -2228,7 +2228,7 @@ def test_tzinfo_now(self):
22282228 # Try with and without naming the keyword.
22292229 off42 = FixedOffset (42 , "42" )
22302230 another = meth (off42 )
2231- again = meth (tzinfo = off42 )
2231+ again = meth (tz = off42 )
22322232 self .failUnless (another .tzinfo is again .tzinfo )
22332233 self .assertEqual (another .utcoffset (), timedelta (minutes = 42 ))
22342234 # Bad argument with and w/o naming the keyword.
@@ -2239,6 +2239,24 @@ def test_tzinfo_now(self):
22392239 # Too many args.
22402240 self .assertRaises (TypeError , meth , off42 , off42 )
22412241
2242+ # We don't know which time zone we're in, and don't have a tzinfo
2243+ # class to represent it, so seeing whether a tz argument actually
2244+ # does a conversion is tricky.
2245+ weirdtz = FixedOffset (timedelta (hours = 15 , minutes = 58 ), "weirdtz" , 0 )
2246+ utc = FixedOffset (0 , "utc" , 0 )
2247+ for dummy in range (3 ):
2248+ now = datetime .now (weirdtz )
2249+ self .failUnless (now .tzinfo is weirdtz )
2250+ utcnow = datetime .utcnow ().replace (tzinfo = utc )
2251+ now2 = utcnow .astimezone (weirdtz )
2252+ if abs (now - now2 ) < timedelta (seconds = 30 ):
2253+ break
2254+ # Else the code is broken, or more than 30 seconds passed between
2255+ # calls; assuming the latter, just try again.
2256+ else :
2257+ # Three strikes and we're out.
2258+ self .fail ("utcnow(), now(tz), or astimezone() may be broken" )
2259+
22422260 def test_tzinfo_fromtimestamp (self ):
22432261 import time
22442262 meth = self .theclass .fromtimestamp
@@ -2448,7 +2466,7 @@ def test_more_astimezone(self):
24482466 f44m = FixedOffset (44 , "44" )
24492467 fm5h = FixedOffset (- timedelta (hours = 5 ), "m300" )
24502468
2451- dt = self .theclass .now (tzinfo = f44m )
2469+ dt = self .theclass .now (tz = f44m )
24522470 self .failUnless (dt .tzinfo is f44m )
24532471 # Replacing with degenerate tzinfo raises an exception.
24542472 self .assertRaises (ValueError , dt .astimezone , fnone )
0 commit comments