diff options
author | Brett Cannon <brett@python.org> | 2016-06-10 12:20:49 -0700 |
---|---|---|
committer | Brett Cannon <brett@python.org> | 2016-06-10 12:20:49 -0700 |
commit | 568be63248614a2cdd7666a67ddfd16e817f7db9 (patch) | |
tree | f59d0822885c5185a7dfb464cd443ea8d5696109 /Lib/test/test_pathlib.py | |
parent | f41b82fb19d1b91f99ab657e4c6a751c44152f12 (diff) | |
download | cpython-568be63248614a2cdd7666a67ddfd16e817f7db9.tar.gz cpython-568be63248614a2cdd7666a67ddfd16e817f7db9.zip |
Issue #27186: Add os.PathLike support to pathlib.
This adds support both to pathlib.PurePath's constructor as well as
implementing __fspath__(). This removes the provisional status for
pathlib.
Initial patch by Dusty Phillips.
Diffstat (limited to 'Lib/test/test_pathlib.py')
-rw-r--r-- | Lib/test/test_pathlib.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/Lib/test/test_pathlib.py b/Lib/test/test_pathlib.py index fbbd448f65d..2f2ba3cbfc7 100644 --- a/Lib/test/test_pathlib.py +++ b/Lib/test/test_pathlib.py @@ -190,13 +190,18 @@ class _BasePurePathTest(object): P = self.cls p = P('a') self.assertIsInstance(p, P) + class PathLike: + def __fspath__(self): + return "a/b/c" P('a', 'b', 'c') P('/a', 'b', 'c') P('a/b/c') P('/a/b/c') + P(PathLike()) self.assertEqual(P(P('a')), P('a')) self.assertEqual(P(P('a'), 'b'), P('a/b')) self.assertEqual(P(P('a'), P('b')), P('a/b')) + self.assertEqual(P(P('a'), P('b'), P('c')), P(PathLike())) def _check_str_subclass(self, *args): # Issue #21127: it should be possible to construct a PurePath object @@ -384,6 +389,12 @@ class _BasePurePathTest(object): parts = p.parts self.assertEqual(parts, (sep, 'a', 'b')) + def test_fspath_common(self): + P = self.cls + p = P('a/b') + self._check_str(p.__fspath__(), ('a/b',)) + self._check_str(os.fspath(p), ('a/b',)) + def test_equivalences(self): for k, tuples in self.equivalences.items(): canon = k.replace('/', self.sep) |