cpython: 76b2ddaee6bd (original) (raw)
Mercurial > cpython
changeset 101723:76b2ddaee6bd
issue27186: fix fsencode/fsdecode and update tests; patch by Jelle Zijlstra [#27186]
Ethan Furman ethan@stoneleaf.us | |
---|---|
date | Sat, 04 Jun 2016 13:47:39 -0700 |
parents | 6e6afc4aee57 |
children | 254125a265d2 |
files | Lib/os.py Lib/test/test_os.py |
diffstat | 2 files changed, 16 insertions(+), 9 deletions(-)[+] [-] Lib/os.py 4 Lib/test/test_os.py 21 |
line wrap: on
line diff
--- a/Lib/os.py +++ b/Lib/os.py @@ -889,7 +889,7 @@ def _fscodec(): return filename.encode(encoding, errors) else: raise TypeError("expected str, bytes or os.PathLike object, not "
+ path_type.__name__)[](#l1.7)
+ type(filename).__name__)[](#l1.8)
def fsdecode(filename): """ @@ -905,7 +905,7 @@ def _fscodec(): return filename.decode(encoding, errors) else: raise TypeError("expected str, bytes or os.PathLike object, not "
+ path_type.__name__)[](#l1.16)
+ type(filename).__name__)[](#l1.17)
--- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -3107,29 +3107,36 @@ class TestPEP519(unittest.TestCase): self.assertEqual(s, os.fspath(s)) def test_fsencode_fsdecode_return_pathlike(self):
class Pathlike:[](#l2.7)
class PathLike:[](#l2.8) def __init__(self, path):[](#l2.9) self.path = path[](#l2.10)
- def fspath(self): return self.path for p in "path/like/object", b"path/like/object":
pathlike = Pathlike(p)[](#l2.16)
pathlike = PathLike(p)[](#l2.17)
self.assertEqual(p, os.fspath(pathlike)) self.assertEqual(b"path/like/object", os.fsencode(pathlike)) self.assertEqual("path/like/object", os.fsdecode(pathlike)) def test_fspathlike(self):
class PathLike(object):[](#l2.24)
class PathLike:[](#l2.25)
def __init__(self, path=''):[](#l2.26)
self.path = path[](#l2.27) def __fspath__(self):[](#l2.28)
return '#feelthegil'[](#l2.29)
self.assertEqual('#feelthegil', os.fspath(PathLike()))[](#l2.31)
return self.path[](#l2.32)
self.assertEqual('#feelthegil', os.fspath(PathLike('#feelthegil')))[](#l2.34) self.assertTrue(issubclass(PathLike, os.PathLike))[](#l2.35) self.assertTrue(isinstance(PathLike(), os.PathLike))[](#l2.36)
message = 'expected str, bytes or os.PathLike object, not'[](#l2.38)
for fn in (os.fsencode, os.fsdecode):[](#l2.39)
for obj in PathLike(None), None:[](#l2.40)
with self.assertRaisesRegex(TypeError, message):[](#l2.41)
fn(obj)[](#l2.42)
+ def test_garbage_in_exception_out(self): vapor = type('blah', (), {}) for o in int, type, os, vapor():