@@ -1364,8 +1364,6 @@ def test_unsupported_operation(self):
13641364 self .assertRaises (e , p .touch )
13651365 self .assertRaises (e , p .chmod , 0o755 )
13661366 self .assertRaises (e , p .lchmod , 0o755 )
1367- self .assertRaises (e , p .unlink )
1368- self .assertRaises (e , p .rmdir )
13691367 self .assertRaises (e , p .owner )
13701368 self .assertRaises (e , p .group )
13711369 self .assertRaises (e , p .as_uri )
@@ -1487,31 +1485,18 @@ def mkdir(self, mode=0o777, parents=False, exist_ok=False):
14871485 self .parent .mkdir (parents = True , exist_ok = True )
14881486 self .mkdir (mode , parents = False , exist_ok = exist_ok )
14891487
1490- def unlink (self , missing_ok = False ):
1491- path = str (self )
1492- name = self .name
1493- parent = str (self .parent )
1494- if path in self ._directories :
1495- raise IsADirectoryError (errno .EISDIR , "Is a directory" , path )
1496- elif path in self ._files :
1497- self ._directories [parent ].remove (name )
1498- del self ._files [path ]
1499- elif not missing_ok :
1500- raise FileNotFoundError (errno .ENOENT , "File not found" , path )
1501-
1502- def rmdir (self ):
1488+ def _delete (self ):
15031489 path = str (self )
15041490 if path in self ._files :
1505- raise NotADirectoryError (errno .ENOTDIR , "Not a directory" , path )
1506- elif path not in self ._directories :
1507- raise FileNotFoundError (errno .ENOENT , "File not found" , path )
1508- elif self ._directories [path ]:
1509- raise OSError (errno .ENOTEMPTY , "Directory not empty" , path )
1510- else :
1511- name = self .name
1512- parent = str (self .parent )
1513- self ._directories [parent ].remove (name )
1491+ del self ._files [path ]
1492+ elif path in self ._directories :
1493+ for name in list (self ._directories [path ]):
1494+ self .joinpath (name )._delete ()
15141495 del self ._directories [path ]
1496+ else :
1497+ raise FileNotFoundError (errno .ENOENT , "File not found" , path )
1498+ parent = str (self .parent )
1499+ self ._directories [parent ].remove (self .name )
15151500
15161501
15171502class DummyPathTest (DummyPurePathTest ):
@@ -2164,30 +2149,11 @@ def test_is_symlink(self):
21642149 self .assertIs ((P / 'linkA\udfff ' ).is_file (), False )
21652150 self .assertIs ((P / 'linkA\x00 ' ).is_file (), False )
21662151
2167- def test_unlink (self ):
2168- p = self .cls (self .base ) / 'fileA'
2169- p .unlink ()
2170- self .assertFileNotFound (p .stat )
2171- self .assertFileNotFound (p .unlink )
2172-
2173- def test_unlink_missing_ok (self ):
2174- p = self .cls (self .base ) / 'fileAAA'
2175- self .assertFileNotFound (p .unlink )
2176- p .unlink (missing_ok = True )
2177-
2178- def test_rmdir (self ):
2179- p = self .cls (self .base ) / 'dirA'
2180- for q in p .iterdir ():
2181- q .unlink ()
2182- p .rmdir ()
2183- self .assertFileNotFound (p .stat )
2184- self .assertFileNotFound (p .unlink )
2185-
21862152 def test_delete_file (self ):
21872153 p = self .cls (self .base ) / 'fileA'
21882154 p ._delete ()
21892155 self .assertFileNotFound (p .stat )
2190- self .assertFileNotFound (p .unlink )
2156+ self .assertFileNotFound (p ._delete )
21912157
21922158 def test_delete_dir (self ):
21932159 base = self .cls (self .base )
0 commit comments