analytics: collect execution info only when available

This commit is contained in:
Mr. Outis
2019-12-07 21:14:31 -06:00
parent 2145daa130
commit c50bd17bb4
3 changed files with 33 additions and 11 deletions
+25
View File
@@ -6,6 +6,7 @@ import json
from voluptuous import Schema, Any
from dvc import analytics
from dvc.cli import parse_args
from dvc.utils.compat import str, builtin_str
@@ -23,6 +24,30 @@ def tmp_global_config(tmp_path):
yield
@mock.patch("dvc.daemon._spawn")
@mock.patch("json.dump")
def test_collect_and_send_report(mock_json, mock_daemon, tmp_global_config):
analytics.collect_and_send_report()
report = mock_json.call_args[0][0]
with pytest.raises(KeyError):
report["cmd_class"]
with pytest.raises(KeyError):
report["cmd_return_code"]
args = parse_args(['add', 'foo'])
return_code = 0
analytics.collect_and_send_report(args, return_code)
report = mock_json.call_args[0][0]
assert report["cmd_class"] == "CmdAdd"
assert report["cmd_return_code"] == return_code
assert mock_daemon.call_count == 2
def test_runtime_info(tmp_global_config):
schema = Schema(
{