summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_io.py
Commit message (Collapse)AuthorAgeFilesLines
* bpo-45196: prevent unittest crash on address sanitizer builds (GH-28331)junyixie2021-09-141-3/+7
|
* bpo-5846: Do not use obsolete unittest functions. (GH-28303)Serhiy Storchaka2021-09-131-2/+4
| | | | Get rid of use of makeSuite() and findTestCases(). Also make test_math and test_threading_local discoverable.
* bpo-37330: open() no longer accept 'U' in file mode (GH-28118)Victor Stinner2021-09-021-10/+7
| | | | | open(), io.open(), codecs.open() and fileinput.FileInput no longer accept "U" ("universal newline") in the file mode. This flag was deprecated since Python 3.3.
* bpo-25130: Add calls of gc.collect() in tests to support PyPy (GH-28005)Serhiy Storchaka2021-08-291-0/+25
|
* bpo-43680: Deprecate io.OpenWrapper (GH-25357)Victor Stinner2021-04-141-2/+8
| | | | | | | | Deprecate io.OpenWrapper and _pyio.OpenWrapper: use io.open and _pyio.open instead. Until Python 3.9, _pyio.open was not a static method and builtins.open was set to OpenWrapper to not become a bound method when set to a class variable. _io.open is a built-in function whereas _pyio.open is a Python function. In Python 3.10, _pyio.open() is now a static method, and builtins.open() is now io.open().
* bpo-43651: PEP 597: Fix EncodingWarning in some tests (GH-25189)Inada Naoki2021-04-061-3/+3
| | | | | | | | | | | | * Fix _sitebuiltins * Fix test_inspect * Fix test_interpreters * Fix test_io * Fix test_iter * Fix test_json * Fix test_linecache * Fix test_lltrace * Fix test_logging * Fix logging
* bpo-43651: Fix EncodingWarning in test_io (GH-25097)Inada Naoki2021-04-011-67/+78
|
* Revert "bpo-43510: PEP 597: Accept `encoding="locale"` in binary mode ↵Inada Naoki2021-03-311-11/+0
| | | | | (GH-25103)" (#25108) This reverts commit ff3c9739bd69aa8b58007e63c9e40e6708b4761e.
* bpo-43510: PEP 597: Accept `encoding="locale"` in binary mode (GH-25103)Inada Naoki2021-03-311-0/+11
| | | | It make `encoding="locale"` usable everywhere `encoding=None` is allowed.
* bpo-43510: Implement PEP 597 opt-in EncodingWarning. (GH-19481)Inada Naoki2021-03-291-0/+23
| | | | | | | | | | | See [PEP 597](https://www.python.org/dev/peps/pep-0597/). * Add `-X warn_default_encoding` and `PYTHONWARNDEFAULTENCODING`. * Add EncodingWarning * Add io.text_encoding() * open(), TextIOWrapper() emits EncodingWarning when encoding is omitted and warn_default_encoding is enabled. * _pyio.TextIOWrapper() uses UTF-8 as fallback default encoding used when failed to import locale module. (used during building Python) * bz2, configparser, gzip, lzma, pathlib, tempfile modules use io.text_encoding(). * What's new entry
* bpo-43260: io: Prevent large data remains in textio buffer. (GH-24592)Inada Naoki2021-02-211-0/+27
| | | | | | | | When very large data remains in TextIOWrapper, flush() may fail forever. So prevent that data larger than chunk_size is remained in TextIOWrapper internal buffer. Co-Authored-By: Eryk Sun
* bpo-41919: Avoid resource leak in test_io (GH-22973)Hai Shi2020-10-251-12/+13
| | | Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
* bpo-41919, test_codecs: Move codecs.register calls to setUp() (GH-22513)Hai Shi2020-10-161-4/+3
| | | | * Move the codecs' (un)register operation to testcases. * Remove _codecs._forget_codec() and _PyCodec_Forget()
* bpo-41401: Fix test_fspath_support in test_io. (GH-21640)Serhiy Storchaka2020-07-271-1/+1
| | | The error is exposed on non-UTF-8 locales.
* bpo-40275: Use new test.support helper submodules in tests (GH-21314)Hai Shi2020-07-061-127/+130
|
* closes bpo-28557: error message for bad raw readinto (GH-7496)David Szotten2020-06-151-0/+16
| | | Co-authored-by: Benjamin Peterson <benjamin@python.org>
* bpo-40275: Adding threading_helper submodule in test.support (GH-20263)Hai Shi2020-05-271-3/+4
|
* bpo-39882: Py_FatalError() logs the function name (GH-18819)Victor Stinner2020-03-061-1/+2
| | | | | | | | | | | | The Py_FatalError() function is replaced with a macro which logs automatically the name of the current function, unless the Py_LIMITED_API macro is defined. Changes: * Add _Py_FatalErrorFunc() function. * Remove the function name from the message of Py_FatalError() calls which included the function name. * Update tests.
* bpo-39674: Revert "bpo-37330: open() no longer accept 'U' in file mode ↵Victor Stinner2020-03-041-7/+10
| | | | | | | (GH-16959)" (GH-18767) This reverts commit e471e72977c83664f13d041c78549140c86c92de. The mode will be removed from Python 3.10.
* bpo-35950: Raise UnsupportedOperation in BufferedReader.truncate() (GH-18586)Berker Peksag2020-02-211-0/+11
| | | | | | | | | | | | | | | The truncate() method of io.BufferedReader() should raise UnsupportedOperation when it is called on a read-only io.BufferedReader() instance. https://bugs.python.org/issue35950 Automerge-Triggered-By: @methane
* closes bpo-39510: Fix use-after-free in BufferedReader.readinto() (GH-18295)Philipp Gesang2020-02-041-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | When called on a closed object, readinto() segfaults on account of a write to a freed buffer: ==220553== Process terminating with default action of signal 11 (SIGSEGV): dumping core ==220553== Access not within mapped region at address 0x2A ==220553== at 0x48408A0: memmove (vg_replace_strmem.c:1272) ==220553== by 0x58DB0C: _buffered_readinto_generic (bufferedio.c:972) ==220553== by 0x58DCBA: _io__Buffered_readinto_impl (bufferedio.c:1053) ==220553== by 0x58DCBA: _io__Buffered_readinto (bufferedio.c.h:253) Reproducer: reader = open ("/dev/zero", "rb") _void = reader.read (42) reader.close () reader.readinto (bytearray (42)) ### BANG! The problem exists since 2012 when commit dc469454ec added code to free the read buffer on close(). Signed-off-by: Philipp Gesang <philipp.gesang@intra2net.com>
* bpo-38076 Clear the interpreter state only after clearing module globals ↵Eddie Elizondo2020-02-041-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (GH-18039) Currently, during runtime destruction, `_PyImport_Cleanup` is clearing the interpreter state before clearing out the modules themselves. This leads to a segfault on modules that rely on the module state to clear themselves up. For example, let's take the small snippet added in the issue by @DinoV : ``` import _struct class C: def __init__(self): self.pack = _struct.pack def __del__(self): self.pack('I', -42) _struct.x = C() ``` The module `_struct` uses the module state to run `pack`. Therefore, the module state has to be alive until after the module has been cleared out to successfully run `C.__del__`. This happens at line 606, when `_PyImport_Cleanup` calls `_PyModule_Clear`. In fact, the loop that calls `_PyModule_Clear` has in its comments: > Now, if there are any modules left alive, clear their globals to minimize potential leaks. All C extension modules actually end up here, since they are kept alive in the interpreter state. That means that we can't clear the module state (which is used by C Extensions) before we run that loop. Moving `_PyInterpreterState_ClearModules` until after it, fixes the segfault in the code snippet. Finally, this updates a test in `io` to correctly assert the error that it now throws (since it now finds the io module state). The test that uses this is: `test_create_at_shutdown_without_encoding`. Given this test is now working is a proof that the module state now stays alive even when `__del__` is called at module destruction time. Thus, I didn't add a new tests for this. https://bugs.python.org/issue38076
* bpo-39489: Remove COUNT_ALLOCS special build (GH-18259)Victor Stinner2020-02-031-2/+0
| | | | | | | | | | | Remove: * COUNT_ALLOCS macro * sys.getcounts() function * SHOW_ALLOC_COUNT code in listobject.c * SHOW_TRACK_COUNT code in tupleobject.c * PyConfig.show_alloc_count field * -X showalloccount command line option * @test.support.requires_type_collecting decorator
* closes bpo-27805: Ignore ESPIPE in initializing seek of append-mode files. ↵Benjamin Peterson2019-11-121-0/+11
| | | | | (GH-17112) This change, which follows the behavior of C stdio's fdopen and Python 2's file object, allows pipes to be opened in append mode.
* bpo-37330: open() no longer accept 'U' in file mode (GH-16959)Victor Stinner2019-10-281-10/+7
| | | | | open(), io.open(), codecs.open() and fileinput.FileInput no longer accept "U" ("universal newline") in the file mode. This flag was deprecated since Python 3.3.
* bpo-37388: Development mode check encoding and errors (GH-14341)Victor Stinner2019-06-251-1/+48
| | | | | | | | | In development mode and in debug build, encoding and errors arguments are now checked on string encoding and decoding operations. Examples: open(), str.encode() and bytes.decode(). By default, for best performances, the errors argument is only checked at the first encoding/decoding error, and the encoding argument is sometimes ignored for empty strings.
* bpo-37261: Document sys.unraisablehook corner cases (GH-14059)Victor Stinner2019-06-141-1/+5
| | | | | | | | | | | Document reference cycle and resurrected objects issues in sys.unraisablehook() and threading.excepthook() documentation. Fix test.support.catch_unraisable_exception(): __exit__() no longer ignores unraisable exceptions. Fix test_io test_writer_close_error_on_close(): use a second catch_unraisable_exception() to catch the BufferedWriter unraisable exception.
* bpo-37223, test_io: silence last 'Exception ignored in:' (GH-14029)Victor Stinner2019-06-121-0/+5
| | | | | | Use catch_unraisable_exception() to ignore 'Exception ignored in:' error when the internal BufferedWriter of the BufferedRWPair is destroyed. The C implementation doesn't give access to the internal BufferedWriter, so just ignore the warning instead.
* bpo-37223: test_io: silence destructor errors (GH-13954)Victor Stinner2019-06-111-0/+10
| | | Implement also MockNonBlockWriterIO.seek() method.
* bpo-36829: Document test.support.catch_unraisable_exception() (GH-13554)Victor Stinner2019-05-241-14/+6
| | | | catch_unraisable_exception() now also removes its 'unraisable' attribute at the context manager exit.
* bpo-36842: Implement PEP 578 (GH-12613)Steve Dower2019-05-231-1/+1
| | | Adds sys.audit, sys.addaudithook, io.open_code, and associated C APIs.
* bpo-18748: _pyio.IOBase emits unraisable exception (GH-13512)Victor Stinner2019-05-231-37/+27
| | | | | | | | In development (-X dev) mode and in a debug build, IOBase finalizer of the _pyio module now logs the exception if the close() method fails. The exception is ignored silently by default in release build. test_io: test_error_through_destructor() now uses support.catch_unraisable_exception() rather than capturing stderr.
* bpo-36929: Modify io/re tests to allow for missing mod name (#13392)Max Bernstein2019-05-211-17/+17
| | | | | | | | | | | | | | | | | | * bpo-36929: Modify io/re tests to allow for missing mod name For a vanishingly small number of internal types, CPython sets the tp_name slot to mod_name.type_name, either in the PyTypeObject or the PyType_Spec. There are a few minor places where this surfaces: * Custom repr functions for those types (some of which ignore the tp_name in favor of using a string literal, such as _io.TextIOWrapper) * Pickling error messages The test suite only tests the former. This commit modifies the test suite to allow Python implementations to omit the module prefix. https://bugs.python.org/issue36929
* bpo-18748: test_io: silence destructor errors (GH-12805)Victor Stinner2019-04-121-0/+29
|
* bpo-18748: io.IOBase destructor now logs close() errors in dev mode (GH-12786)Victor Stinner2019-04-121-6/+25
| | | | | In development mode (-X dev) and in debug build, the io.IOBase destructor now logs close() exceptions. These exceptions are silent by default in release mode.
* bpo-35214: Skip test_io tests that'd cause a huge malloc under msan (#11385)Gregory P. Smith2018-12-311-0/+14
| | | | | | | | | | * skip test_constructor under msan. * fix the others as well. * reuse existing related news entry. * typo fix
* bpo-31731: Fix test_io.check_interrupted_write() (GH-11225)Victor Stinner2018-12-181-3/+9
| | | | | | | Fix a race condition in check_interrupted_write() of test_io: create directly the thread with SIGALRM signal blocked, rather than blocking the signal later from the thread. Previously, it was possible that the thread gets the signal before the signal is blocked.
* bpo-35504: Fix segfaults and SystemErrors when deleting certain attrs. ↵Zackery Spytz2018-12-171-0/+5
| | | | (GH-11175)
* bpo-33578: Add getstate/setstate for CJK codec (GH-6984)Christopher Thorne2018-11-011-0/+28
| | | | | | | | This implements getstate and setstate for the cjkcodecs multibyte incremental encoders/decoders, primarily to fix issues with seek/tell. The encoder getstate/setstate is slightly tricky as the "state" is pending bytes + MultibyteCodec_State but only an integer can be returned. The approach I've taken is to encode this data into a long, similar to how .tell() encodes a "cookie_type" as a long. https://bugs.python.org/issue33578
* bpo-35062: Fix parsing _io.IncrementalNewlineDecoder's *translate* argument. ↵Xiang Zhang2018-10-311-0/+10
| | | | | | (GH-10217) _io.IncrementalNewlineDecoder's initializer possibly assigns out-of-range value to the bitwise struct field.
* bpo-32236: open() emits RuntimeWarning if buffering=1 for binary mode (GH-4842)Alexey Izbyshev2018-10-201-1/+1
| | | | | | | | | If buffering=1 is specified for open() in binary mode, it is silently treated as buffering=-1 (i.e., the default buffer size). Coupled with the fact that line buffering is always supported in Python 2, such behavior caused several issues (e.g., bpo-10344, bpo-21332). Warn that line buffering is not supported if open() is called with binary mode and buffering=1.
* bpo-34068: _io__IOBase_close_impl could call _PyObject_SetAttrId with an ↵Zackery Spytz2018-07-171-0/+10
| | | | exception set (GH-8282)
* bpo-25862: Fix assertion failures in io.TextIOWrapper.tell(). (GH-3918)Zackery Spytz2018-06-291-0/+11
|
* Revert "bpo-33671: Add support.MS_WINDOWS and support.MACOS (GH-7800)" (GH-7919)Victor Stinner2018-06-261-1/+1
| | | This reverts commit 8fbbdf0c3107c3052659e166f73990b466eacbb0.
* bpo-33671: Add support.MS_WINDOWS and support.MACOS (GH-7800)Victor Stinner2018-06-221-1/+1
| | | | | | | | * Add support.MS_WINDOWS: True if Python is running on Microsoft Windows. * Add support.MACOS: True if Python is running on Apple macOS. * Replace support.is_android with support.ANDROID * Replace support.is_jython with support.JYTHON * Cleanup code to initialize unix_shell
* bpo-33760: Fix file leaks in test_io. (GH-7361)Serhiy Storchaka2018-06-041-0/+4
|
* bpo-32964: Reuse a testing implementation of the path protocol in tests. (#5930)Serhiy Storchaka2018-03-021-11/+14
|
* bpo-32228: Reset raw_pos after unwinding the raw stream (#4858)Nitish Chandra2018-01-281-0/+17
| | | Ensure that ``truncate()`` preserves the file position (as reported by ``tell()``) after writes longer than the buffer size.
* bpo-32593: Drop FreeBSD 9 and older support (#5232)Victor Stinner2018-01-221-2/+0
| | | Drop support of FreeBSD 9 and older.
* bpo-15216: io: TextIOWrapper.reconfigure() accepts encoding, errors and ↵INADA Naoki2017-12-211-0/+117
| | | | newline (GH-2343)