@@ -1876,13 +1876,23 @@ def test_iterdir_status(self):
18761876        for  child  in  p .iterdir ():
18771877            entry  =  child .status 
18781878            self .assertIsInstance (entry , Status )
1879+             self .assertTrue (entry .exists (follow_symlinks = False ))
18791880            self .assertEqual (entry .is_dir (follow_symlinks = False ),
18801881                             child .is_dir (follow_symlinks = False ))
18811882            self .assertEqual (entry .is_file (follow_symlinks = False ),
18821883                             child .is_file (follow_symlinks = False ))
18831884            self .assertEqual (entry .is_symlink (),
18841885                             child .is_symlink ())
1885-             if  child .name  !=  'brokenLinkLoop' :
1886+             if  child .name  ==  'brokenLink' :
1887+                 self .assertFalse (entry .exists ())
1888+                 self .assertFalse (entry .is_dir ())
1889+                 self .assertFalse (entry .is_file ())
1890+             elif  child .name  ==  'brokenLinkLoop' :
1891+                 self .assertRaises (OSError , entry .exists )
1892+                 self .assertRaises (OSError , entry .is_dir )
1893+                 self .assertRaises (OSError , entry .is_file )
1894+             else :
1895+                 self .assertTrue (entry .exists ())
18861896                self .assertEqual (entry .is_dir (), child .is_dir ())
18871897                self .assertEqual (entry .is_file (), child .is_file ())
18881898
@@ -2010,6 +2020,27 @@ def test_rglob_windows(self):
20102020        self .assertEqual (set (p .rglob ("FILEd" )), { P (self .base , "dirC/dirD/fileD" ) })
20112021        self .assertEqual (set (p .rglob ("*\\ " )), { P (self .base , "dirC/dirD/" ) })
20122022
2023+     def  test_exists (self ):
2024+         p  =  self .cls (self .base )
2025+         self .assertTrue (p .status .exists ())
2026+         self .assertTrue ((p  /  'dirA' ).status .exists ())
2027+         self .assertTrue ((p  /  'dirA' ).status .exists (follow_symlinks = False ))
2028+         self .assertTrue ((p  /  'fileA' ).status .exists ())
2029+         self .assertTrue ((p  /  'fileA' ).status .exists (follow_symlinks = False ))
2030+         self .assertFalse ((p  /  'non-existing' ).status .exists ())
2031+         self .assertFalse ((p  /  'non-existing' ).status .exists (follow_symlinks = False ))
2032+         if  self .can_symlink :
2033+             self .assertTrue ((p  /  'linkA' ).status .exists ())
2034+             self .assertTrue ((p  /  'linkA' ).status .exists (follow_symlinks = False ))
2035+             self .assertTrue ((p  /  'linkB' ).status .exists ())
2036+             self .assertTrue ((p  /  'linkB' ).status .exists (follow_symlinks = True ))
2037+             self .assertFalse ((p  /  'brokenLink' ).status .exists ())
2038+             self .assertTrue ((p  /  'brokenLink' ).status .exists (follow_symlinks = False ))
2039+         self .assertFalse ((p  /  'fileA\udfff ' ).status .exists ())
2040+         self .assertFalse ((p  /  'fileA\udfff ' ).status .exists (follow_symlinks = False ))
2041+         self .assertFalse ((p  /  'fileA\x00 ' ).status .exists ())
2042+         self .assertFalse ((p  /  'fileA\x00 ' ).status .exists (follow_symlinks = False ))
2043+ 
20132044    def  test_status_is_dir (self ):
20142045        p  =  self .cls (self .base )
20152046        self .assertTrue ((p  /  'dirA' ).status .is_dir ())
0 commit comments