11
11
import tempfile
12
12
import unittest
13
13
from unittest import mock
14
- import warnings
15
14
16
15
from test .support import import_helper
17
16
from test .support import set_recursion_limit
@@ -1787,44 +1786,41 @@ def test_iterdir_nodir(self):
1787
1786
errno .ENOENT , errno .EINVAL ))
1788
1787
1789
1788
def test_glob_common (self ):
1790
- def _check (path , glob , expected ):
1791
- with self .assertWarns (DeprecationWarning ):
1792
- actual = {q for q in path .glob (glob )}
1793
- self .assertEqual (actual , { P (BASE , q ) for q in expected })
1789
+ def _check (glob , expected ):
1790
+ self .assertEqual (set (glob ), { P (BASE , q ) for q in expected })
1794
1791
P = self .cls
1795
1792
p = P (BASE )
1796
- with self .assertWarns (DeprecationWarning ):
1797
- it = p .glob ("fileA" )
1798
- self .assertIsInstance (it , collections .abc .Iterator )
1799
- self .assertEqual (set (it ), { P (BASE , "fileA" ) })
1800
- _check (p , "fileB" , [])
1801
- _check (p , "dir*/file*" , ["dirB/fileB" , "dirC/fileC" ])
1793
+ it = p .glob ("fileA" )
1794
+ self .assertIsInstance (it , collections .abc .Iterator )
1795
+ _check (it , ["fileA" ])
1796
+ _check (p .glob ("fileB" ), [])
1797
+ _check (p .glob ("dir*/file*" ), ["dirB/fileB" , "dirC/fileC" ])
1802
1798
if not os_helper .can_symlink ():
1803
- _check (p , "*A" , ['dirA' , 'fileA' ])
1799
+ _check (p . glob ( "*A" ) , ['dirA' , 'fileA' ])
1804
1800
else :
1805
- _check (p , "*A" , ['dirA' , 'fileA' , 'linkA' ])
1801
+ _check (p . glob ( "*A" ) , ['dirA' , 'fileA' , 'linkA' ])
1806
1802
if not os_helper .can_symlink ():
1807
- _check (p , "*B/*" , ['dirB/fileB' ])
1803
+ _check (p . glob ( "*B/*" ) , ['dirB/fileB' ])
1808
1804
else :
1809
- _check (p , "*B/*" , ['dirB/fileB' , 'dirB/linkD' ,
1805
+ _check (p . glob ( "*B/*" ) , ['dirB/fileB' , 'dirB/linkD' ,
1810
1806
'linkB/fileB' , 'linkB/linkD' ])
1811
1807
if not os_helper .can_symlink ():
1812
- _check (p , "*/fileB" , ['dirB/fileB' ])
1808
+ _check (p . glob ( "*/fileB" ) , ['dirB/fileB' ])
1813
1809
else :
1814
- _check (p , "*/fileB" , ['dirB/fileB' , 'linkB/fileB' ])
1810
+ _check (p . glob ( "*/fileB" ) , ['dirB/fileB' , 'linkB/fileB' ])
1815
1811
if os_helper .can_symlink ():
1816
- _check (p , "brokenLink" , ['brokenLink' ])
1812
+ _check (p . glob ( "brokenLink" ) , ['brokenLink' ])
1817
1813
1818
1814
if not os_helper .can_symlink ():
1819
- _check (p , "*/" , ["dirA" , "dirB" , "dirC" , "dirE" ])
1815
+ _check (p . glob ( "*/" ) , ["dirA" , "dirB" , "dirC" , "dirE" ])
1820
1816
else :
1821
- _check (p , "*/" , ["dirA" , "dirB" , "dirC" , "dirE" , "linkB" ])
1817
+ _check (p . glob ( "*/" ) , ["dirA" , "dirB" , "dirC" , "dirE" , "linkB" ])
1822
1818
1823
1819
@os_helper .skip_unless_symlink
1824
1820
def test_glob_follow_symlinks_common (self ):
1825
1821
def _check (path , glob , expected ):
1826
- actual = {q for q in path .glob (glob , follow_symlinks = True )
1827
- if "linkD" not in q .parent .parts } # exclude symlink loop.
1822
+ actual = {path for path in path .glob (glob , follow_symlinks = True )
1823
+ if "linkD" not in path .parent .parts } # exclude symlink loop.
1828
1824
self .assertEqual (actual , { P (BASE , q ) for q in expected })
1829
1825
P = self .cls
1830
1826
p = P (BASE )
@@ -1838,7 +1834,7 @@ def _check(path, glob, expected):
1838
1834
@os_helper .skip_unless_symlink
1839
1835
def test_glob_no_follow_symlinks_common (self ):
1840
1836
def _check (path , glob , expected ):
1841
- actual = {q for q in path .glob (glob , follow_symlinks = False )}
1837
+ actual = {path for path in path .glob (glob , follow_symlinks = False )}
1842
1838
self .assertEqual (actual , { P (BASE , q ) for q in expected })
1843
1839
P = self .cls
1844
1840
p = P (BASE )
@@ -1850,46 +1846,43 @@ def _check(path, glob, expected):
1850
1846
_check (p , "*/" , ["dirA" , "dirB" , "dirC" , "dirE" ])
1851
1847
1852
1848
def test_rglob_common (self ):
1853
- def _check (path , glob , expected ):
1854
- with self .assertWarns (DeprecationWarning ):
1855
- actual = {q for q in path .rglob (glob )}
1856
- self .assertEqual (actual , { P (BASE , q ) for q in expected })
1849
+ def _check (glob , expected ):
1850
+ self .assertEqual (set (glob ), { P (BASE , q ) for q in expected })
1857
1851
P = self .cls
1858
1852
p = P (BASE )
1859
- with self .assertWarns (DeprecationWarning ):
1860
- it = p .rglob ("fileA" )
1861
- self .assertIsInstance (it , collections .abc .Iterator )
1862
- self .assertEqual (set (it ), { P (BASE , "fileA" ) })
1863
- _check (p , "fileB" , ["dirB/fileB" ])
1864
- _check (p , "*/fileA" , [])
1853
+ it = p .rglob ("fileA" )
1854
+ self .assertIsInstance (it , collections .abc .Iterator )
1855
+ _check (it , ["fileA" ])
1856
+ _check (p .rglob ("fileB" ), ["dirB/fileB" ])
1857
+ _check (p .rglob ("*/fileA" ), [])
1865
1858
if not os_helper .can_symlink ():
1866
- _check (p , "*/fileB" , ["dirB/fileB" ])
1859
+ _check (p . rglob ( "*/fileB" ) , ["dirB/fileB" ])
1867
1860
else :
1868
- _check (p , "*/fileB" , ["dirB/fileB" , "dirB/linkD/fileB" ,
1861
+ _check (p . rglob ( "*/fileB" ) , ["dirB/fileB" , "dirB/linkD/fileB" ,
1869
1862
"linkB/fileB" , "dirA/linkC/fileB" ])
1870
- _check (p , "file*" , ["fileA" , "dirB/fileB" ,
1863
+ _check (p . rglob ( "file*" ) , ["fileA" , "dirB/fileB" ,
1871
1864
"dirC/fileC" , "dirC/dirD/fileD" ])
1872
1865
if not os_helper .can_symlink ():
1873
- _check (p , "*/" , [
1866
+ _check (p . rglob ( "*/" ) , [
1874
1867
"dirA" , "dirB" , "dirC" , "dirC/dirD" , "dirE" ,
1875
1868
])
1876
1869
else :
1877
- _check (p , "*/" , [
1870
+ _check (p . rglob ( "*/" ) , [
1878
1871
"dirA" , "dirA/linkC" , "dirB" , "dirB/linkD" , "dirC" ,
1879
1872
"dirC/dirD" , "dirE" , "linkB" ,
1880
1873
])
1881
- _check (p , "" , ["" , "dirA" , "dirB" , "dirC" , "dirE" , "dirC/dirD" ])
1874
+ _check (p . rglob ( "" ) , ["" , "dirA" , "dirB" , "dirC" , "dirE" , "dirC/dirD" ])
1882
1875
1883
1876
p = P (BASE , "dirC" )
1884
- _check (p , "*" , ["dirC/fileC" , "dirC/novel.txt" ,
1877
+ _check (p . rglob ( "*" ) , ["dirC/fileC" , "dirC/novel.txt" ,
1885
1878
"dirC/dirD" , "dirC/dirD/fileD" ])
1886
- _check (p , "file*" , ["dirC/fileC" , "dirC/dirD/fileD" ])
1887
- _check (p , "*/*" , ["dirC/dirD/fileD" ])
1888
- _check (p , "*/" , ["dirC/dirD" ])
1889
- _check (p , "" , ["dirC" , "dirC/dirD" ])
1879
+ _check (p . rglob ( "file*" ) , ["dirC/fileC" , "dirC/dirD/fileD" ])
1880
+ _check (p . rglob ( "*/*" ) , ["dirC/dirD/fileD" ])
1881
+ _check (p . rglob ( "*/" ) , ["dirC/dirD" ])
1882
+ _check (p . rglob ( "" ) , ["dirC" , "dirC/dirD" ])
1890
1883
# gh-91616, a re module regression
1891
- _check (p , "*.txt" , ["dirC/novel.txt" ])
1892
- _check (p , "*.*" , ["dirC/novel.txt" ])
1884
+ _check (p . rglob ( "*.txt" ) , ["dirC/novel.txt" ])
1885
+ _check (p . rglob ( "*.*" ) , ["dirC/novel.txt" ])
1893
1886
1894
1887
@os_helper .skip_unless_symlink
1895
1888
def test_rglob_follow_symlinks_common (self ):
@@ -1950,7 +1943,7 @@ def test_rglob_symlink_loop(self):
1950
1943
# Don't get fooled by symlink loops (Issue #26012).
1951
1944
P = self .cls
1952
1945
p = P (BASE )
1953
- given = set (p .rglob ('*' , follow_symlinks = False ))
1946
+ given = set (p .rglob ('*' ))
1954
1947
expect = {'brokenLink' ,
1955
1948
'dirA' , 'dirA/linkC' ,
1956
1949
'dirB' , 'dirB/fileB' , 'dirB/linkD' ,
@@ -1971,10 +1964,10 @@ def test_glob_many_open_files(self):
1971
1964
p = P (base , * (['d' ]* depth ))
1972
1965
p .mkdir (parents = True )
1973
1966
pattern = '/' .join (['*' ] * depth )
1974
- iters = [base .glob (pattern , follow_symlinks = True ) for j in range (100 )]
1967
+ iters = [base .glob (pattern ) for j in range (100 )]
1975
1968
for it in iters :
1976
1969
self .assertEqual (next (it ), p )
1977
- iters = [base .rglob ('d' , follow_symlinks = True ) for j in range (100 )]
1970
+ iters = [base .rglob ('d' ) for j in range (100 )]
1978
1971
p = base
1979
1972
for i in range (depth ):
1980
1973
p = p / 'd'
@@ -1985,14 +1978,14 @@ def test_glob_dotdot(self):
1985
1978
# ".." is not special in globs.
1986
1979
P = self .cls
1987
1980
p = P (BASE )
1988
- self .assertEqual (set (p .glob (".." , follow_symlinks = True )), { P (BASE , ".." ) })
1989
- self .assertEqual (set (p .glob ("../.." , follow_symlinks = True )), { P (BASE , ".." , ".." ) })
1990
- self .assertEqual (set (p .glob ("dirA/.." , follow_symlinks = True )), { P (BASE , "dirA" , ".." ) })
1991
- self .assertEqual (set (p .glob ("dirA/../file*" , follow_symlinks = True )), { P (BASE , "dirA/../fileA" ) })
1992
- self .assertEqual (set (p .glob ("dirA/../file*/.." , follow_symlinks = True )), set ())
1993
- self .assertEqual (set (p .glob ("../xyzzy" , follow_symlinks = True )), set ())
1994
- self .assertEqual (set (p .glob ("xyzzy/.." , follow_symlinks = True )), set ())
1995
- self .assertEqual (set (p .glob ("/" .join ([".." ] * 50 ), follow_symlinks = True )), { P (BASE , * [".." ] * 50 )})
1981
+ self .assertEqual (set (p .glob (".." )), { P (BASE , ".." ) })
1982
+ self .assertEqual (set (p .glob ("../.." )), { P (BASE , ".." , ".." ) })
1983
+ self .assertEqual (set (p .glob ("dirA/.." )), { P (BASE , "dirA" , ".." ) })
1984
+ self .assertEqual (set (p .glob ("dirA/../file*" )), { P (BASE , "dirA/../fileA" ) })
1985
+ self .assertEqual (set (p .glob ("dirA/../file*/.." )), set ())
1986
+ self .assertEqual (set (p .glob ("../xyzzy" )), set ())
1987
+ self .assertEqual (set (p .glob ("xyzzy/.." )), set ())
1988
+ self .assertEqual (set (p .glob ("/" .join ([".." ] * 50 ))), { P (BASE , * [".." ] * 50 )})
1996
1989
1997
1990
@os_helper .skip_unless_symlink
1998
1991
def test_glob_permissions (self ):
@@ -2022,11 +2015,11 @@ def my_scandir(path):
2022
2015
return contextlib .nullcontext (entries )
2023
2016
2024
2017
with mock .patch ("os.scandir" , my_scandir ):
2025
- self .assertEqual (len (set (base .glob ("*" , follow_symlinks = True ))), 3 )
2018
+ self .assertEqual (len (set (base .glob ("*" ))), 3 )
2026
2019
subdir .mkdir ()
2027
- self .assertEqual (len (set (base .glob ("*" , follow_symlinks = True ))), 4 )
2020
+ self .assertEqual (len (set (base .glob ("*" ))), 4 )
2028
2021
subdir .chmod (000 )
2029
- self .assertEqual (len (set (base .glob ("*" , follow_symlinks = True ))), 4 )
2022
+ self .assertEqual (len (set (base .glob ("*" ))), 4 )
2030
2023
2031
2024
def _check_resolve (self , p , expected , strict = True ):
2032
2025
q = p .resolve (strict )
@@ -2970,7 +2963,7 @@ def test_unsupported_flavour(self):
2970
2963
def test_glob_empty_pattern (self ):
2971
2964
p = self .cls ()
2972
2965
with self .assertRaisesRegex (ValueError , 'Unacceptable pattern' ):
2973
- list (p .glob ('' , follow_symlinks = True ))
2966
+ list (p .glob ('' ))
2974
2967
2975
2968
2976
2969
@only_posix
@@ -3063,18 +3056,18 @@ def test_resolve_loop(self):
3063
3056
def test_glob (self ):
3064
3057
P = self .cls
3065
3058
p = P (BASE )
3066
- given = set (p .glob ("FILEa" , follow_symlinks = True ))
3059
+ given = set (p .glob ("FILEa" ))
3067
3060
expect = set () if not os_helper .fs_is_case_insensitive (BASE ) else given
3068
3061
self .assertEqual (given , expect )
3069
- self .assertEqual (set (p .glob ("FILEa*" , follow_symlinks = True )), set ())
3062
+ self .assertEqual (set (p .glob ("FILEa*" )), set ())
3070
3063
3071
3064
def test_rglob (self ):
3072
3065
P = self .cls
3073
3066
p = P (BASE , "dirC" )
3074
- given = set (p .rglob ("FILEd" , follow_symlinks = True ))
3067
+ given = set (p .rglob ("FILEd" ))
3075
3068
expect = set () if not os_helper .fs_is_case_insensitive (BASE ) else given
3076
3069
self .assertEqual (given , expect )
3077
- self .assertEqual (set (p .rglob ("FILEd*" , follow_symlinks = True )), set ())
3070
+ self .assertEqual (set (p .rglob ("FILEd*" )), set ())
3078
3071
3079
3072
@unittest .skipUnless (hasattr (pwd , 'getpwall' ),
3080
3073
'pwd module does not expose getpwall()' )
@@ -3137,7 +3130,7 @@ def test_expanduser(self):
3137
3130
"Bad file descriptor in /dev/fd affects only macOS" )
3138
3131
def test_handling_bad_descriptor (self ):
3139
3132
try :
3140
- file_descriptors = list (pathlib .Path ('/dev/fd' ).rglob ("*" , follow_symlinks = True ))[3 :]
3133
+ file_descriptors = list (pathlib .Path ('/dev/fd' ).rglob ("*" ))[3 :]
3141
3134
if not file_descriptors :
3142
3135
self .skipTest ("no file descriptors - issue was not reproduced" )
3143
3136
# Checking all file descriptors because there is no guarantee
@@ -3209,18 +3202,18 @@ def test_absolute(self):
3209
3202
def test_glob (self ):
3210
3203
P = self .cls
3211
3204
p = P (BASE )
3212
- self .assertEqual (set (p .glob ("FILEa" , follow_symlinks = True )), { P (BASE , "fileA" ) })
3213
- self .assertEqual (set (p .glob ("*a\\ " , follow_symlinks = True )), { P (BASE , "dirA" ) })
3214
- self .assertEqual (set (p .glob ("F*a" , follow_symlinks = True )), { P (BASE , "fileA" ) })
3215
- self .assertEqual (set (map (str , p .glob ("FILEa" , follow_symlinks = True ))), {f"{ p } \\ fileA" })
3216
- self .assertEqual (set (map (str , p .glob ("F*a" , follow_symlinks = True ))), {f"{ p } \\ fileA" })
3205
+ self .assertEqual (set (p .glob ("FILEa" )), { P (BASE , "fileA" ) })
3206
+ self .assertEqual (set (p .glob ("*a\\ " )), { P (BASE , "dirA" ) })
3207
+ self .assertEqual (set (p .glob ("F*a" )), { P (BASE , "fileA" ) })
3208
+ self .assertEqual (set (map (str , p .glob ("FILEa" ))), {f"{ p } \\ fileA" })
3209
+ self .assertEqual (set (map (str , p .glob ("F*a" ))), {f"{ p } \\ fileA" })
3217
3210
3218
3211
def test_rglob (self ):
3219
3212
P = self .cls
3220
3213
p = P (BASE , "dirC" )
3221
- self .assertEqual (set (p .rglob ("FILEd" , follow_symlinks = True )), { P (BASE , "dirC/dirD/fileD" ) })
3222
- self .assertEqual (set (p .rglob ("*\\ " , follow_symlinks = True )), { P (BASE , "dirC/dirD" ) })
3223
- self .assertEqual (set (map (str , p .rglob ("FILEd" , follow_symlinks = True ))), {f"{ p } \\ dirD\\ fileD" })
3214
+ self .assertEqual (set (p .rglob ("FILEd" )), { P (BASE , "dirC/dirD/fileD" ) })
3215
+ self .assertEqual (set (p .rglob ("*\\ " )), { P (BASE , "dirC/dirD" ) })
3216
+ self .assertEqual (set (map (str , p .rglob ("FILEd" ))), {f"{ p } \\ dirD\\ fileD" })
3224
3217
3225
3218
def test_expanduser (self ):
3226
3219
P = self .cls
0 commit comments