repo
stringclasses
454 values
file_path
stringlengths
5
201
extension
stringclasses
1 value
content
stringlengths
8
509k
num_lines
int64
3
16.9k
size_bytes
int64
8
511k
mlflow
tests/genai/scorers/phoenix/test_registry.py
.py
from unittest import mock import pytest from mlflow.exceptions import MlflowException phoenix_evals = pytest.importorskip("phoenix.evals") @pytest.mark.parametrize( ("metric_name", "evaluator_name"), [ ("Hallucination", "HallucinationEvaluator"), ("Relevance", "RelevanceEvaluator"), ...
44
1,353
mlflow
tests/genai/scorers/phoenix/test_models.py
.py
from unittest.mock import Mock, patch import pytest from mlflow.exceptions import MlflowException from mlflow.genai.scorers.phoenix.models import ( MlflowPhoenixModel, create_phoenix_model, ) @pytest.fixture def mock_call_chat_completions(): with patch( "mlflow.genai.judges.adapters.databricks_m...
161
5,261
mlflow
tests/genai/scorers/phoenix/test_phoenix.py
.py
from unittest.mock import Mock, patch import phoenix.evals as phoenix_evals import pytest from mlflow.entities.assessment import Feedback from mlflow.entities.assessment_source import AssessmentSourceType from mlflow.exceptions import MlflowException from mlflow.genai.scorers.base import Scorer, ScorerKind from mlflo...
205
7,874
mlflow
tests/genai/scorers/phoenix/test_utils.py
.py
import json import sys import time from unittest.mock import patch import pytest from opentelemetry.sdk.trace import ReadableSpan as OTelReadableSpan from mlflow.entities.span import Span from mlflow.entities.trace import Trace, TraceData, TraceInfo from mlflow.entities.trace_location import TraceLocation from mlflow...
142
4,608
mlflow
tests/genai/scorers/online/test_sampler.py
.py
import json import uuid import pytest from mlflow.genai.scorers.builtin_scorers import Completeness, ConversationCompleteness from mlflow.genai.scorers.online.entities import OnlineScorer, OnlineScoringConfig from mlflow.genai.scorers.online.sampler import OnlineScorerSampler def make_online_scorer( scorer, ...
148
5,078
mlflow
tests/genai/scorers/online/test_trace_processor.py
.py
import json import uuid from unittest.mock import MagicMock, patch import pytest from mlflow.entities import Trace, TraceData, TraceInfo from mlflow.genai.scorers.builtin_scorers import Completeness from mlflow.genai.scorers.online.entities import OnlineScorer, OnlineScoringConfig from mlflow.genai.scorers.online.sam...
530
19,853
mlflow
tests/genai/scorers/online/test_session_processor.py
.py
import json import uuid from unittest.mock import MagicMock, patch import pytest from mlflow.entities import Trace, TraceData, TraceInfo from mlflow.entities.assessment import Assessment from mlflow.entities.trace_location import ( MlflowExperimentLocation, TraceLocation, TraceLocationType, ) from mlflow....
726
27,472
mlflow
tests/genai/scorers/online/test_trace_checkpointer.py
.py
import time from unittest.mock import MagicMock import pytest from mlflow.environment_variables import ( MLFLOW_ONLINE_SCORING_DEFAULT_TRACE_COMPLETION_BUFFER_SECONDS, ) from mlflow.genai.scorers.online.constants import MAX_LOOKBACK_MS from mlflow.genai.scorers.online.trace_checkpointer import ( OnlineTraceCh...
236
8,953
mlflow
tests/genai/scorers/online/test_trace_loader.py
.py
from unittest.mock import MagicMock, patch import pytest from mlflow.entities import Trace, TraceInfo from mlflow.genai.scorers.online.trace_loader import OnlineTraceLoader from mlflow.tracing.constant import SpansLocation, TraceTagKey @pytest.fixture def mock_store(): return MagicMock() @pytest.fixture def t...
249
8,414
mlflow
tests/genai/scorers/online/test_session_checkpointer.py
.py
import time from unittest.mock import MagicMock import pytest from mlflow.environment_variables import ( MLFLOW_ONLINE_SCORING_DEFAULT_SESSION_COMPLETION_BUFFER_SECONDS, ) from mlflow.genai.scorers.online.constants import MAX_LOOKBACK_MS from mlflow.genai.scorers.online.session_checkpointer import ( OnlineSes...
171
6,402
mlflow
tests/genai/scorers/guardrails/test_registry.py
.py
from unittest.mock import MagicMock, patch import pytest from mlflow.exceptions import MlflowException from mlflow.genai.scorers.guardrails.registry import get_validator_class @pytest.mark.parametrize( ("validator_name", "expected_class"), [ ("ToxicLanguage", "ToxicLanguage"), ("NSFWText", "...
43
1,299
mlflow
tests/genai/scorers/guardrails/test_guardrails.py
.py
from unittest.mock import patch import guardrails import pytest from guardrails import Validator, register_validator from guardrails.classes.validation.validation_result import FailResult, PassResult import mlflow from mlflow.entities.assessment import Feedback from mlflow.entities.assessment_source import Assessment...
277
9,224
mlflow
tests/genai/scorers/guardrails/test_utils.py
.py
import sys from unittest.mock import patch import pytest import mlflow from mlflow.exceptions import MlflowException from mlflow.genai.scorers.guardrails.utils import ( check_guardrails_installed, map_scorer_inputs_to_text, ) def _create_test_trace(inputs=None, outputs=None): """Create a test trace usin...
67
1,953
mlflow
tests/genai/scorers/trulens/test_trulens.py
.py
from unittest.mock import Mock, patch import pytest import trulens # noqa: F401 from mlflow.entities.assessment import Feedback from mlflow.entities.assessment_source import AssessmentSourceType from mlflow.exceptions import MlflowException from mlflow.genai.judges.utils import CategoricalRating from mlflow.genai.sc...
291
10,665
mlflow
tests/genai/scorers/trulens/test_registry.py
.py
import pytest from mlflow.genai.scorers.trulens.registry import get_argument_mapping, get_feedback_method_name @pytest.mark.parametrize( ("metric_name", "expected_method"), [ ("Groundedness", "groundedness_measure_with_cot_reasons"), ("ContextRelevance", "context_relevance_with_cot_reasons"),...
41
1,491
mlflow
tests/genai/scorers/trulens/test_models.py
.py
import importlib from unittest.mock import Mock, patch import pytest import trulens # noqa: F401 from mlflow.exceptions import MlflowException from mlflow.genai.scorers.trulens.models import create_trulens_provider @pytest.fixture def mock_call_chat_completions(): with patch( "mlflow.genai.judges.adapt...
108
3,635
mlflow
tests/genai/scorers/trulens/test_utils.py
.py
import pytest import mlflow from mlflow.genai.scorers.trulens.utils import ( format_rationale, map_scorer_inputs_to_trulens_args, ) def _create_test_trace( inputs: dict[str, str] | None = None, outputs: dict[str, str] | None = None, ): with mlflow.start_span() as span: if inputs is not No...
128
3,813
mlflow
tests/genai/scorers/trulens/scorers/test_agent_trace.py
.py
from unittest.mock import Mock, patch import pytest import trulens # noqa: F401 import mlflow from mlflow.entities.assessment import Feedback from mlflow.entities.assessment_source import AssessmentSourceType from mlflow.entities.span import SpanType from mlflow.exceptions import MlflowException @pytest.fixture de...
156
5,488
mlflow
tests/genai/scorers/google_adk/test_google_adk.py
.py
from unittest.mock import Mock, patch import pytest import mlflow from mlflow.entities.assessment import Feedback from mlflow.entities.assessment_source import AssessmentSource, AssessmentSourceType from mlflow.entities.span import SpanType from mlflow.genai.judges.utils import CategoricalRating from mlflow.genai.sco...
929
31,241
mlflow
tests/genai/scorers/ragas/test_registry.py
.py
from unittest import mock import pytest from mlflow.exceptions import MlflowException from mlflow.genai.scorers.ragas.registry import ( get_metric_class, is_agentic_or_multiturn_metric, requires_args_from_placeholders, requires_embeddings, requires_llm_at_score_time, requires_llm_in_constructo...
113
3,160
mlflow
tests/genai/scorers/ragas/test_models.py
.py
import sys from unittest.mock import Mock, patch import pytest from pydantic import BaseModel from mlflow.exceptions import MlflowException from mlflow.genai.scorers.ragas.models import MlflowRagasLLM, create_ragas_model class DummyResponseModel(BaseModel): answer: str score: int @pytest.fixture(autouse=T...
102
3,338
mlflow
tests/genai/scorers/ragas/test_ragas_scorer.py
.py
from unittest.mock import MagicMock, patch import pytest from pydantic import BaseModel from ragas.embeddings.base import BaseRagasEmbedding import mlflow from mlflow.entities.assessment import Feedback from mlflow.entities.assessment_source import AssessmentSourceType from mlflow.exceptions import MlflowException fr...
531
17,588
mlflow
tests/genai/scorers/ragas/test_utils.py
.py
import pytest from langchain_core.documents import Document from ragas.dataset_schema import MultiTurnSample, SingleTurnSample from ragas.messages import AIMessage, HumanMessage, ToolCall import mlflow from mlflow.entities.span import SpanType from mlflow.genai.scorers.ragas.utils import ( create_mlflow_error_mess...
249
8,297
mlflow
tests/genai/scorers/deepeval/test_registry.py
.py
from unittest import mock import pytest from mlflow.exceptions import MlflowException from mlflow.genai.scorers.deepeval.registry import get_metric_class, is_deterministic_metric def test_get_metric_class_returns_valid_class(): metric_class = get_metric_class("AnswerRelevancy") assert metric_class.__name__ ...
44
1,484
mlflow
tests/genai/scorers/deepeval/test_deepeval_scorer.py
.py
from unittest.mock import Mock, patch import pydantic import pytest import mlflow from mlflow.entities.assessment import Feedback from mlflow.entities.assessment_source import AssessmentSourceType from mlflow.exceptions import MlflowException from mlflow.genai.judges.utils import CategoricalRating from mlflow.genai.s...
556
19,770
mlflow
tests/genai/scorers/deepeval/test_models.py
.py
from unittest.mock import Mock, patch import pytest from mlflow.genai.scorers.deepeval.models import MlflowDeepEvalLLM, create_deepeval_model @pytest.fixture def mock_call_chat_completions(): with patch( "mlflow.genai.judges.adapters.databricks_managed_judge_adapter.call_chat_completions", ) as mock...
94
3,421
mlflow
tests/genai/scorers/deepeval/test_utils.py
.py
from unittest.mock import Mock import pytest from mlflow.entities.span import Span, SpanAttributeKey, SpanType from mlflow.exceptions import MlflowException from mlflow.genai.scorers.deepeval.models import create_deepeval_model from mlflow.genai.scorers.deepeval.utils import ( _convert_to_deepeval_tool_calls, ...
143
4,673
mlflow
tests/genai/prompts/test_prompts.py
.py
import json import threading import time from concurrent.futures import ThreadPoolExecutor from unittest import mock import jinja2 import pytest from pydantic import BaseModel, ValidationError import mlflow from mlflow import MlflowClient from mlflow.entities.model_registry import PromptModelConfig, PromptVersion fro...
2,098
75,531
mlflow
tests/genai/datasets/test_fluent.py
.py
import json import os import sys import warnings from types import SimpleNamespace from unittest import mock import pandas as pd import pytest import mlflow from mlflow.data import Dataset from mlflow.data.pyfunc_dataset_mixin import PyFuncConvertibleDatasetMixin from mlflow.entities.dataset_record_source import Data...
2,369
79,667
mlflow
tests/genai/datasets/test_evaluation_dataset.py
.py
import json from datetime import datetime, timezone from types import SimpleNamespace from typing import Any from unittest.mock import Mock import pandas as pd import pytest from mlflow.data.dataset_source_registry import ( get_dataset_source_from_json, register_dataset_source, ) from mlflow.data.spark_datase...
316
11,652
mlflow
tests/genai/datasets/test_databricks_evaluation_dataset_source.py
.py
import json import pytest from mlflow.genai.datasets.databricks_evaluation_dataset_source import ( DatabricksEvaluationDatasetSource, ) def test_databricks_evaluation_dataset_source_init(): source = DatabricksEvaluationDatasetSource( table_name="catalog.schema.table", dataset_id="12345" ) as...
105
3,469
mlflow
tests/genai/label_schemas/test_label_schemas.py
.py
import dataclasses from contextlib import contextmanager from unittest.mock import MagicMock, patch import pytest from mlflow.genai import label_schemas from mlflow.genai.label_schemas import ( EXPECTED_FACTS, EXPECTED_RESPONSE, GUIDELINES, InputCategorical, InputCategoricalList, InputNumeric,...
791
25,546
mlflow
tests/genai/label_schemas/test_label_schemas_oss.py
.py
from unittest.mock import patch import pytest from mlflow.exceptions import MlflowException from mlflow.genai.label_schemas import ( InputCategorical, InputPassFail, LabelSchema, LabelSchemaType, create_label_schema, delete_label_schema, get_label_schema, list_label_schemas, update...
153
5,608
mlflow
tests/genai/utils/test_llm_utils.py
.py
from unittest import mock import pydantic import pytest from mlflow.genai.utils.gateway_utils import GatewayLiteLLMConfig from mlflow.genai.utils.llm_utils import ( _call_llm, _call_llm_via_gateway, _fetch_model_cost, _lookup_model_cost, _ModelCost, _resolve_model_for_gateway, _TokenCounte...
473
16,764
mlflow
tests/genai/utils/test_message_utils.py
.py
from enum import Enum import pydantic import pytest from mlflow.genai.utils.message_utils import ( _enforce_strict_json_schema, pydantic_to_response_format, serialize_messages_to_prompts, ) from mlflow.types.llm import ChatMessage, FunctionToolCallArguments, ToolCall @pytest.mark.parametrize( ("mess...
289
9,820
mlflow
tests/genai/utils/test_display_utils.py
.py
from unittest import mock import mlflow from mlflow.genai.utils import display_utils from mlflow.store.tracking.rest_store import RestStore from mlflow.tracking.client import MlflowClient from mlflow.utils.mlflow_tags import MLFLOW_DATABRICKS_WORKSPACE_URL def test_display_outputs_jupyter(monkeypatch): mock_stor...
81
3,188
mlflow
tests/genai/utils/test_trace_utils.py
.py
import asyncio import json from collections import OrderedDict from typing import Any from unittest import mock import httpx import numpy as np import openai import pandas as pd import pytest from opentelemetry.sdk.trace import ReadableSpan as OTelReadableSpan import mlflow from mlflow.entities.assessment import Expe...
1,754
58,625
mlflow
tests/genai/utils/test_gateway_utils.py
.py
import base64 from unittest import mock import pytest from mlflow.exceptions import MlflowException from mlflow.genai.utils.gateway_utils import GatewayLiteLLMConfig, get_gateway_litellm_config from mlflow.utils.credentials import MlflowCreds GATEWAY_URI = "http://localhost:5000" @pytest.fixture def gateway_env(mo...
121
4,010
mlflow
tests/genai/utils/test_prompt_cache.py
.py
import threading import time import pytest from mlflow.prompt.registry_utils import PromptCache, PromptCacheKey @pytest.fixture(autouse=True) def reset_cache(): """Reset the prompt cache before and after each test.""" PromptCache._reset_instance() yield PromptCache._reset_instance() def test_singl...
204
5,798
mlflow
tests/genai/utils/test_data_validation.py
.py
import pytest import mlflow from mlflow.exceptions import MlflowException from mlflow.genai.utils.data_validation import check_model_prediction from tests.tracing.helper import get_traces def _extract_code_example(e: MlflowException) -> str: """Extract the code example from the exception message.""" return ...
202
6,041
mlflow
tests/genai/optimize/test_optimize.py
.py
import json from typing import Any import pandas as pd import pytest import mlflow from mlflow.entities.model_registry import PromptModelConfig from mlflow.exceptions import MlflowException from mlflow.genai.datasets import create_dataset from mlflow.genai.optimize.optimize import _deserialize_chat_template, optimize...
656
24,378
mlflow
tests/genai/optimize/test_util.py
.py
from typing import Any, Union import pytest from pydantic import BaseModel from mlflow.entities.assessment import Feedback from mlflow.exceptions import MlflowException from mlflow.genai.judges import CategoricalRating from mlflow.genai.optimize.util import ( create_metric_from_scorers, infer_type_from_value,...
224
6,850
mlflow
tests/genai/optimize/test_job.py
.py
import sys from unittest import mock import pytest import mlflow from mlflow.exceptions import MlflowException from mlflow.genai.optimize.job import ( OptimizerType, _build_predict_fn, _create_optimizer, _load_scorers, optimize_prompts_job, ) from mlflow.genai.optimize.optimizers import GepaPrompt...
318
12,006
mlflow
tests/genai/optimize/optimizers/test_metaprompt_optimizer.py
.py
import json from typing import Any from unittest.mock import Mock, patch import pytest from mlflow.exceptions import MlflowException from mlflow.genai.optimize.optimizers.metaprompt_optimizer import MetaPromptOptimizer from mlflow.genai.optimize.types import EvaluationResultRecord, PromptOptimizerOutput _CALL_LLM = ...
523
19,286
mlflow
tests/genai/optimize/optimizers/test_gepa_optimizer.py
.py
import json import sys from pathlib import Path from typing import Any from unittest.mock import MagicMock, Mock, patch import pytest import mlflow from mlflow.genai.optimize.optimizers.gepa_optimizer import GepaPromptOptimizer from mlflow.genai.optimize.types import EvaluationResultRecord, PromptOptimizerOutput @p...
662
23,380
mlflow
tests/genai/review_queues/test_review_queues_entity.py
.py
import pytest from mlflow.exceptions import MlflowException from mlflow.genai.review_queues import ( ReviewItemType, ReviewQueue, ReviewQueueItem, ReviewQueueType, ReviewStatus, ) from mlflow.protos import review_queues_pb2 as pb @pytest.mark.parametrize( ("enum_cls", "member", "proto_value")...
140
3,981
mlflow
tests/genai/review_queues/test_review_queues_sdk.py
.py
from unittest.mock import patch import pytest import mlflow from mlflow.exceptions import MlflowException from mlflow.genai.review_queues import ( ReviewItemType, ReviewQueue, ReviewQueueItem, ReviewQueueType, ReviewStatus, add_items_to_review_queue, create_review_queue, delete_review_...
213
7,591
mlflow
tests/genai/labeling/test_labeling.py
.py
from mlflow.genai import labeling from mlflow.genai.labeling import ( Agent, LabelingSession, ReviewApp, create_labeling_session, delete_labeling_session, get_labeling_session, get_labeling_sessions, get_review_app, ) from tests.genai.conftest import databricks_only @databricks_only d...
26
825
mlflow
tests/genai/discovery/test_extraction.py
.py
from unittest import mock import pytest import mlflow from mlflow.entities.assessment_source import AssessmentSource, AssessmentSourceType from mlflow.genai.discovery.entities import _ConversationAnalysis from mlflow.genai.discovery.extraction import ( collect_session_rationales, extract_assessment_rationale,...
264
8,681
mlflow
tests/genai/discovery/test_pipeline.py
.py
import json from unittest.mock import MagicMock, patch import pytest import mlflow from mlflow.entities.assessment import Feedback from mlflow.entities.assessment_source import AssessmentSource, AssessmentSourceType from mlflow.genai.discovery.clustering import recluster_singletons from mlflow.genai.discovery.constan...
1,292
43,343
mlflow
tests/genai/discovery/test_clustering.py
.py
import json from unittest.mock import MagicMock, patch from mlflow.entities.issue import IssueSeverity, IssueStatus from mlflow.genai.discovery.clustering import ( cluster_by_llm, summarize_cluster, ) from mlflow.genai.discovery.constants import build_cluster_summary_prompt from mlflow.genai.discovery.entities...
194
5,985
mlflow
tests/genai/discovery/test_sampling.py
.py
from unittest.mock import patch from mlflow.genai.discovery.sampling import sample_traces from mlflow.genai.discovery.utils import group_traces_by_session # ---- sample_traces ---- def test_sample_traces_no_sessions(make_trace): traces = [make_trace() for _ in range(20)] search_kwargs = {"filter_string": No...
101
3,020
mlflow
tests/genai/discovery/test_utils.py
.py
import time from unittest import mock import pytest from mlflow.entities.issue import Issue, IssueStatus from mlflow.entities.trace import Trace from mlflow.entities.trace_data import TraceData from mlflow.entities.trace_info import TraceInfo from mlflow.entities.trace_location import TraceLocation from mlflow.entiti...
377
12,016
mlflow
tests/genai/discovery/test_job.py
.py
from unittest import mock import pytest from mlflow.entities.run_status import RunStatus from mlflow.exceptions import MlflowException from mlflow.genai.discovery.job import ( _fetch_provider_credentials, invoke_issue_detection_job, ) @pytest.mark.parametrize( ("provider", "secret_value", "auth_config",...
260
10,318
mlflow
tests/genai/discovery/conftest.py
.py
import pytest import mlflow from mlflow.entities.span import SpanType from mlflow.entities.trace import Trace from mlflow.entities.trace_info import TraceInfo from mlflow.genai.scorers.base import Scorer class _TestScorer(Scorer): """Minimal Scorer subclass for use in discovery pipeline tests.""" def __call...
77
2,309
mlflow
tests/statsmodels/test_statsmodels_autolog.py
.py
from unittest import mock import numpy as np import pytest from statsmodels.tsa.base.tsa_model import TimeSeriesModel import mlflow import mlflow.statsmodels from mlflow import MlflowClient from tests.statsmodels.model_fixtures import ( arma_model, failing_logit_model, gee_model, glm_model, gls_m...
239
7,735
mlflow
tests/statsmodels/test_statsmodels_model_export.py
.py
import json import os from pathlib import Path from unittest import mock import numpy as np import pandas as pd import pytest import yaml import mlflow.pyfunc.scoring_server as pyfunc_scoring_server import mlflow.statsmodels from mlflow import pyfunc from mlflow.exceptions import MlflowException from mlflow.models im...
485
17,982
mlflow
tests/statsmodels/model_fixtures.py
.py
from typing import Any, NamedTuple import numpy as np import pandas as pd import statsmodels.api as sm from scipy.linalg import toeplitz from statsmodels.tsa.arima.model import ARIMA from statsmodels.tsa.arima_process import arma_generate_sample from mlflow.models import ModelSignature from mlflow.types.schema import...
238
7,568
mlflow
tests/rfunc/test_backend.py
.py
from unittest import mock import pytest from mlflow.rfunc.backend import RFuncBackend, _r_quote @pytest.mark.parametrize( ("value", "expected"), [ ("localhost", "'localhost'"), ("0.0.0.0", "'0.0.0.0'"), ("foo bar", "'foo bar'"), ("it's", "'it\\'s'"), ("back\\slash", "...
79
2,551
mlflow
tests/spark/test_spark_model_export.py
.py
import inspect import json import logging import os from pathlib import Path from typing import Any, NamedTuple from unittest import mock import numpy as np import pandas as pd import pyspark import pytest import yaml from packaging.version import Version from pyspark.ml.classification import LogisticRegression from p...
1,086
42,959
mlflow
tests/spark/test_spark_autologging_stop.py
.py
import logging import threading import time from unittest.mock import MagicMock, patch import pytest import mlflow.spark.autologging as autologging_module from mlflow.spark.autologging import _stop_listen_for_spark_activity @pytest.fixture def autolog_caplog(caplog): # "mlflow" sets propagate=False, so its reco...
107
3,690
mlflow
tests/spark/test_sparkml_param_integration.py
.py
from pyspark.ml.param import Param as SparkMLParam from pyspark.ml.util import Identifiable from mlflow.entities import Param def test_spark_integration(): key = SparkMLParam(Identifiable(), "name", "doc") value = 123 param = Param(key, value) assert param.key == "name" assert param.value == "123...
13
322
mlflow
tests/spark/test_spark_connect_model_export.py
.py
import json import os from unittest import mock import numpy as np import pandas as pd import pyspark import pytest from packaging.version import Version from pyspark.sql import SparkSession from pyspark.sql import functions as F from pyspark.sql.types import LongType from sklearn import datasets import mlflow import...
162
5,719
mlflow
tests/spark/autologging/utils.py
.py
import os import pyspark from packaging.version import Version from pyspark.sql import SparkSession import mlflow from mlflow.spark.autologging import _SPARK_TABLE_INFO_TAG_NAME def _get_mlflow_spark_jar_path(): spark_dir = "spark_2.13" if Version(pyspark.__version__).major >= 4 else "spark_2.12" jar_dir = ...
43
1,566
mlflow
tests/spark/autologging/datasource/test_spark_datasource_autologging_missing_jar.py
.py
import pytest import mlflow.spark from mlflow.exceptions import MlflowException from tests.spark.autologging.utils import _get_or_create_spark_session def test_enabling_autologging_throws_for_missing_jar(): with _get_or_create_spark_session(jars=""): with pytest.raises(MlflowException, match="ensure you...
13
394
mlflow
tests/spark/autologging/datasource/test_autologging_behavior_without_spark_session.py
.py
import mlflow def test_enabling_autologging_does_not_throw_when_spark_hasnt_been_started(): from pyspark.sql import SparkSession assert SparkSession.getActiveSession() is None mlflow.spark.autolog(disable=True)
10
227
mlflow
tests/spark/autologging/datasource/test_spark_datasource_autologging_crossframework.py
.py
import time import numpy as np import pytest from sklearn.linear_model import LinearRegression import mlflow import mlflow.spark from tests.spark.autologging.utils import _assert_spark_data_logged @pytest.fixture def http_tracking_uri_mock(): mlflow.set_tracking_uri("http://some-cool-uri") yield mlflow...
121
3,836
mlflow
tests/spark/autologging/datasource/test_spark_disable_autologging.py
.py
import time import mlflow import mlflow.spark from tests.spark.autologging.utils import ( _assert_spark_data_logged, _assert_spark_data_not_logged, ) # Note that the following tests run one-after-the-other and operate on the SAME spark_session # (it is not reset between tests) def test_autologging_disabl...
100
2,955
mlflow
tests/spark/autologging/datasource/test_spark_datasource_autologging.py
.py
import time from unittest import mock from pyspark.sql import Row from pyspark.sql.types import IntegerType, StructField, StructType import mlflow import mlflow.spark from mlflow.spark.autologging import _SPARK_TABLE_INFO_TAG_NAME from mlflow.utils.validation import MAX_TAG_VAL_LENGTH from tests.spark.autologging.ut...
287
10,882
mlflow
tests/spark/autologging/datasource/test_spark_datasource_autologging_unit.py
.py
from unittest import mock import pytest import mlflow.spark from mlflow.exceptions import MlflowException from mlflow.spark.autologging import PythonSubscriber, _get_current_listener @pytest.fixture def mock_get_current_listener(): with mock.patch( "mlflow.spark.autologging._get_current_listener", retur...
61
2,114
mlflow
tests/spark/autologging/datasource/test_spark_datasource_autologging_order.py
.py
import os import time import pytest from pyspark.sql import Row from pyspark.sql.types import IntegerType, StructField, StructType import mlflow import mlflow.spark from tests.spark.autologging.utils import ( _assert_spark_data_logged, _assert_spark_data_not_logged, _get_or_create_spark_session, ) @pyt...
49
1,481
mlflow
tests/spark/autologging/datasource/conftest.py
.py
import os import tempfile import pytest from pyspark.sql import Row from pyspark.sql.types import IntegerType, StringType, StructField, StructType from mlflow.spark.autologging import clear_table_infos from tests.spark.autologging.utils import _get_or_create_spark_session # Module-scoped version of pytest monkeypa...
78
2,661
mlflow
tests/spark/autologging/ml/test_pyspark_ml_autologging_custom_allowlist.py
.py
import os from pyspark.sql import SparkSession import mlflow # Put this test in separate module because it require a spark context # with a special conf and the conf is immutable in runtime. def test_custom_log_model_allowlist(tmp_path): allowlist_file_path = os.path.join(tmp_path, "allowlist") with open(al...
88
3,808
mlflow
tests/spark/autologging/ml/test_pyspark_ml_autologging.py
.py
import importlib import json import math import pathlib from typing import Any, NamedTuple from unittest import mock import numpy as np import pandas as pd import pyspark import pytest import yaml from packaging.version import Version from pyspark.ml import Pipeline from pyspark.ml.classification import ( LinearSV...
1,351
52,120
mlflow
tests/pyfunc/test_backward_compatibility.py
.py
import pytest import mlflow @pytest.mark.parametrize("version", ["2.7.1", "2.8.1"]) def test_backward_compatibility(version): model = mlflow.pyfunc.load_model(f"tests/resources/pyfunc_models/{version}") assert model.predict("MLflow is great!") == "MLflow is great!"
10
277
mlflow
tests/pyfunc/test_dependencies_functions.py
.py
from pathlib import Path from unittest import mock import pytest import sklearn from sklearn.linear_model import LinearRegression import mlflow.utils.requirements_utils from mlflow.exceptions import MlflowException from mlflow.pyfunc import get_model_dependencies from mlflow.utils import PYTHON_VERSION def test_get...
140
4,313
mlflow
tests/pyfunc/test_pyfunc_model_with_type_hints.py
.py
import datetime import json import os import subprocess import sys from typing import Any, Dict, List, NamedTuple, Optional, Union from unittest import mock import pandas as pd import pydantic import pytest from pyspark.sql import SparkSession from pyspark.sql.types import ( ArrayType, IntegerType, MapType...
1,153
42,741
mlflow
tests/pyfunc/utils.py
.py
import json import os from typing import TYPE_CHECKING from fastapi.testclient import TestClient import mlflow from mlflow.pyfunc import scoring_server if TYPE_CHECKING: import httpx def score_model_in_process(model_uri: str, data: str, content_type: str) -> "httpx.Response": """Score a model using in-proc...
40
1,381
mlflow
tests/pyfunc/test_chat_agent.py
.py
import json from typing import Any from uuid import uuid4 import pydantic import pytest import mlflow from mlflow.exceptions import MlflowException from mlflow.models.model import Model from mlflow.models.signature import ModelSignature from mlflow.models.utils import load_serving_example from mlflow.pyfunc.loaders.c...
471
17,282
mlflow
tests/pyfunc/test_pyfunc_input_converter.py
.py
from dataclasses import asdict, dataclass from typing import Optional import pandas as pd import pytest from mlflow.models.rag_signatures import ChatCompletionRequest from mlflow.pyfunc.utils.input_converter import _hydrate_dataclass def test_hydrate_dataclass_input_no_dataclass(): # Define a class that is not ...
90
2,529
mlflow
tests/pyfunc/test_model_export_with_loader_module_and_data_path.py
.py
import os import pickle import types from unittest import mock import cloudpickle import numpy as np import pytest import sklearn.datasets import sklearn.neighbors import yaml import mlflow import mlflow.pyfunc from mlflow.exceptions import MlflowException from mlflow.models import Model, infer_signature from mlflow....
369
12,659
mlflow
tests/pyfunc/test_virtualenv.py
.py
import os import sys from io import BytesIO from stat import S_IRGRP, S_IROTH, S_IRUSR, S_IXGRP, S_IXOTH, S_IXUSR from typing import NamedTuple import numpy as np import pandas as pd import pytest import sklearn from sklearn.datasets import load_iris from sklearn.linear_model import LogisticRegression import mlflow f...
232
8,129
mlflow
tests/pyfunc/test_pyfunc_class_methods.py
.py
import mlflow from mlflow.pyfunc import PythonModel, load_model, log_model def test_unwrap_python_model_from_pyfunc_class(): class MyModel(PythonModel): def __init__(self, param_1: str, param_2: int): self.param_1 = param_1 self.param_2 = param_2 def predict(self, context,...
26
958
mlflow
tests/pyfunc/test_pyfunc_exceptions.py
.py
import pytest import mlflow from mlflow.exceptions import MlflowException class UnpicklableModel(mlflow.pyfunc.PythonModel): def __init__(self, path): with open(path, "w+") as f: pass self.not_a_file = f def test_pyfunc_unpicklable_exception(tmp_path): model = UnpicklableModel(...
23
579
mlflow
tests/pyfunc/test_inferred_code_path.py
.py
import os import pickle import numpy as np import pytest import sklearn.datasets import sklearn.neighbors import mlflow from mlflow.models import Model @pytest.fixture def model_path(tmp_path): return tmp_path / "model" @pytest.fixture(scope="module") def iris_data(): iris = sklearn.datasets.load_iris() ...
150
4,553
mlflow
tests/pyfunc/test_pyfunc_schema_enforcement_pyspark.py
.py
from datetime import datetime import pytest from pyspark.sql import Row, SparkSession from pyspark.sql.types import ( ArrayType, BinaryType, BooleanType, DateType, DoubleType, FloatType, IntegerType, LongType, ShortType, StringType, StructField, StructType, Timestamp...
338
10,510
mlflow
tests/pyfunc/test_spark.py
.py
import datetime import os import random import shutil import subprocess import sys import threading import time from pathlib import Path from typing import Any, Iterator, NamedTuple from unittest import mock import cloudpickle import numpy as np import pandas as pd import pyspark import pytest from packaging.version i...
1,779
64,229
mlflow
tests/pyfunc/test_responses_agent_validation.py
.py
import pytest from pydantic import ValidationError from mlflow.types.responses import ( ResponsesAgentRequest, ResponsesAgentResponse, ResponsesAgentStreamEvent, responses_to_cc, to_chat_completions_input, ) from mlflow.types.responses_helpers import FunctionCallOutput, Message def test_responses...
233
7,521
mlflow
tests/pyfunc/test_uv_model_logging.py
.py
import platform import shutil import subprocess import sys from pathlib import Path from unittest import mock import pytest import mlflow import mlflow.pyfunc from mlflow.utils.os import is_windows from mlflow.utils.uv_utils import ( _PYPROJECT_FILE, _PYTHON_VERSION_FILE, _UV_LOCK_FILE, is_uv_availabl...
504
16,338
mlflow
tests/pyfunc/test_scoring_server.py
.py
import json import math import os import random import signal from io import BytesIO, StringIO from typing import Any, NamedTuple import keras import numpy as np import pandas as pd import pydantic import pytest import sklearn.linear_model as logreg_module from packaging.version import Version from sklearn import data...
1,133
41,049
mlflow
tests/pyfunc/test_logged_models.py
.py
import json import os from concurrent.futures import ThreadPoolExecutor import pytest import mlflow from mlflow.entities.logged_model_status import LoggedModelStatus from mlflow.exceptions import MlflowException from mlflow.models import Model from mlflow.tracing.constant import TraceMetadataKey from mlflow.utils.mlf...
158
6,171
mlflow
tests/pyfunc/test_responses_agent.py
.py
import functools import pathlib import pickle from typing import Generator from uuid import uuid4 import pytest import mlflow from mlflow.entities.span import SpanType from mlflow.exceptions import MlflowException from mlflow.models.signature import ModelSignature from mlflow.pyfunc.loaders.responses_agent import _Re...
1,491
56,626
mlflow
tests/pyfunc/test_model_export_with_class_and_artifacts.py
.py
from __future__ import annotations import importlib.metadata import json import ntpath import os import subprocess import sys import types import uuid from pathlib import Path from subprocess import PIPE, Popen from typing import Any, Dict, List from unittest import mock import cloudpickle import numpy as np import p...
2,948
110,389
mlflow
tests/pyfunc/test_spark_connect.py
.py
import numpy as np import pandas as pd import pytest from pyspark.sql import SparkSession from sklearn.datasets import load_iris from sklearn.linear_model import LogisticRegression import mlflow @pytest.fixture(scope="module") def spark(): spark = SparkSession.builder.remote("local[2]").getOrCreate() yield s...
53
1,932
mlflow
tests/pyfunc/test_chat_model_validation.py
.py
import pytest from mlflow.types.llm import ( ChatChoice, ChatCompletionRequest, ChatCompletionResponse, ChatMessage, TokenUsageStats, ) MOCK_RESPONSE = { "id": "123", "object": "chat.completion", "created": 1677652288, "model": "MyChatModel", "choices": [ { ...
274
8,477
mlflow
tests/pyfunc/test_context.py
.py
import random import time from threading import Thread import pytest import mlflow from mlflow.pyfunc.context import ( Context, get_prediction_context, set_prediction_context, ) def test_prediction_context_thread_safe(): def set_context(context): with set_prediction_context(context): ...
67
2,150
mlflow
tests/pyfunc/test_chat_model.py
.py
import json import pathlib import pickle import uuid from dataclasses import asdict import pytest import mlflow from mlflow.exceptions import MlflowException from mlflow.models.model import Model from mlflow.models.signature import ModelSignature from mlflow.models.utils import load_serving_example from mlflow.pyfunc...
662
21,901
mlflow
tests/pyfunc/test_pyfunc_schema_enforcement.py
.py
import base64 import datetime import decimal import json import os import re from unittest import mock import cloudpickle import numpy as np import pandas as pd import pytest import sklearn.linear_model from packaging.version import Version import mlflow import mlflow.pyfunc.scoring_server as pyfunc_scoring_server fr...
3,084
119,325
mlflow
tests/pyfunc/test_pyfunc_model_config.py
.py
import os import pytest import yaml import mlflow from mlflow.models import Model @pytest.fixture def model_path(tmp_path): return os.path.join(tmp_path, "model") @pytest.fixture def model_config(): return { "use_gpu": True, "temperature": 0.9, "timeout": 300, } def _load_pyf...
155
5,259
mlflow
tests/pyfunc/test_rag_model.py
.py
import json from dataclasses import asdict import mlflow from mlflow.models.model import Model from mlflow.models.rag_signatures import ( ChainCompletionChoice, ChatCompletionRequest, ChatCompletionResponse, Message, ) from mlflow.models.signature import ModelSignature from tests.helper_functions impo...
60
2,145