-
Notifications
You must be signed in to change notification settings - Fork 1.3k
tests: replace spy() with pytest-mock spy #3208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
efiop
merged 4 commits into
treeverse:master
from
fabiosantoscode:feature/3198-remove-spy-method
Jan 23, 2020
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,6 @@ | |
| from unittest import SkipTest | ||
|
|
||
| import pytest | ||
| from mock import patch | ||
|
|
||
| from dvc.cache import NamedCache | ||
| from dvc.config import Config | ||
|
|
@@ -28,7 +27,6 @@ | |
| from dvc.utils.stage import dump_stage_file | ||
| from dvc.utils.stage import load_stage_file | ||
| from tests.basic_env import TestDvc | ||
| from tests.utils import spy | ||
|
|
||
| from tests.remotes import ( | ||
| Azure, | ||
|
|
@@ -585,24 +583,21 @@ def test(self): | |
| self._test_recursive_pull() | ||
|
|
||
|
|
||
| class TestCheckSumRecalculation(TestDvc): | ||
| def test(self): | ||
| test_get_file_checksum = spy(RemoteLOCAL.get_file_checksum) | ||
| with patch.object( | ||
| RemoteLOCAL, "get_file_checksum", test_get_file_checksum | ||
| ): | ||
| url = Local.get_url() | ||
| ret = main(["remote", "add", "-d", TEST_REMOTE, url]) | ||
| self.assertEqual(ret, 0) | ||
| ret = main(["config", "cache.type", "hardlink"]) | ||
| self.assertEqual(ret, 0) | ||
| ret = main(["add", self.FOO]) | ||
| self.assertEqual(ret, 0) | ||
| ret = main(["push"]) | ||
| self.assertEqual(ret, 0) | ||
| ret = main(["run", "-d", self.FOO, "echo foo"]) | ||
| self.assertEqual(ret, 0) | ||
| self.assertEqual(test_get_file_checksum.mock.call_count, 1) | ||
| def test_checksum_recalculation(mocker, dvc, tmp_dir): | ||
| tmp_dir.gen({"foo": "foo"}) | ||
| test_get_file_checksum = mocker.spy(RemoteLOCAL, "get_file_checksum") | ||
| url = Local.get_url() | ||
| ret = main(["remote", "add", "-d", TEST_REMOTE, url]) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to use
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pared I think it is out of scope for this change 🙂 |
||
| assert ret == 0 | ||
| ret = main(["config", "cache.type", "hardlink"]) | ||
| assert ret == 0 | ||
| ret = main(["add", "foo"]) | ||
| assert ret == 0 | ||
| ret = main(["push"]) | ||
| assert ret == 0 | ||
| ret = main(["run", "-d", "foo", "echo foo"]) | ||
| assert ret == 0 | ||
| assert test_get_file_checksum.mock.call_count == 1 | ||
|
|
||
|
|
||
| class TestShouldWarnOnNoChecksumInLocalAndRemoteCache(TestDvc): | ||
|
|
||
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
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be simplified to
file_md5_counter.call_count, this applies to each use case ofspyThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pared It is a direct conversion that is explicit, we could leave it as is with
== 1.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I change it to not have
.mockthen? It does seem to do the same thing.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does, I don't think its crucial, let's leave it as is.