New submission from Paul Ganssle <p.gans...@gmail.com>:
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. ---------- components: Tests keywords: easy messages: 341336 nosy: p-ganssle priority: low severity: normal status: open title: Add tests for the datetime C API type: enhancement versions: Python 3.8, Python 3.9 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue36782> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com