(
tmp_dir, dvc, scm, exp_stage, mocker, monkeypatch, tmp, offline, dvc_exp_git_remote
)
| 19 | @pytest.mark.parametrize("offline", [True, False]) |
| 20 | @pytest.mark.parametrize("dvc_exp_git_remote", [None, "DVC_EXP_GIT_REMOTE"]) |
| 21 | def test_post_to_studio( |
| 22 | tmp_dir, dvc, scm, exp_stage, mocker, monkeypatch, tmp, offline, dvc_exp_git_remote |
| 23 | ): |
| 24 | valid_response = mocker.MagicMock() |
| 25 | valid_response.status_code = 200 |
| 26 | live_metrics = mocker.spy(post_live_metrics, "post_live_metrics") |
| 27 | mocked_post = mocker.patch("requests.post", return_value=valid_response) |
| 28 | |
| 29 | monkeypatch.setenv(DVC_STUDIO_REPO_URL, "STUDIO_REPO_URL") |
| 30 | monkeypatch.setenv(DVC_STUDIO_TOKEN, "STUDIO_TOKEN") |
| 31 | monkeypatch.setenv(DVC_STUDIO_URL, "https://0.0.0.0") |
| 32 | monkeypatch.setenv(DVC_STUDIO_OFFLINE, str(offline)) |
| 33 | if dvc_exp_git_remote: |
| 34 | monkeypatch.setenv(DVC_EXP_GIT_REMOTE, dvc_exp_git_remote) |
| 35 | |
| 36 | baseline_sha = scm.get_rev() |
| 37 | exp_rev = first( |
| 38 | dvc.experiments.run(exp_stage.addressing, params=["foo=1"], tmp_dir=tmp) |
| 39 | ) |
| 40 | name = dvc.experiments.get_exact_name([exp_rev])[exp_rev] |
| 41 | |
| 42 | assert live_metrics.call_count == 2 |
| 43 | start_call, done_call = live_metrics.call_args_list |
| 44 | |
| 45 | if offline: |
| 46 | assert mocked_post.call_count == 0 |
| 47 | |
| 48 | else: |
| 49 | start_call, done_call = live_metrics.call_args_list |
| 50 | assert start_call.kwargs["dvc_studio_config"]["token"] == "STUDIO_TOKEN" |
| 51 | assert start_call.kwargs["dvc_studio_config"]["repo_url"] == "STUDIO_REPO_URL" |
| 52 | |
| 53 | assert mocked_post.call_count == 2 |
| 54 | |
| 55 | start_call, done_call = mocked_post.call_args_list |
| 56 | |
| 57 | assert start_call.kwargs["json"] == { |
| 58 | "type": "start", |
| 59 | "repo_url": dvc_exp_git_remote or "STUDIO_REPO_URL", |
| 60 | "baseline_sha": baseline_sha, |
| 61 | "name": name, |
| 62 | "params": {"params.yaml": {"foo": 1}}, |
| 63 | "client": "dvc", |
| 64 | } |
| 65 | |
| 66 | assert done_call.kwargs["json"] == { |
| 67 | "type": "done", |
| 68 | "repo_url": dvc_exp_git_remote or "STUDIO_REPO_URL", |
| 69 | "baseline_sha": baseline_sha, |
| 70 | "name": name, |
| 71 | "client": "dvc", |
| 72 | "experiment_rev": exp_rev, |
| 73 | "metrics": {"metrics.yaml": {"data": {"foo": 1}}}, |
| 74 | } |
| 75 | |
| 76 | |
| 77 | @pytest.mark.studio |
nothing calls this directly
no test coverage detected