mirror of
https://github.com/theupdateframework/python-tuf
synced 2026-05-24 10:08:28 +00:00
Use alternative way of testing for non-EEXIST exceptions
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
This commit is contained in:
parent
0f4d7a76fc
commit
52aeeec8db
1 changed files with 11 additions and 9 deletions
|
|
@ -84,6 +84,7 @@ def tearDownClass(cls):
|
|||
# metadata, targets, and key files generated for the test cases.
|
||||
tuf.roledb.clear_roledb(clear_all=True)
|
||||
tuf.keydb.clear_keydb(clear_all=True)
|
||||
|
||||
shutil.rmtree(cls.temporary_directory)
|
||||
|
||||
|
||||
|
|
@ -853,19 +854,20 @@ def test_create_tuf_client_directory(self):
|
|||
# Test invalid client metadata directory (i.e., non-errno.EEXIST exceptions
|
||||
# should be re-raised.)
|
||||
shutil.rmtree(metadata_directory)
|
||||
current_client_directory_mode = os.stat(client_directory)[stat.ST_MODE]
|
||||
|
||||
# Remove write access for the client directory so that the 'metadata'
|
||||
# directory cannot be created. create_tuf_client_directory() should
|
||||
# re-raise the 'OSError' (i.e., errno.EACCES) exception and only handle
|
||||
# errno.EEXIST.
|
||||
os.chmod(client_directory, current_client_directory_mode & ~stat.S_IWUSR)
|
||||
# Save the original metadata directory name so that it can be restored
|
||||
# after testing.
|
||||
metadata_directory_name = repo_lib.METADATA_DIRECTORY_NAME
|
||||
repo_lib.METADATA_DIRECTORY_NAME = '/'
|
||||
|
||||
# Creation of the '/' directory is forbidden on all supported OSs. The '/'
|
||||
# argument to create_tuf_client_directory should cause it to re-raise a
|
||||
# non-errno.EEXIST exception.
|
||||
self.assertRaises(OSError, repo_lib.create_tuf_client_directory,
|
||||
repository_directory, client_directory)
|
||||
repository_directory, '/')
|
||||
|
||||
# Reset the client directory's mode.
|
||||
os.chmod(client_directory, current_client_directory_mode)
|
||||
# Restore the metadata directory name in repo_lib.
|
||||
repo_lib.METADATA_DIRECTORY_NAME = metadata_directory_name
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue