def test_mlflow_artifact_uri_formats_resolved():
    base_url = "/api/2.0/mlflow-artifacts/artifacts"
    base_path = "/my/artifact/path"
    conditions = [
        (
            f"mlflow-artifacts://myhostname:4242{base_path}/hostport",
            f"http://myhostname:4242{base_url}{base_path}/hostport",
        ),
        (
            f"mlflow-artifacts://myhostname{base_path}/host",
            f"http://myhostname{base_url}{base_path}/host",
        ),
        (
            f"mlflow-artifacts:{base_path}/nohost",
            f"http://localhost:5000{base_url}{base_path}/nohost",
        ),
        (
            f"mlflow-artifacts://{base_path}/redundant",
            f"http://localhost:5000{base_url}{base_path}/redundant",
        ),
        (
            "mlflow-artifacts:/",
            f"http://localhost:5000{base_url}",
        ),
    ]
    failing_conditions = [
        f"mlflow-artifacts://5000/{base_path}", "mlflow-artifacts://5000/"
    ]

    for submit, resolved in conditions:
        artifact_repo = MlflowArtifactsRepository(submit)
        assert artifact_repo.resolve_uri(submit) == resolved
    for failing_condition in failing_conditions:
        with pytest.raises(
                MlflowException,
                match=
                "The mlflow-artifacts uri was supplied with a port number: 5000, but no "
                "host was defined.",
        ):
            MlflowArtifactsRepository(failing_condition)
def test_mlflow_artifact_uri_raises_with_invalid_tracking_uri():
    failing_conditions = [
        f"mlflow-artifacts://5000/{base_path}", "mlflow-artifacts://5000/"
    ]

    for failing_condition in failing_conditions:
        with pytest.raises(
                MlflowException,
                match=
                "The mlflow-artifacts uri was supplied with a port number: 5000, but no "
                "host was defined.",
        ):
            MlflowArtifactsRepository(failing_condition)
def test_mlflow_artifact_uri_formats_resolved(artifact_uri, resolved_uri,
                                              tracking_uri):

    assert MlflowArtifactsRepository.resolve_uri(artifact_uri,
                                                 tracking_uri) == resolved_uri
def mlflow_artifact_repo_with_host():
    artifact_uri = "mlflow-artifacts://test.com:5000/api/2.0/mlflow-artifacts/artifacts"
    return MlflowArtifactsRepository(artifact_uri)
def mlflow_artifact_repo():
    artifact_uri = "mlflow-artifacts:/api/2.0/mlflow-artifacts/artifacts"
    return MlflowArtifactsRepository(artifact_uri)