summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_io.py
diff options
context:
space:
mode:
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 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()