Skip to content

Commit 0165997

Browse files
cmaloneyclaude
andcommitted
gh-163124: Remove the _pyio tests
Run the io tests against the C implementation only. The _pyio test classes and mocks go away, and tests that the C classes shared with them move into mixins. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 18911bc commit 0165997

14 files changed

Lines changed: 40 additions & 267 deletions

‎Lib/test/test_io/__init__.py‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Tests for the io module and its implementations (_io and _pyio)
1+
"""Tests for the io module
22
33
Tests are split across multiple files to increase
44
parallelism and focus on specific implementation pieces.
@@ -9,14 +9,8 @@
99
* test_builtin, test_print - open(), input() and print()
1010
* test_cmd_line, test_subprocess - stdio buffering and newlines at startup
1111
and through pipes
12-
* test_utf8_mode - UTF-8 mode encodings, including with _pyio
12+
* test_utf8_mode - UTF-8 mode encodings
1313
* test_os, test_eintr - fd-level I/O and EINTR retries
14-
15-
.. attention::
16-
When writing tests for io, it's important to test both the C and Python
17-
implementations. This is usually done by writing a base test that refers to
18-
the type it is testing as an attribute. Then it provides custom subclasses to
19-
test both implementations. This directory contains lots of examples.
2014
"""
2115

2216
import os

‎Lib/test/test_io/test_bufferedio.py‎

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@
1111
from itertools import cycle, count
1212
from test import support
1313
from test.support import check_sanitizer, os_helper, threading_helper
14-
from .utils import byteslike, CTestCase, PyTestCase
14+
from .utils import byteslike, CTestCase
1515

1616

1717
import io # C implementation.
18-
import _pyio as pyio # Python implementation.
1918

2019

2120
class CommonBufferedTests:
@@ -595,13 +594,10 @@ def test_initialization(self):
595594
def test_misbehaved_io_read(self):
596595
rawio = self.MisbehavedRawIO((b"abc", b"d", b"efg"))
597596
bufio = self.tp(rawio)
598-
# _pyio.BufferedReader seems to implement reading different, so that
599-
# checking this is not so easy.
600597
self.assertRaises(OSError, bufio.read, 10)
601598

602599
def test_garbage_collection(self):
603600
# C BufferedReader objects are collected.
604-
# The Python version has __del__, so it ends into gc.garbage instead
605601
self.addCleanup(os_helper.unlink, os_helper.TESTFN)
606602
# Note that using warnings_helper.check_warnings() will keep the
607603
# file alive due to the `source` argument to warn(). So, use
@@ -657,10 +653,6 @@ def test_read1_error_does_not_cause_reentrant_failure(self):
657653
self.assertEqual(bufio.read1(1), b"h")
658654

659655

660-
class PyBufferedReaderTest(BufferedReaderTest, PyTestCase):
661-
tp = pyio.BufferedReader
662-
663-
664656
class BufferedWriterTest(CommonBufferedTests):
665657
write_mode = "wb"
666658

@@ -972,7 +964,6 @@ def test_initialization(self):
972964
def test_garbage_collection(self):
973965
# C BufferedWriter objects are collected, and collecting them flushes
974966
# all data to disk.
975-
# The Python version has __del__, so it ends into gc.garbage instead
976967
self.addCleanup(os_helper.unlink, os_helper.TESTFN)
977968
# Note that using warnings_helper.check_warnings() will keep the
978969
# file alive due to the `source` argument to warn(). So, use
@@ -1017,9 +1008,6 @@ def closed(self):
10171008
self.assertRaisesRegex(ValueError, "test", bufio.close)
10181009

10191010

1020-
class PyBufferedWriterTest(BufferedWriterTest, PyTestCase):
1021-
tp = pyio.BufferedWriter
1022-
10231011
class BufferedRWPairTest:
10241012

10251013
def test_constructor(self):
@@ -1273,9 +1261,6 @@ def test_weakref_clearing(self):
12731261
class CBufferedRWPairTest(BufferedRWPairTest, CTestCase):
12741262
tp = io.BufferedRWPair
12751263

1276-
class PyBufferedRWPairTest(BufferedRWPairTest, PyTestCase):
1277-
tp = pyio.BufferedRWPair
1278-
12791264

