This repository was archived by the owner on Feb 27, 2023. It is now read-only.
forked from mlflow/mlflow
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_cli.py
More file actions
78 lines (63 loc) · 3.53 KB
/
Copy pathtest_cli.py
File metadata and controls
78 lines (63 loc) · 3.53 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from click.testing import CliRunner
from mock import mock
import pytest
from mlflow.cli import run, server, ui
from mlflow.server import handlers
def test_server_static_prefix_validation():
with mock.patch("mlflow.cli._run_server") as run_server_mock:
CliRunner().invoke(server)
run_server_mock.assert_called_once()
with mock.patch("mlflow.cli._run_server") as run_server_mock:
CliRunner().invoke(server, ["--static-prefix", "/mlflow"])
run_server_mock.assert_called_once()
with mock.patch("mlflow.cli._run_server") as run_server_mock:
result = CliRunner().invoke(server, ["--static-prefix", "mlflow/"])
assert "--static-prefix must begin with a '/'." in result.output
run_server_mock.assert_not_called()
with mock.patch("mlflow.cli._run_server") as run_server_mock:
result = CliRunner().invoke(server, ["--static-prefix", "/mlflow/"])
assert "--static-prefix should not end with a '/'." in result.output
run_server_mock.assert_not_called()
def test_server_default_artifact_root_validation():
with mock.patch("mlflow.cli._run_server") as run_server_mock:
result = CliRunner().invoke(server, ["--backend-store-uri", "sqlite:///my.db"])
assert result.output.startswith("Option 'default-artifact-root' is required")
run_server_mock.assert_not_called()
@pytest.mark.parametrize("command", [server, ui])
def test_tracking_uri_validation_failure(command):
handlers._store = None
with mock.patch("mlflow.cli._run_server") as run_server_mock:
# SQLAlchemy expects postgresql:// not postgres://
CliRunner().invoke(command,
["--backend-store-uri", "postgres://user:pwd@host:5432/mydb",
"--default-artifact-root", "./mlruns"])
run_server_mock.assert_not_called()
@pytest.mark.parametrize("command", [server, ui])
def test_tracking_uri_validation_sql_driver_uris(command):
handlers._store = None
with mock.patch("mlflow.cli._run_server") as run_server_mock,\
mock.patch("mlflow.store.sqlalchemy_store.SqlAlchemyStore") as sql_store:
CliRunner().invoke(command,
["--backend-store-uri", "mysql+pymysql://user:pwd@host:5432/mydb",
"--default-artifact-root", "./mlruns"])
sql_store.assert_called_once_with("mysql+pymysql://user:pwd@host:5432/mydb", "./mlruns")
run_server_mock.assert_called()
def test_mlflow_run():
with mock.patch("mlflow.cli.projects") as mock_projects:
result = CliRunner().invoke(run)
mock_projects.run.assert_not_called()
assert 'Missing argument "URI"' in result.output
with mock.patch("mlflow.cli.projects") as mock_projects:
CliRunner().invoke(run, ["project_uri"])
mock_projects.run.assert_called_once()
with mock.patch("mlflow.cli.projects") as mock_projects:
CliRunner().invoke(run, ["--experiment-id", "5", "project_uri"])
mock_projects.run.assert_called_once()
with mock.patch("mlflow.cli.projects") as mock_projects:
CliRunner().invoke(run, ["--experiment-name", "random name", "project_uri"])
mock_projects.run.assert_called_once()
with mock.patch("mlflow.cli.projects") as mock_projects:
result = CliRunner().invoke(run, ["--experiment-id", "51",
"--experiment-name", "name blah", "uri"])
mock_projects.run.assert_not_called()
assert "Specify only one of 'experiment-name' or 'experiment-id' options." in result.output