-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
analytics: refactor into a module #2826
Conversation
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.
Removing a class, but splitting it into several files kind of defeat the purpose of trying to make it more readable.
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.
Maybe I was too harsh on files, but I think we shouldn't separate them too much. I've read the old code now and see how is it confusing, you can't even understand the structure of the report at a glance.
Agree, @Suor 🙂 |
Tests were sort of exhaustive |
@MrOutis Tests are still failing, please take a look. |
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.
Looks pretty good! I'm still worried about breaking the backend analytics logic by this, so please see some requests for tests up above. Really don't fancy working on analytics backend these days, so we need to do our best to make sure that the reports are exactly the same as they were before and they won't break anything.
excellent observations, @efiop, thanks again for the review 👍 mind checking if my changes address your comments?
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!
Fixture to prevent modifying the actual global config | ||
""" | ||
with mock.patch( | ||
"dvc.config.Config.get_global_config_dir", return_value=str(tmp_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.
Why not fspath()
?
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.
removed the patch for fspath
and now it doesn't work with pathlib.Path in 3.5: #2903
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 for me, patch is only needed for Python 3.5 builtin pathlib
, but pytests tmp_path
uses pathlib2
.
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.
@Suor we've been using str
in all other places, so it is no biggie. We need to revisit that more carefully later and fix everywhere.
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.
@Suor , didn't new that pytest uses pathlib2
!
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.
my bad, then, @Suor , I just assumed it was using builtin pathlib
def test_send(mock_post, tmp_path): | ||
url = "https://analytics.dvc.org" | ||
report = {"name": "dummy report"} | ||
fname = str(tmp_path / "report") |
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.
Use fspath()
.
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 as this one #2826 (comment)
😞
with open(fname, "w") as fobj: | ||
json.dump(report, fobj) |
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.
(tmp_path / "report").write_text(json.dumps(report))
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.
@Suor , would need to use fspath
on analytics.send
:
@mock.patch("requests.post")
def test_send(mock_post, tmp_path):
url = "https://analytics.dvc.org"
report = {"name": "dummy report"}
file = (tmp_path / "report")
data = convert_to_unicode(json.dumps(report))
file.write_text(data)
analytics.send(fspath(file))
assert mock_post.called
assert mock_post.call_args.args[0] == url
I'd prefer to leave it like this for now, since we lack support for python 3.5 🙁
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.
Only we don't, what exactly doesn't work in Python 3.5 for you?
Follow up from discussion on #2819
TODO: