-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat/backup rather than hash check (#30)
* Back up existing required files rather than checking the hash in conversion script Signed-off-by: Andrea Waltlova <[email protected]> * Back up existing required files rather than checking the hash in pre-conversion script Signed-off-by: Andrea Waltlova <[email protected]> * Satisfy pre-commit Signed-off-by: Andrea Waltlova <[email protected]> * Let backup restore function throw IOError, it will be catched in main Signed-off-by: Andrea Waltlova <[email protected]> * Add attribute allowing us to keep required files when conversion successfull Signed-off-by: Andrea Waltlova <[email protected]> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Signed-off-by: Andrea Waltlova <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
8b96685
commit a969ea1
Showing
13 changed files
with
266 additions
and
294 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import pytest | ||
from mock import patch | ||
|
||
from scripts.conversion_script import ( | ||
RequiredFile, | ||
_create_or_restore_backup_file, | ||
) | ||
|
||
|
||
@patch("scripts.conversion_script.os") | ||
def test_backup_existing_file(mock_os): | ||
filepath = "/path/to/file" | ||
required_file = RequiredFile(path=filepath) | ||
mock_os.path.exists.side_effect = [False, True] | ||
|
||
_create_or_restore_backup_file(required_file) | ||
|
||
mock_os.path.exists.assert_called_with(filepath) | ||
mock_os.rename.assert_called_once_with(filepath, filepath + ".backup") | ||
|
||
|
||
@patch("scripts.conversion_script.os") | ||
def test_restore_existing_file(mock_os): | ||
filepath = "/path/to/file" | ||
required_file = RequiredFile(path=filepath) | ||
mock_os.path.exists.side_effect = [True] | ||
|
||
_create_or_restore_backup_file(required_file) | ||
|
||
mock_os.path.exists.assert_called_with(filepath + ".backup") | ||
mock_os.rename.assert_called_once_with(filepath + ".backup", filepath) | ||
|
||
|
||
@patch("scripts.conversion_script.os") | ||
def test_ioerror_restore_or_backup(mock_os): | ||
filepath = "/path/to/file" | ||
required_file = RequiredFile(path=filepath) | ||
mock_os.path.exists.side_effect = IOError | ||
|
||
with pytest.raises(IOError): | ||
_create_or_restore_backup_file(required_file) |
This file contains 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
Oops, something went wrong.