diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2018-03-03 12:19:29 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-03 12:19:29 (GMT) |
commit | fbdd075c64a5229dfa26632cf1b2cf2361dc5003 (patch) | |
tree | a959f2fc206302c629b217ca811f305b7f5060be /Lib/test/test_io.py | |
parent | 10fb1bf7766e7eb9500d328ddd1035e3f823fb57 (diff) | |
download | cpython-fbdd075c64a5229dfa26632cf1b2cf2361dc5003.zip cpython-fbdd075c64a5229dfa26632cf1b2cf2361dc5003.tar.gz cpython-fbdd075c64a5229dfa26632cf1b2cf2361dc5003.tar.bz2 |
[3.6] bpo-32964: Reuse a testing implementation of the path protocol in tests. (GH-5930). (GH-5958)
(cherry picked from commit b21d155f57d284aecf9092a9bd24258293965c2f)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Lib/test/test_io.py')
-rw-r--r-- | Lib/test/test_io.py | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py index 6c30a44..3f3b390 100644 --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -36,6 +36,7 @@ from collections import deque, UserList from itertools import cycle, count from test import support from test.support.script_helper import assert_python_ok, run_python_until_end +from test.support import FakePath import codecs import io # C implementation of io @@ -880,13 +881,6 @@ class IOTest(unittest.TestCase): self.assertEqual(bytes(buffer), b"12345") def test_fspath_support(self): - class PathLike: - def __init__(self, path): - self.path = path - - def __fspath__(self): - return self.path - def check_path_succeeds(path): with self.open(path, "w") as f: f.write("egg\n") @@ -894,16 +888,25 @@ class IOTest(unittest.TestCase): with self.open(path, "r") as f: self.assertEqual(f.read(), "egg\n") - check_path_succeeds(PathLike(support.TESTFN)) - check_path_succeeds(PathLike(support.TESTFN.encode('utf-8'))) + check_path_succeeds(FakePath(support.TESTFN)) + check_path_succeeds(FakePath(support.TESTFN.encode('utf-8'))) + + with self.open(support.TESTFN, "w") as f: + bad_path = FakePath(f.fileno()) + with self.assertRaises(TypeError): + self.open(bad_path, 'w') - bad_path = PathLike(TypeError) + bad_path = FakePath(None) with self.assertRaises(TypeError): self.open(bad_path, 'w') + bad_path = FakePath(FloatingPointError) + with self.assertRaises(FloatingPointError): + self.open(bad_path, 'w') + # ensure that refcounting is correct with some error conditions with self.assertRaisesRegex(ValueError, 'read/write/append mode'): - self.open(PathLike(support.TESTFN), 'rwxa') + self.open(FakePath(support.TESTFN), 'rwxa') def test_RawIOBase_readall(self): # Exercise the default unlimited RawIOBase.read() and readall() |