Repository navigation
Fix SFTP path checks hiding a failed reconnect, restore the SFTP tests - #175
Merged
Merged
Conversation
mkdir, rm_rf, upload and download were tested only by skipped tests whose mocks no longer matched the code (os.path and os.walk instead of pathlib). - Rewrite them as pytest functions on the shared conftest fixtures. - Use a temporary local tree instead of mocking the local filesystem. - Cover upload into a remote directory and download of a missing path and of a directory.
Since 8.2.1 a closed client reconnects before opening SFTP, but exists, isfile, isdir and islink did that inside the try that maps OSError to False. A reconnect that failed with a socket error (connection refused, host unreachable) was therefore reported as a missing path, and a caller skipped a cleanup or an upload without any error. - Open the session before the try, so only an error from lstat becomes False. - Document the raised exceptions in the docstrings and in SSHClient.rst.
upload() copied the contents of a local directory but never created the remote directory they go into. A target that did not exist yet was created only as a side effect of mkdir -p for a subdirectory, so the upload failed when a file came first, and an empty directory produced nothing. - Create the target directory before copying what is inside the source. - Test upload into an existing remote directory and to a new path.
Collaborator
Coverage Report for CI Build 40923968677Coverage increased (+2.2%) to 88.564%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to 8.2.1: the path checks reported a failed reconnect as a missing path, and the restored SFTP tests found a defect in
upload().exists,isfile,isdirandislinkopened the SFTP session inside thetrythat mapsOSErrortoFalse.Since 8.2.1 a closed client reconnects there, so a refused or unreachable host was reported as "path does not exist" and callers silently skipped work.
The session is now opened before the
try; only an error fromlstatbecomesFalse.upload()of a directory never created the remote directory it copies into (regression from the move topathlib).A new target was created only as a side effect of
mkdir -pfor a subdirectory, so the upload failed when a file came first, and an empty directory produced nothing.mkdir,rm_rf,upload_file,upload_dir,download) are ported to pytest on the shared fixtures, with a temporary local tree instead ofos.path/os.walkmocks. No test is skipped any more.Behaviour change: a path check on a client whose reconnect fails now raises instead of returning
False; documented asversionchanged:: 8.2.2.