forked from mlflow/mlflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_runs.py
59 lines (50 loc) · 1.73 KB
/
test_runs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import os
import textwrap
from unittest import mock
import pytest
from click.testing import CliRunner
import mlflow
from mlflow import experiments
from mlflow.runs import list_run
def test_list_run():
with mlflow.start_run(run_name="apple"):
pass
result = CliRunner().invoke(list_run, ["--experiment-id", "0"])
assert "apple" in result.output
def test_list_run_experiment_id_required():
result = CliRunner().invoke(list_run, [])
assert "Missing option '--experiment-id'" in result.output
@pytest.mark.skipif(
"MLFLOW_SKINNY" in os.environ,
reason="Skinny Client does not support predict due to the pandas dependency",
)
def test_csv_generation(tmp_path):
import numpy as np
import pandas as pd
with mock.patch(
"mlflow.experiments.fluent.search_runs",
return_value=pd.DataFrame(
{
"run_id": np.array(["all_set", "with_none", "with_nan"]),
"experiment_id": np.array([1, 1, 1]),
"param_optimizer": np.array(["Adam", None, "Adam"]),
"avg_loss": np.array([42.0, None, np.nan], dtype=np.float32),
},
columns=["run_id", "experiment_id", "param_optimizer", "avg_loss"],
),
):
expected_csv = textwrap.dedent(
"""\
run_id,experiment_id,param_optimizer,avg_loss
all_set,1,Adam,42.0
with_none,1,,
with_nan,1,Adam,
"""
)
result_filename = os.path.join(tmp_path, "result.csv")
CliRunner().invoke(
experiments.generate_csv_with_runs,
["--experiment-id", "1", "--filename", result_filename],
)
with open(result_filename) as fd:
assert expected_csv == fd.read()