summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorPablo Galindo <Pablogsal@gmail.com>2019-02-18 10:46:34 (GMT)
committerGitHub <noreply@github.com>2019-02-18 10:46:34 (GMT)
commit09fbcd6085e18b534fd4161844ff39f77eb4a082 (patch)
tree18814d4cc2ac1949afac68a27474645973f835f5 /Lib/test
parentac28147e78c45a6217d348ce90ca5281d91f676f (diff)
downloadcpython-09fbcd6085e18b534fd4161844ff39f77eb4a082.zip
cpython-09fbcd6085e18b534fd4161844ff39f77eb4a082.tar.gz
cpython-09fbcd6085e18b534fd4161844ff39f77eb4a082.tar.bz2
bpo-35942: Improve the error message if __fspath__ returns invalid types in path_converter (GH-11831)
The error message emitted when returning invalid types from __fspath__ in interfaces that allow passing PathLike objects has been improved and now it does explain the origin of the error.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_os.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
index b7e1c45..d478c64 100644
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -3344,7 +3344,7 @@ class PathTConverterTests(unittest.TestCase):
cleanup_fn(result)
with self.assertRaisesRegex(
- TypeError, 'should be string, bytes'):
+ TypeError, 'to return str or bytes'):
fn(int_fspath, *extra_args)
if allow_fd:
@@ -3357,6 +3357,23 @@ class PathTConverterTests(unittest.TestCase):
'os.PathLike'):
fn(fd, *extra_args)
+ def test_path_t_converter_and_custom_class(self):
+ with self.assertRaisesRegex(
+ TypeError,
+ '__fspath__\(\) to return str or bytes, not int'
+ ):
+ os.stat(FakePath(2))
+ with self.assertRaisesRegex(
+ TypeError,
+ '__fspath__\(\) to return str or bytes, not float'
+ ):
+ os.stat(FakePath(2.34))
+ with self.assertRaisesRegex(
+ TypeError,
+ '__fspath__\(\) to return str or bytes, not object'
+ ):
+ os.stat(FakePath(object()))
+
@unittest.skipUnless(hasattr(os, 'get_blocking'),
'needs os.get_blocking() and os.set_blocking()')