[Python-checkins] r82173 - in sandbox/branches/py3k-datetime: datetime.py test_datetime.py

alexander.belopolsky python-checkins at python.org
Wed Jun 23 02:44:25 CEST 2010


Author: alexander.belopolsky
Date: Wed Jun 23 02:44:25 2010
New Revision: 82173

Log:
Removed unused code and added tests for nearly complete coverage.

Modified:
   sandbox/branches/py3k-datetime/datetime.py
   sandbox/branches/py3k-datetime/test_datetime.py

Modified: sandbox/branches/py3k-datetime/datetime.py
==============================================================================
--- sandbox/branches/py3k-datetime/datetime.py	(original)
+++ sandbox/branches/py3k-datetime/datetime.py	Wed Jun 23 02:44:25 2010
@@ -1209,12 +1209,6 @@
         _check_tzinfo_arg(tzinfo)
         return time(hour, minute, second, microsecond, tzinfo)
 
-    # Return an integer (or None) instead of a timedelta (or None).
-    def _dst(self):
-        offset = _call_tzinfo_method(self._tzinfo, "dst", None)
-        offset = _check_utc_offset("dst", offset)
-        return offset
-
     def __bool__(self):
         if self.second or self.microsecond:
             return True

Modified: sandbox/branches/py3k-datetime/test_datetime.py
==============================================================================
--- sandbox/branches/py3k-datetime/test_datetime.py	(original)
+++ sandbox/branches/py3k-datetime/test_datetime.py	Wed Jun 23 02:44:25 2010
@@ -171,6 +171,7 @@
         with self.assertRaises(TypeError): timezone(42)
         with self.assertRaises(TypeError): timezone(ZERO, None)
         with self.assertRaises(TypeError): timezone(ZERO, 42)
+        with self.assertRaises(TypeError): timezone(ZERO, 'ABC', 'extra')
 
     def test_inheritance(self):
         self.assertIsInstance(timezone.utc, tzinfo)
@@ -206,6 +207,8 @@
     def test_fromutc(self):
         with self.assertRaises(ValueError):
             timezone.utc.fromutc(self.DT)
+        with self.assertRaises(TypeError):
+            timezone.utc.fromutc('not datetime')
         for tz in [self.EST, self.ACDT, Eastern]:
             utctime = self.DT.replace(tzinfo=tz)
             local = tz.fromutc(utctime)
@@ -1844,6 +1847,8 @@
         self.assertRaises(TypeError, combine, t, d) # args reversed
         self.assertRaises(TypeError, combine, d, t, 1) # too many args
         self.assertRaises(TypeError, combine, "date", "time") # wrong types
+        self.assertRaises(TypeError, combine, d, "time") # wrong type
+        self.assertRaises(TypeError, combine, "date", t) # wrong type
 
     def test_replace(self):
         cls = self.theclass
@@ -1886,6 +1891,8 @@
             def dst(self, dt): return timedelta(0)
         bog = Bogus()
         self.assertRaises(ValueError, dt.astimezone, bog)   # naive
+        self.assertRaises(ValueError,
+                          dt.replace(tzinfo=bog).astimezone, f)
 
         class AlsoBogus(tzinfo):
             def utcoffset(self, dt): return timedelta(0)
@@ -2862,6 +2869,11 @@
         maxdiff = max - min
         self.assertEqual(maxdiff, self.theclass.max - self.theclass.min +
                                   timedelta(minutes=2*1439))
+        # Different tzinfo, but the same offset
+        tza = timezone(HOUR, 'A')
+        tzb = timezone(HOUR, 'B')
+        delta = min.replace(tzinfo=tza) - max.replace(tzinfo=tzb)
+        self.assertEqual(delta, self.theclass.min - self.theclass.max)
 
     def test_tzinfo_now(self):
         meth = self.theclass.now


More information about the Python-checkins mailing list