The last remaining set of tests to split out that are focused on one
specific implementation portion (`bufferedio.c`).
test_io.test_general is now largely tests around `io.open` and module
properties (ex. pickling, class hierarchy, module members, etc).
This closes#138013.
gh-138013: Split TextIO tests from test_general
These tests take 1.3 seconds on my dev machine, match fairly closely
with testing `textio.c` implementation only.
Increase parallelism by splitting out `SignalsTest` from test_general.
`SignalsTest` takes 24.2 seconds on my dev machine when fully enabled
making it the largest part of `test_io`. Code move done via copy/paste
then tweak imports.
After splitting `test_io.test_general` is down to 10.1 seconds on my dev
box with all parts enabled.
In `_io__Buffered_flush_impl` the macro `CHECK_CLOSED` is used to check
the `buffered*` is in a good state to be flushed. That differs slightly
from `buffered_closed`.
In some cases, that difference would result in `close()` thinking the
file needed to be flushed and closed while `flush()` thought the file
was already closed.
This could happen during GC and would result in an unraisable exception.
Rely on default test discovery.
Validation:
```bash
# Run before commit
./python -m test test_io -uall,walltime,largefile,cpu,extralargefile -M25G -o --fail-env-changed -j0 --list-cases | sort > old_cases.txt
# Run after commit
./python -m test test_io -uall,walltime,largefile,cpu,extralargefile -M25G -o --fail-env-changed -j0 --list-cases | sort > new_cases.txt
diff new_cases.txt old_cases.
# <outputs no changes in case list>
```
Reduce what happens in `load_tests` so that the next change,
moving the `Buffered*` tests to `test_bufferdio` is purely mechanical
movement and updating imports.
This adds two classes, one per I/O implementation, to act as dispatch to
the implementation-specific mocks as well as module members. Previously
the mappings CTestCase and PyTestCase provide were injected directly
during `load_tests`.
CTestCase and PyTestCase inherit from `unittest.TestCase` so when the
split happens default test discovery will work for the classes in
`test_bufferedio`. `test_general` keeps a manual test list for this
refactoring; some of the tests (ex. `ProtocolsTest`) aren't currently
run and fixing that + helpers to not be picked up is out of my current
scope.
CTestCase and PyTestCase have an `io` class member which points to the
implementation meaning that can be removed from individual test cases
which now inherit from them.
This code is picking up `MockRawIO` which is defined globally in the
module but these should use the mock specific to the I/O implementation
being tested.
Co-authored-by: Victor Stinner <vstinner@python.org>
Centralize `io` tests into the `test_io` module so they are easier to
find and work on. This will make it easier to split `test_general` which
takes 30+ seconds in a debug build on my machine.
This renames `test_bufio` to be `test_bufferedio` so that it matches
the implementation file name (`bufferedio.c`).
Validation performed:
Tests are run in parallel after change:
```bash
./python.exe -m test test_io -uall,largefile,extralargefile -M12G -j8
```
Docstring reformat in `test_io/__init__.py` looks reasonable:
```python
>>> import test.test_io
>>> help(test.test_io)
```
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>