I am trying to test some code, and to test it I need to get an exception in a specific location:
def makeThisFunctionReturnTrue(filename):
if os.path.exists(input) and os.path.isfile(filename):
try:
open(filename, "r")
except IOError, err:
return True
return False
I need to figure out what input filename would cause the above function to return True. I think that the solution lies with either changing permissions or attributes in the file. I am able to force the error manually by going into the properties of a file through windows explorer and then going to security and then denying permissions. However, I need to be able to create the file dynamically in Python and then change the permissions through Python to force the error.
My first thought was to use os.chmod(); however, this function appears to be limited in a Windows environment.
A co-worker of mine suggested that I use win32file.SetFileAttributes(), but I cannot find any good documentation on this function.
Thanks for the help.
Caleb Rouleau
自己提出异常
raise IOError('SUITABLE INFO HERE')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.