-
Notifications
You must be signed in to change notification settings - Fork 2
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
test_landings: increase git landing coverage (bug 1934485) #190
Conversation
shtrom
commented
Jan 6, 2025
•
edited
Loading
edited
- upgrade landings tests to work with both Hg and Git repos
- fix a few simple bugs in the Git implementation
aea01be
to
8411436
Compare
8411436
to
15c0d4e
Compare
15c0d4e
to
18e9068
Compare
18e9068
to
2588f72
Compare
src/lando/api/tests/test_landings.py
Outdated
def _scm_get_previous_hash(scm: AbstractSCM) -> str: | ||
if scm.scm_type() == SCM_TYPE_HG: | ||
return HgSCM.run_hg(scm, ["log", "-r", "tip^", "-T", "{node}"]).decode("utf-8") | ||
return GitSCM._git_run("rev-parse", "HEAD^", cwd=scm.path) |
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.
We should have an AbstractSCM.get_previous_hash
instead of this function which checks for the specific implementation.
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.
If these are only used in tests, I would hesitate to put them directly in the main implementation, but maybe they can be added in a mixin or a test class that extends AbstractSCM
. Again, depends if they are only used in tests.
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 had the same thought as @zzzeid here. Same for the other one that gets the whole commit message.
Both are only used in tests at the moment.
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 don't think it's an issue that it's a function only used in tests, worst case we could add a comment pointing that out in the docstring. This way it seems like we are going against the purpose of the AbstractSCM
. I'm not too fussed about it either way though, happy to go with whatever you decide.
src/lando/api/tests/test_landings.py
Outdated
def _scm_get_last_commit_message(scm: AbstractSCM) -> str: | ||
if scm.scm_type() == SCM_TYPE_HG: | ||
return HgSCM.run_hg(scm, ["log", "-r", "tip", "-T", "{desc}"]).decode("utf-8") | ||
return GitSCM._git_run("log", "--pretty=%B", "HEAD^..", cwd=scm.path) |
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.
Same as above, these methods should go on the AbstractSCM
and the implementations.
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.
Same comment here as in _scm_get_previous_hash
-- i.e., maybe those should be added to a mixin or test class.
src/lando/api/tests/test_landings.py
Outdated
def _scm_get_previous_hash(scm: AbstractSCM) -> str: | ||
if scm.scm_type() == SCM_TYPE_HG: | ||
return HgSCM.run_hg(scm, ["log", "-r", "tip^", "-T", "{node}"]).decode("utf-8") | ||
return GitSCM._git_run("rev-parse", "HEAD^", cwd=scm.path) |
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.
If these are only used in tests, I would hesitate to put them directly in the main implementation, but maybe they can be added in a mixin or a test class that extends AbstractSCM
. Again, depends if they are only used in tests.
if "nothing to commit, working tree clean" in exc.out: | ||
return [] |
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.
Is there a more rigorous way of doing this check? Is there a specific error code we could be checking when raising SCMException
? Looking at your implementation of _git_run
, looks like we are raising this exception specifically based on a return code, and perhaps we shouldn't be raising this as an exception at all from the get go.
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.
The initial implementation had a conditional to allow throwing an exception or not, but I realised at the time that we always were throwing an exception, so I removed the parameter.
We could re-add it, but I can't find documentation about git commit
's error codes (at the moment it return 1
for this case), so we'd still have to inspect the error message to determine the cause of the error (FWIW, this is also how we do it for Mercurial) https://github.com/mozilla-conduit/lando/blob/main/src/lando/main/scm/hg.py#L372-L377
Co-authored-by: Connor Sheehan <[email protected]>
Co-authored-by: Connor Sheehan <[email protected]>
Updated mc_repo
factory, fixed nits.
Hum. The tests in GitHub fail https://github.com/mozilla-conduit/lando/pull/190/checks#step:6:390. They were fine on last week, and still pass locally. Something's odd with GHActions, I think. |
src/lando/api/tests/test_landings.py
Outdated
def _scm_get_previous_hash(scm: AbstractSCM) -> str: | ||
if scm.scm_type() == SCM_TYPE_HG: | ||
return HgSCM.run_hg(scm, ["log", "-r", "tip^", "-T", "{node}"]).decode("utf-8") | ||
return GitSCM._git_run("rev-parse", "HEAD^", cwd=scm.path) |
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 don't think it's an issue that it's a function only used in tests, worst case we could add a comment pointing that out in the docstring. This way it seems like we are going against the purpose of the AbstractSCM
. I'm not too fussed about it either way though, happy to go with whatever you decide.
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.
nit: in first line of commit message: test -> test_landings
.