summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_os.py
diff options
context:
space:
mode:
authorEthan Furman <ethan@stoneleaf.us>2016-06-04 20:47:39 (GMT)
committerEthan Furman <ethan@stoneleaf.us>2016-06-04 20:47:39 (GMT)
commit228c636908bda8a6b20b0f6930655fbaedc4ebad (patch)
treef91930ec2dfe5fdb8525ec90a3f2226d218ca686 /Lib/test/test_os.py
parentdb780cffc887fbf4c4fb9452fc6dc7a3c722e290 (diff)
downloadcpython-228c636908bda8a6b20b0f6930655fbaedc4ebad.zip
cpython-228c636908bda8a6b20b0f6930655fbaedc4ebad.tar.gz
cpython-228c636908bda8a6b20b0f6930655fbaedc4ebad.tar.bz2
issue27186: fix fsencode/fsdecode and update tests; patch by Jelle Zijlstra
Diffstat (limited to 'Lib/test/test_os.py')
-rw-r--r--Lib/test/test_os.py19
1 files changed, 13 insertions, 6 deletions
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
index e740edf..6853ebb 100644
--- 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:
+ class PathLike:
def __init__(self, path):
self.path = path
-
def __fspath__(self):
return self.path
for p in "path/like/object", b"path/like/object":
- pathlike = Pathlike(p)
+ pathlike = PathLike(p)
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):
+ class PathLike:
+ def __init__(self, path=''):
+ self.path = path
def __fspath__(self):
- return '#feelthegil'
+ return self.path
- self.assertEqual('#feelthegil', os.fspath(PathLike()))
+ self.assertEqual('#feelthegil', os.fspath(PathLike('#feelthegil')))
self.assertTrue(issubclass(PathLike, os.PathLike))
self.assertTrue(isinstance(PathLike(), os.PathLike))
+ message = 'expected str, bytes or os.PathLike object, not'
+ for fn in (os.fsencode, os.fsdecode):
+ for obj in PathLike(None), None:
+ with self.assertRaisesRegex(TypeError, message):
+ fn(obj)
+
def test_garbage_in_exception_out(self):
vapor = type('blah', (), {})
for o in int, type, os, vapor():