summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_io.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2018-03-02 09:53:51 (GMT)
committerGitHub <noreply@github.com>2018-03-02 09:53:51 (GMT)
commitb21d155f57d284aecf9092a9bd24258293965c2f (patch)
tree3bf7797282fa3d3fc48e668214ae5f5c6bce1dff /Lib/test/test_io.py
parentbf63e8d55fd2853df3bb99d66de7f428107aadb3 (diff)
downloadcpython-b21d155f57d284aecf9092a9bd24258293965c2f.zip
cpython-b21d155f57d284aecf9092a9bd24258293965c2f.tar.gz
cpython-b21d155f57d284aecf9092a9bd24258293965c2f.tar.bz2
bpo-32964: Reuse a testing implementation of the path protocol in tests. (#5930)
Diffstat (limited to 'Lib/test/test_io.py')
-rw-r--r--Lib/test/test_io.py25
1 files changed, 14 insertions, 11 deletions
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
index 4be5631..343c5a4 100644
--- a/Lib/test/test_io.py
+++ b/Lib/test/test_io.py
@@ -37,6 +37,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
@@ -891,13 +892,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")
@@ -905,16 +899,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()