summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_io.py
diff options
context:
space:
mode:
authorEthan Furman <ethan@stoneleaf.us>2016-06-04 21:38:43 (GMT)
committerEthan Furman <ethan@stoneleaf.us>2016-06-04 21:38:43 (GMT)
commitd62548afede899e71e59a2a0b31f19fdf031c560 (patch)
tree11dc76fe4b5c89d93c63e8bdf4b9ec535fde6451 /Lib/test/test_io.py
parent228c636908bda8a6b20b0f6930655fbaedc4ebad (diff)
downloadcpython-d62548afede899e71e59a2a0b31f19fdf031c560.zip
cpython-d62548afede899e71e59a2a0b31f19fdf031c560.tar.gz
cpython-d62548afede899e71e59a2a0b31f19fdf031c560.tar.bz2
issue27186: add open/io.open; patch by Jelle Zijlstra
Diffstat (limited to 'Lib/test/test_io.py')
-rw-r--r--Lib/test/test_io.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
index 53e776d..5584d6b 100644
--- a/Lib/test/test_io.py
+++ b/Lib/test/test_io.py
@@ -844,6 +844,32 @@ class IOTest(unittest.TestCase):
self.assertEqual(getattr(stream, method)(buffer), 5)
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")
+
+ 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')))
+
+ bad_path = PathLike(TypeError)
+ with self.assertRaisesRegex(TypeError, 'invalid file'):
+ 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')
+
class CIOTest(IOTest):