summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_fileio.py
diff options
context:
space:
mode:
authorSteve Dower <steve.dower@microsoft.com>2019-05-23 15:45:22 (GMT)
committerGitHub <noreply@github.com>2019-05-23 15:45:22 (GMT)
commitb82e17e626f7b1cd98aada0b1ebb65cb9f8fb184 (patch)
tree5370a2a075707cb0b37ce135cad6ffe23da424c4 /Lib/test/test_fileio.py
parente788057a9188ff37e232729815dfda2529079420 (diff)
downloadcpython-b82e17e626f7b1cd98aada0b1ebb65cb9f8fb184.zip
cpython-b82e17e626f7b1cd98aada0b1ebb65cb9f8fb184.tar.gz
cpython-b82e17e626f7b1cd98aada0b1ebb65cb9f8fb184.tar.bz2
bpo-36842: Implement PEP 578 (GH-12613)
Adds sys.audit, sys.addaudithook, io.open_code, and associated C APIs.
Diffstat (limited to 'Lib/test/test_fileio.py')
-rw-r--r--Lib/test/test_fileio.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/Lib/test/test_fileio.py b/Lib/test/test_fileio.py
index 57a0265..26e4500 100644
--- a/Lib/test/test_fileio.py
+++ b/Lib/test/test_fileio.py
@@ -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.