12801265
class BufferedRandomTest(BufferedReaderTest, BufferedWriterTest):
12811266
read_mode = "rb+"
@@ -1570,10 +1555,6 @@ def flush():
15701555
self.assertFalse(rawio.closed)
15711556

15721557

1573-
class PyBufferedRandomTest(BufferedRandomTest, PyTestCase):
1574-
tp = pyio.BufferedRandom
1575-
1576-
15771558
# Simple test to ensure that optimizations in the IO library deliver the
15781559
# expected results. For best testing, run this under a debug-build Python too
15791560
# (to exercise asserts in the C code).
@@ -1635,9 +1616,6 @@ def test_nullpat(self):
16351616
class CBufferSizeTest(BufferSizeTest, unittest.TestCase):
16361617
open = io.open
16371618

1638-
class PyBufferSizeTest(BufferSizeTest, unittest.TestCase):
1639-
open = staticmethod(pyio.open)
1640-
16411619

16421620
if __name__ == "__main__":
16431621
unittest.main()

‎Lib/test/test_io/test_file.py‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from weakref import proxy
66

77
import io
8-
import _pyio as pyio
98

109
from test.support import gc_collect
1110
from test.support.os_helper import TESTFN
@@ -135,9 +134,6 @@ def testReadWhenWriting(self):
135134
class CAutoFileTests(AutoFileTests, unittest.TestCase):
136135
open = io.open
137136

138-
class PyAutoFileTests(AutoFileTests, unittest.TestCase):
139-
open = staticmethod(pyio.open)
140-
141137

142138
class OtherFileTests:
143139

@@ -354,9 +350,6 @@ def testIteration(self):
354350
class COtherFileTests(OtherFileTests, unittest.TestCase):
355351
open = io.open
356352

357-
class PyOtherFileTests(OtherFileTests, unittest.TestCase):
358-
open = staticmethod(pyio.open)
359-
360353

361354
if __name__ == '__main__':
362355
unittest.main()

‎Lib/test/test_io/test_file_eintr.py‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
# Test import all of the things we're about to try testing up front.
2424
import _io # noqa: F401
25-
import _pyio # noqa: F401
2625

2726
@unittest.skipUnless(os.name == 'posix', 'tests requires a posix system.')
2827
class TestFileIOSignalInterrupt:
@@ -186,9 +185,6 @@ def test_readall(self):
186185
class CTestFileIOSignalInterrupt(TestFileIOSignalInterrupt, unittest.TestCase):
187186
modname = '_io'
188187

189-
class PyTestFileIOSignalInterrupt(TestFileIOSignalInterrupt, unittest.TestCase):
190-
modname = '_pyio'
191-
192188

193189
class TestBufferedIOSignalInterrupt(TestFileIOSignalInterrupt):
194190
def _generate_infile_setup_code(self):
@@ -208,9 +204,6 @@ def test_readall(self):
208204
class CTestBufferedIOSignalInterrupt(TestBufferedIOSignalInterrupt, unittest.TestCase):
209205
modname = '_io'
210206

211-
class PyTestBufferedIOSignalInterrupt(TestBufferedIOSignalInterrupt, unittest.TestCase):
212-
modname = '_pyio'
213-
214207

215208
class TestTextIOSignalInterrupt(TestFileIOSignalInterrupt):
216209
def _generate_infile_setup_code(self):
@@ -247,9 +240,6 @@ def test_readall(self):
247240
class CTestTextIOSignalInterrupt(TestTextIOSignalInterrupt, unittest.TestCase):
248241
modname = '_io'
249242

250-
class PyTestTextIOSignalInterrupt(TestTextIOSignalInterrupt, unittest.TestCase):
251-
modname = '_pyio'
252-
253243

254244
if __name__ == '__main__':
255245
unittest.main()

‎Lib/test/test_io/test_fileio.py‎

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
from collections import UserList
2222

2323
import _io # C implementation of io
24-
import _pyio # Python implementation of io
2524

2625

2726
_strace_flags=["--trace=%file,%desc"]
@@ -524,11 +523,6 @@ def testFinalizing(self):
524523
self.f._finalizing = False
525524

526525

527-
class PyAutoFileTests(AutoFileTests, unittest.TestCase):
528-
FileIO = _pyio.FileIO
529-
modulename = '_pyio'
530-
531-
532526
class OtherFileTests:
533527

534528
def testAbles(self):
@@ -779,24 +773,6 @@ def test_open_code(self):
779773
self.assertEqual(expected, actual)
780774

781775

782-
class PyOtherFileTests(OtherFileTests, unittest.TestCase):
783-
FileIO = _pyio.FileIO
784-
modulename = '_pyio'
785-
open = _pyio.open
786-
787-
def test_open_code(self):
788-
# Check that the default behaviour of open_code matches
789-
# open("rb")
790-
with self.FileIO(__file__, "rb") as f:
791-
expected = f.read()
792-
with check_warnings(quiet=True) as w:
793-
# Always test _open_code_with_warning
794-
with _pyio._open_code_with_warning(__file__) as f:
795-
actual = f.read()
796-
self.assertEqual(expected, actual)
797-
self.assertNotEqual(w.warnings, [])
798-
799-
800776
def tearDownModule():
801777
# Historically, these tests have been sloppy about removing TESTFN.
802778
# So get rid of it no matter what.

‎Lib/test/test_io/test_free_threading.py‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import codecs
22
import io
3-
import _pyio as pyio
43
import threading
54
from unittest import SkipTest, TestCase
65
from test.support import Py_GIL_DISABLED, threading_helper
@@ -182,9 +181,6 @@ def reader():
182181
with threading_helper.start_threads(threads):
183182
pass
184183

185-
class PyBytesIOTest(ThreadSafetyMixin, TestCase):
186-
ioclass = pyio.BytesIO
187-
188184

189185
class IncrementalNewlineDecoderTest(TestCase):
190186
def make_decoder(self):

‎Lib/test/test_io/test_general.py‎

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@
2121
import_helper, is_apple, os_helper, threading_helper, warnings_helper,
2222
)
2323
from test.support.os_helper import FakePath
24-
from .utils import byteslike, CTestCase, PyTestCase
24+
from .utils import byteslike, CTestCase
2525

2626
import io # C implementation of io
27-
import _pyio as pyio # Python implementation of io
2827

2928

3029
class IOTest:
@@ -1007,24 +1006,6 @@ def test_stringio_setstate(self):
10071006
obj.__setstate__(('', '', 0, {}))
10081007
self.assertEqual(obj.getvalue(), '')
10091008

1010-
class PyIOTest(IOTest, PyTestCase):
1011-
pass
1012-
1013-
1014-
@support.cpython_only
1015-
class APIMismatchTest(unittest.TestCase):
1016-
1017-
def test_RawIOBase_io_in_pyio_match(self):
1018-
"""Test that pyio RawIOBase class has all c RawIOBase methods"""
1019-
mismatch = support.detect_api_mismatch(pyio.RawIOBase, io.RawIOBase,
1020-
ignore=('__weakref__', '__static_attributes__'))
1021-
self.assertEqual(mismatch, set(), msg='Python RawIOBase does not have all C RawIOBase methods')
1022-
1023-
def test_RawIOBase_pyio_in_io_match(self):
1024-
"""Test that c RawIOBase class has all pyio RawIOBase methods"""
1025-
mismatch = support.detect_api_mismatch(io.RawIOBase, pyio.RawIOBase)
1026-
self.assertEqual(mismatch, set(), msg='C RawIOBase does not have all Python RawIOBase methods')
1027-
10281009

10291010
# XXX Tests for open()
10301011

@@ -1489,12 +1470,6 @@ def test_daemon_threads_shutdown_stderr_deadlock(self):
14891470
self.check_daemon_threads_shutdown_deadlock('stderr')
14901471

14911472

1492-
class PyMiscIOTest(MiscIOTest, PyTestCase):
1493-
name_of_module = "_pyio", "io"
1494-
extra_exported = "BlockingIOError", "open_code",
1495-
not_exported = "valid_seek_flags",
1496-
1497-
14981473
class ProtocolsTest(unittest.TestCase):
14991474
class MyReader:
15001475
def read(self, sz=-1):

‎Lib/test/test_io/test_largefile.py‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from test.support import socket_helper
1313
from test.support.os_helper import TESTFN, unlink
1414
import io # C implementation of io
15-
import _pyio as pyio # Python implementation of io
1615

1716
# size of file to create (>2 GiB; 2 GiB == 2,147,483,648 bytes)
1817
size = 2_500_000_000
@@ -297,10 +296,6 @@ class CLargeFileTest(TestFileMethods, unittest.TestCase):
297296
open = staticmethod(io.open)
298297

