20
20
# this package
21
21
from domdf_python_tools .paths import PathPlus , PosixPathPlus , WindowsPathPlus
22
22
23
-
24
23
try :
25
- import grp , pwd
24
+ # stdlib
25
+ import grp
26
+ import pwd
26
27
except ImportError :
27
28
grp = pwd = None # type: ignore
28
29
@@ -198,6 +199,7 @@ class PathTest(unittest.TestCase):
198
199
cls = PathPlus
199
200
200
201
def setUp (self ):
202
+
201
203
def cleanup ():
202
204
os .chmod (join ('dirE' ), 0o777 )
203
205
support .rmtree (BASE )
@@ -232,13 +234,15 @@ def cleanup():
232
234
def dirlink (self , src , dest ):
233
235
os .symlink (src , dest , target_is_directory = True )
234
236
else :
237
+
235
238
def dirlink (self , src , dest ):
236
239
os .symlink (src , dest )
237
240
238
241
def assertSame (self , path_a , path_b ):
239
242
self .assertTrue (
240
243
os .path .samefile (str (path_a ), str (path_b )),
241
- f"{ path_a !r} and { path_b !r} don't point to the same file" )
244
+ f"{ path_a !r} and { path_b !r} don't point to the same file"
245
+ )
242
246
243
247
def assertFileNotFound (self , func , * args , ** kwargs ):
244
248
with self .assertRaises (FileNotFoundError ) as cm :
@@ -346,8 +350,7 @@ def test_read_write_bytes(self):
346
350
def test_read_write_text (self ):
347
351
p = PathPlus (BASE )
348
352
(p / 'fileA' ).write_text ('äbcdefg' , encoding = 'latin-1' )
349
- self .assertEqual ((p / 'fileA' ).read_text (
350
- encoding = 'utf-8' , errors = 'ignore' ), 'bcdefg' )
353
+ self .assertEqual ((p / 'fileA' ).read_text (encoding = 'utf-8' , errors = 'ignore' ), 'bcdefg' )
351
354
# check that trying to write bytes does not truncate the file
352
355
self .assertRaises (TypeError , (p / 'fileA' ).write_text , b'somebytes' )
353
356
self .assertEqual ((p / 'fileA' ).read_text (encoding = 'latin-1' ), 'äbcdefg' )
@@ -381,6 +384,7 @@ def test_iterdir_nodir(self):
381
384
self .assertIn (cm .exception .errno , (errno .ENOTDIR , errno .ENOENT , errno .EINVAL ))
382
385
383
386
def test_glob_common (self ):
387
+
384
388
def _check (glob , expected ):
385
389
self .assertEqual (set (glob ), {P (BASE , q ) for q in expected })
386
390
@@ -405,6 +409,7 @@ def _check(glob, expected):
405
409
_check (p .glob ("*/fileB" ), ['dirB/fileB' , 'linkB/fileB' ])
406
410
407
411
def test_rglob_common (self ):
412
+
408
413
def _check (glob , expected ):
409
414
self .assertEqual (set (glob ), {P (BASE , q ) for q in expected })
410
415
@@ -418,8 +423,7 @@ def _check(glob, expected):
418
423
if symlink_skip_reason :
419
424
_check (p .rglob ("*/fileB" ), ["dirB/fileB" ])
420
425
else :
421
- _check (p .rglob ("*/fileB" ), ["dirB/fileB" , "dirB/linkD/fileB" ,
422
- "linkB/fileB" , "dirA/linkC/fileB" ])
426
+ _check (p .rglob ("*/fileB" ), ["dirB/fileB" , "dirB/linkD/fileB" , "linkB/fileB" , "dirA/linkC/fileB" ])
423
427
_check (p .rglob ("file*" ), ["fileA" , "dirB/fileB" , "dirC/fileC" , "dirC/dirD/fileD" ])
424
428
p = P (BASE , "dirC" )
425
429
_check (p .rglob ("file*" ), ["dirC/fileC" , "dirC/dirD/fileD" ])
@@ -433,9 +437,15 @@ def test_rglob_symlink_loop(self):
433
437
given = set (p .rglob ('*' ))
434
438
expect = {
435
439
'brokenLink' ,
436
- 'dirA' , 'dirA/linkC' ,
437
- 'dirB' , 'dirB/fileB' , 'dirB/linkD' ,
438
- 'dirC' , 'dirC/dirD' , 'dirC/dirD/fileD' , 'dirC/fileC' ,
440
+ 'dirA' ,
441
+ 'dirA/linkC' ,
442
+ 'dirB' ,
443
+ 'dirB/fileB' ,
444
+ 'dirB/linkD' ,
445
+ 'dirC' ,
446
+ 'dirC/dirD' ,
447
+ 'dirC/dirD/fileD' ,
448
+ 'dirC/fileC' ,
439
449
'dirE' ,
440
450
'fileA' ,
441
451
'linkA' ,
@@ -907,8 +917,7 @@ def test_is_socket_true(self):
907
917
try :
908
918
sock .bind (str (P ))
909
919
except OSError as e :
910
- if (isinstance (e , PermissionError ) or
911
- "AF_UNIX path too long" in str (e )):
920
+ if isinstance (e , PermissionError ) or "AF_UNIX path too long" in str (e ):
912
921
self .skipTest ("cannot bind Unix socket: " + str (e ))
913
922
self .assertTrue (P .is_socket ())
914
923
self .assertFalse (P .is_fifo ())
@@ -1008,8 +1017,7 @@ def test_complex_symlinks_relative_dot_dot(self):
1008
1017
1009
1018
def test_concrete_class (self ):
1010
1019
p = PathPlus ('a' )
1011
- self .assertIs (type (p ),
1012
- WindowsPathPlus if os .name == 'nt' else PosixPathPlus )
1020
+ self .assertIs (type (p ), WindowsPathPlus if os .name == 'nt' else PosixPathPlus )
1013
1021
1014
1022
def test_unsupported_flavour (self ):
1015
1023
if os .name == 'nt' :
0 commit comments