File tree Expand file tree Collapse file tree 3 files changed +55
-23
lines changed Expand file tree Collapse file tree 3 files changed +55
-23
lines changed Original file line number Diff line number Diff line change 44
55import os .path
66import pathlib .types
7+ import posixpath
78
89
910class LexicalPath (pathlib .types ._JoinablePath ):
@@ -31,3 +32,8 @@ def __repr__(self):
3132
3233 def with_segments (self , * pathsegments ):
3334 return type (self )(* pathsegments )
35+
36+
37+ class LexicalPosixPath (LexicalPath ):
38+ __slots__ = ()
39+ parser = posixpath
Original file line number Diff line number Diff line change 1+ """
2+ Tests for Posix-flavoured pathlib.types._JoinablePath
3+ """
4+
5+ import os
6+ import unittest
7+
8+ from pathlib import PurePosixPath , PosixPath
9+ from test .test_pathlib .support .lexical_path import LexicalPosixPath
10+
11+
12+ class JoinTestBase :
13+ def test_join (self ):
14+ P = self .cls
15+ p = P ('//a' )
16+ pp = p .joinpath ('b' )
17+ self .assertEqual (pp , P ('//a/b' ))
18+ pp = P ('/a' ).joinpath ('//c' )
19+ self .assertEqual (pp , P ('//c' ))
20+ pp = P ('//a' ).joinpath ('/c' )
21+ self .assertEqual (pp , P ('/c' ))
22+
23+ def test_div (self ):
24+ # Basically the same as joinpath().
25+ P = self .cls
26+ p = P ('//a' )
27+ pp = p / 'b'
28+ self .assertEqual (pp , P ('//a/b' ))
29+ pp = P ('/a' ) / '//c'
30+ self .assertEqual (pp , P ('//c' ))
31+ pp = P ('//a' ) / '/c'
32+ self .assertEqual (pp , P ('/c' ))
33+
34+
35+ class LexicalPosixPathJoinTest (JoinTestBase , unittest .TestCase ):
36+ cls = LexicalPosixPath
37+
38+
39+ class PurePosixPathJoinTest (JoinTestBase , unittest .TestCase ):
40+ cls = PurePosixPath
41+
42+
43+ if os .name != 'nt' :
44+ class PosixPathJoinTest (JoinTestBase , unittest .TestCase ):
45+ cls = PosixPath
46+
47+
48+ if __name__ == "__main__" :
49+ unittest .main ()
Original file line number Diff line number Diff line change @@ -108,17 +108,6 @@ def test_str_subclass_windows(self):
108108 self ._check_str_subclass ('\\ \\ some\\ share\\ a' )
109109 self ._check_str_subclass ('\\ \\ some\\ share\\ a\\ b.txt' )
110110
111- @needs_posix
112- def test_join_posix (self ):
113- P = self .cls
114- p = P ('//a' )
115- pp = p .joinpath ('b' )
116- self .assertEqual (pp , P ('//a/b' ))
117- pp = P ('/a' ).joinpath ('//c' )
118- self .assertEqual (pp , P ('//c' ))
119- pp = P ('//a' ).joinpath ('/c' )
120- self .assertEqual (pp , P ('/c' ))
121-
122111 @needs_windows
123112 def test_join_windows (self ):
124113 P = self .cls
@@ -157,18 +146,6 @@ def test_join_windows(self):
157146 pp = P ('//./BootPartition' ).joinpath ('Windows' )
158147 self .assertEqual (pp , P ('//./BootPartition/Windows' ))
159148
160- @needs_posix
161- def test_div_posix (self ):
162- # Basically the same as joinpath().
163- P = self .cls
164- p = P ('//a' )
165- pp = p / 'b'
166- self .assertEqual (pp , P ('//a/b' ))
167- pp = P ('/a' ) / '//c'
168- self .assertEqual (pp , P ('//c' ))
169- pp = P ('//a' ) / '/c'
170- self .assertEqual (pp , P ('/c' ))
171-
172149 @needs_windows
173150 def test_div_windows (self ):
174151 # Basically the same as joinpath().
You can’t perform that action at this time.
0 commit comments