299298

300-
class PyLargeFileTest(TestFileMethods, unittest.TestCase):
301-
open = staticmethod(pyio.open)
302-
303-
304299
def tearDownModule():
305300
unlink(TESTFN)
306301
unlink(TESTFN2)

‎Lib/test/test_io/test_memoryio.py‎

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import gc
1010
import io
11-
import _pyio as pyio
1211
import pickle
1312
import struct
1413
import sys
@@ -436,15 +435,10 @@ def __init__(me, initvalue, foo):
436435
del __main__.PickleTestMemIO
437436

438437

439-
class PyBytesIOTest(MemoryTestMixin, MemorySeekTestMixin, unittest.TestCase):
440-
# Test _pyio.BytesIO; class also inherited for testing C implementation
441-
442-
UnsupportedOperation = pyio.UnsupportedOperation
443-
438+
class BytesIOTest(MemoryTestMixin, MemorySeekTestMixin):
444439
@staticmethod
445440
def buftype(s):
446441
return s.encode("ascii")
447-
ioclass = pyio.BytesIO
448442
EOF = b""
449443

450444
def test_getbuffer(self):
@@ -928,11 +922,8 @@ def test_newline_argument(self):
928922
self.ioclass(newline=newline)
929923

930924

931-
class PyStringIOTest(MemoryTestMixin, MemorySeekTestMixin,
932-
TextIOTestMixin, unittest.TestCase):
925+
class StringIOTest(MemoryTestMixin, MemorySeekTestMixin, TextIOTestMixin):
933926
buftype = str
934-
ioclass = pyio.StringIO
935-
UnsupportedOperation = pyio.UnsupportedOperation
936927
EOF = ""
937928

938929
def test_lone_surrogates(self):
@@ -945,21 +936,7 @@ def test_lone_surrogates(self):
945936
self.assertEqual(memio.getvalue(), '\ud800')
946937

947938

948-
class PyStringIOPickleTest(TextIOTestMixin, unittest.TestCase):
949-
"""Test if pickle restores properly the internal state of StringIO.
950-
"""
951-
buftype = str
952-
UnsupportedOperation = pyio.UnsupportedOperation
953-
EOF = ""
954-
955-
class ioclass(pyio.StringIO):
956-
def __new__(cls, *args, **kwargs):
957-
return pickle.loads(pickle.dumps(pyio.StringIO(*args, **kwargs)))
958-
def __init__(self, *args, **kwargs):
959-
pass
960-
961-
962-
class CBytesIOTest(PyBytesIOTest):
939+
class CBytesIOTest(BytesIOTest, unittest.TestCase):
963940
ioclass = io.BytesIO
964941
UnsupportedOperation = io.UnsupportedOperation
965942

@@ -1152,7 +1129,7 @@ def test_write_with_export(self):
11521129
self.assertEqual(memio.getvalue(), b"abXd")
11531130

11541131

1155-
class CStringIOTest(PyStringIOTest):
1132+
class CStringIOTest(StringIOTest, unittest.TestCase):
11561133
ioclass = io.StringIO
11571134
UnsupportedOperation = io.UnsupportedOperation
11581135

@@ -1174,8 +1151,6 @@ def __index__(self):
11741151
self.assertEqual(stream.truncate(2**31), 2**31)
11751152
self.assertEqual(stream.getvalue(), "abc")
11761153

1177-
# XXX: For the Python version of io.StringIO, this is highly
1178-
# dependent on the encoding used for the underlying buffer.
11791154
def test_widechar(self):
11801155
buf = self.buftype("\U0002030a\U00020347")
11811156
memio = self.ioclass(buf)
@@ -1274,7 +1249,11 @@ def test_memory_error_consistent_state(self):
12741249
self.assertEqual(memio.getvalue(), text + "!")
12751250

12761251

1277-
class CStringIOPickleTest(PyStringIOPickleTest):
1252+
class CStringIOPickleTest(TextIOTestMixin, unittest.TestCase):
1253+
"""Test if pickle restores properly the internal state of StringIO.
1254+
"""
1255+
buftype = str
1256+
EOF = ""
12781257
UnsupportedOperation = io.UnsupportedOperation
12791258

12801259
class ioclass(io.StringIO):

0 commit comments

Comments
 (0)