MCPcopy
hub / github.com/treeverse/dvc / test_analytics

Function test_analytics

tests/func/test_daemon.py:89–130  ·  view source on GitHub ↗
(tmp_path, server)

Source from the content-addressed store, hash-verified

87
88
89def test_analytics(tmp_path, server):
90 addr = server.server_address
91 logfile = tmp_path / "logfile"
92
93 env = {
94 **os.environ,
95 DVC_DAEMON_LOGFILE: str(logfile),
96 DVC_ANALYTICS_ENDPOINT: "http://{}:{}".format(*addr),
97 }
98 env.pop("DVC_TEST", None)
99 env.pop("DVC_NO_ANALYTICS", None)
100 # The `iterative-telemetry` package calls `gh api` to generate a CI id.
101 # This might hang especially on Windows,
102 # possibly due to system load from the running tests.
103 # Removing the GITHUB_ACTIONS env var avoids calling `gh api`.
104 env.pop("GITHUB_ACTIONS", None)
105
106 output = subprocess.check_output(
107 [*_get_dvc_args(), "config", "-l", "-vv"],
108 env=env,
109 text=True,
110 )
111
112 match = re.search(r".*Saving analytics report to (.*)", output, flags=re.MULTILINE)
113 assert match, "no match for the report file"
114 report_file = match.group(1).strip()
115
116 match = re.search(
117 r".*Spawned .*analytics.* with pid (.*)", output, flags=re.MULTILINE
118 )
119 assert match, "no match for the pid"
120 pid = int(match.group(1).strip())
121
122 with suppress(psutil.NoSuchProcess):
123 psutil.Process(pid).wait(timeout=10)
124
125 log_contents = logfile.read_text(encoding="utf8")
126 expected_line = (f"Process {pid} " if os.name != "nt" else "") + "exiting with 0"
127 assert expected_line in log_contents
128
129 assert not os.path.exists(report_file)
130 assert server.RequestHandlerClass.hits == {"POST": 1}
131
132
133def test_updater(tmp_dir, dvc, server):

Callers

nothing calls this directly

Calls 5

_get_dvc_argsFunction · 0.90
waitMethod · 0.80
formatMethod · 0.45
read_textMethod · 0.45
existsMethod · 0.45

Tested by

no test coverage detected