Skip to content

Commit

Permalink
Fix failing test and revisit is_readonly flag
Browse files Browse the repository at this point in the history
  • Loading branch information
atugushev committed Sep 5, 2019
1 parent 85a5ae1 commit b5c1c76
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/pip/_internal/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def rmtree_errorhandler(func, path, exc_info):
remove them, an exception is thrown. We catch that here, remove the
read-only attribute, and hopefully continue without problems."""
try:
is_readonly = os.stat(path).st_mode & stat.S_IREAD
is_readonly = not (os.stat(path).st_mode & stat.S_IWRITE)
except (IOError, OSError):
# The path already removed, nothing to do
return
Expand Down
18 changes: 7 additions & 11 deletions tests/unit/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,19 +421,15 @@ def test_rmtree_errorhandler_reraises_error(tmpdir):
"""
# Create directory without read permission
path = str((tmpdir / 'subdir').mkdir())
os.chmod(path, ~stat.S_IREAD)
os.chmod(path, stat.S_IWRITE)

mock_func = Mock()
try:
# Make sure the handler reraises an exception.
# Note that the raise statement without expression and
# active exception in the current scope throws
# the RuntimeError on Python3 and the TypeError on Python2.
with pytest.raises((RuntimeError, TypeError)):
rmtree_errorhandler(mock_func, path, None)
finally:
# Restore the read permission to let the pytest to clean up temp dirs
os.chmod(path, stat.S_IREAD)
# Make sure the handler reraises an exception.
# Note that the raise statement without expression and
# active exception in the current scope throws
# the RuntimeError on Python3 and the TypeError on Python2.
with pytest.raises((RuntimeError, TypeError)):
rmtree_errorhandler(mock_func, path, None)

mock_func.assert_not_called()

Expand Down

0 comments on commit b5c1c76

Please sign in to comment.