summaryrefslogtreecommitdiffstats
path: root/Lib/test/datetimetester.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2017-11-10 00:52:05 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2017-11-10 00:52:05 (GMT)
commitb9a40aca2935d2569191844c88f8b61269e383cb (patch)
tree77d18498d553e8369c34724371ec7c681daf4e2f /Lib/test/datetimetester.py
parent596286f8f3c8e53ef010d6298464775dc900a515 (diff)
downloadcpython-b9a40aca2935d2569191844c88f8b61269e383cb.zip
cpython-b9a40aca2935d2569191844c88f8b61269e383cb.tar.gz
cpython-b9a40aca2935d2569191844c88f8b61269e383cb.tar.bz2
bpo-31222: Make (datetime|date|time).replace return subclass type in Pure Python (GH-4176) (#4356)
(cherry picked from commit 191e993365ac3206f46132dcf46236471ec54bfa)
Diffstat (limited to 'Lib/test/datetimetester.py')
-rw-r--r--Lib/test/datetimetester.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py
index c00e38c..f23a530 100644
--- a/Lib/test/datetimetester.py
+++ b/Lib/test/datetimetester.py
@@ -1500,6 +1500,13 @@ class TestDate(HarmlessMixedComparison, unittest.TestCase):
base = cls(2000, 2, 29)
self.assertRaises(ValueError, base.replace, year=2001)
+ def test_subclass_replace(self):
+ class DateSubclass(self.theclass):
+ pass
+
+ dt = DateSubclass(2012, 1, 1)
+ self.assertIs(type(dt.replace(year=2013)), DateSubclass)
+
def test_subclass_date(self):
class C(self.theclass):
@@ -2599,6 +2606,13 @@ class TestTime(HarmlessMixedComparison, unittest.TestCase):
self.assertRaises(ValueError, base.replace, second=100)
self.assertRaises(ValueError, base.replace, microsecond=1000000)
+ def test_subclass_replace(self):
+ class TimeSubclass(self.theclass):
+ pass
+
+ ctime = TimeSubclass(12, 30)
+ self.assertIs(type(ctime.replace(hour=10)), TimeSubclass)
+
def test_subclass_time(self):
class C(self.theclass):