@@ -2993,6 +2993,103 @@ def test_unlink(self):
2993
2993
os .chmod (wdir_file5 , 0o600 )
2994
2994
2995
2995
2996
+ class unlink_files_TestCase (TestCmdTestCase ):
2997
+ def test_unlink_files (self ):
2998
+ """Test unlink_files()"""
2999
+ test = TestCmd .TestCmd (workdir = '' , subdir = 'foo' )
3000
+ wdir_file1 = os .path .join (test .workdir , 'file1' )
3001
+ wdir_file2 = os .path .join (test .workdir , 'file2' )
3002
+ wdir_foo_file3a = os .path .join (test .workdir , 'foo' , 'file3a' )
3003
+ wdir_foo_file3b = os .path .join (test .workdir , 'foo' , 'file3b' )
3004
+ wdir_foo_file3c = os .path .join (test .workdir , 'foo' , 'file3c' )
3005
+ wdir_foo_file3d = os .path .join (test .workdir , 'foo' , 'file3d' )
3006
+ wdir_foo_file4a = os .path .join (test .workdir , 'foo' , 'file4a' )
3007
+ wdir_foo_file4b = os .path .join (test .workdir , 'foo' , 'file4b' )
3008
+ wdir_foo_file4c = os .path .join (test .workdir , 'foo' , 'file4c' )
3009
+ wdir_foo_file4d = os .path .join (test .workdir , 'foo' , 'file4d' )
3010
+ wdir_file5 = os .path .join (test .workdir , 'file5' )
3011
+
3012
+ with open (wdir_file1 , 'w' ) as f :
3013
+ f .write ("" )
3014
+ with open (wdir_file2 , 'w' ) as f :
3015
+ f .write ("" )
3016
+ with open (wdir_foo_file3a , 'w' ) as f :
3017
+ f .write ("" )
3018
+ with open (wdir_foo_file3b , 'w' ) as f :
3019
+ f .write ("" )
3020
+ with open (wdir_foo_file3c , 'w' ) as f :
3021
+ f .write ("" )
3022
+ with open (wdir_foo_file3d , 'w' ) as f :
3023
+ f .write ("" )
3024
+ with open (wdir_foo_file4a , 'w' ) as f :
3025
+ f .write ("" )
3026
+ with open (wdir_foo_file4b , 'w' ) as f :
3027
+ f .write ("" )
3028
+ with open (wdir_foo_file4c , 'w' ) as f :
3029
+ f .write ("" )
3030
+ with open (wdir_foo_file4d , 'w' ) as f :
3031
+ f .write ("" )
3032
+ with open (wdir_file5 , 'w' ) as f :
3033
+ f .write ("" )
3034
+
3035
+ test .unlink_files ('' , [
3036
+ 'no_file_a' ,
3037
+ 'no_file_b' ,
3038
+ ])
3039
+
3040
+ test .unlink_files ('' , [
3041
+ 'file1' ,
3042
+ 'file2' ,
3043
+ ])
3044
+ assert not os .path .exists (wdir_file1 )
3045
+ assert not os .path .exists (wdir_file2 )
3046
+
3047
+ test .unlink_files ('foo' , [
3048
+ 'file3a' ,
3049
+ 'file3b' ,
3050
+ ])
3051
+ assert not os .path .exists (wdir_foo_file3a )
3052
+ assert not os .path .exists (wdir_foo_file3b )
3053
+
3054
+ test .unlink_files (['foo' ], [
3055
+ 'file3c' ,
3056
+ 'file3d' ,
3057
+ ])
3058
+ assert not os .path .exists (wdir_foo_file3c )
3059
+ assert not os .path .exists (wdir_foo_file3d )
3060
+
3061
+ test .unlink_files ('' , [
3062
+ ['foo' , 'file4a' ],
3063
+ ['foo' , 'file4b' ],
3064
+ ])
3065
+ assert not os .path .exists (wdir_foo_file4a )
3066
+ assert not os .path .exists (wdir_foo_file4b )
3067
+
3068
+ test .unlink_files (['' ], [
3069
+ ['foo' , 'file4c' ],
3070
+ ['foo' , 'file4d' ],
3071
+ ])
3072
+ assert not os .path .exists (wdir_foo_file4c )
3073
+ assert not os .path .exists (wdir_foo_file4d )
3074
+
3075
+ # Make it so we can't unlink file5.
3076
+ # For UNIX, remove write permission from the dir and the file.
3077
+ # For Windows, open the file.
3078
+ os .chmod (test .workdir , 0o500 )
3079
+ os .chmod (wdir_file5 , 0o400 )
3080
+ with open (wdir_file5 , 'r' ):
3081
+ try :
3082
+ try :
3083
+ test .unlink_files ('' , ['file5' ])
3084
+ except OSError : # expect "Permission denied"
3085
+ pass
3086
+ except :
3087
+ raise
3088
+ finally :
3089
+ os .chmod (test .workdir , 0o700 )
3090
+ os .chmod (wdir_file5 , 0o600 )
3091
+
3092
+
2996
3093
class touch_TestCase (TestCmdTestCase ):
2997
3094
def test_touch (self ) -> None :
2998
3095
"""Test touch()"""
0 commit comments