Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
d9945c2
created a c API wrapper for pyDate_FromDate and added the test
May 4, 2019
f1573d6
📜🤖 Added by blurb_it.
blurb-it[bot] May 4, 2019
0284ced
fixed auto-alignment by vscode
May 4, 2019
8cca15f
Merge branch 'bpo-36782' of https://github.com/SimiCode/cpython into …
May 4, 2019
d9ecbf5
made changes as per PEP7
May 4, 2019
7967114
Update 2019-05-04-21-25-19.bpo-36782.h3oPIb.rst
edison12a May 4, 2019
f6b3ab8
Refactored code as per requested changes
May 6, 2019
3b2095d
Remove Whitespace to Fix failed travis build
May 6, 2019
f6d590f
Update 2019-05-04-21-25-19.bpo-36782.h3oPIb.rst
edison12a May 6, 2019
7598e26
Add a new line at end of ACKS
edison12a May 6, 2019
f9e6213
Added C API function for PyDateTime_FromDateAndTime
May 6, 2019
948b2ce
Added a test for the C API wrapper of PyDateTime_FromDateAndTime
May 6, 2019
64b4ae2
Added C API function for PyDateTime_FromDateAndTime
May 6, 2019
2e8188c
Added a test for the C API wrapper of PyDateTime_FromDateAndTimeAndFold
May 6, 2019
642e802
Remove Whitespace using patchcheck
May 6, 2019
a9ada00
Added a C API function for PyTime_FromTime
May 6, 2019
f3b692e
Added a test for the C API wrapper of PyTime_FromTime
May 6, 2019
ddba978
Added a C API function for PyTime_FromTimeAndFold
May 6, 2019
64632de
Added a test for the C API wrapper of PyTime_FromTimeAndFold
May 6, 2019
501d26b
Added a C API function for PyDelta_FromDSU
May 6, 2019
9adbc3d
Added a test for the C API wrapper of PyDelta_FromDSU
May 6, 2019
237413a
Refactor code, re-edit lines longer than 80 chars
May 7, 2019
dc6ac8e
Fix Whitespace issues in DatetimeTester
May 7, 2019
d7b8a5e
List all tests that were added in this PR
May 7, 2019
ce9e56d
Update 2019-05-04-21-25-19.bpo-36782.h3oPIb.rst
edison12a May 7, 2019
2f3f64e
Reformat code as per PEP7 guidelines
May 7, 2019
a8817d3
Remove unused varibles from another function
May 7, 2019
ab0308a
Merge branch 'bpo-36782' of https://github.com/SimiCode/cpython into …
May 7, 2019
2781d2e
Added specific tests for the Fold Attribute
May 7, 2019
91fce02
Update 2019-05-04-21-25-19.bpo-36782.h3oPIb.rst
edison12a May 7, 2019
5cb05e1
Reformat code according to requested changes
May 7, 2019
6039531
Reformat code to PEP7 Guidelines
May 7, 2019
07924e6
Reformat code to PEP7 Guidelines
May 7, 2019
59d4ba0
Re-add name to blurb
May 7, 2019
0c00468
Added a backtick to blurb file
May 7, 2019
1d4ebfc
Update 2019-05-04-21-25-19.bpo-36782.h3oPIb.rst
matrixise May 7, 2019
40ebd42
Remove empty line and useless comment
May 8, 2019
75cc9c0
Remove the need to initialize mandatory parameters
May 8, 2019
a9422a0
Make the macro parameter mandatory
May 8, 2019
3397abe
Resolve blurb merge conflict
May 8, 2019
6df027e
Re-arrange the order of unit-test args
May 8, 2019
48f7e03
Removed the need to initialize macro
edison12a May 11, 2019
7e91753
Removed the need to initialize macro
edison12a May 11, 2019
588d95a
Removed the need to initialize macro
edison12a May 11, 2019
eb3e060
Removed the need to initialize macro
edison12a May 11, 2019
1e4db07
Removed the need to initialize macro
edison12a May 11, 2019
a9c7623
Removed the need to initialize macro
edison12a May 11, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 94 additions & 3 deletions Lib/test/datetimetester.py
Original file line number Diff line number Diff line change
Expand Up @@ -6018,6 +6018,100 @@ class TZInfoSubclass(tzinfo):
with self.subTest(arg=arg, exact=exact):
self.assertFalse(is_tzinfo(arg, exact))

