diff options
author | Alexander Belopolsky <alexander.belopolsky@gmail.com> | 2010-06-18 18:44:37 (GMT) |
---|---|---|
committer | Alexander Belopolsky <alexander.belopolsky@gmail.com> | 2010-06-18 18:44:37 (GMT) |
commit | f568218e7e6211fa93d390eb327379776962867e (patch) | |
tree | 3c397cb0eb3030ac9bdd5c5d7504eab7d697c2a0 /Lib/test/test_datetime.py | |
parent | 49d7a57f33f2ed984f41082d02e1a1834778225d (diff) | |
download | cpython-f568218e7e6211fa93d390eb327379776962867e.zip cpython-f568218e7e6211fa93d390eb327379776962867e.tar.gz cpython-f568218e7e6211fa93d390eb327379776962867e.tar.bz2 |
Issue #6641: Original commit for this issue, r82053, introduced a
regression making datetime subclass' strptime return datetime rather
than subclass instances. Fixed this bug and a few typos.
Diffstat (limited to 'Lib/test/test_datetime.py')
-rw-r--r-- | Lib/test/test_datetime.py | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/Lib/test/test_datetime.py b/Lib/test/test_datetime.py index b320e1f..42c18e6 100644 --- a/Lib/test/test_datetime.py +++ b/Lib/test/test_datetime.py @@ -1100,8 +1100,13 @@ class TestDate(HarmlessMixedComparison, unittest.TestCase): self.assertEqual(b.__format__(fmt), 'B') def test_resolution_info(self): - self.assertIsInstance(self.theclass.min, self.theclass) - self.assertIsInstance(self.theclass.max, self.theclass) + # XXX: Should min and max respect subclassing? + if issubclass(self.theclass, datetime): + expected_class = datetime + else: + expected_class = date + self.assertIsInstance(self.theclass.min, expected_class) + self.assertIsInstance(self.theclass.max, expected_class) self.assertIsInstance(self.theclass.resolution, timedelta) self.assertTrue(self.theclass.max > self.theclass.min) @@ -1732,9 +1737,11 @@ class TestDateTime(TestDate): string = '2004-12-01 13:02:47.197' format = '%Y-%m-%d %H:%M:%S.%f' - expected = _strptime._strptime_datetime(string, format) + expected = _strptime._strptime_datetime(self.theclass, string, format) got = self.theclass.strptime(string, format) self.assertEqual(expected, got) + self.assertIs(type(expected), self.theclass) + self.assertIs(type(got), self.theclass) strptime = self.theclass.strptime self.assertEqual(strptime("+0002", "%z").utcoffset(), 2 * MINUTE) @@ -1896,6 +1903,12 @@ class TestDateTime(TestDate): self.assertEqual(dt2.newmeth(-7), dt1.year + dt1.month + dt1.second - 7) +class TestSubclassDateTime(TestDateTime): + theclass = SubclassDatetime + # Override tests not designed for subclass + def test_roundtrip(self): + pass + class SubclassTime(time): sub_var = 1 |