import os.path
import pathlib.types
+import posixpath
class LexicalPath(pathlib.types._JoinablePath):
def with_segments(self, *pathsegments):
return type(self)(*pathsegments)
+
+
+class LexicalPosixPath(LexicalPath):
+ __slots__ = ()
+ parser = posixpath
--- /dev/null
+"""
+Tests for Posix-flavoured pathlib.types._JoinablePath
+"""
+
+import os
+import unittest
+
+from pathlib import PurePosixPath, PosixPath
+from test.test_pathlib.support.lexical_path import LexicalPosixPath
+
+
+class JoinTestBase:
+ def test_join(self):
+ P = self.cls
+ p = P('//a')
+ pp = p.joinpath('b')
+ self.assertEqual(pp, P('//a/b'))
+ pp = P('/a').joinpath('//c')
+ self.assertEqual(pp, P('//c'))
+ pp = P('//a').joinpath('/c')
+ self.assertEqual(pp, P('/c'))
+
+ def test_div(self):
+ # Basically the same as joinpath().
+ P = self.cls
+ p = P('//a')
+ pp = p / 'b'
+ self.assertEqual(pp, P('//a/b'))
+ pp = P('/a') / '//c'
+ self.assertEqual(pp, P('//c'))
+ pp = P('//a') / '/c'
+ self.assertEqual(pp, P('/c'))
+
+
+class LexicalPosixPathJoinTest(JoinTestBase, unittest.TestCase):
+ cls = LexicalPosixPath
+
+
+class PurePosixPathJoinTest(JoinTestBase, unittest.TestCase):
+ cls = PurePosixPath
+
+
+if os.name != 'nt':
+ class PosixPathJoinTest(JoinTestBase, unittest.TestCase):
+ cls = PosixPath
+
+
+if __name__ == "__main__":
+ unittest.main()
self._check_str_subclass('\\\\some\\share\\a')
self._check_str_subclass('\\\\some\\share\\a\\b.txt')
- @needs_posix
- def test_join_posix(self):
- P = self.cls
- p = P('//a')
- pp = p.joinpath('b')
- self.assertEqual(pp, P('//a/b'))
- pp = P('/a').joinpath('//c')
- self.assertEqual(pp, P('//c'))
- pp = P('//a').joinpath('/c')
- self.assertEqual(pp, P('/c'))
-
@needs_windows
def test_join_windows(self):
P = self.cls
pp = P('//./BootPartition').joinpath('Windows')
self.assertEqual(pp, P('//./BootPartition/Windows'))
- @needs_posix
- def test_div_posix(self):
- # Basically the same as joinpath().
- P = self.cls
- p = P('//a')
- pp = p / 'b'
- self.assertEqual(pp, P('//a/b'))
- pp = P('/a') / '//c'
- self.assertEqual(pp, P('//c'))
- pp = P('//a') / '/c'
- self.assertEqual(pp, P('/c'))
-
@needs_windows
def test_div_windows(self):
# Basically the same as joinpath().