Open encukou opened 2 years ago
ideally without polluting the namespace of top-level modules
Can hypothetical Lib/_testcapimodule/*.c
export their objects as test.capi.*
?
As far as I know they can, as long as test.capi
itself is not an extension module. It would need some extra support in both make and Windows builds, though.
PR: #94549
I tried to group de 299 attributes of the _testcapi extension module. I'm not sure about each attribute, I only looked quickly at the name, sometimes at the implementation. But it should give a coarse idea of which "groups" make sense or not.
It might be interesting to split the large _testcapi module into multiple modules. But I like the idea of starting by splitting the long C file into multiple C files.
You do not need to include _testcapi/vectorcall.c
in MODULE__TESTCAPI_DEPS
. It is already listed as dependency for _testcapi
in the Setup file.
Thank you for the fix! I'll :hammer: test-with-buildbots next time I touch the buildsystem. (I wonder why this issue didn't get the broken buildbot notification, though...)
Thank you for the fix! I'll hammer test-with-buildbots next time I touch the buildsystem. (I wonder why this issue didn't get the broken buildbot notification, though...)
We think that there was a problem in the buildbot hook, https://github.com/python/buildmaster-config/issues/333
How should raiseTestError
be handled?
https://github.com/python/cpython/blob/c7e5bbaee88a71dc6e633e3cd451ed1798436382/Modules/_testcapimodule.c#L52-L62
Edit: For the Unicode tests I copied it and renamed it to _testcapi.unicode_error
.
I'd switch to the built-in AssertionError
, unless it's specifically a test for custom exceptions.
https://github.com/python/devguide/pull/936 proposes a Devguide update on C API tests.
https://github.com/python/cpython/pull/8551 started a similar reorganization for the Python code.
New "watcher" APIs have been added recently (and some are soon to land):
IMO, we could extract the watcher APIs to a separate test file under Modules/_testcapi/
. (I should've thought about that while reviewing those PRs.)
In moved PyFrameObject C API tests from the big test_capi to the end of test_frame. But since test_capi.py became a package, maybe it would make sense to move back these tests there? I don't know. test_unicode and many other tests have tests on their C API. Should we put all C API tests to test_capi just because they are implemented in C, or is it better to move C API tests is each test_xxx file?
They are tons of test files which use _testcapi:
$ (cd Lib/test/; grep -l _testcapi *.py)
audit-tests.py
datetimetester.py
pythoninfo.py
string_tests.py
test_array.py
test_buffer.py
test_bytes.py
test_call.py
test_class.py
test_cmath.py
test_cmd_line.py
test_codecs.py
test_code.py
test_context.py
test_coroutines.py
test_csv.py
test_decimal.py
test_descr.py
test_devpoll.py
test_dict.py
test_dict_version.py
test_embed.py
test_exceptions.py
test_faulthandler.py
test_fcntl.py
test_fileio.py
test_fileutils.py
test_finalization.py
test_float.py
test_format.py
test_frame.py
test_gc.py
test_gdb.py
test_generators.py
test_genericclass.py
test_getpath.py
test_inspect.py
test_marshal.py
test_multibytecodec.py
test_os.py
test_poll.py
test_posix.py
test_regrtest.py
test_repl.py
test_signal.py
test_socket.py
test_stable_abi_ctypes.py
test_struct.py
test_subprocess.py
test_sys.py
test_sys_settrace.py
test_tcl.py
test_threading.py
test_time.py
test_traceback.py
test_tracemalloc.py
test_type_cache.py
test_ucn.py
test_unicode.py
test_weakref.py
I prefer to have Unicode C API tests in test_unicode, PyFrameObject C API tests in test_frame, etc. But I'm not 100% sure if it's the best :-)
Should test_capi become a monster, since our C API is a monster? :-D
Should test_capi become a monster, since our C API is a monster? :-D
I believe test_capi is a monster, hence this issue ;) I'm not sure what is the final perfect structure here, but as Petr said earlier in this issue (and to which I also concur), splitting up _testcapimodule.c is a step in the right direction.
splitting up _testcapimodule.c is a step in the right direction.
Oh sure, I totally agree on that! Thanks for working on it.
I prefer to have Unicode C API tests in test_unicode, PyFrameObject C API tests in test_frame, etc. But I'm not 100% sure if it's the best :-)
That makes a lot of sense!
There's still plenty of things that belong it test_capi, though – module init, heap/static types, PyMemberDef
, PyStructSequence
, PyErr_Clear
, PyCapsule
, PyArg
, ...
There's still plenty of things that belong it test_capi, though – module init, heap/static types,
PyMemberDef
,PyStructSequence
,PyErr_Clear
,PyCapsule
,PyArg
, ...
BTW, I'm working on a PR for PyArg (the getarg and modsupport stuff in Victor's earlier post).
There's still plenty of things that belong it test_capi, though – module init, heap/static types, PyMemberDef, PyStructSequence, PyErr_Clear, PyCapsule, PyArg, ...
I agree. Maybe we can write down (somewhere, in the C/Python code of test_capi, in the devguide?) a list of tests which belong to test_capi file, and which tests should be done in more specific test files? Like a general guideline.
Maybe my comment is just outdated. Ignore it if it's the case :-)
I don't understand compiler warnings on the old PR #95793 (merged last August):
These warnings should only occur when assert() statements are removed by the compiler. Otherwise, these two variables are used.
And the purpose of this PR is to make sure that assertions are not removed. Does it mean that NDEBUG is undefined too late?
In Modules/_testcapimodule.c
, I undefined the macro before the first include. In Modules/_testcapi/parts.h
, it's undefined after including pyconfig.h
. It seems ok to me.
Sadly, Address Sanitizer logs of this PR are no longer available:
The logs for this run have expired and are no longer available.
.github/workflows/build.yml
currently builds Python with:
- name: Configure CPython
run: ./configure --with-address-sanitizer --without-pymalloc
- name: Build CPython
run: make -j4
- name: Display build info
run: make pythoninfo
On a recent job, I see: CC.version: gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
in test.pythoninfo.
Is it time to close issue #78453 to continue the work here? cc @serhiy-storchaka
I moved PyUnicode C API tests from test_unicode
to test_capi.test_unicode
, because I am going to cover by test all C API, and I think that such large chunk of test is better in a separate file. test_unicode
is large even without C API tests.
$ grep -c PyAPI_FUNC Include/unicodeobject.h Include/cpython/unicodeobject.h
Include/unicodeobject.h:83
Include/cpython/unicodeobject.h:69
There are around 152 "PyUnicode" C API functions. That's a lot knowing that Python 3.12 exports 939 public functions (and 354 private functions): stats on the C API.
$ wc -l Lib/test/test_{codecs,unicode}.py
3560 Lib/test/test_codecs.py
2701 Lib/test/test_unicode.py
6261 total
Currently, test_codecs is around 3 500 lines and test_unicode around 2 700 lines.
If we want to extend the coverage of the PyUnicode C API (what is being discussed here :-)), I agree that moving the Python parts of PyUnicode C API tests can be the newly added Lib/test/test_capi/test_unicode.py
.
In PR #99613, I proposed to @serhiy-storchaka to separate "codecs" tests from "unicode" tests. For me, "codecs" includes PyCodec C API but also "encode" and "decode" functions of the PyUnicode C API. What do you think?
I think this issue and issue #78453 are different. This issue is about reorganization of the C code, and #78453 is more about reorganization of the Python code.
_testcapi extension was splitted into sub-tests: multiple extensions and test_capi package with multiple tests.
The issue can now be closed, no?
I wouldn't close it -- the module still has a lot of tests that can be split out.
I agree, there are still useful refactors to be made.
See also issue gh-78453.
I created a _testlimitedcapi
extension to test the C API via the limited C API: see issue gh-116417 (completed).
Modules/_testcapimodule.c
is a nearly-8000-line behemoth with no clear structure or organization. It is getting hard to maintain.It also doesn't work well with testing (a) feature macros that affect
Python.h
and (b) module initialization, so we have additional C-API testing modules:_testmultiphase
,_testimportmultiple
,_testinternalcapi
._testbuffer
is already split out, but there are many other aspects of the API that would use a similar dedicated test suite.We should split and combine these, ideally without polluting the namespace of top-level modules.