From b3c87ae11a8909130a4f6f7290c03823b7f5d6c1 Mon Sep 17 00:00:00 2001 From: nanjekyejoannah Date: Sun, 14 Jul 2019 20:26:49 -0300 Subject: [PATCH 01/11] test missing date macros --- Lib/test/datetimetester.py | 96 +++++++++++++++++++++++++++++++ Modules/_testcapimodule.c | 112 +++++++++++++++++++++++++++++++++++++ 2 files changed, 208 insertions(+) diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py index 37ddd4b1a8bc5c..434f0a06a01062 100644 --- a/Lib/test/datetimetester.py +++ b/Lib/test/datetimetester.py @@ -5916,6 +5916,102 @@ def test_timezones_capi(self): self.assertEqual(dt1.astimezone(timezone.utc), dt_utc) + def test_get_delta_object_macros(self): + class TimeDeltaSubclass(timedelta): + pass + + exp_td = timedelta(1) + exp_tds = TimeDeltaSubclass(1) + + days, seconds, microseconds = _testcapi.get_fields_from_delta(exp_td) + days_s, seconds_s, microseconds_s = _testcapi.get_fields_from_delta(exp_tds) + + with self.subTest(testname="PyDateTime_DELTA_GET_DAYS"): + self.assertEqual(days, exp_dt.days) + self.assertEqual(days_s, exp_tds.days) + + with self.subTest(testname="PyDateTime_DELTA_GET_SECONDS"): + self.assertEqual(seconds, exp_td.seconds) + self.assertEqual(seconds_s, exp_tds.seconds) + + with self.subTest(testname="PyDateTime_DELTA_GET_MICROSECONDS"): + self.assertEqual(microseconds, exp_td.microseconds) + self.assertEqual(microseconds_s, exp_tds.microseconds) + + def test_get_date_object_macros(self): + class DateSubclass(date): + pass + + exp_dt = date(2000, 1, 2) + exp_dts = DateSubclass(2000, 1, 2) + + year, month, day = _testcapi.get_fields_from_date(exp_dt) + year_s, month_s, day_s = _testcapi.get_fields_from_date(exp_dts) + + with self.subTest(testname="PyDateTime_GET_YEAR"): + self.assertEqual(year, exp_dt.year) + self.assertEqual(year_s, exp_dts.year) + + with self.subTest(testname="PyDateTime_GET_MONTH"): + self.assertEqual(month, exp_dt.month) + self.assertEqual(month_s, exp_dts.month) + + with self.subTest(testname="PyDateTime_GET_DAY"): + self.assertEqual(day, exp_dt.day) + self.assertEqual(day_s, exp_dts.day) + + def test_get_datetime_object_macros(self): + class DateTimeSubclass(datetime): + pass + + exp_dt = datetime(1993, 8, 26, 22, 12, 55, 99999) + exp_dts = DateTimeSubclass(1993, 8, 26, 22, 12, 55, 99999) + + hour, minute, second, microsecond = _testcapi.get_fields_from_datetime(exp_dt) + hour_s, minute_s, second_s, microsecond_s = _testcapi.get_fields_from_datetime(exp_dts) + + with self.subTest(testname="PyDateTime_DATE_GET_HOUR"): + self.assertEqual(hour, exp_dt.hour) + self.assertEqual(hour_s, exp_dts.hour) + + with self.subTest(testname="PyDateTime_DATE_GET_MINUTE"): + self.assertEqual(minute, exp_dt.minute) + self.assertEqual(minute_s, exp_dts.minute) + + with self.subTest(testname="PyDateTime_DATE_GET_SECOND"): + self.assertEqual(second, exp_dt.second) + self.assertEqual(minute_s, exp_dts.second) + + with self.subTest(testname="PyDateTime_DATE_GET_MICROSECOND"): + self.assertEqual(microsecond, exp_dt.microsecond) + self.assertEqual(microsecond_s, exp_dts.microsecond) + + def test_get_time_object_macros(self): + class TimeSubclass(time): + pass + + exp_t = time(12, 30) + exp_ts = TimeSubclass(12, 30) + + hour, minute, second, microsecond = _testcapi.get_fields_from_time(exp_t) + hour_s, minute_s, second_s, microsecond_s = _testcapi.get_fields_from_time(exp_ts) + + with self.subTest(testname="PyDateTime_TIME_GET_HOUR"): + self.assertEqual(hour, exp_t.hour) + self.assertEqual(hour_s, exp_ts.hour) + + with self.subTest(testname="PyDateTime_TIME_GET_MINUTE"): + self.assertEqual(minute, exp_t.minute) + self.assertEqual(minute_s, exp_ts.minute) + + with self.subTest(testname="PyDateTime_TIME_GET_SECOND"): + self.assertEqual(second, exp_t.second) + self.assertEqual(minute_s, exp_ts.second) + + with self.subTest(testname="PyDateTime_TIME_GET_MICROSECOND"): + self.assertEqual(microsecond, exp_t.microsecond) + self.assertEqual(microsecond_s, exp_ts.microsecond) + def test_timezones_offset_zero(self): utc0, utc1, non_utc = _testcapi.get_timezones_offset_zero() diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 8f34e935353ba1..de6cbbe5ae2ee5 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -2587,6 +2587,114 @@ get_datetime_fromtimestamp(PyObject* self, PyObject *args) return rv; } +static PyObject * +get_fields_from_date(PyObject* self, PyObject *args) +{ + PyObject *obj = NULL; + int *rv = NULL; + int year, month, day; + + if (!PyArg_ParseTuple(args, "p", &obj)) { + return NULL; + } + + year = PyDateTime_GET_YEAR(obj); + month = PyDateTime_GET_MONTH(obj); + day = PyDateTime_GET_DAY(obj); + + Py_DecRef(obj); + + rv = PyTuple_New(3); + + PyTuple_SET_ITEM(rv, 0, (PyObject *)year); + PyTuple_SET_ITEM(rv, 1, (PyObject *)month); + PyTuple_SET_ITEM(rv, 2, (PyObject *)day); + + return rv; +} + +static PyObject * +get_fields_from_datetime(PyObject* self, PyObject *args) +{ + PyObject *obj = NULL; + PyObject *rv = NULL; + int hour, minute, second, microsecond; + + if (!PyArg_ParseTuple(args, "p", &obj)) { + return NULL; + } + + hour = PyDateTime_DATE_GET_HOUR(obj); + minute = PyDateTime_DATE_GET_MINUTE(obj); + second = PyDateTime_DATE_GET_SECOND(obj); + microsecond = PyDateTime_DATE_GET_MICROSECOND(obj); + + Py_DecRef(obj); + + rv = PyTuple_New(4); + + PyTuple_SET_ITEM(rv, 0, (PyObject *)hour); + PyTuple_SET_ITEM(rv, 1, (PyObject *)minute); + PyTuple_SET_ITEM(rv, 2, (PyObject *)second); + PyTuple_SET_ITEM(rv, 3, (PyObject *)microsecond); + + return rv; +} + +static PyObject * +get_fields_from_time(PyObject* self, PyObject *args) +{ + PyObject *obj = NULL; + PyObject *rv = NULL; + int hour, minute, second, microsecond; + + if (!PyArg_ParseTuple(args, "p", &obj)) { + return NULL; + } + + hour = PyDateTime_TIME_GET_HOUR(obj); + minute = PyDateTime_TIME_GET_MINUTE(obj); + second = PyDateTime_TIME_GET_SECOND(obj); + microsecond = PyDateTime_TIME_GET_MICROSECOND(obj); + + Py_DecRef(obj); + + rv = PyTuple_New(4); + + PyTuple_SET_ITEM(rv, 0, (PyObject *)hour); + PyTuple_SET_ITEM(rv, 1, (PyObject *)minute); + PyTuple_SET_ITEM(rv, 2, (PyObject *)second); + PyTuple_SET_ITEM(rv, 3, (PyObject *)microsecond); + + return rv; +} + +static PyObject * +get_fields_from_delta(PyObject* self, PyObject *args) +{ + PyObject *obj = NULL; + PyObject *rv = NULL; + int days, seconds, microseconds; + + if (!PyArg_ParseTuple(args, "p", &obj)) { + return NULL; + } + + days = PyDateTime_DELTA_GET_DAYS(obj); + seconds = PyDateTime_DELTA_GET_SECONDS(obj); + microseconds = PyDateTime_DELTA_GET_MICROSECONDS(obj); + + Py_DecRef(obj); + + rv = PyTuple_New(3); + + PyTuple_SET_ITEM(rv, 0, (PyObject *)days); + PyTuple_SET_ITEM(rv, 1, (PyObject *)seconds); + PyTuple_SET_ITEM(rv, 2, (PyObject *)microseconds); + + return rv; +} + /* test_thread_state spawns a thread of its own, and that thread releases * `thread_done` when it's finished. The driver code has to know when the @@ -5076,6 +5184,10 @@ static PyMethodDef TestMethods[] = { {"get_delta_fromdsu", get_delta_fromdsu, METH_VARARGS}, {"get_date_fromtimestamp", get_date_fromtimestamp, METH_VARARGS}, {"get_datetime_fromtimestamp", get_datetime_fromtimestamp, METH_VARARGS}, + {"get_fields_from_date", get_fields_from_date, METH_VARARGS}, + {"get_fields_from_datetime", get_fields_from_datetime, METH_VARARGS}, + {"get_fields_from_time", get_fields_from_time, METH_VARARGS}, + {"get_fields_from_delta", get_fields_from_delta, METH_VARARGS}, {"test_list_api", test_list_api, METH_NOARGS}, {"test_dict_iteration", test_dict_iteration, METH_NOARGS}, {"dict_getitem_knownhash", dict_getitem_knownhash, METH_VARARGS}, From 5f255eb185020df4c3714506b1dc6d8d2ac7eaf6 Mon Sep 17 00:00:00 2001 From: nanjekyejoannah Date: Thu, 18 Jul 2019 11:43:37 -0300 Subject: [PATCH 02/11] Fi segfault and delta tests --- Lib/test/datetimetester.py | 30 ++++++++--------- Modules/_testcapimodule.c | 67 ++++++++++++++++++++------------------ 2 files changed, 50 insertions(+), 47 deletions(-) diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py index 434f0a06a01062..4edd0674243543 100644 --- a/Lib/test/datetimetester.py +++ b/Lib/test/datetimetester.py @@ -5920,24 +5920,24 @@ def test_get_delta_object_macros(self): class TimeDeltaSubclass(timedelta): pass - exp_td = timedelta(1) - exp_tds = TimeDeltaSubclass(1) + exp_delta = timedelta(26, 55, 99999) + exp_delta_s = TimeDeltaSubclass(26, 55, 99999) - days, seconds, microseconds = _testcapi.get_fields_from_delta(exp_td) - days_s, seconds_s, microseconds_s = _testcapi.get_fields_from_delta(exp_tds) + days, seconds, microseconds = _testcapi.get_fields_from_delta(exp_delta) + days_s, seconds_s, microseconds_s = _testcapi.get_fields_from_delta(exp_delta_s) with self.subTest(testname="PyDateTime_DELTA_GET_DAYS"): - self.assertEqual(days, exp_dt.days) - self.assertEqual(days_s, exp_tds.days) + self.assertEqual(days, exp_delta.days) + self.assertEqual(days_s, exp_delta_s.days) with self.subTest(testname="PyDateTime_DELTA_GET_SECONDS"): - self.assertEqual(seconds, exp_td.seconds) - self.assertEqual(seconds_s, exp_tds.seconds) + self.assertEqual(seconds, exp_delta.seconds) + self.assertEqual(seconds_s, exp_delta_s.seconds) with self.subTest(testname="PyDateTime_DELTA_GET_MICROSECONDS"): - self.assertEqual(microseconds, exp_td.microseconds) - self.assertEqual(microseconds_s, exp_tds.microseconds) - + self.assertEqual(microseconds, exp_delta.microseconds) + self.assertEqual(microseconds_s, exp_delta_s.microseconds) + def test_get_date_object_macros(self): class DateSubclass(date): pass @@ -5980,7 +5980,7 @@ class DateTimeSubclass(datetime): with self.subTest(testname="PyDateTime_DATE_GET_SECOND"): self.assertEqual(second, exp_dt.second) - self.assertEqual(minute_s, exp_dts.second) + self.assertEqual(second_s, exp_dts.second) with self.subTest(testname="PyDateTime_DATE_GET_MICROSECOND"): self.assertEqual(microsecond, exp_dt.microsecond) @@ -5990,8 +5990,8 @@ def test_get_time_object_macros(self): class TimeSubclass(time): pass - exp_t = time(12, 30) - exp_ts = TimeSubclass(12, 30) + exp_t = time(12, 30, 20, 10) + exp_ts = TimeSubclass(12, 30, 20, 10) hour, minute, second, microsecond = _testcapi.get_fields_from_time(exp_t) hour_s, minute_s, second_s, microsecond_s = _testcapi.get_fields_from_time(exp_ts) @@ -6006,7 +6006,7 @@ class TimeSubclass(time): with self.subTest(testname="PyDateTime_TIME_GET_SECOND"): self.assertEqual(second, exp_t.second) - self.assertEqual(minute_s, exp_ts.second) + self.assertEqual(second_s, exp_ts.second) with self.subTest(testname="PyDateTime_TIME_GET_MICROSECOND"): self.assertEqual(microsecond, exp_t.microsecond) diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index de6cbbe5ae2ee5..29482068da81ff 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -2591,24 +2591,25 @@ static PyObject * get_fields_from_date(PyObject* self, PyObject *args) { PyObject *obj = NULL; - int *rv = NULL; + PyObject *rv; int year, month, day; - if (!PyArg_ParseTuple(args, "p", &obj)) { + if (!PyArg_ParseTuple(args, "O", &obj)) { return NULL; } - + year = PyDateTime_GET_YEAR(obj); month = PyDateTime_GET_MONTH(obj); day = PyDateTime_GET_DAY(obj); - Py_DecRef(obj); - rv = PyTuple_New(3); + if (rv == NULL) { + return NULL; + } - PyTuple_SET_ITEM(rv, 0, (PyObject *)year); - PyTuple_SET_ITEM(rv, 1, (PyObject *)month); - PyTuple_SET_ITEM(rv, 2, (PyObject *)day); + PyTuple_SET_ITEM(rv, 0, PyLong_FromSsize_t(year)); + PyTuple_SET_ITEM(rv, 1, PyLong_FromSsize_t(month)); + PyTuple_SET_ITEM(rv, 2, PyLong_FromSsize_t(day)); return rv; } @@ -2617,10 +2618,10 @@ static PyObject * get_fields_from_datetime(PyObject* self, PyObject *args) { PyObject *obj = NULL; - PyObject *rv = NULL; + PyObject *rv; int hour, minute, second, microsecond; - if (!PyArg_ParseTuple(args, "p", &obj)) { + if (!PyArg_ParseTuple(args, "O", &obj)) { return NULL; } @@ -2629,14 +2630,15 @@ get_fields_from_datetime(PyObject* self, PyObject *args) second = PyDateTime_DATE_GET_SECOND(obj); microsecond = PyDateTime_DATE_GET_MICROSECOND(obj); - Py_DecRef(obj); - rv = PyTuple_New(4); + if (rv == NULL) { + return NULL; + } - PyTuple_SET_ITEM(rv, 0, (PyObject *)hour); - PyTuple_SET_ITEM(rv, 1, (PyObject *)minute); - PyTuple_SET_ITEM(rv, 2, (PyObject *)second); - PyTuple_SET_ITEM(rv, 3, (PyObject *)microsecond); + PyTuple_SET_ITEM(rv, 0, PyLong_FromSsize_t(hour)); + PyTuple_SET_ITEM(rv, 1, PyLong_FromSsize_t(minute)); + PyTuple_SET_ITEM(rv, 2, PyLong_FromSsize_t(second)); + PyTuple_SET_ITEM(rv, 3, PyLong_FromSsize_t(microsecond)); return rv; } @@ -2645,10 +2647,10 @@ static PyObject * get_fields_from_time(PyObject* self, PyObject *args) { PyObject *obj = NULL; - PyObject *rv = NULL; + PyObject *rv; int hour, minute, second, microsecond; - if (!PyArg_ParseTuple(args, "p", &obj)) { + if (!PyArg_ParseTuple(args, "O", &obj)) { return NULL; } @@ -2657,14 +2659,15 @@ get_fields_from_time(PyObject* self, PyObject *args) second = PyDateTime_TIME_GET_SECOND(obj); microsecond = PyDateTime_TIME_GET_MICROSECOND(obj); - Py_DecRef(obj); - rv = PyTuple_New(4); + if (rv == NULL) { + return NULL; + } - PyTuple_SET_ITEM(rv, 0, (PyObject *)hour); - PyTuple_SET_ITEM(rv, 1, (PyObject *)minute); - PyTuple_SET_ITEM(rv, 2, (PyObject *)second); - PyTuple_SET_ITEM(rv, 3, (PyObject *)microsecond); + PyTuple_SET_ITEM(rv, 0, PyLong_FromSsize_t(hour)); + PyTuple_SET_ITEM(rv, 1, PyLong_FromSsize_t(minute)); + PyTuple_SET_ITEM(rv, 2, PyLong_FromSsize_t(second)); + PyTuple_SET_ITEM(rv, 3, PyLong_FromSsize_t(microsecond)); return rv; } @@ -2673,10 +2676,10 @@ static PyObject * get_fields_from_delta(PyObject* self, PyObject *args) { PyObject *obj = NULL; - PyObject *rv = NULL; + PyObject *rv; int days, seconds, microseconds; - if (!PyArg_ParseTuple(args, "p", &obj)) { + if (!PyArg_ParseTuple(args, "O", &obj)) { return NULL; } @@ -2684,18 +2687,18 @@ get_fields_from_delta(PyObject* self, PyObject *args) seconds = PyDateTime_DELTA_GET_SECONDS(obj); microseconds = PyDateTime_DELTA_GET_MICROSECONDS(obj); - Py_DecRef(obj); - rv = PyTuple_New(3); + if (rv == NULL) { + return NULL; + } - PyTuple_SET_ITEM(rv, 0, (PyObject *)days); - PyTuple_SET_ITEM(rv, 1, (PyObject *)seconds); - PyTuple_SET_ITEM(rv, 2, (PyObject *)microseconds); + PyTuple_SET_ITEM(rv, 0, PyLong_FromSsize_t(days)); + PyTuple_SET_ITEM(rv, 1, PyLong_FromSsize_t(seconds)); + PyTuple_SET_ITEM(rv, 2, PyLong_FromSsize_t(microseconds)); return rv; } - /* test_thread_state spawns a thread of its own, and that thread releases * `thread_done` when it's finished. The driver code has to know when the * thread finishes, because the thread uses a PyObject (the callable) that From 2bdf625a6753b241a35687fe3f52faae27b33b6e Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Thu, 18 Jul 2019 14:53:02 +0000 Subject: [PATCH 03/11] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20b?= =?UTF-8?q?lurb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2019-07-18-14-52-58.bpo-36833.Zoe9ek.rst | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Misc/NEWS.d/next/Tests/2019-07-18-14-52-58.bpo-36833.Zoe9ek.rst diff --git a/Misc/NEWS.d/next/Tests/2019-07-18-14-52-58.bpo-36833.Zoe9ek.rst b/Misc/NEWS.d/next/Tests/2019-07-18-14-52-58.bpo-36833.Zoe9ek.rst new file mode 100644 index 00000000000000..e402f47bdc28be --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2019-07-18-14-52-58.bpo-36833.Zoe9ek.rst @@ -0,0 +1,18 @@ +Added test for the following Untested macros with no corresponding API module: + +- `PyDateTime_GET_YEAR` +- `PyDateTime_GET_MONTH` +- `PyDateTime_GET_DAY` +- `PyDateTime_DATE_GET_HOUR` +- `PyDateTime_DATE_GET_MINUTE` +- `PyDateTime_DATE_GET_SECOND` +- `PyDateTime_DATE_GET_MICROSECOND` + +- `PyDateTime_TIME_GET_HOUR` +- `PyDateTime_TIME_GET_MINUTE` +- `PyDateTime_TIME_GET_SECOND` +- `PyDateTime_TIME_GET_MICROSECOND` + +- `PyDateTime_DELTA_GET_DAYS` +- `PyDateTime_DELTA_GET_SECONDS` +- `PyDateTime_DELTA_GET_MICROSECONDS` \ No newline at end of file From 1c69ba787939c8dc582a8f093d0410de238f0be8 Mon Sep 17 00:00:00 2001 From: nanjekyejoannah Date: Thu, 18 Jul 2019 12:43:27 -0300 Subject: [PATCH 04/11] Remove space --- Lib/test/datetimetester.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py index 4edd0674243543..8c6c4f46722a42 100644 --- a/Lib/test/datetimetester.py +++ b/Lib/test/datetimetester.py @@ -5963,7 +5963,7 @@ class DateSubclass(date): def test_get_datetime_object_macros(self): class DateTimeSubclass(datetime): pass - + exp_dt = datetime(1993, 8, 26, 22, 12, 55, 99999) exp_dts = DateTimeSubclass(1993, 8, 26, 22, 12, 55, 99999) From a6f9d7acebff61080fb4f5d6ee53ca401a0c5a06 Mon Sep 17 00:00:00 2001 From: Joannah Nanjekye <33177550+nanjekyejoannah@users.noreply.github.com> Date: Thu, 1 Aug 2019 13:54:31 -0300 Subject: [PATCH 05/11] Update 2019-07-18-14-52-58.bpo-36833.Zoe9ek.rst --- .../2019-07-18-14-52-58.bpo-36833.Zoe9ek.rst | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/Misc/NEWS.d/next/Tests/2019-07-18-14-52-58.bpo-36833.Zoe9ek.rst b/Misc/NEWS.d/next/Tests/2019-07-18-14-52-58.bpo-36833.Zoe9ek.rst index e402f47bdc28be..14296ac87a6315 100644 --- a/Misc/NEWS.d/next/Tests/2019-07-18-14-52-58.bpo-36833.Zoe9ek.rst +++ b/Misc/NEWS.d/next/Tests/2019-07-18-14-52-58.bpo-36833.Zoe9ek.rst @@ -1,18 +1 @@ -Added test for the following Untested macros with no corresponding API module: - -- `PyDateTime_GET_YEAR` -- `PyDateTime_GET_MONTH` -- `PyDateTime_GET_DAY` -- `PyDateTime_DATE_GET_HOUR` -- `PyDateTime_DATE_GET_MINUTE` -- `PyDateTime_DATE_GET_SECOND` -- `PyDateTime_DATE_GET_MICROSECOND` - -- `PyDateTime_TIME_GET_HOUR` -- `PyDateTime_TIME_GET_MINUTE` -- `PyDateTime_TIME_GET_SECOND` -- `PyDateTime_TIME_GET_MICROSECOND` - -- `PyDateTime_DELTA_GET_DAYS` -- `PyDateTime_DELTA_GET_SECONDS` -- `PyDateTime_DELTA_GET_MICROSECONDS` \ No newline at end of file +Added tests for the macros with no corresponding API module. From 39c16e6b8d4a0db19397494c49621ababc3d38ee Mon Sep 17 00:00:00 2001 From: Joannah Nanjekye Date: Fri, 9 Aug 2019 18:11:36 +0000 Subject: [PATCH 06/11] refactor the tests --- Lib/test/datetimetester.py | 107 ++++++++++++------------------------- Modules/_testcapimodule.c | 10 ++-- 2 files changed, 40 insertions(+), 77 deletions(-) diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py index 8c6c4f46722a42..53b2a201db5875 100644 --- a/Lib/test/datetimetester.py +++ b/Lib/test/datetimetester.py @@ -5920,97 +5920,60 @@ def test_get_delta_object_macros(self): class TimeDeltaSubclass(timedelta): pass - exp_delta = timedelta(26, 55, 99999) - exp_delta_s = TimeDeltaSubclass(26, 55, 99999) - - days, seconds, microseconds = _testcapi.get_fields_from_delta(exp_delta) - days_s, seconds_s, microseconds_s = _testcapi.get_fields_from_delta(exp_delta_s) - - with self.subTest(testname="PyDateTime_DELTA_GET_DAYS"): - self.assertEqual(days, exp_delta.days) - self.assertEqual(days_s, exp_delta_s.days) - - with self.subTest(testname="PyDateTime_DELTA_GET_SECONDS"): - self.assertEqual(seconds, exp_delta.seconds) - self.assertEqual(seconds_s, exp_delta_s.seconds) + 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.get_fields_from_delta(d) - with self.subTest(testname="PyDateTime_DELTA_GET_MICROSECONDS"): - self.assertEqual(microseconds, exp_delta.microseconds) - self.assertEqual(microseconds_s, exp_delta_s.microseconds) + self.assertEqual(days, d.days) + self.assertEqual(seconds, d.seconds) + self.assertEqual(microseconds, d.microseconds) def test_get_date_object_macros(self): class DateSubclass(date): pass - exp_dt = date(2000, 1, 2) - exp_dts = DateSubclass(2000, 1, 2) + 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.get_fields_from_date(d) - year, month, day = _testcapi.get_fields_from_date(exp_dt) - year_s, month_s, day_s = _testcapi.get_fields_from_date(exp_dts) - - with self.subTest(testname="PyDateTime_GET_YEAR"): - self.assertEqual(year, exp_dt.year) - self.assertEqual(year_s, exp_dts.year) - - with self.subTest(testname="PyDateTime_GET_MONTH"): - self.assertEqual(month, exp_dt.month) - self.assertEqual(month_s, exp_dts.month) - - with self.subTest(testname="PyDateTime_GET_DAY"): - self.assertEqual(day, exp_dt.day) - self.assertEqual(day_s, exp_dts.day) + self.assertEqual(year, d.year) + self.assertEqual(month, d.month) + self.assertEqual(day, d.day) def test_get_datetime_object_macros(self): class DateTimeSubclass(datetime): pass - exp_dt = datetime(1993, 8, 26, 22, 12, 55, 99999) - exp_dts = DateTimeSubclass(1993, 8, 26, 22, 12, 55, 99999) - - hour, minute, second, microsecond = _testcapi.get_fields_from_datetime(exp_dt) - hour_s, minute_s, second_s, microsecond_s = _testcapi.get_fields_from_datetime(exp_dts) + 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.get_fields_from_datetime(d) - with self.subTest(testname="PyDateTime_DATE_GET_HOUR"): - self.assertEqual(hour, exp_dt.hour) - self.assertEqual(hour_s, exp_dts.hour) - - with self.subTest(testname="PyDateTime_DATE_GET_MINUTE"): - self.assertEqual(minute, exp_dt.minute) - self.assertEqual(minute_s, exp_dts.minute) - - with self.subTest(testname="PyDateTime_DATE_GET_SECOND"): - self.assertEqual(second, exp_dt.second) - self.assertEqual(second_s, exp_dts.second) - - with self.subTest(testname="PyDateTime_DATE_GET_MICROSECOND"): - self.assertEqual(microsecond, exp_dt.microsecond) - self.assertEqual(microsecond_s, exp_dts.microsecond) + self.assertEqual(hour, d.hour) + self.assertEqual(minute, d.minute) + self.assertEqual(second, d.second) + self.assertEqual(microsecond, d.microsecond) def test_get_time_object_macros(self): class TimeSubclass(time): pass - exp_t = time(12, 30, 20, 10) - exp_ts = TimeSubclass(12, 30, 20, 10) - - hour, minute, second, microsecond = _testcapi.get_fields_from_time(exp_t) - hour_s, minute_s, second_s, microsecond_s = _testcapi.get_fields_from_time(exp_ts) - - with self.subTest(testname="PyDateTime_TIME_GET_HOUR"): - self.assertEqual(hour, exp_t.hour) - self.assertEqual(hour_s, exp_ts.hour) - - with self.subTest(testname="PyDateTime_TIME_GET_MINUTE"): - self.assertEqual(minute, exp_t.minute) - self.assertEqual(minute_s, exp_ts.minute) - - with self.subTest(testname="PyDateTime_TIME_GET_SECOND"): - self.assertEqual(second, exp_t.second) - self.assertEqual(second_s, exp_ts.second) + 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.get_fields_from_time(d) - with self.subTest(testname="PyDateTime_TIME_GET_MICROSECOND"): - self.assertEqual(microsecond, exp_t.microsecond) - self.assertEqual(microsecond_s, exp_ts.microsecond) + 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() diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 29482068da81ff..0b5c5d388d0158 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -2588,7 +2588,7 @@ get_datetime_fromtimestamp(PyObject* self, PyObject *args) } static PyObject * -get_fields_from_date(PyObject* self, PyObject *args) +get_fields_from_date(PyObject *self, PyObject *args) { PyObject *obj = NULL; PyObject *rv; @@ -2597,7 +2597,7 @@ get_fields_from_date(PyObject* self, PyObject *args) if (!PyArg_ParseTuple(args, "O", &obj)) { return NULL; } - + year = PyDateTime_GET_YEAR(obj); month = PyDateTime_GET_MONTH(obj); day = PyDateTime_GET_DAY(obj); @@ -2615,7 +2615,7 @@ get_fields_from_date(PyObject* self, PyObject *args) } static PyObject * -get_fields_from_datetime(PyObject* self, PyObject *args) +get_fields_from_datetime(PyObject *self, PyObject *args) { PyObject *obj = NULL; PyObject *rv; @@ -2644,7 +2644,7 @@ get_fields_from_datetime(PyObject* self, PyObject *args) } static PyObject * -get_fields_from_time(PyObject* self, PyObject *args) +get_fields_from_time(PyObject *self, PyObject *args) { PyObject *obj = NULL; PyObject *rv; @@ -2673,7 +2673,7 @@ get_fields_from_time(PyObject* self, PyObject *args) } static PyObject * -get_fields_from_delta(PyObject* self, PyObject *args) +get_fields_from_delta(PyObject *self, PyObject *args) { PyObject *obj = NULL; PyObject *rv; From 7813efa729564aabca999499cb139f89c92a6710 Mon Sep 17 00:00:00 2001 From: Joannah Nanjekye Date: Fri, 16 Aug 2019 13:55:15 +0000 Subject: [PATCH 07/11] changing from PyLong_FromSsize_t() to PyLong_FromLong() --- Modules/_testcapimodule.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 0b5c5d388d0158..3602c54d0b6172 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -2607,9 +2607,9 @@ get_fields_from_date(PyObject *self, PyObject *args) return NULL; } - PyTuple_SET_ITEM(rv, 0, PyLong_FromSsize_t(year)); - PyTuple_SET_ITEM(rv, 1, PyLong_FromSsize_t(month)); - PyTuple_SET_ITEM(rv, 2, PyLong_FromSsize_t(day)); + PyTuple_SET_ITEM(rv, 0, PyLong_FromLong(year)); + PyTuple_SET_ITEM(rv, 1, PyLong_FromLong(month)); + PyTuple_SET_ITEM(rv, 2, PyLong_FromLong(day)); return rv; } @@ -2635,10 +2635,10 @@ get_fields_from_datetime(PyObject *self, PyObject *args) return NULL; } - PyTuple_SET_ITEM(rv, 0, PyLong_FromSsize_t(hour)); - PyTuple_SET_ITEM(rv, 1, PyLong_FromSsize_t(minute)); - PyTuple_SET_ITEM(rv, 2, PyLong_FromSsize_t(second)); - PyTuple_SET_ITEM(rv, 3, PyLong_FromSsize_t(microsecond)); + PyTuple_SET_ITEM(rv, 0, PyLong_FromLong(hour)); + PyTuple_SET_ITEM(rv, 1, PyLong_FromLong(minute)); + PyTuple_SET_ITEM(rv, 2, PyLong_FromLong(second)); + PyTuple_SET_ITEM(rv, 3, PyLong_FromLong(microsecond)); return rv; } @@ -2664,10 +2664,10 @@ get_fields_from_time(PyObject *self, PyObject *args) return NULL; } - PyTuple_SET_ITEM(rv, 0, PyLong_FromSsize_t(hour)); - PyTuple_SET_ITEM(rv, 1, PyLong_FromSsize_t(minute)); - PyTuple_SET_ITEM(rv, 2, PyLong_FromSsize_t(second)); - PyTuple_SET_ITEM(rv, 3, PyLong_FromSsize_t(microsecond)); + PyTuple_SET_ITEM(rv, 0, PyLong_FromLong(hour)); + PyTuple_SET_ITEM(rv, 1, PyLong_FromLong(minute)); + PyTuple_SET_ITEM(rv, 2, PyLong_FromLong(second)); + PyTuple_SET_ITEM(rv, 3, PyLong_FromLong(microsecond)); return rv; } @@ -2692,9 +2692,9 @@ get_fields_from_delta(PyObject *self, PyObject *args) return NULL; } - PyTuple_SET_ITEM(rv, 0, PyLong_FromSsize_t(days)); - PyTuple_SET_ITEM(rv, 1, PyLong_FromSsize_t(seconds)); - PyTuple_SET_ITEM(rv, 2, PyLong_FromSsize_t(microseconds)); + PyTuple_SET_ITEM(rv, 0, PyLong_FromLong(days)); + PyTuple_SET_ITEM(rv, 1, PyLong_FromLong(seconds)); + PyTuple_SET_ITEM(rv, 2, PyLong_FromLong(microseconds)); return rv; } From dc7dcf238bc1f813f142803b2a6f04aaf6eef265 Mon Sep 17 00:00:00 2001 From: Joannah Nanjekye Date: Mon, 19 Aug 2019 12:32:14 +0000 Subject: [PATCH 08/11] rename helper functions --- Lib/test/datetimetester.py | 8 ++++---- Modules/_testcapimodule.c | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py index 53b2a201db5875..4bea08caf4899d 100644 --- a/Lib/test/datetimetester.py +++ b/Lib/test/datetimetester.py @@ -5924,7 +5924,7 @@ class TimeDeltaSubclass(timedelta): for args in [(26, 55, 99999), (26, 55, 99999)]: d = klass(*args) with self.subTest(cls=klass, date=args): - days, seconds, microseconds = _testcapi.get_fields_from_delta(d) + days, seconds, microseconds = _testcapi.PyDateTime_DELTA_GET(d) self.assertEqual(days, d.days) self.assertEqual(seconds, d.seconds) @@ -5938,7 +5938,7 @@ class DateSubclass(date): for args in [(2000, 1, 2), (2012, 2, 29)]: d = klass(*args) with self.subTest(cls=klass, date=args): - year, month, day = _testcapi.get_fields_from_date(d) + year, month, day = _testcapi.PyDateTime_GET(d) self.assertEqual(year, d.year) self.assertEqual(month, d.month) @@ -5953,7 +5953,7 @@ class DateTimeSubclass(datetime): (1993, 8, 26, 22, 12, 55, 99999)]: d = klass(*args) with self.subTest(cls=klass, date=args): - hour, minute, second, microsecond = _testcapi.get_fields_from_datetime(d) + hour, minute, second, microsecond = _testcapi.PyDateTime_DATE_GET(d) self.assertEqual(hour, d.hour) self.assertEqual(minute, d.minute) @@ -5968,7 +5968,7 @@ class TimeSubclass(time): 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.get_fields_from_time(d) + hour, minute, second, microsecond = _testcapi.PyDateTime_TIME_GET(d) self.assertEqual(hour, d.hour) self.assertEqual(minute, d.minute) diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 3602c54d0b6172..f61153b6bc564d 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -2588,7 +2588,7 @@ get_datetime_fromtimestamp(PyObject* self, PyObject *args) } static PyObject * -get_fields_from_date(PyObject *self, PyObject *args) +test_PyDateTime_GET(PyObject *self, PyObject *args) { PyObject *obj = NULL; PyObject *rv; @@ -2615,7 +2615,7 @@ get_fields_from_date(PyObject *self, PyObject *args) } static PyObject * -get_fields_from_datetime(PyObject *self, PyObject *args) +test_PyDateTime_DATE_GET(PyObject *self, PyObject *args) { PyObject *obj = NULL; PyObject *rv; @@ -2644,7 +2644,7 @@ get_fields_from_datetime(PyObject *self, PyObject *args) } static PyObject * -get_fields_from_time(PyObject *self, PyObject *args) +test_PyDateTime_TIME_GET(PyObject *self, PyObject *args) { PyObject *obj = NULL; PyObject *rv; @@ -2673,7 +2673,7 @@ get_fields_from_time(PyObject *self, PyObject *args) } static PyObject * -get_fields_from_delta(PyObject *self, PyObject *args) +test_PyDateTime_DELTA_GET(PyObject *self, PyObject *args) { PyObject *obj = NULL; PyObject *rv; @@ -5187,10 +5187,10 @@ static PyMethodDef TestMethods[] = { {"get_delta_fromdsu", get_delta_fromdsu, METH_VARARGS}, {"get_date_fromtimestamp", get_date_fromtimestamp, METH_VARARGS}, {"get_datetime_fromtimestamp", get_datetime_fromtimestamp, METH_VARARGS}, - {"get_fields_from_date", get_fields_from_date, METH_VARARGS}, - {"get_fields_from_datetime", get_fields_from_datetime, METH_VARARGS}, - {"get_fields_from_time", get_fields_from_time, METH_VARARGS}, - {"get_fields_from_delta", get_fields_from_delta, METH_VARARGS}, + {"PyDateTime_GET", test_PyDateTime_GET, METH_VARARGS}, + {"PyDateTime_DATE_GET", test_PyDateTime_DATE_GET, METH_VARARGS}, + {"PyDateTime_TIME_GET", test_PyDateTime_TIME_GET, METH_VARARGS}, + {"PyDateTime_DELTA_GET", test_PyDateTime_DELTA_GET, METH_VARARGS}, {"test_list_api", test_list_api, METH_NOARGS}, {"test_dict_iteration", test_dict_iteration, METH_NOARGS}, {"dict_getitem_knownhash", dict_getitem_knownhash, METH_VARARGS}, From 3904ce41710fcf49f6707e412d6da118614a4f7e Mon Sep 17 00:00:00 2001 From: Joannah Nanjekye Date: Mon, 19 Aug 2019 13:31:40 +0000 Subject: [PATCH 09/11] rename python functins too --- Lib/test/datetimetester.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py index 4bea08caf4899d..31ab4146467ee0 100644 --- a/Lib/test/datetimetester.py +++ b/Lib/test/datetimetester.py @@ -5916,7 +5916,7 @@ def test_timezones_capi(self): self.assertEqual(dt1.astimezone(timezone.utc), dt_utc) - def test_get_delta_object_macros(self): + def test_PyDateTime_DELTA_GET(self): class TimeDeltaSubclass(timedelta): pass @@ -5930,7 +5930,7 @@ class TimeDeltaSubclass(timedelta): self.assertEqual(seconds, d.seconds) self.assertEqual(microseconds, d.microseconds) - def test_get_date_object_macros(self): + def test_PyDateTime_GET(self): class DateSubclass(date): pass @@ -5944,7 +5944,7 @@ class DateSubclass(date): self.assertEqual(month, d.month) self.assertEqual(day, d.day) - def test_get_datetime_object_macros(self): + def test_PyDateTime_DATE_GET(self): class DateTimeSubclass(datetime): pass @@ -5960,7 +5960,7 @@ class DateTimeSubclass(datetime): self.assertEqual(second, d.second) self.assertEqual(microsecond, d.microsecond) - def test_get_time_object_macros(self): + def test_PyDateTime_TIME_GET(self): class TimeSubclass(time): pass From 1a5cc4d5b0249beea7555190399daf9da083858d Mon Sep 17 00:00:00 2001 From: Joannah Nanjekye Date: Sat, 24 Aug 2019 21:55:21 +0000 Subject: [PATCH 10/11] use Py_BuildValue --- .../2019-07-18-14-52-58.bpo-36833.Zoe9ek.rst | 3 +- Modules/_testcapimodule.c | 86 +++---------------- 2 files changed, 14 insertions(+), 75 deletions(-) diff --git a/Misc/NEWS.d/next/Tests/2019-07-18-14-52-58.bpo-36833.Zoe9ek.rst b/Misc/NEWS.d/next/Tests/2019-07-18-14-52-58.bpo-36833.Zoe9ek.rst index 14296ac87a6315..3632f98f34f028 100644 --- a/Misc/NEWS.d/next/Tests/2019-07-18-14-52-58.bpo-36833.Zoe9ek.rst +++ b/Misc/NEWS.d/next/Tests/2019-07-18-14-52-58.bpo-36833.Zoe9ek.rst @@ -1 +1,2 @@ -Added tests for the macros with no corresponding API module. +Added tests for PyDateTime_xxx_GET_xxx() macros of the C API of +the :mod:`datetime` module. Patch by Joannah Nanjekye. \ No newline at end of file diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index f61153b6bc564d..85708164c834db 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -2588,115 +2588,53 @@ get_datetime_fromtimestamp(PyObject* self, PyObject *args) } static PyObject * -test_PyDateTime_GET(PyObject *self, PyObject *args) +test_PyDateTime_GET(PyObject *self, PyObject *obj) { - PyObject *obj = NULL; - PyObject *rv; int year, month, day; - if (!PyArg_ParseTuple(args, "O", &obj)) { - return NULL; - } - year = PyDateTime_GET_YEAR(obj); month = PyDateTime_GET_MONTH(obj); day = PyDateTime_GET_DAY(obj); - rv = PyTuple_New(3); - if (rv == NULL) { - return NULL; - } - - PyTuple_SET_ITEM(rv, 0, PyLong_FromLong(year)); - PyTuple_SET_ITEM(rv, 1, PyLong_FromLong(month)); - PyTuple_SET_ITEM(rv, 2, PyLong_FromLong(day)); - - return rv; + return Py_BuildValue("[lll]", year, month, day); } static PyObject * -test_PyDateTime_DATE_GET(PyObject *self, PyObject *args) +test_PyDateTime_DATE_GET(PyObject *self, PyObject *obj) { - PyObject *obj = NULL; - PyObject *rv; int hour, minute, second, microsecond; - if (!PyArg_ParseTuple(args, "O", &obj)) { - return NULL; - } - hour = PyDateTime_DATE_GET_HOUR(obj); minute = PyDateTime_DATE_GET_MINUTE(obj); second = PyDateTime_DATE_GET_SECOND(obj); microsecond = PyDateTime_DATE_GET_MICROSECOND(obj); - rv = PyTuple_New(4); - if (rv == NULL) { - return NULL; - } - - PyTuple_SET_ITEM(rv, 0, PyLong_FromLong(hour)); - PyTuple_SET_ITEM(rv, 1, PyLong_FromLong(minute)); - PyTuple_SET_ITEM(rv, 2, PyLong_FromLong(second)); - PyTuple_SET_ITEM(rv, 3, PyLong_FromLong(microsecond)); - - return rv; + return Py_BuildValue("[llll]", hour, minute, second, microsecond); } static PyObject * -test_PyDateTime_TIME_GET(PyObject *self, PyObject *args) +test_PyDateTime_TIME_GET(PyObject *self, PyObject *obj) { - PyObject *obj = NULL; - PyObject *rv; int hour, minute, second, microsecond; - if (!PyArg_ParseTuple(args, "O", &obj)) { - return NULL; - } - hour = PyDateTime_TIME_GET_HOUR(obj); minute = PyDateTime_TIME_GET_MINUTE(obj); second = PyDateTime_TIME_GET_SECOND(obj); microsecond = PyDateTime_TIME_GET_MICROSECOND(obj); - rv = PyTuple_New(4); - if (rv == NULL) { - return NULL; - } - - PyTuple_SET_ITEM(rv, 0, PyLong_FromLong(hour)); - PyTuple_SET_ITEM(rv, 1, PyLong_FromLong(minute)); - PyTuple_SET_ITEM(rv, 2, PyLong_FromLong(second)); - PyTuple_SET_ITEM(rv, 3, PyLong_FromLong(microsecond)); - - return rv; + return Py_BuildValue("[llll]", hour, minute, second, microsecond); } static PyObject * -test_PyDateTime_DELTA_GET(PyObject *self, PyObject *args) +test_PyDateTime_DELTA_GET(PyObject *self, PyObject *obj) { - PyObject *obj = NULL; - PyObject *rv; int days, seconds, microseconds; - if (!PyArg_ParseTuple(args, "O", &obj)) { - return NULL; - } - days = PyDateTime_DELTA_GET_DAYS(obj); seconds = PyDateTime_DELTA_GET_SECONDS(obj); microseconds = PyDateTime_DELTA_GET_MICROSECONDS(obj); - rv = PyTuple_New(3); - if (rv == NULL) { - return NULL; - } - - PyTuple_SET_ITEM(rv, 0, PyLong_FromLong(days)); - PyTuple_SET_ITEM(rv, 1, PyLong_FromLong(seconds)); - PyTuple_SET_ITEM(rv, 2, PyLong_FromLong(microseconds)); - - return rv; + return Py_BuildValue("[lll]", days, seconds, microseconds); } /* test_thread_state spawns a thread of its own, and that thread releases @@ -5187,10 +5125,10 @@ static PyMethodDef TestMethods[] = { {"get_delta_fromdsu", get_delta_fromdsu, METH_VARARGS}, {"get_date_fromtimestamp", get_date_fromtimestamp, METH_VARARGS}, {"get_datetime_fromtimestamp", get_datetime_fromtimestamp, METH_VARARGS}, - {"PyDateTime_GET", test_PyDateTime_GET, METH_VARARGS}, - {"PyDateTime_DATE_GET", test_PyDateTime_DATE_GET, METH_VARARGS}, - {"PyDateTime_TIME_GET", test_PyDateTime_TIME_GET, METH_VARARGS}, - {"PyDateTime_DELTA_GET", test_PyDateTime_DELTA_GET, METH_VARARGS}, + {"PyDateTime_GET", test_PyDateTime_GET, METH_O}, + {"PyDateTime_DATE_GET", test_PyDateTime_DATE_GET, METH_O}, + {"PyDateTime_TIME_GET", test_PyDateTime_TIME_GET, METH_O}, + {"PyDateTime_DELTA_GET", test_PyDateTime_DELTA_GET, METH_O}, {"test_list_api", test_list_api, METH_NOARGS}, {"test_dict_iteration", test_dict_iteration, METH_NOARGS}, {"dict_getitem_knownhash", dict_getitem_knownhash, METH_VARARGS}, From 639451d46952cf7ce34697985f44cea2edfb9ce8 Mon Sep 17 00:00:00 2001 From: Joannah Nanjekye Date: Wed, 28 Aug 2019 13:15:52 +0000 Subject: [PATCH 11/11] build a tuple instead of a list --- Modules/_testcapimodule.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 85708164c834db..3efed1e9082d87 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -2596,7 +2596,7 @@ test_PyDateTime_GET(PyObject *self, PyObject *obj) month = PyDateTime_GET_MONTH(obj); day = PyDateTime_GET_DAY(obj); - return Py_BuildValue("[lll]", year, month, day); + return Py_BuildValue("(lll)", year, month, day); } static PyObject * @@ -2609,7 +2609,7 @@ test_PyDateTime_DATE_GET(PyObject *self, PyObject *obj) second = PyDateTime_DATE_GET_SECOND(obj); microsecond = PyDateTime_DATE_GET_MICROSECOND(obj); - return Py_BuildValue("[llll]", hour, minute, second, microsecond); + return Py_BuildValue("(llll)", hour, minute, second, microsecond); } static PyObject * @@ -2622,7 +2622,7 @@ test_PyDateTime_TIME_GET(PyObject *self, PyObject *obj) second = PyDateTime_TIME_GET_SECOND(obj); microsecond = PyDateTime_TIME_GET_MICROSECOND(obj); - return Py_BuildValue("[llll]", hour, minute, second, microsecond); + return Py_BuildValue("(llll)", hour, minute, second, microsecond); } static PyObject * @@ -2634,7 +2634,7 @@ test_PyDateTime_DELTA_GET(PyObject *self, PyObject *obj) seconds = PyDateTime_DELTA_GET_SECONDS(obj); microseconds = PyDateTime_DELTA_GET_MICROSECONDS(obj); - return Py_BuildValue("[lll]", days, seconds, microseconds); + return Py_BuildValue("(lll)", days, seconds, microseconds); } /* test_thread_state spawns a thread of its own, and that thread releases