Author p-ganssle
Recipients p-ganssle
Date 2019-05-03.13:46:57
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1556891217.54.0.801221071749.issue36782@roundup.psfhosted.org>
In-reply-to
Content
A decent fraction of the datetime C API has no tests. If we had tests, we could have prevented bpo #36025, which was a regression in the FromTimestamp method.

I would like to open this issue to suggest the addition of tests for the full interface, to prevent further regressions here.

To write a test, first add a wrapper function in the _testcapimodule module: https://github.com/python/cpython/blob/master/Modules/_testcapimodule.c#L2218

Then test that function here: https://github.com/python/cpython/blob/master/Lib/test/datetimetester.py#L5821

See an example at GH PR 11922: https://github.com/python/cpython/pull/11922

I recommend testing *both* the version of the function accessed by the Macro (e.g. PyDate_FromTimestamp) and from the C API capsule (e.g. PyDateTimeApi->FromTimestamp), since projects access these functions in both ways.

C API Documentation is here: https://docs.python.org/3/c-api/datetime.html


Currently untested:

- PyDate_FromDate / PyDateTimeAPI->Date_FromDate
- PyDateTime_FromDateAndTime / PyDateTimeAPI->DateTime_FromDateAndTime
- PyDateTime_FromDateAndTimeAndFold / PyDateTimeAPI->DateTime_FromDateAndTimeAndFold
- PyTime_FromTime -> PyDateTimeAPI->Time_FromTime
- PyTime_FromTimeAndFold -> PyDateTime->Time_FromTimeAndFold
- PyDelta_FromDSU / PyDateTime->Delta_FromDelta

Untested macros with no corresponding API module:

- PyDateTime_DATE_GET_YEAR
- PyDateTime_DATE_GET_MONTH
- PyDateTime_DATE_GET_DAY
- PyDateTime_DATE_GET_HOUR
- PyDateTime_DATE_GET_MINUTE
- PyDateTime_DATE_GET_SECOND
- PyDateTime_DATE_GET_MICROSECOND

- PyDateTime_DELTA_GET_DAYS
- PyDateTime_DELTA_GET_SECONDS
- PyDateTime_DELTA_GET_MICROSECONDS

I can spawn smaller issues for this if that's preferred, but I figured we'd start with this big meta-issue.
History
Date User Action Args
2019-05-03 13:46:57p-gansslesetrecipients: + p-ganssle
2019-05-03 13:46:57p-gansslesetmessageid: <1556891217.54.0.801221071749.issue36782@roundup.psfhosted.org>
2019-05-03 13:46:57p-gansslelinkissue36782 messages
2019-05-03 13:46:57p-gansslecreate