analytics: define private methods

This commit is contained in:
Mr. Outis
2019-12-06 16:26:10 -06:00
parent 5a8033415d
commit 2145daa130
3 changed files with 22 additions and 22 deletions
+17 -17
View File
@@ -35,7 +35,7 @@ def collect_and_send_report(args=None, return_code=None):
report as a JSON, where the _collector_ generates it and the _sender_
removes it after sending it.
"""
report = runtime_info()
report = _runtime_info()
# Include command execution information on the report
report.update(
@@ -50,19 +50,6 @@ def collect_and_send_report(args=None, return_code=None):
daemon(["analytics", fobj.name])
def runtime_info():
"""
Gather information from the environment where DVC runs to fill a report.
"""
return {
"dvc_version": __version__,
"is_binary": is_binary(),
"scm_class": scm_in_use(),
"system_info": system_info(),
"user_id": find_or_create_user_id(),
}
def is_enabled():
if env2bool("DVC_TEST"):
return False
@@ -95,7 +82,7 @@ def send(report):
os.remove(report)
def scm_in_use():
def _scm_in_use():
try:
scm = SCM(root_dir=Repo.find_root())
return type(scm).__name__
@@ -103,7 +90,20 @@ def scm_in_use():
pass
def system_info():
def _runtime_info():
"""
Gather information from the environment where DVC runs to fill a report.
"""
return {
"dvc_version": __version__,
"is_binary": is_binary(),
"scm_class": _scm_in_use(),
"system_info": _system_info(),
"user_id": _find_or_create_user_id(),
}
def _system_info():
system = platform.system()
if system == "Windows":
@@ -131,7 +131,7 @@ def system_info():
return {"os": system.lower()}
def find_or_create_user_id():
def _find_or_create_user_id():
"""
The user's ID is stored on a file under the global config directory.
+1 -1
View File
@@ -14,7 +14,7 @@ def test_daemon_analytics(mock_send, tmp_path):
@mock.patch("dvc.daemon._spawn")
@mock.patch("dvc.analytics.is_enabled", return_value=True)
@mock.patch("dvc.analytics.runtime_info", return_value={})
@mock.patch("dvc.analytics._runtime_info", return_value={})
def test_main_analytics(mock_is_enabled, mock_daemon, mock_report, dvc_repo):
assert 0 == main(["add", "foo"])
assert mock_is_enabled.called
+4 -4
View File
@@ -34,7 +34,7 @@ def test_runtime_info(tmp_global_config):
}
)
assert schema(analytics.runtime_info())
assert schema(analytics._runtime_info())
@mock.patch("requests.post")
@@ -99,11 +99,11 @@ def test_system_info():
}
)
assert schema(analytics.system_info())
assert schema(analytics._system_info())
def test_find_or_create_user_id(tmp_global_config):
created = analytics.find_or_create_user_id()
found = analytics.find_or_create_user_id()
created = analytics._find_or_create_user_id()
found = analytics._find_or_create_user_id()
assert created == found