def test_date_from_date(self):
exp_date = date(1993, 8, 26)

for macro in [0, 1]:
with self.subTest(macro=macro):
c_api_date = _testcapi.get_date_fromdate(
macro,
exp_date.year,
exp_date.month,
exp_date.day)

self.assertEqual(c_api_date, exp_date)

def test_datetime_from_dateandtime(self):
exp_date = datetime(1993, 8, 26, 22, 12, 55, 99999)

for macro in [0, 1]:
with self.subTest(macro=macro):
c_api_date = _testcapi.get_datetime_fromdateandtime(
macro,
exp_date.year,
exp_date.month,
exp_date.day,
exp_date.hour,
exp_date.minute,
exp_date.second,
exp_date.microsecond)

self.assertEqual(c_api_date, exp_date)

def test_datetime_from_dateandtimeandfold(self):
exp_date = datetime(1993, 8, 26, 22, 12, 55, 99999)

for fold in [0, 1]:
for macro in [0, 1]:
with self.subTest(macro=macro, fold=fold):
c_api_date = _testcapi.get_datetime_fromdateandtimeandfold(
macro,
exp_date.year,
exp_date.month,
exp_date.day,
exp_date.hour,
exp_date.minute,
exp_date.second,
exp_date.microsecond,
exp_date.fold)

self.assertEqual(c_api_date, exp_date)
Comment thread
edison12a marked this conversation as resolved.
self.assertEqual(c_api_date.fold, exp_date.fold)

def test_time_from_time(self):
exp_time = time(22, 12, 55, 99999)

for macro in [0, 1]:
with self.subTest(macro=macro):
c_api_time = _testcapi.get_time_fromtime(
macro,
exp_time.hour,
exp_time.minute,
exp_time.second,
exp_time.microsecond)

self.assertEqual(c_api_time, exp_time)

def test_time_from_timeandfold(self):
exp_time = time(22, 12, 55, 99999)

for fold in [0, 1]:
for macro in [0, 1]:
with self.subTest(macro=macro, fold=fold):
c_api_time = _testcapi.get_time_fromtimeandfold(
macro,
exp_time.hour,
exp_time.minute,
exp_time.second,
exp_time.microsecond,
exp_time.fold)

self.assertEqual(c_api_time, exp_time)
Comment thread
edison12a marked this conversation as resolved.
self.assertEqual(c_api_time.fold, exp_time.fold)

def test_delta_from_dsu(self):
exp_delta = timedelta(26, 55, 99999)

for macro in [0, 1]:
with self.subTest(macro=macro):
c_api_delta = _testcapi.get_delta_fromdsu(
macro,
exp_delta.days,
exp_delta.seconds,
exp_delta.microseconds)

self.assertEqual(c_api_delta, exp_delta)

def test_date_from_timestamp(self):
ts = datetime(1995, 4, 12).timestamp()

Expand All @@ -6028,9 +6122,6 @@ def test_date_from_timestamp(self):
self.assertEqual(d, date(1995, 4, 12))

def test_datetime_from_timestamp(self):
ts0 = datetime(1995, 4, 12).timestamp()
ts1 = datetime(1995, 4, 12, 12, 30).timestamp()

cases = [
((1995, 4, 12), None, False),
((1995, 4, 12), None, True),
Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -1853,3 +1853,4 @@ Peter Åstrand
Zheao Li
Carsten Klein
Diego Rojas
Edison Abahurire
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add tests for several C API functions in the :mod:`datetime` module. Patch by Edison Abahurire.
170 changes: 169 additions & 1 deletion Modules/_testcapimodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2340,6 +2340,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;

Comment thread
edison12a marked this conversation as resolved.
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(
Comment thread
edison12a marked this conversation as resolved.
year, month, day,
hour, minute, second, microsecond,
fold);
}
else {
rv = PyDateTimeAPI->DateTime_FromDateAndTimeAndFold(
Comment thread
edison12a marked this conversation as resolved.
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(
Comment thread
edison12a marked this conversation as resolved.
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(
Comment thread
edison12a marked this conversation as resolved.
days, seconds, microseconds, 1,
PyDateTimeAPI->DeltaType);
}

return rv;
}

static PyObject *
get_date_fromtimestamp(PyObject* self, PyObject *args)
{
Expand Down Expand Up @@ -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},
Expand All @@ -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},
Expand Down