mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
bpo-36842: Implement PEP 578 (GH-12613)
Adds sys.audit, sys.addaudithook, io.open_code, and associated C APIs.
This commit is contained in:
parent
e788057a91
commit
b82e17e626
70 changed files with 3565 additions and 1816 deletions
|
@ -565,6 +565,7 @@ class OtherFileTests:
|
|||
self.assertRaises(MyException, MyFileIO, fd)
|
||||
os.close(fd) # should not raise OSError(EBADF)
|
||||
|
||||
|
||||
class COtherFileTests(OtherFileTests, unittest.TestCase):
|
||||
FileIO = _io.FileIO
|
||||
modulename = '_io'
|
||||
|
@ -576,10 +577,32 @@ class COtherFileTests(OtherFileTests, unittest.TestCase):
|
|||
self.assertRaises(TypeError, self.FileIO, _testcapi.INT_MAX + 1)
|
||||
self.assertRaises(TypeError, self.FileIO, _testcapi.INT_MIN - 1)
|
||||
|
||||
def test_open_code(self):
|
||||
# Check that the default behaviour of open_code matches
|
||||
# open("rb")
|
||||
with self.FileIO(__file__, "rb") as f:
|
||||
expected = f.read()
|
||||
with _io.open_code(__file__) as f:
|
||||
actual = f.read()
|
||||
self.assertEqual(expected, actual)
|
||||
|
||||
|
||||
class PyOtherFileTests(OtherFileTests, unittest.TestCase):
|
||||
FileIO = _pyio.FileIO
|
||||
modulename = '_pyio'
|
||||
|
||||
def test_open_code(self):
|
||||
# Check that the default behaviour of open_code matches
|
||||
# open("rb")
|
||||
with self.FileIO(__file__, "rb") as f:
|
||||
expected = f.read()
|
||||
with check_warnings(quiet=True) as w:
|
||||
# Always test _open_code_with_warning
|
||||
with _pyio._open_code_with_warning(__file__) as f:
|
||||
actual = f.read()
|
||||
self.assertEqual(expected, actual)
|
||||
self.assertNotEqual(w.warnings, [])
|
||||
|
||||
|
||||
def test_main():
|
||||
# Historically, these tests have been sloppy about removing TESTFN.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue