summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2014-04-22 22:34:51 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2014-04-22 22:34:51 (GMT)
commit711ee2512e56240dcc78a7b0ed02d42e76615eb4 (patch)
treee19b7a81f09da0f133d791995e513823456d25eb /Lib/test
parent29c47776dd9f7b7f240a1cd3d4d61a1e98044ae9 (diff)
parentcb5ec77d33f1c6db2e0e1684d8ebf9c4cf7346b9 (diff)
downloadcpython-711ee2512e56240dcc78a7b0ed02d42e76615eb4.zip
cpython-711ee2512e56240dcc78a7b0ed02d42e76615eb4.tar.gz
cpython-711ee2512e56240dcc78a7b0ed02d42e76615eb4.tar.bz2
Issue #21127: Path objects can now be instantiated from str subclass instances (such as numpy.str_).
Thanks to Antony Lee for the report and preliminary patch.
Diffstat (limited to 'Lib/test')
-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 2268f94..6378d8c 100644
--- a/Lib/test/test_pathlib.py
+++ b/Lib/test/test_pathlib.py
@@ -197,6 +197,25 @@ class _BasePurePathTest(object):
self.assertEqual(P(P('a'), 'b'), P('a/b'))
self.assertEqual(P(P('a'), P('b')), P('a/b'))
+ def _check_str_subclass(self, *args):
+ # Issue #21127: it should be possible to construct a PurePath object
+ # from an str subclass instance, and it then gets converted to
+ # a pure str object.
+ class StrSubclass(str):
+ pass
+ P = self.cls
+ p = P(*(StrSubclass(x) for x in args))
+ self.assertEqual(p, P(*args))
+ for part in p.parts:
+ self.assertIs(type(part), str)
+
+ def test_str_subclass_common(self):
+ self._check_str_subclass('')
+ self._check_str_subclass('.')
+ self._check_str_subclass('a')
+ self._check_str_subclass('a/b.txt')
+ self._check_str_subclass('/a/b.txt')
+
def test_join_common(self):
P = self.cls
p = P('a/b')
@@ -690,6 +709,17 @@ class PureWindowsPathTest(_BasePurePathTest, unittest.TestCase):
p = self.cls('//a/b/c/d')
self.assertEqual(str(p), '\\\\a\\b\\c\\d')
+ def test_str_subclass(self):
+ self._check_str_subclass('c:')
+ self._check_str_subclass('c:a')
+ self._check_str_subclass('c:a\\b.txt')
+ self._check_str_subclass('c:\\')
+ self._check_str_subclass('c:\\a')
+ self._check_str_subclass('c:\\a\\b.txt')
+ self._check_str_subclass('\\\\some\\share')
+ self._check_str_subclass('\\\\some\\share\\a')
+ self._check_str_subclass('\\\\some\\share\\a\\b.txt')
+
def test_eq(self):
P = self.cls
self.assertEqual(P('c:a/b'), P('c:a/b'))