summaryrefslogtreecommitdiff
path: root/Lib/test/datetimetester.py
diff options
context:
space:
mode:
authorJoannah Nanjekye <33177550+nanjekyejoannah@users.noreply.github.com>2019-08-29 09:54:46 -0300
committerVictor Stinner <vstinner@redhat.com>2019-08-29 14:54:46 +0200
commit2c5fb1711818926862d0d7b2e5effcaa5a5eb002 (patch)
tree319ff936d7616ace90e1585f9301006b0e1dbc7c /Lib/test/datetimetester.py
parent35f6301d68bdb0517be284421782d64407dfe72c (diff)
downloadcpython-git-2c5fb1711818926862d0d7b2e5effcaa5a5eb002.tar.gz
bpo-36833: Add tests for Datetime C API Macros (GH-14842)
Added tests for PyDateTime_xxx_GET_xxx() macros of the C API of the datetime module.
Diffstat (limited to 'Lib/test/datetimetester.py')
-rw-r--r--Lib/test/datetimetester.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py
index b440e5ab5f..d09255d79b 100644
--- a/Lib/test/datetimetester.py
+++ b/Lib/test/datetimetester.py
@@ -5941,6 +5941,65 @@ class CapiTest(unittest.TestCase):
self.assertEqual(dt1.astimezone(timezone.utc), dt_utc)
+ def test_PyDateTime_DELTA_GET(self):
+ class TimeDeltaSubclass(timedelta):
+ pass
+
+ for klass in [timedelta, TimeDeltaSubclass]:
+ for args in [(26, 55, 99999), (26, 55, 99999)]:
+ d = klass(*args)
+ with self.subTest(cls=klass, date=args):
+ days, seconds, microseconds = _testcapi.PyDateTime_DELTA_GET(d)
+
+ self.assertEqual(days, d.days)
+ self.assertEqual(seconds, d.seconds)
+ self.assertEqual(microseconds, d.microseconds)
+
+ def test_PyDateTime_GET(self):
+ class DateSubclass(date):
+ pass
+
+ for klass in [date, DateSubclass]:
+ for args in [(2000, 1, 2), (2012, 2, 29)]:
+ d = klass(*args)
+ with self.subTest(cls=klass, date=args):
+ year, month, day = _testcapi.PyDateTime_GET(d)
+
+ self.assertEqual(year, d.year)
+ self.assertEqual(month, d.month)
+ self.assertEqual(day, d.day)
+
+ def test_PyDateTime_DATE_GET(self):
+ class DateTimeSubclass(datetime):
+ pass
+
+ for klass in [datetime, DateTimeSubclass]:
+ for args in [(1993, 8, 26, 22, 12, 55, 99999),
+ (1993, 8, 26, 22, 12, 55, 99999)]:
+ d = klass(*args)
+ with self.subTest(cls=klass, date=args):
+ hour, minute, second, microsecond = _testcapi.PyDateTime_DATE_GET(d)
+
+ self.assertEqual(hour, d.hour)
+ self.assertEqual(minute, d.minute)
+ self.assertEqual(second, d.second)
+ self.assertEqual(microsecond, d.microsecond)
+
+ def test_PyDateTime_TIME_GET(self):
+ class TimeSubclass(time):
+ pass
+
+ for klass in [time, TimeSubclass]:
+ for args in [(12, 30, 20, 10), (12, 30, 20, 10)]:
+ d = klass(*args)
+ with self.subTest(cls=klass, date=args):
+ hour, minute, second, microsecond = _testcapi.PyDateTime_TIME_GET(d)
+
+ self.assertEqual(hour, d.hour)
+ self.assertEqual(minute, d.minute)
+ self.assertEqual(second, d.second)
+ self.assertEqual(microsecond, d.microsecond)
+
def test_timezones_offset_zero(self):
utc0, utc1, non_utc = _testcapi.get_timezones_offset_zero()