test_cli.py
1 import pytest 2 from click.testing import CliRunner 3 4 from mlflow.gateway import cli as gateway_cli 5 from mlflow.gateway.cli import start 6 7 8 def test_start_help(): 9 runner = CliRunner() 10 res = runner.invoke( 11 start, 12 ["--help"], 13 catch_exceptions=False, 14 ) 15 assert res.exit_code == 0 16 17 18 def test_start_invalid_config(tmp_path): 19 runner = CliRunner() 20 config = tmp_path.joinpath("config.yml") 21 res = runner.invoke( 22 start, 23 ["--config-path", config], 24 catch_exceptions=False, 25 ) 26 assert res.exit_code == 2 27 assert "does not exist" in res.output 28 29 config.write_text("\t") 30 res = runner.invoke( 31 start, 32 ["--config-path", config], 33 catch_exceptions=False, 34 ) 35 assert res.exit_code == 2 36 assert "not a valid yaml file" in res.output 37 38 config.write_text( 39 """ 40 endpoints: 41 - model: 42 name: invalid 43 """ 44 ) 45 res = runner.invoke( 46 start, 47 ["--config-path", config], 48 catch_exceptions=False, 49 ) 50 assert res.exit_code == 2 51 assert "The gateway configuration is invalid" in res.output 52 53 54 def test_start_warns_deprecation(monkeypatch, tmp_path): 55 runner = CliRunner() 56 config = tmp_path.joinpath("config.yml") 57 config.write_text("unused") 58 59 monkeypatch.setattr(gateway_cli, "_validate_config", lambda _: None) 60 monkeypatch.setattr(gateway_cli, "_record_event", lambda *_args, **_kwargs: None) 61 monkeypatch.setattr(gateway_cli, "run_app", lambda **_kwargs: None) 62 monkeypatch.setattr(gateway_cli, "is_windows", lambda: False) 63 64 with pytest.warns(FutureWarning, match="mlflow.gateway.cli.start.*deprecated"): 65 res = runner.invoke( 66 start, 67 ["--config-path", config], 68 catch_exceptions=False, 69 ) 70 assert res.exit_code == 0