summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_pathlib.py
diff options
context:
space:
mode:
authorJoshua Cannon <joshua.cannon@ni.com>2020-11-20 15:40:39 (GMT)
committerGitHub <noreply@github.com>2020-11-20 15:40:39 (GMT)
commit452058448335b39c784af9a047f9c4a1767c0b00 (patch)
tree689ce4a242fa55ae5ff479fa936596d04d92f3dd /Lib/test/test_pathlib.py
parentd20b7ed9c1fabac3fdebb7ec362fe4f022a54639 (diff)
downloadcpython-452058448335b39c784af9a047f9c4a1767c0b00.zip
cpython-452058448335b39c784af9a047f9c4a1767c0b00.tar.gz
cpython-452058448335b39c784af9a047f9c4a1767c0b00.tar.bz2
bpo-35498: Added slice support to PathLib parents attribute. (GH-11165)
Added slice support to the `pathlib.Path.parents` sequence. For a `Path` `p`, slices of `p.parents` should return the same thing as slices of `tuple(p.parents)`.
Diffstat (limited to 'Lib/test/test_pathlib.py')
-rw-r--r--Lib/test/test_pathlib.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/Lib/test/test_pathlib.py b/Lib/test/test_pathlib.py
index 17292dc..f145179 100644
--- a/Lib/test/test_pathlib.py
+++ b/Lib/test/test_pathlib.py
@@ -440,6 +440,12 @@ class _BasePurePathTest(object):
self.assertEqual(par[0], P('a/b'))
self.assertEqual(par[1], P('a'))
self.assertEqual(par[2], P('.'))
+ self.assertEqual(par[0:1], (P('a/b'),))
+ self.assertEqual(par[:2], (P('a/b'), P('a')))
+ self.assertEqual(par[:-1], (P('a/b'), P('a')))
+ self.assertEqual(par[1:], (P('a'), P('.')))
+ self.assertEqual(par[::2], (P('a/b'), P('.')))
+ self.assertEqual(par[::-1], (P('.'), P('a'), P('a/b')))
self.assertEqual(list(par), [P('a/b'), P('a'), P('.')])
with self.assertRaises(IndexError):
par[-1]
@@ -454,6 +460,12 @@ class _BasePurePathTest(object):
self.assertEqual(par[0], P('/a/b'))
self.assertEqual(par[1], P('/a'))
self.assertEqual(par[2], P('/'))
+ self.assertEqual(par[0:1], (P('/a/b'),))
+ self.assertEqual(par[:2], (P('/a/b'), P('/a')))
+ self.assertEqual(par[:-1], (P('/a/b'), P('/a')))
+ self.assertEqual(par[1:], (P('/a'), P('/')))
+ self.assertEqual(par[::2], (P('/a/b'), P('/')))
+ self.assertEqual(par[::-1], (P('/'), P('/a'), P('/a/b')))
self.assertEqual(list(par), [P('/a/b'), P('/a'), P('/')])
with self.assertRaises(IndexError):
par[3]
@@ -905,6 +917,12 @@ class PureWindowsPathTest(_BasePurePathTest, unittest.TestCase):
self.assertEqual(len(par), 2)
self.assertEqual(par[0], P('z:a'))
self.assertEqual(par[1], P('z:'))
+ self.assertEqual(par[0:1], (P('z:a'),))
+ self.assertEqual(par[:-1], (P('z:a'),))
+ self.assertEqual(par[:2], (P('z:a'), P('z:')))
+ self.assertEqual(par[1:], (P('z:'),))
+ self.assertEqual(par[::2], (P('z:a'),))
+ self.assertEqual(par[::-1], (P('z:'), P('z:a')))
self.assertEqual(list(par), [P('z:a'), P('z:')])
with self.assertRaises(IndexError):
par[2]
@@ -913,6 +931,12 @@ class PureWindowsPathTest(_BasePurePathTest, unittest.TestCase):
self.assertEqual(len(par), 2)
self.assertEqual(par[0], P('z:/a'))
self.assertEqual(par[1], P('z:/'))
+ self.assertEqual(par[0:1], (P('z:/a'),))
+ self.assertEqual(par[0:-1], (P('z:/a'),))
+ self.assertEqual(par[:2], (P('z:/a'), P('z:/')))
+ self.assertEqual(par[1:], (P('z:/'),))
+ self.assertEqual(par[::2], (P('z:/a'),))
+ self.assertEqual(par[::-1], (P('z:/'), P('z:/a'),))
self.assertEqual(list(par), [P('z:/a'), P('z:/')])
with self.assertRaises(IndexError):
par[2]
@@ -921,6 +945,12 @@ class PureWindowsPathTest(_BasePurePathTest, unittest.TestCase):
self.assertEqual(len(par), 2)
self.assertEqual(par[0], P('//a/b/c'))
self.assertEqual(par[1], P('//a/b'))
+ self.assertEqual(par[0:1], (P('//a/b/c'),))
+ self.assertEqual(par[0:-1], (P('//a/b/c'),))
+ self.assertEqual(par[:2], (P('//a/b/c'), P('//a/b')))
+ self.assertEqual(par[1:], (P('//a/b'),))
+ self.assertEqual(par[::2], (P('//a/b/c'),))
+ self.assertEqual(par[::-1], (P('//a/b'), P('//a/b/c')))
self.assertEqual(list(par), [P('//a/b/c'), P('//a/b')])
with self.assertRaises(IndexError):
par[2]