-
Notifications
You must be signed in to change notification settings - Fork 1.3k
diff: fix missing key bug (#6720) #7406
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
Conversation
daavoo
left a comment
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.
Not sure if we need a test for this. Couldn't find any relevant ones specific to the CmdDiff logic.
Could be something like:
https://github.com/iterative/dvc/blob/main/tests/unit/command/test_diff.py#L163
|
Thanks @daavoo! Added a test. |
tests/unit/command/test_diff.py
Outdated
| def test_no_changes_hide_missing(mocker, capsys): | ||
| args = parse_args(["diff", "--json", "--hide-missing"]) | ||
| cmd = args.func(args) | ||
| mocker.patch("dvc.repo.Repo.diff", return_value={}) |
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.
Please use pytest.mark.parametrize in test_no_changes.
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.
You can change the above test test_no_changes to something like following:
@pytest.mark.parametrize("opts", ([], ["a_rev", "b_rev"], ["--hide-missing"]))
def test_no_changes(mocker, capsys, opts):
args = parse_args(["diff", "--json", *opts])
cmd = args.func(args)
mocker.patch("dvc.repo.Repo.diff", return_value={})
assert 0 == cmd.run()
out, _ = capsys.readouterr()
assert "{}" in out
args = parse_args(["diff", *opts])
cmd = args.func(args)
assert 0 == cmd.run()
out, _ = capsys.readouterr()
assert not outThere 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.
Sorry, just got a little lazy/sloppy here trying to fix this as quickly as possible.
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.
@skshetry Updated the tests with parametrized options and output formats.
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.
@skshetry Pinging on this. Could you review the updated tests when you have a chance? π
|
I'd prefer fixing this in >>> repo.diff()
{
'added': [],
'deleted': [],
'modified': [],
'renamed': [],
'not in cache': []
} |
|
@skshetry Up to you. I went with the quickest fix since it seemed like a small enough issue to resolve quickly in |
β I have followed the Contributing to DVC checklist.
[N/A] π If this PR requires documentation updates, I have created a separate PR (or issue, at least) in dvc.org and linked it here.
dvc difffails when there is no diff andhide_missingis true (hide_missingis implied when comparing two revisions) becauseCmdDiff.runtries to delete thenot in cacheinfo from an empty dict. It seemed easy enough to fix.Not sure if we need a test for this. Couldn't find any relevant ones specific to the
CmdDifflogic.