@@ -160,45 +160,30 @@ def with_segments(self, *pathsegments):
160160 for parent in p .parents :
161161 self .assertEqual (42 , parent .session_id )
162162
163- def _get_drive_root_parts (self , parts ):
164- path = self .cls (* parts )
165- return path .drive , path .root , path .parts
166-
167- def _check_drive_root_parts (self , arg , * expected ):
163+ def _check_parse_path (self , raw_path , * expected ):
168164 sep = self .pathmod .sep
169- actual = self ._get_drive_root_parts ([ x .replace ('/' , sep ) for x in arg ] )
165+ actual = self .cls . _parse_path ( raw_path .replace ('/' , sep ))
170166 self .assertEqual (actual , expected )
171167 if altsep := self .pathmod .altsep :
172- actual = self ._get_drive_root_parts ([ x .replace ('/' , altsep ) for x in arg ] )
168+ actual = self .cls . _parse_path ( raw_path .replace ('/' , altsep ))
173169 self .assertEqual (actual , expected )
174170
175- def test_drive_root_parts_common (self ):
176- check = self ._check_drive_root_parts
171+ def test_parse_path_common (self ):
172+ check = self ._check_parse_path
177173 sep = self .pathmod .sep
178- # Unanchored parts.
179- check ((), '' , '' , ())
180- check (('a' ,), '' , '' , ('a' ,))
181- check (('a/' ,), '' , '' , ('a' ,))
182- check (('a' , 'b' ), '' , '' , ('a' , 'b' ))
183- # Expansion.
184- check (('a/b' ,), '' , '' , ('a' , 'b' ))
185- check (('a/b/' ,), '' , '' , ('a' , 'b' ))
186- check (('a' , 'b/c' , 'd' ), '' , '' , ('a' , 'b' , 'c' , 'd' ))
187- # Collapsing and stripping excess slashes.
188- check (('a' , 'b//c' , 'd' ), '' , '' , ('a' , 'b' , 'c' , 'd' ))
189- check (('a' , 'b/c/' , 'd' ), '' , '' , ('a' , 'b' , 'c' , 'd' ))
190- # Eliminating standalone dots.
191- check (('.' ,), '' , '' , ())
192- check (('.' , '.' , 'b' ), '' , '' , ('b' ,))
193- check (('a' , '.' , 'b' ), '' , '' , ('a' , 'b' ))
194- check (('a' , '.' , '.' ), '' , '' , ('a' ,))
195- # The first part is anchored.
196- check (('/a/b' ,), '' , sep , (sep , 'a' , 'b' ))
197- check (('/a' , 'b' ), '' , sep , (sep , 'a' , 'b' ))
198- check (('/a/' , 'b' ), '' , sep , (sep , 'a' , 'b' ))
199- # Ignoring parts before an anchored part.
200- check (('a' , '/b' , 'c' ), '' , sep , (sep , 'b' , 'c' ))
201- check (('a' , '/b' , '/c' ), '' , sep , (sep , 'c' ))
174+ check ('' , '' , '' , [])
175+ check ('a' , '' , '' , ['a' ])
176+ check ('a/' , '' , '' , ['a' ])
177+ check ('a/b' , '' , '' , ['a' , 'b' ])
178+ check ('a/b/' , '' , '' , ['a' , 'b' ])
179+ check ('a/b/c/d' , '' , '' , ['a' , 'b' , 'c' , 'd' ])
180+ check ('a/b//c/d' , '' , '' , ['a' , 'b' , 'c' , 'd' ])
181+ check ('a/b/c/d' , '' , '' , ['a' , 'b' , 'c' , 'd' ])
182+ check ('.' , '' , '' , [])
183+ check ('././b' , '' , '' , ['b' ])
184+ check ('a/./b' , '' , '' , ['a' , 'b' ])
185+ check ('a/./.' , '' , '' , ['a' ])
186+ check ('/a/b' , '' , sep , ['a' , 'b' ])
202187
203188 def test_join_common (self ):
204189 P = self .cls
@@ -792,17 +777,17 @@ def test_repr_roundtrips(self):
792777class PurePosixPathTest (PurePathTest ):
793778 cls = pathlib .PurePosixPath
794779
795- def test_drive_root_parts (self ):
796- check = self ._check_drive_root_parts
780+ def test_parse_path (self ):
781+ check = self ._check_parse_path
797782 # Collapsing of excess leading slashes, except for the double-slash
798783 # special case.
799- check (( '//a' , 'b' ) , '' , '//' , ( '//' , ' a' , 'b' ) )
800- check (( '///a' , 'b' ) , '' , '/' , ( '/' , ' a' , 'b' ) )
801- check (( '////a' , 'b' ), '' , '/' , ( '/' , ' a' , 'b' ) )
784+ check ('//a/b' , '' , '//' , [ ' a' , 'b' ] )
785+ check ('///a/b' , '' , '/' , [ ' a' , 'b' ] )
786+ check ('////a/b' , '' , '/' , [ ' a' , 'b' ] )
802787 # Paths which look like NT paths aren't treated specially.
803- check (( 'c:a' ,), '' , '' , ( 'c:a' ,) )
804- check (( 'c:\\ a' ,), '' , '' , ( 'c:\\ a' ,) )
805- check (( '\\ a' ,), '' , '' , ( '\\ a' ,) )
788+ check ('c:a' , '' , '' , [ 'c:a' ,] )
789+ check ('c:\\ a' , '' , '' , [ 'c:\\ a' ,] )
790+ check ('\\ a' , '' , '' , [ '\\ a' ,] )
806791
807792 def test_root (self ):
808793 P = self .cls
@@ -900,67 +885,53 @@ class PureWindowsPathTest(PurePathTest):
900885 ],
901886 })
902887
903- def test_drive_root_parts (self ):
904- check = self ._check_drive_root_parts
888+ def test_parse_path (self ):
889+ check = self ._check_parse_path
905890 # First part is anchored.
906- check (('c:' ,), 'c:' , '' , ('c:' ,))
907- check (('c:/' ,), 'c:' , '\\ ' , ('c:\\ ' ,))
908- check (('/' ,), '' , '\\ ' , ('\\ ' ,))
909- check (('c:a' ,), 'c:' , '' , ('c:' , 'a' ))
910- check (('c:/a' ,), 'c:' , '\\ ' , ('c:\\ ' , 'a' ))
911- check (('/a' ,), '' , '\\ ' , ('\\ ' , 'a' ))
912- # UNC paths.
913- check (('//' ,), '\\ \\ ' , '' , ('\\ \\ ' ,))
914- check (('//a' ,), '\\ \\ a' , '' , ('\\ \\ a' ,))
915- check (('//a/' ,), '\\ \\ a\\ ' , '' , ('\\ \\ a\\ ' ,))
916- check (('//a/b' ,), '\\ \\ a\\ b' , '\\ ' , ('\\ \\ a\\ b\\ ' ,))
917- check (('//a/b/' ,), '\\ \\ a\\ b' , '\\ ' , ('\\ \\ a\\ b\\ ' ,))
918- check (('//a/b/c' ,), '\\ \\ a\\ b' , '\\ ' , ('\\ \\ a\\ b\\ ' , 'c' ))
919- # Second part is anchored, so that the first part is ignored.
920- check (('a' , 'Z:b' , 'c' ), 'Z:' , '' , ('Z:' , 'b' , 'c' ))
921- check (('a' , 'Z:/b' , 'c' ), 'Z:' , '\\ ' , ('Z:\\ ' , 'b' , 'c' ))
891+ check ('c:' , 'c:' , '' , [])
892+ check ('c:/' , 'c:' , '\\ ' , [])
893+ check ('/' , '' , '\\ ' , [])
894+ check ('c:a' , 'c:' , '' , ['a' ])
895+ check ('c:/a' , 'c:' , '\\ ' , ['a' ])
896+ check ('/a' , '' , '\\ ' , ['a' ])
922897 # UNC paths.
923- check (('a' , '//b/c' , 'd' ), '\\ \\ b\\ c' , '\\ ' , ('\\ \\ b\\ c\\ ' , 'd' ))
898+ check ('//' , '\\ \\ ' , '' , [])
899+ check ('//a' , '\\ \\ a' , '' , [])
900+ check ('//a/' , '\\ \\ a\\ ' , '' , [])
901+ check ('//a/b' , '\\ \\ a\\ b' , '\\ ' , [])
902+ check ('//a/b/' , '\\ \\ a\\ b' , '\\ ' , [])
903+ check ('//a/b/c' , '\\ \\ a\\ b' , '\\ ' , ['c' ])
924904 # Collapsing and stripping excess slashes.
925- check (( 'a' , ' Z://b//c/' , ' d/'), 'Z:' , '\\ ' , ( 'Z: \\ ' , ' b' , 'c' , 'd' ) )
905+ check (' Z://b//c/d/', 'Z:' , '\\ ' , [ ' b' , 'c' , 'd' ] )
926906 # UNC paths.
927- check (( 'a' , ' //b/c//' , 'd' ) , '\\ \\ b\\ c' , '\\ ' , ( ' \\ \\ b \\ c \\ ' , 'd' ) )
907+ check (' //b/c//d' , '\\ \\ b\\ c' , '\\ ' , [ 'd' ] )
928908 # Extended paths.
929- check (('//./c:' ,), '\\ \\ .\\ c:' , '' , ('\\ \\ .\\ c:' ,))
930- check (('//?/c:/' ,), '\\ \\ ?\\ c:' , '\\ ' , ('\\ \\ ?\\ c:\\ ' ,))
931- check (('//?/c:/a' ,), '\\ \\ ?\\ c:' , '\\ ' , ('\\ \\ ?\\ c:\\ ' , 'a' ))
932- check (('//?/c:/a' , '/b' ), '\\ \\ ?\\ c:' , '\\ ' , ('\\ \\ ?\\ c:\\ ' , 'b' ))
909+ check ('//./c:' , '\\ \\ .\\ c:' , '' , [])
910+ check ('//?/c:/' , '\\ \\ ?\\ c:' , '\\ ' , [])
911+ check ('//?/c:/a' , '\\ \\ ?\\ c:' , '\\ ' , ['a' ])
933912 # Extended UNC paths (format is "\\?\UNC\server\share").
934- check (( '//?' ,), '\\ \\ ?' , '' , ( ' \\ \\ ?' ,) )
935- check (( '//?/' ,), '\\ \\ ?\\ ' , '' , ( ' \\ \\ ? \\ ' ,) )
936- check (( '//?/UNC' ,), '\\ \\ ?\\ UNC' , '' , ( ' \\ \\ ? \\ UNC' ,) )
937- check (( '//?/UNC/' ,), '\\ \\ ?\\ UNC\\ ' , '' , ( ' \\ \\ ? \\ UNC \\ ' ,) )
938- check (( '//?/UNC/b' ,), '\\ \\ ?\\ UNC\\ b' , '' , ( ' \\ \\ ? \\ UNC \\ b' ,) )
939- check (( '//?/UNC/b/' ,), '\\ \\ ?\\ UNC\\ b\\ ' , '' , ( ' \\ \\ ? \\ UNC \\ b \\ ' ,) )
940- check (( '//?/UNC/b/c' ,), '\\ \\ ?\\ UNC\\ b\\ c' , '\\ ' , ( ' \\ \\ ? \\ UNC \\ b \\ c \\ ' ,) )
941- check (( '//?/UNC/b/c/' ,), '\\ \\ ?\\ UNC\\ b\\ c' , '\\ ' , ( ' \\ \\ ? \\ UNC \\ b \\ c \\ ' ,) )
942- check (( '//?/UNC/b/c/d' ,), '\\ \\ ?\\ UNC\\ b\\ c' , '\\ ' , ( ' \\ \\ ? \\ UNC \\ b \\ c \\ ' , 'd' ) )
913+ check ('//?' , '\\ \\ ?' , '' , [] )
914+ check ('//?/' , '\\ \\ ?\\ ' , '' , [] )
915+ check ('//?/UNC' , '\\ \\ ?\\ UNC' , '' , [] )
916+ check ('//?/UNC/' , '\\ \\ ?\\ UNC\\ ' , '' , [] )
917+ check ('//?/UNC/b' , '\\ \\ ?\\ UNC\\ b' , '' , [] )
918+ check ('//?/UNC/b/' , '\\ \\ ?\\ UNC\\ b\\ ' , '' , [] )
919+ check ('//?/UNC/b/c' , '\\ \\ ?\\ UNC\\ b\\ c' , '\\ ' , [] )
920+ check ('//?/UNC/b/c/' , '\\ \\ ?\\ UNC\\ b\\ c' , '\\ ' , [] )
921+ check ('//?/UNC/b/c/d' , '\\ \\ ?\\ UNC\\ b\\ c' , '\\ ' , [ 'd' ] )
943922 # UNC device paths
944- check (('//./BootPartition/' ,), '\\ \\ .\\ BootPartition' , '\\ ' , ('\\ \\ .\\ BootPartition\\ ' ,))
945- check (('//?/BootPartition/' ,), '\\ \\ ?\\ BootPartition' , '\\ ' , ('\\ \\ ?\\ BootPartition\\ ' ,))
946- check (('//./PhysicalDrive0' ,), '\\ \\ .\\ PhysicalDrive0' , '' , ('\\ \\ .\\ PhysicalDrive0' ,))
947- check (('//?/Volume{}/' ,), '\\ \\ ?\\ Volume{}' , '\\ ' , ('\\ \\ ?\\ Volume{}\\ ' ,))
948- check (('//./nul' ,), '\\ \\ .\\ nul' , '' , ('\\ \\ .\\ nul' ,))
949- # Second part has a root but not drive.
950- check (('a' , '/b' , 'c' ), '' , '\\ ' , ('\\ ' , 'b' , 'c' ))
951- check (('Z:/a' , '/b' , 'c' ), 'Z:' , '\\ ' , ('Z:\\ ' , 'b' , 'c' ))
952- check (('//?/Z:/a' , '/b' , 'c' ), '\\ \\ ?\\ Z:' , '\\ ' , ('\\ \\ ?\\ Z:\\ ' , 'b' , 'c' ))
953- # Joining with the same drive => the first path is appended to if
954- # the second path is relative.
955- check (('c:/a/b' , 'c:x/y' ), 'c:' , '\\ ' , ('c:\\ ' , 'a' , 'b' , 'x' , 'y' ))
956- check (('c:/a/b' , 'c:/x/y' ), 'c:' , '\\ ' , ('c:\\ ' , 'x' , 'y' ))
923+ check ('//./BootPartition/' , '\\ \\ .\\ BootPartition' , '\\ ' , [])
924+ check ('//?/BootPartition/' , '\\ \\ ?\\ BootPartition' , '\\ ' , [])
925+ check ('//./PhysicalDrive0' , '\\ \\ .\\ PhysicalDrive0' , '' , [])
926+ check ('//?/Volume{}/' , '\\ \\ ?\\ Volume{}' , '\\ ' , [])
927+ check ('//./nul' , '\\ \\ .\\ nul' , '' , [])
957928 # Paths to files with NTFS alternate data streams
958- check (( './c:s' ,), '' , '' , ( 'c:s' ,) )
959- check (( 'cc:s' ,), '' , '' , ( 'cc:s' ,) )
960- check (( 'C:c:s' ,), 'C:' , '' , ( 'C:' , ' c:s') )
961- check (( 'C:/c:s' ,), 'C:' , '\\ ' , ( 'C: \\ ' , ' c:s') )
962- check (( 'D:a' , '. /c:b') , 'D:' , '' , ( 'D:' , ' a' , 'c:b' ) )
963- check (( 'D:/a' , '. /c:b') , 'D:' , '\\ ' , ( 'D: \\ ' , ' a' , 'c:b' ) )
929+ check ('./c:s' , '' , '' , [ 'c:s' ] )
930+ check ('cc:s' , '' , '' , [ 'cc:s' ] )
931+ check ('C:c:s' , 'C:' , '' , [ ' c:s'] )
932+ check ('C:/c:s' , 'C:' , '\\ ' , [ ' c:s'] )
933+ check ('D:a/c:b' , 'D:' , '' , [ ' a' , 'c:b' ] )
934+ check ('D:/a/c:b' , 'D:' , '\\ ' , [ ' a' , 'c:b' ] )
964935
965936 def test_str (self ):
966937 p = self .cls ('a/b/c' )
0 commit comments