@@ -38,6 +38,9 @@ def test_magic_methods(self):
38
38
self .assertIs (P .__gt__ , object .__gt__ )
39
39
self .assertIs (P .__ge__ , object .__ge__ )
40
40
41
+ def test_pathmod (self ):
42
+ self .assertIs (self .cls .pathmod , posixpath )
43
+
41
44
42
45
class DummyPurePath (pathlib ._abc .PurePathBase ):
43
46
def __eq__ (self , other ):
@@ -52,8 +55,8 @@ def __hash__(self):
52
55
class DummyPurePathTest (unittest .TestCase ):
53
56
cls = DummyPurePath
54
57
55
- # Make sure any symbolic links in the base test path are resolved .
56
- base = os . path . realpath ( TESTFN )
58
+ # Use a base path that's unrelated to any real filesystem path .
59
+ base = f'/this/ path/kills/fascists/ { TESTFN } '
57
60
58
61
# Keys are canonical paths, values are list of tuples of arguments
59
62
# supposed to produce equal paths.
@@ -86,37 +89,6 @@ def test_constructor_common(self):
86
89
P ('a/b/c' )
87
90
P ('/a/b/c' )
88
91
89
- def test_concrete_class (self ):
90
- if self .cls is pathlib .PurePath :
91
- expected = pathlib .PureWindowsPath if os .name == 'nt' else pathlib .PurePosixPath
92
- else :
93
- expected = self .cls
94
- p = self .cls ('a' )
95
- self .assertIs (type (p ), expected )
96
-
97
- def test_different_pathmods_unequal (self ):
98
- p = self .cls ('a' )
99
- if p .pathmod is posixpath :
100
- q = pathlib .PureWindowsPath ('a' )
101
- else :
102
- q = pathlib .PurePosixPath ('a' )
103
- self .assertNotEqual (p , q )
104
-
105
- def test_different_pathmods_unordered (self ):
106
- p = self .cls ('a' )
107
- if p .pathmod is posixpath :
108
- q = pathlib .PureWindowsPath ('a' )
109
- else :
110
- q = pathlib .PurePosixPath ('a' )
111
- with self .assertRaises (TypeError ):
112
- p < q
113
- with self .assertRaises (TypeError ):
114
- p <= q
115
- with self .assertRaises (TypeError ):
116
- p > q
117
- with self .assertRaises (TypeError ):
118
- p >= q
119
-
120
92
def _check_str_subclass (self , * args ):
121
93
# Issue #21127: it should be possible to construct a PurePath object
122
94
# from a str subclass instance, and it then gets converted to
@@ -721,15 +693,6 @@ def test_fspath_common(self):
721
693
def test_as_bytes_common (self ):
722
694
self .assertRaises (TypeError , bytes , self .cls ())
723
695
724
- def test_matches_path_api (self ):
725
- our_names = {name for name in dir (self .cls ) if name [0 ] != '_' }
726
- path_names = {name for name in dir (pathlib .Path ) if name [0 ] != '_' }
727
- self .assertEqual (our_names , path_names )
728
- for attr_name in our_names :
729
- our_attr = getattr (self .cls , attr_name )
730
- path_attr = getattr (pathlib .Path , attr_name )
731
- self .assertEqual (our_attr .__doc__ , path_attr .__doc__ )
732
-
733
696
734
697
class DummyPathIO (io .BytesIO ):
735
698
"""
@@ -905,11 +868,13 @@ def assertFileNotFound(self, func, *args, **kwargs):
905
868
self .assertEqual (cm .exception .errno , errno .ENOENT )
906
869
907
870
def assertEqualNormCase (self , path_a , path_b ):
908
- self .assertEqual (os .path .normcase (path_a ), os .path .normcase (path_b ))
871
+ normcase = self .pathmod .normcase
872
+ self .assertEqual (normcase (path_a ), normcase (path_b ))
909
873
910
874
def test_samefile (self ):
911
- fileA_path = os .path .join (self .base , 'fileA' )
912
- fileB_path = os .path .join (self .base , 'dirB' , 'fileB' )
875
+ pathmod = self .pathmod
876
+ fileA_path = pathmod .join (self .base , 'fileA' )
877
+ fileB_path = pathmod .join (self .base , 'dirB' , 'fileB' )
913
878
p = self .cls (fileA_path )
914
879
pp = self .cls (fileA_path )
915
880
q = self .cls (fileB_path )
@@ -918,7 +883,7 @@ def test_samefile(self):
918
883
self .assertFalse (p .samefile (fileB_path ))
919
884
self .assertFalse (p .samefile (q ))
920
885
# Test the non-existent file case
921
- non_existent = os . path .join (self .base , 'foo' )
886
+ non_existent = pathmod .join (self .base , 'foo' )
922
887
r = self .cls (non_existent )
923
888
self .assertRaises (FileNotFoundError , p .samefile , r )
924
889
self .assertRaises (FileNotFoundError , p .samefile , non_existent )
@@ -1379,14 +1344,15 @@ def test_resolve_common(self):
1379
1344
p .resolve (strict = True )
1380
1345
self .assertEqual (cm .exception .errno , errno .ENOENT )
1381
1346
# Non-strict
1347
+ pathmod = self .pathmod
1382
1348
self .assertEqualNormCase (str (p .resolve (strict = False )),
1383
- os . path .join (self .base , 'foo' ))
1349
+ pathmod .join (self .base , 'foo' ))
1384
1350
p = P (self .base , 'foo' , 'in' , 'spam' )
1385
1351
self .assertEqualNormCase (str (p .resolve (strict = False )),
1386
- os . path .join (self .base , 'foo' , 'in' , 'spam' ))
1352
+ pathmod .join (self .base , 'foo' , 'in' , 'spam' ))
1387
1353
p = P (self .base , '..' , 'foo' , 'in' , 'spam' )
1388
1354
self .assertEqualNormCase (str (p .resolve (strict = False )),
1389
- os . path . abspath ( os . path . join ( 'foo' , 'in' , 'spam' ) ))
1355
+ pathmod . join ( pathmod . dirname ( self . base ), 'foo' , 'in' , 'spam' ))
1390
1356
# These are all relative symlinks.
1391
1357
p = P (self .base , 'dirB' , 'fileB' )
1392
1358
self ._check_resolve_relative (p , p )
@@ -1401,7 +1367,7 @@ def test_resolve_common(self):
1401
1367
self ._check_resolve_relative (p , P (self .base , 'dirB' , 'fileB' , 'foo' , 'in' ,
1402
1368
'spam' ), False )
1403
1369
p = P (self .base , 'dirA' , 'linkC' , '..' , 'foo' , 'in' , 'spam' )
1404
- if os . name == 'nt' and isinstance ( p , pathlib . Path ) :
1370
+ if self . cls . pathmod is not posixpath :
1405
1371
# In Windows, if linkY points to dirB, 'dirA\linkY\..'
1406
1372
# resolves to 'dirA' without resolving linkY first.
1407
1373
self ._check_resolve_relative (p , P (self .base , 'dirA' , 'foo' , 'in' ,
@@ -1421,7 +1387,7 @@ def test_resolve_common(self):
1421
1387
self ._check_resolve_relative (p , P (self .base , 'dirB' , 'foo' , 'in' , 'spam' ),
1422
1388
False )
1423
1389
p = P (self .base , 'dirA' , 'linkX' , 'linkY' , '..' , 'foo' , 'in' , 'spam' )
1424
- if os . name == 'nt' and isinstance ( p , pathlib . Path ) :
1390
+ if self . cls . pathmod is not posixpath :
1425
1391
# In Windows, if linkY points to dirB, 'dirA\linkY\..'
1426
1392
# resolves to 'dirA' without resolving linkY first.
1427
1393
self ._check_resolve_relative (p , P (d , 'foo' , 'in' , 'spam' ), False )
@@ -1434,10 +1400,11 @@ def test_resolve_dot(self):
1434
1400
# See http://web.archive.org/web/20200623062557/https://bitbucket.org/pitrou/pathlib/issues/9/
1435
1401
if not self .can_symlink :
1436
1402
self .skipTest ("symlinks required" )
1403
+ pathmod = self .pathmod
1437
1404
p = self .cls (self .base )
1438
1405
p .joinpath ('0' ).symlink_to ('.' , target_is_directory = True )
1439
- p .joinpath ('1' ).symlink_to (os . path .join ('0' , '0' ), target_is_directory = True )
1440
- p .joinpath ('2' ).symlink_to (os . path .join ('1' , '1' ), target_is_directory = True )
1406
+ p .joinpath ('1' ).symlink_to (pathmod .join ('0' , '0' ), target_is_directory = True )
1407
+ p .joinpath ('2' ).symlink_to (pathmod .join ('1' , '1' ), target_is_directory = True )
1441
1408
q = p / '2'
1442
1409
self .assertEqual (q .resolve (strict = True ), p )
1443
1410
r = q / '3' / '4'
@@ -1454,7 +1421,7 @@ def _check_symlink_loop(self, *args):
1454
1421
def test_resolve_loop (self ):
1455
1422
if not self .can_symlink :
1456
1423
self .skipTest ("symlinks required" )
1457
- if os . name == 'nt' and issubclass ( self .cls , pathlib . Path ) :
1424
+ if self .cls . pathmod is not posixpath :
1458
1425
self .skipTest ("symlink loops work differently with concrete Windows paths" )
1459
1426
# Loops with relative symlinks.
1460
1427
self .cls (self .base , 'linkX' ).symlink_to ('linkX/inside' )
@@ -1657,10 +1624,11 @@ def _check_complex_symlinks(self, link0_target):
1657
1624
self .skipTest ("symlinks required" )
1658
1625
1659
1626
# Test solving a non-looping chain of symlinks (issue #19887).
1627
+ pathmod = self .pathmod
1660
1628
P = self .cls (self .base )
1661
- P .joinpath ('link1' ).symlink_to (os . path .join ('link0' , 'link0' ), target_is_directory = True )
1662
- P .joinpath ('link2' ).symlink_to (os . path .join ('link1' , 'link1' ), target_is_directory = True )
1663
- P .joinpath ('link3' ).symlink_to (os . path .join ('link2' , 'link2' ), target_is_directory = True )
1629
+ P .joinpath ('link1' ).symlink_to (pathmod .join ('link0' , 'link0' ), target_is_directory = True )
1630
+ P .joinpath ('link2' ).symlink_to (pathmod .join ('link1' , 'link1' ), target_is_directory = True )
1631
+ P .joinpath ('link3' ).symlink_to (pathmod .join ('link2' , 'link2' ), target_is_directory = True )
1664
1632
P .joinpath ('link0' ).symlink_to (link0_target , target_is_directory = True )
1665
1633
1666
1634
# Resolve absolute paths.
@@ -1707,7 +1675,7 @@ def test_complex_symlinks_relative(self):
1707
1675
self ._check_complex_symlinks ('.' )
1708
1676
1709
1677
def test_complex_symlinks_relative_dot_dot (self ):
1710
- self ._check_complex_symlinks (os . path .join ('dirA' , '..' ))
1678
+ self ._check_complex_symlinks (self . pathmod .join ('dirA' , '..' ))
1711
1679
1712
1680
def setUpWalk (self ):
1713
1681
# Build:
0 commit comments