@@ -1176,25 +1176,10 @@ def test_different_flavours_unordered(self):
1176
1176
join = lambda * x : os .path .join (BASE , * x )
1177
1177
rel_join = lambda * x : os .path .join (TESTFN , * x )
1178
1178
1179
- def symlink_skip_reason ():
1180
- if not pathlib .supports_symlinks :
1181
- return "no system support for symlinks"
1182
- try :
1183
- os .symlink (__file__ , BASE )
1184
- except OSError as e :
1185
- return str (e )
1186
- else :
1187
- support .unlink (BASE )
1188
- return None
1189
-
1190
- symlink_skip_reason = symlink_skip_reason ()
1191
-
1192
1179
only_nt = unittest .skipIf (os .name != 'nt' ,
1193
1180
'test requires a Windows-compatible system' )
1194
1181
only_posix = unittest .skipIf (os .name == 'nt' ,
1195
1182
'test requires a POSIX-compatible system' )
1196
- with_symlinks = unittest .skipIf (symlink_skip_reason , symlink_skip_reason )
1197
-
1198
1183
1199
1184
@only_posix
1200
1185
class PosixPathAsPureTest (PurePosixPathTest ):
@@ -1256,7 +1241,7 @@ def cleanup():
1256
1241
with open (join ('dirC' , 'dirD' , 'fileD' ), 'wb' ) as f :
1257
1242
f .write (b"this is file D\n " )
1258
1243
os .chmod (join ('dirE' ), 0 )
1259
- if not symlink_skip_reason :
1244
+ if support . can_symlink () :
1260
1245
# Relative symlinks
1261
1246
os .symlink ('fileA' , join ('linkA' ))
1262
1247
os .symlink ('non-existing' , join ('brokenLink' ))
@@ -1350,7 +1335,7 @@ def test_exists(self):
1350
1335
self .assertIs (True , (p / 'dirA' ).exists ())
1351
1336
self .assertIs (True , (p / 'fileA' ).exists ())
1352
1337
self .assertIs (False , (p / 'fileA' / 'bah' ).exists ())
1353
- if not symlink_skip_reason :
1338
+ if support . can_symlink () :
1354
1339
self .assertIs (True , (p / 'linkA' ).exists ())
1355
1340
self .assertIs (True , (p / 'linkB' ).exists ())
1356
1341
self .assertIs (True , (p / 'linkB' / 'fileB' ).exists ())
@@ -1393,11 +1378,11 @@ def test_iterdir(self):
1393
1378
it = p .iterdir ()
1394
1379
paths = set (it )
1395
1380
expected = ['dirA' , 'dirB' , 'dirC' , 'dirE' , 'fileA' ]
1396
- if not symlink_skip_reason :
1381
+ if support . can_symlink () :
1397
1382
expected += ['linkA' , 'linkB' , 'brokenLink' ]
1398
1383
self .assertEqual (paths , { P (BASE , q ) for q in expected })
1399
1384
1400
- @with_symlinks
1385
+ @support . skip_unless_symlink
1401
1386
def test_iterdir_symlink (self ):
1402
1387
# __iter__ on a symlink to a directory
1403
1388
P = self .cls
@@ -1426,16 +1411,16 @@ def _check(glob, expected):
1426
1411
_check (it , ["fileA" ])
1427
1412
_check (p .glob ("fileB" ), [])
1428
1413
_check (p .glob ("dir*/file*" ), ["dirB/fileB" , "dirC/fileC" ])
1429
- if symlink_skip_reason :
1414
+ if not support . can_symlink () :
1430
1415
_check (p .glob ("*A" ), ['dirA' , 'fileA' ])
1431
1416
else :
1432
1417
_check (p .glob ("*A" ), ['dirA' , 'fileA' , 'linkA' ])
1433
- if symlink_skip_reason :
1418
+ if not support . can_symlink () :
1434
1419
_check (p .glob ("*B/*" ), ['dirB/fileB' ])
1435
1420
else :
1436
1421
_check (p .glob ("*B/*" ), ['dirB/fileB' , 'dirB/linkD' ,
1437
1422
'linkB/fileB' , 'linkB/linkD' ])
1438
- if symlink_skip_reason :
1423
+ if not support . can_symlink () :
1439
1424
_check (p .glob ("*/fileB" ), ['dirB/fileB' ])
1440
1425
else :
1441
1426
_check (p .glob ("*/fileB" ), ['dirB/fileB' , 'linkB/fileB' ])
@@ -1450,7 +1435,7 @@ def _check(glob, expected):
1450
1435
_check (it , ["fileA" ])
1451
1436
_check (p .rglob ("fileB" ), ["dirB/fileB" ])
1452
1437
_check (p .rglob ("*/fileA" ), [])
1453
- if symlink_skip_reason :
1438
+ if not support . can_symlink () :
1454
1439
_check (p .rglob ("*/fileB" ), ["dirB/fileB" ])
1455
1440
else :
1456
1441
_check (p .rglob ("*/fileB" ), ["dirB/fileB" , "dirB/linkD/fileB" ,
@@ -1461,7 +1446,7 @@ def _check(glob, expected):
1461
1446
_check (p .rglob ("file*" ), ["dirC/fileC" , "dirC/dirD/fileD" ])
1462
1447
_check (p .rglob ("*/*" ), ["dirC/dirD/fileD" ])
1463
1448
1464
- @with_symlinks
1449
+ @support . skip_unless_symlink
1465
1450
def test_rglob_symlink_loop (self ):
1466
1451
# Don't get fooled by symlink loops (Issue #26012)
1467
1452
P = self .cls
@@ -1494,7 +1479,7 @@ def _check_resolve(self, p, expected, strict=True):
1494
1479
# this can be used to check both relative and absolute resolutions
1495
1480
_check_resolve_relative = _check_resolve_absolute = _check_resolve
1496
1481
1497
- @with_symlinks
1482
+ @support . skip_unless_symlink
1498
1483
def test_resolve_common (self ):
1499
1484
P = self .cls
1500
1485
p = P (BASE , 'foo' )
@@ -1551,7 +1536,7 @@ def test_resolve_common(self):
1551
1536
# resolves to 'dirB/..' first before resolving to parent of dirB.
1552
1537
self ._check_resolve_relative (p , P (BASE , 'foo' ), False )
1553
1538
1554
- @with_symlinks
1539
+ @support . skip_unless_symlink
1555
1540
def test_resolve_dot (self ):
1556
1541
# See https://bitbucket.org/pitrou/pathlib/issue/9/pathresolve-fails-on-complex-symlinks
1557
1542
p = self .cls (BASE )
@@ -1603,7 +1588,7 @@ def test_stat(self):
1603
1588
self .addCleanup (p .chmod , st .st_mode )
1604
1589
self .assertNotEqual (p .stat (), st )
1605
1590
1606
- @with_symlinks
1591
+ @support . skip_unless_symlink
1607
1592
def test_lstat (self ):
1608
1593
p = self .cls (BASE )/ 'linkA'
1609
1594
st = p .stat ()
@@ -1816,7 +1801,7 @@ def test_mkdir_no_parents_file(self):
1816
1801
p .mkdir (exist_ok = True )
1817
1802
self .assertEqual (cm .exception .errno , errno .EEXIST )
1818
1803
1819
- @with_symlinks
1804
+ @support . skip_unless_symlink
1820
1805
def test_symlink_to (self ):
1821
1806
P = self .cls (BASE )
1822
1807
target = P / 'fileA'
@@ -1846,7 +1831,7 @@ def test_is_dir(self):
1846
1831
self .assertFalse ((P / 'fileA' ).is_dir ())
1847
1832
self .assertFalse ((P / 'non-existing' ).is_dir ())
1848
1833
self .assertFalse ((P / 'fileA' / 'bah' ).is_dir ())
1849
- if not symlink_skip_reason :
1834
+ if support . can_symlink () :
1850
1835
self .assertFalse ((P / 'linkA' ).is_dir ())
1851
1836
self .assertTrue ((P / 'linkB' ).is_dir ())
1852
1837
self .assertFalse ((P / 'brokenLink' ).is_dir ())
@@ -1857,7 +1842,7 @@ def test_is_file(self):
1857
1842
self .assertFalse ((P / 'dirA' ).is_file ())
1858
1843
self .assertFalse ((P / 'non-existing' ).is_file ())
1859
1844
self .assertFalse ((P / 'fileA' / 'bah' ).is_file ())
1860
- if not symlink_skip_reason :
1845
+ if support . can_symlink () :
1861
1846
self .assertTrue ((P / 'linkA' ).is_file ())
1862
1847
self .assertFalse ((P / 'linkB' ).is_file ())
1863
1848
self .assertFalse ((P / 'brokenLink' ).is_file ())
@@ -1868,7 +1853,7 @@ def test_is_symlink(self):
1868
1853
self .assertFalse ((P / 'dirA' ).is_symlink ())
1869
1854
self .assertFalse ((P / 'non-existing' ).is_symlink ())
1870
1855
self .assertFalse ((P / 'fileA' / 'bah' ).is_symlink ())
1871
- if not symlink_skip_reason :
1856
+ if support . can_symlink () :
1872
1857
self .assertTrue ((P / 'linkA' ).is_symlink ())
1873
1858
self .assertTrue ((P / 'linkB' ).is_symlink ())
1874
1859
self .assertTrue ((P / 'brokenLink' ).is_symlink ())
@@ -1991,15 +1976,15 @@ def _check_complex_symlinks(self, link0_target):
1991
1976
finally :
1992
1977
os .chdir (old_path )
1993
1978
1994
- @with_symlinks
1979
+ @support . skip_unless_symlink
1995
1980
def test_complex_symlinks_absolute (self ):
1996
1981
self ._check_complex_symlinks (BASE )
1997
1982
1998
- @with_symlinks
1983
+ @support . skip_unless_symlink
1999
1984
def test_complex_symlinks_relative (self ):
2000
1985
self ._check_complex_symlinks ('.' )
2001
1986
2002
- @with_symlinks
1987
+ @support . skip_unless_symlink
2003
1988
def test_complex_symlinks_relative_dot_dot (self ):
2004
1989
self ._check_complex_symlinks (os .path .join ('dirA' , '..' ))
2005
1990
@@ -2062,7 +2047,7 @@ def test_touch_mode(self):
2062
2047
st = os .stat (join ('masked_new_file' ))
2063
2048
self .assertEqual (stat .S_IMODE (st .st_mode ), 0o750 )
2064
2049
2065
- @with_symlinks
2050
+ @support . skip_unless_symlink
2066
2051
def test_resolve_loop (self ):
2067
2052
# Loops with relative symlinks
2068
2053
os .symlink ('linkX/inside' , join ('linkX' ))
0 commit comments