summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2003-05-17 02:25:20 (GMT)
committerTim Peters <tim.peters@gmail.com>2003-05-17 02:25:20 (GMT)
commiteb1a496039d39135188bbee20e348e796c4807ea (patch)
tree5ddb713aa77282fdab84812fa442473bcde98d00
parent1ba24b4fbb1c675cd2edbdf2b1c0fbb5054b8969 (diff)
downloadcpython-eb1a496039d39135188bbee20e348e796c4807ea.zip
cpython-eb1a496039d39135188bbee20e348e796c4807ea.tar.gz
cpython-eb1a496039d39135188bbee20e348e796c4807ea.tar.bz2
test_subclass_date(): Beefed this up, to check that new instance
attributes and methods work, that new arguments can be passed to the constructor, and that inherited methods and attrs still work. Added XXX comments about what to do when datetime becomes usably subclassable too (it's not yet).
-rw-r--r--Lib/test/test_datetime.py30
1 files changed, 28 insertions, 2 deletions
diff --git a/Lib/test/test_datetime.py b/Lib/test/test_datetime.py
index b86286b..51b5f4f 100644
--- a/Lib/test/test_datetime.py
+++ b/Lib/test/test_datetime.py
@@ -480,10 +480,35 @@ class TestDateOnly(unittest.TestCase):
self.assertEqual(dt2, dt - days)
def test_subclass_date(self):
+
+ # XXX When datetime becomes usably subclassable, uncomment the
+ # XXX "self.theclass" lines and move this into TestDate.
+ # class C(self.theclass):
class C(date):
theAnswer = 42
- dt = C(2003, 4, 14)
- self.assertEqual(dt.__class__, C)
+
+ def __new__(cls, *args, **kws):
+ temp = kws.copy()
+ extra = temp.pop('extra')
+ # result = self.theclass.__new__(cls, *args, **temp)
+ result = date.__new__(cls, *args, **temp)
+ result.extra = extra
+ return result
+
+ def newmeth(self, start):
+ return start + self.year + self.month
+
+ args = 2003, 4, 14
+
+ # dt1 = self.theclass(*args)
+ dt1 = date(*args)
+ dt2 = C(*args, **{'extra': 7})
+
+ self.assertEqual(dt2.__class__, C)
+ self.assertEqual(dt2.theAnswer, 42)
+ self.assertEqual(dt2.extra, 7)
+ self.assertEqual(dt1.toordinal(), dt2.toordinal())
+ self.assertEqual(dt2.newmeth(-7), dt1.year + dt1.month - 7)
class TestDate(HarmlessMixedComparison):
# Tests here should pass for both dates and datetimes, except for a
@@ -977,6 +1002,7 @@ class TestDate(HarmlessMixedComparison):
base = cls(2000, 2, 29)
self.assertRaises(ValueError, base.replace, year=2001)
+
#############################################################################
# datetime tests