summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2003-01-23 19:58:02 (GMT)
committerTim Peters <tim.peters@gmail.com>2003-01-23 19:58:02 (GMT)
commit10cadce41ec7b94aafc11b4f2c9cfb7587f5b81d (patch)
treea08fd27ddaa04db1b7cad9c552b08fd964e53a68 /Lib/test
parent250684ddd8223de98b5944d13e89a12673d0a51a (diff)
downloadcpython-10cadce41ec7b94aafc11b4f2c9cfb7587f5b81d.zip
cpython-10cadce41ec7b94aafc11b4f2c9cfb7587f5b81d.tar.gz
cpython-10cadce41ec7b94aafc11b4f2c9cfb7587f5b81d.tar.bz2
Reimplemented datetime.now() to be useful.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_datetime.py22
1 files changed, 20 insertions, 2 deletions
diff --git a/Lib/test/test_datetime.py b/Lib/test/test_datetime.py
index 8878386..7d503e0 100644
--- a/Lib/test/test_datetime.py
+++ b/Lib/test/test_datetime.py
@@ -2228,7 +2228,7 @@ class TestDateTimeTZ(TestDateTime, TZInfoBase):
# Try with and without naming the keyword.
off42 = FixedOffset(42, "42")
another = meth(off42)
- again = meth(tzinfo=off42)
+ again = meth(tz=off42)
self.failUnless(another.tzinfo is again.tzinfo)
self.assertEqual(another.utcoffset(), timedelta(minutes=42))
# Bad argument with and w/o naming the keyword.
@@ -2239,6 +2239,24 @@ class TestDateTimeTZ(TestDateTime, TZInfoBase):
# Too many args.
self.assertRaises(TypeError, meth, off42, off42)
+ # We don't know which time zone we're in, and don't have a tzinfo
+ # class to represent it, so seeing whether a tz argument actually
+ # does a conversion is tricky.
+ weirdtz = FixedOffset(timedelta(hours=15, minutes=58), "weirdtz", 0)
+ utc = FixedOffset(0, "utc", 0)
+ for dummy in range(3):
+ now = datetime.now(weirdtz)
+ self.failUnless(now.tzinfo is weirdtz)
+ utcnow = datetime.utcnow().replace(tzinfo=utc)
+ now2 = utcnow.astimezone(weirdtz)
+ if abs(now - now2) < timedelta(seconds=30):
+ break
+ # Else the code is broken, or more than 30 seconds passed between
+ # calls; assuming the latter, just try again.
+ else:
+ # Three strikes and we're out.
+ self.fail("utcnow(), now(tz), or astimezone() may be broken")
+
def test_tzinfo_fromtimestamp(self):
import time
meth = self.theclass.fromtimestamp
@@ -2448,7 +2466,7 @@ class TestDateTimeTZ(TestDateTime, TZInfoBase):
f44m = FixedOffset(44, "44")
fm5h = FixedOffset(-timedelta(hours=5), "m300")
- dt = self.theclass.now(tzinfo=f44m)
+ dt = self.theclass.now(tz=f44m)
self.failUnless(dt.tzinfo is f44m)
# Replacing with degenerate tzinfo raises an exception.
self.assertRaises(ValueError, dt.astimezone, fnone)