-
Notifications
You must be signed in to change notification settings - Fork 15
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
[fact] Refactor git module #983
Conversation
- Remove underscore from all methods in git if existed - Push -> PushSpec
@slarse I am unsure why the tests are failing. I tried to debug |
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.
I think I found the problem, you ran into one of the gnarlier pitfalls of mocking in Python. Try my fixes and see if it works.
tests/unit_tests/repobee/test_git.py
Outdated
@@ -200,13 +200,13 @@ async def raise_(pt): | |||
"Push failed", 128, b"some error", pt.repo_url | |||
) | |||
|
|||
mocker.patch("_repobee.git._push_async", side_effect=raise_) | |||
mocker.patch("_repobee.git.push_async", side_effect=raise_) |
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.
Mocks work by monkeypatching the reference to the object. This is the wrong reference to mock, you need to mock the reference that's used in the module you're testing. It took me a long time to debug the first time I ran into this :)
mocker.patch("_repobee.git.push_async", side_effect=raise_) | |
mocker.patch("_repobee.git._push.push_async", side_effect=raise_) |
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.
This is the wrong reference to mock, you need to mock the reference that's used in the module you're testing.
I looked up what is monkey patching and I think I get the gist and use of it. But I don't think I get why this was the wrong reference and we need to provide an exact reference to the method used. Could you please explain "the reference that's used in the module you're testing" again?
tests/unit_tests/repobee/test_git.py
Outdated
|
||
successful_pts, failed_pts = git.push(push_tuples, tries=tries) | ||
|
||
assert not successful_pts | ||
assert failed_pts == push_tuples | ||
git._push_async.assert_has_calls(expected_calls, any_order=True) | ||
git.push_async.assert_has_calls(expected_calls, any_order=True) |
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.
git.push_async.assert_has_calls(expected_calls, any_order=True) | |
git._push.push_async.assert_has_calls(expected_calls, any_order=True) |
tests/unit_tests/repobee/test_git.py
Outdated
@@ -230,7 +230,7 @@ async def raise_(pt): | |||
) | |||
|
|||
async_push_mock = mocker.patch( | |||
"_repobee.git._push_async", side_effect=raise_once | |||
"_repobee.git.push_async", side_effect=raise_once |
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.
"_repobee.git.push_async", side_effect=raise_once | |
"_repobee.git._push.push_async", side_effect=raise_once |
tests/unit_tests/repobee/test_git.py
Outdated
@@ -307,7 +307,7 @@ async def raise_(spec, *args, **kwargs): | |||
) | |||
|
|||
clone_mock = mocker.patch( | |||
"_repobee.git._clone_async", autospec=True, side_effect=raise_ | |||
"_repobee.git.clone_async", autospec=True, side_effect=raise_ |
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.
"_repobee.git.clone_async", autospec=True, side_effect=raise_ | |
"_repobee.git._fetch.clone_async", autospec=True, side_effect=raise_ |
src/_repobee/git/__init__.py
Outdated
CloneSpec, | ||
CloneStatus, | ||
clone, | ||
clone_async, |
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.
This should not be exposed in the API of this package, as it was private in the module.
clone_async, |
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.
I exposed it because it was directly used in the tests. I can make it private.
src/_repobee/git/__init__.py
Outdated
.. moduleauthor:: Simon Larsén | ||
""" | ||
|
||
from _repobee.git._push import PushSpec, push, push_async # NOQA |
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.
This should not be exposed in the API of this package, as it was private in the module.
from _repobee.git._push import PushSpec, push, push_async # NOQA | |
from _repobee.git._push import PushSpec, push # NOQA |
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.
Nice!
Now I'd just suggest removing the moduleauthor
directive from the module docstrings. It's super inconvenient trying to keep those up-to-date with multiple contributors.
src/_repobee/git/_fetch.py
Outdated
|
||
.. moduleauthor:: Simon Larsén |
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.
.. moduleauthor:: Simon Larsén |
src/_repobee/git/_local.py
Outdated
|
||
.. moduleauthor:: Simon Larsén |
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.
.. moduleauthor:: Simon Larsén |
src/_repobee/git/_push.py
Outdated
|
||
.. moduleauthor:: Simon Larsén |
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.
.. moduleauthor:: Simon Larsén |
src/_repobee/git/_util.py
Outdated
|
||
.. moduleauthor:: Simon Larsén |
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.
.. moduleauthor:: Simon Larsén |
@slarse I think we can keep the directive for now since the author has not changed. I would count myself as an author if I had made a fix or added a feature. If there were any authors before, then it makes sense to remove them. |
@algomaster99 I'm iteratively removing the |
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.
Thanks @algomaster99 , very nice refactoring!
Okay. I removed the directive from all files suggested above and also git.init.
#980 was also a pure refactoring so I didn't count myself as an author. :) |
I accidentally edited your comment instead of posting a reply... Anyway, the way I see it, if you edit a file you're an author of that file. I think few devs disagree with that. |
Fixes #982
The changes refactor the
git
module. While restructuring it, I also made the following changesPush
toPushSpec
to avoid confusion betweenpush
andPush
.__init__.py
.CONCURRENT_TASKS
and_EMPTY_REPO_ERROR
inside the only function they were used.