Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

gh-117398: Add multiphase support to _datetime #119373

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
Kinda fix the C API tests
  • Loading branch information
erlend-aasland committed May 22, 2024
commit 863ecd71d302896cdb964d4ae2e6b117c2a90eae
6 changes: 5 additions & 1 deletion 6 Lib/test/datetimetester.py
Original file line number Diff line number Diff line change
Expand Up @@ -6384,14 +6384,18 @@ class IranTest(ZoneInfoTest):

@unittest.skipIf(_testcapi is None, 'need _testcapi module')
class CapiTest(unittest.TestCase):

def setUp(self):
# Since the C API is not present in the _Pure tests, skip all tests
if self.__class__.__name__.endswith('Pure'):
self.skipTest('Not relevant in pure Python')

# This *must* be called, and it must be called first, so until either
# restriction is loosened, we'll call it as part of test setup
_testcapi.test_datetime_capi()
_testcapi.setup_capi()

def tearDown(self):
_testcapi.teardown_capi()

def test_utc_capi(self):
for use_macro in (True, False):
Expand Down
34 changes: 15 additions & 19 deletions 34 Modules/_testcapi/datetime.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,21 @@
static int test_run_counter = 0;

static PyObject *
test_datetime_capi(PyObject *self, PyObject *args)
setup_capi(PyObject *self, PyObject *args)
{
if (PyDateTimeAPI) {
if (test_run_counter) {
/* Probably regrtest.py -R */
Py_RETURN_NONE;
}
else {
PyErr_SetString(PyExc_AssertionError,
"PyDateTime_CAPI somehow initialized");
return NULL;
}
}
test_run_counter++;
PyDateTime_IMPORT;

if (PyDateTimeAPI) {
Py_RETURN_NONE;
if (!test_run_counter++) {
PyDateTime_IMPORT;
}
return NULL;
assert(PyDateTimeAPI);
Py_RETURN_NONE;
}

static PyObject *
teardown_capi(PyObject *self, PyObject *args)
{
test_run_counter--;
assert(test_run_counter >= 0);
Py_RETURN_NONE;
}

/* Functions exposing the C API type checking for testing */
Expand Down Expand Up @@ -467,7 +462,8 @@ static PyMethodDef test_methods[] = {
{"get_timezone_utc_capi", get_timezone_utc_capi, METH_VARARGS},
{"get_timezones_offset_zero", get_timezones_offset_zero, METH_NOARGS},
{"make_timezones_capi", make_timezones_capi, METH_NOARGS},
{"test_datetime_capi", test_datetime_capi, METH_NOARGS},
{"setup_capi", setup_capi, METH_NOARGS},
{"teardown_capi", teardown_capi, METH_NOARGS},
{NULL},
};

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.