File tree 3 files changed +55
-23
lines changed 3 files changed +55
-23
lines changed Original file line number Diff line number Diff line change 4
4
5
5
import os .path
6
6
import pathlib .types
7
+ import posixpath
7
8
8
9
9
10
class LexicalPath (pathlib .types ._JoinablePath ):
@@ -31,3 +32,8 @@ def __repr__(self):
31
32
32
33
def with_segments (self , * pathsegments ):
33
34
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):
108
108
self ._check_str_subclass ('\\ \\ some\\ share\\ a' )
109
109
self ._check_str_subclass ('\\ \\ some\\ share\\ a\\ b.txt' )
110
110
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
-
122
111
@needs_windows
123
112
def test_join_windows (self ):
124
113
P = self .cls
@@ -157,18 +146,6 @@ def test_join_windows(self):
157
146
pp = P ('//./BootPartition' ).joinpath ('Windows' )
158
147
self .assertEqual (pp , P ('//./BootPartition/Windows' ))
159
148
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
-
172
149
@needs_windows
173
150
def test_div_windows (self ):
174
151
# Basically the same as joinpath().
You can’t perform that action at this time.
0 commit comments