summaryrefslogtreecommitdiffstats
path: root/Modules/_testcapimodule.c
diff options
context:
space:
mode:
authorEdison A <20975616+SimiCode@users.noreply.github.com>2019-05-17 20:28:42 (GMT)
committerVictor Stinner <vstinner@redhat.com>2019-05-17 20:28:42 (GMT)
commit98ff4d5fb6a9d01b0176b7786db61346952e5295 (patch)
tree9104c4f434349d9726dcb8803a747ce0201d80fa /Modules/_testcapimodule.c
parentfeac6cd7753425fba006e97e2d9b74a0c0c75894 (diff)
downloadcpython-98ff4d5fb6a9d01b0176b7786db61346952e5295.zip
cpython-98ff4d5fb6a9d01b0176b7786db61346952e5295.tar.gz
cpython-98ff4d5fb6a9d01b0176b7786db61346952e5295.tar.bz2
bpo-36782: Created C API wrappers and added missing tests for functions in the PyDateTimeAPI. (#13088)
* created a c API wrapper for pyDate_FromDate and added the test * 📜🤖 Added by blurb_it. * fixed auto-alignment by vscode * made changes as per PEP7 * Update 2019-05-04-21-25-19.bpo-36782.h3oPIb.rst * Refactored code as per requested changes * Remove Whitespace to Fix failed travis build * Update 2019-05-04-21-25-19.bpo-36782.h3oPIb.rst * Add a new line at end of ACKS * Added C API function for PyDateTime_FromDateAndTime * Added a test for the C API wrapper of PyDateTime_FromDateAndTime * Added C API function for PyDateTime_FromDateAndTime * Added a test for the C API wrapper of PyDateTime_FromDateAndTimeAndFold * Remove Whitespace using patchcheck * Added a C API function for PyTime_FromTime * Added a test for the C API wrapper of PyTime_FromTime * Added a C API function for PyTime_FromTimeAndFold * Added a test for the C API wrapper of PyTime_FromTimeAndFold * Added a C API function for PyDelta_FromDSU * Added a test for the C API wrapper of PyDelta_FromDSU * Refactor code, re-edit lines longer than 80 chars * Fix Whitespace issues in DatetimeTester * List all tests that were added in this PR * Update 2019-05-04-21-25-19.bpo-36782.h3oPIb.rst * Reformat code as per PEP7 guidelines * Remove unused varibles from another function * Added specific tests for the Fold Attribute * Update 2019-05-04-21-25-19.bpo-36782.h3oPIb.rst * Reformat code according to requested changes * Reformat code to PEP7 Guidelines * Reformat code to PEP7 Guidelines * Re-add name to blurb * Added a backtick to blurb file * Update 2019-05-04-21-25-19.bpo-36782.h3oPIb.rst * Remove the need to initialize mandatory parameters * Make the macro parameter mandatory * Re-arrange the order of unit-test args * Removed the need to initialize macro change all the int macro = 0 to int macro; now that macro is required Co-Authored-By: Paul Ganssle <pganssle@users.noreply.github.com> * Removed the need to initialize macro change all the `int macro = 0` to `int macro`; now that macro is required Co-Authored-By: Paul Ganssle <pganssle@users.noreply.github.com> * Removed the need to initialize macro change all the `int macro = 0` to `int macro`; now that macro is required Co-Authored-By: Paul Ganssle <pganssle@users.noreply.github.com> * Removed the need to initialize macro change all the `int macro = 0` to `int macro`; now that macro is required Co-Authored-By: Paul Ganssle <pganssle@users.noreply.github.com> * Removed the need to initialize macro change all the `int macro = 0` to `int macro`; now that macro is required Co-Authored-By: Paul Ganssle <pganssle@users.noreply.github.com> * Removed the need to initialize macro change all the `int macro = 0` to `int macro`; now that macro is required Co-Authored-By: Paul Ganssle <pganssle@users.noreply.github.com>
Diffstat (limited to 'Modules/_testcapimodule.c')
-rw-r--r--Modules/_testcapimodule.c170
1 files changed, 169 insertions, 1 deletions
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index 59b42df..2af5539 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -2341,6 +2341,168 @@ get_timezone_utc_capi(PyObject* self, PyObject *args) {
}
static PyObject *
+get_date_fromdate(PyObject *self, PyObject *args)
+{
+ PyObject *rv = NULL;
+ int macro;
+ int year, month, day;
+
+ if (!PyArg_ParseTuple(args, "piii", &macro, &year, &month, &day)) {
+ return NULL;
+ }
+
+ if (macro) {
+ rv = PyDate_FromDate(year, month, day);
+ }
+ else {
+ rv = PyDateTimeAPI->Date_FromDate(
+ year, month, day,
+ PyDateTimeAPI->DateType);
+ }
+ return rv;
+}
+
+static PyObject *
+get_datetime_fromdateandtime(PyObject *self, PyObject *args)
+{
+ PyObject *rv = NULL;
+ int macro;
+ int year, month, day;
+ int hour, minute, second, microsecond;
+
+ if (!PyArg_ParseTuple(args, "piiiiiii",
+ &macro,
+ &year, &month, &day,
+ &hour, &minute, &second, &microsecond)) {
+ return NULL;
+ }
+
+ if (macro) {
+ rv = PyDateTime_FromDateAndTime(
+ year, month, day,
+ hour, minute, second, microsecond);
+ }
+ else {
+ rv = PyDateTimeAPI->DateTime_FromDateAndTime(
+ year, month, day,
+ hour, minute, second, microsecond,
+ Py_None,
+ PyDateTimeAPI->DateTimeType);
+ }
+ return rv;
+}
+
+static PyObject *
+get_datetime_fromdateandtimeandfold(PyObject *self, PyObject *args)
+{
+ PyObject *rv = NULL;
+ int macro;
+ int year, month, day;
+ int hour, minute, second, microsecond, fold;
+
+ if (!PyArg_ParseTuple(args, "piiiiiiii",
+ &macro,
+ &year, &month, &day,
+ &hour, &minute, &second, &microsecond,
+ &fold)) {
+ return NULL;
+ }
+
+ if (macro) {
+ rv = PyDateTime_FromDateAndTimeAndFold(
+ year, month, day,
+ hour, minute, second, microsecond,
+ fold);
+ }
+ else {
+ rv = PyDateTimeAPI->DateTime_FromDateAndTimeAndFold(
+ year, month, day,
+ hour, minute, second, microsecond,
+ Py_None,
+ fold,
+ PyDateTimeAPI->DateTimeType);
+ }
+ return rv;
+}
+
+static PyObject *
+get_time_fromtime(PyObject *self, PyObject *args)
+{
+ PyObject *rv = NULL;
+ int macro;
+ int hour, minute, second, microsecond;
+
+ if (!PyArg_ParseTuple(args, "piiii",
+ &macro,
+ &hour, &minute, &second, &microsecond)) {
+ return NULL;
+ }
+
+ if (macro) {
+ rv = PyTime_FromTime(hour, minute, second, microsecond);
+ }
+ else {
+ rv = PyDateTimeAPI->Time_FromTime(
+ hour, minute, second, microsecond,
+ Py_None,
+ PyDateTimeAPI->TimeType);
+ }
+ return rv;
+}
+
+static PyObject *
+get_time_fromtimeandfold(PyObject *self, PyObject *args)
+{
+ PyObject *rv = NULL;
+ int macro;
+ int hour, minute, second, microsecond, fold;
+
+ if (!PyArg_ParseTuple(args, "piiiii",
+ &macro,
+ &hour, &minute, &second, &microsecond,
+ &fold)) {
+ return NULL;
+ }
+
+ if (macro) {
+ rv = PyTime_FromTimeAndFold(hour, minute, second, microsecond, fold);
+ }
+ else {
+ rv = PyDateTimeAPI->Time_FromTimeAndFold(
+ hour, minute, second, microsecond,
+ Py_None,
+ fold,
+ PyDateTimeAPI->TimeType);
+ }
+ return rv;
+}
+
+static PyObject *
+get_delta_fromdsu(PyObject *self, PyObject *args)
+{
+ PyObject *rv = NULL;
+ int macro;
+ int days, seconds, microseconds;
+
+ if (!PyArg_ParseTuple(args, "piii",
+ &macro,
+ &days, &seconds, &microseconds)) {
+ return NULL;
+ }
+
+ if (macro) {
+ rv = PyDelta_FromDSU(days, seconds, microseconds);
+ }
+ else {
+ rv = PyDateTimeAPI->Delta_FromDelta(
+ days, seconds, microseconds, 1,
+ PyDateTimeAPI->DeltaType);
+ }
+
+ return rv;
+}
+
+static PyObject *
get_date_fromtimestamp(PyObject* self, PyObject *args)
{
PyObject *tsargs = NULL, *ts = NULL, *rv = NULL;
@@ -4826,7 +4988,7 @@ static PyMethodDef TestMethods[] = {
{"set_errno", set_errno, METH_VARARGS},
{"test_config", test_config, METH_NOARGS},
{"test_sizeof_c_types", test_sizeof_c_types, METH_NOARGS},
- {"test_datetime_capi", test_datetime_capi, METH_NOARGS},
+ {"test_datetime_capi", test_datetime_capi, METH_NOARGS},
{"datetime_check_date", datetime_check_date, METH_VARARGS},
{"datetime_check_time", datetime_check_time, METH_VARARGS},
{"datetime_check_datetime", datetime_check_datetime, METH_VARARGS},
@@ -4835,6 +4997,12 @@ static PyMethodDef TestMethods[] = {
{"make_timezones_capi", make_timezones_capi, METH_NOARGS},
{"get_timezones_offset_zero", get_timezones_offset_zero, METH_NOARGS},
{"get_timezone_utc_capi", get_timezone_utc_capi, METH_VARARGS},
+ {"get_date_fromdate", get_date_fromdate, METH_VARARGS},
+ {"get_datetime_fromdateandtime", get_datetime_fromdateandtime, METH_VARARGS},
+ {"get_datetime_fromdateandtimeandfold", get_datetime_fromdateandtimeandfold, METH_VARARGS},
+ {"get_time_fromtime", get_time_fromtime, METH_VARARGS},
+ {"get_time_fromtimeandfold", get_time_fromtimeandfold, METH_VARARGS},
+ {"get_delta_fromdsu", get_delta_fromdsu, METH_VARARGS},
{"get_date_fromtimestamp", get_date_fromtimestamp, METH_VARARGS},
{"get_datetime_fromtimestamp", get_datetime_fromtimestamp, METH_VARARGS},
{"test_list_api", test_list_api, METH_NOARGS},