From 568be63248614a2cdd7666a67ddfd16e817f7db9 Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Fri, 10 Jun 2016 12:20:49 -0700 Subject: 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. --- Lib/test/test_pathlib.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'Lib/test/test_pathlib.py') 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) -- cgit v1.2.3