code
stringlengths
66
870k
docstring
stringlengths
19
26.7k
func_name
stringlengths
1
138
language
stringclasses
1 value
repo
stringlengths
7
68
path
stringlengths
5
324
url
stringlengths
46
389
license
stringclasses
7 values
def test_create_logged_models_with_params( monkeypatch, params_count, expected_call_count, create_batch_size, log_batch_size ): """Test creating logged models with parameters.""" # Set environment variables using monkeypatch monkeypatch.setenv(_MLFLOW_CREATE_LOGGED_MODEL_PARAMS_BATCH_SIZE.name, create_b...
Test creating logged models with parameters.
test_create_logged_models_with_params
python
mlflow/mlflow
tests/store/tracking/test_rest_store.py
https://github.com/mlflow/mlflow/blob/master/tests/store/tracking/test_rest_store.py
Apache-2.0
def test_log_metric_concurrent_logging_succeeds(store: SqlAlchemyStore): """ Verifies that concurrent logging succeeds without deadlock, which has been an issue in previous MLflow releases """ experiment_id = _create_experiments(store, "concurrency_exp") run_config = _get_run_configs(experiment_...
Verifies that concurrent logging succeeds without deadlock, which has been an issue in previous MLflow releases
test_log_metric_concurrent_logging_succeeds
python
mlflow/mlflow
tests/store/tracking/test_sqlalchemy_store.py
https://github.com/mlflow/mlflow/blob/master/tests/store/tracking/test_sqlalchemy_store.py
Apache-2.0
def test_log_batch_with_unchanged_and_new_params(store: SqlAlchemyStore): """ Test case to ensure the following code works: --------------------------------------------- mlflow.log_params({"a": 0, "b": 1}) mlflow.log_params({"a": 0, "c": 2}) --------------------------------------------- """ ...
Test case to ensure the following code works: --------------------------------------------- mlflow.log_params({"a": 0, "b": 1}) mlflow.log_params({"a": 0, "c": 2}) ---------------------------------------------
test_log_batch_with_unchanged_and_new_params
python
mlflow/mlflow
tests/store/tracking/test_sqlalchemy_store.py
https://github.com/mlflow/mlflow/blob/master/tests/store/tracking/test_sqlalchemy_store.py
Apache-2.0
def test_search_runs_returns_expected_results_with_large_experiment( store: SqlAlchemyStore, ): """ This case tests the SQLAlchemyStore implementation of the SearchRuns API to ensure that search queries over an experiment containing many runs, each with a large number of metrics, parameters, and tag...
This case tests the SQLAlchemyStore implementation of the SearchRuns API to ensure that search queries over an experiment containing many runs, each with a large number of metrics, parameters, and tags, are performant and return the expected results.
test_search_runs_returns_expected_results_with_large_experiment
python
mlflow/mlflow
tests/store/tracking/test_sqlalchemy_store.py
https://github.com/mlflow/mlflow/blob/master/tests/store/tracking/test_sqlalchemy_store.py
Apache-2.0
def _create_trace( store: SqlAlchemyStore, request_id: str, experiment_id=0, timestamp_ms=0, execution_time_ms=0, status=TraceStatus.OK, request_metadata=None, tags=None, ) -> TraceInfoV2: """Helper function to create a test trace in the database.""" if not store.get_experiment(e...
Helper function to create a test trace in the database.
_create_trace
python
mlflow/mlflow
tests/store/tracking/test_sqlalchemy_store.py
https://github.com/mlflow/mlflow/blob/master/tests/store/tracking/test_sqlalchemy_store.py
Apache-2.0
def test_running_migrations_generates_expected_schema(tmp_path, expected_schema_file, db_url): """Test that migrating an existing database generates the desired schema.""" engine = sqlalchemy.create_engine(db_url) InitialBase.metadata.create_all(engine) invoke_cli_runner(mlflow.db.commands, ["upgrade", ...
Test that migrating an existing database generates the desired schema.
test_running_migrations_generates_expected_schema
python
mlflow/mlflow
tests/store/tracking/test_sqlalchemy_store_schema.py
https://github.com/mlflow/mlflow/blob/master/tests/store/tracking/test_sqlalchemy_store_schema.py
Apache-2.0
def configure_client_for_uc(mock_databricks_uc_host_creds): """ Configure MLflow client to register models to UC """ with mock.patch("mlflow.utils.databricks_utils.get_databricks_host_creds"): orig_registry_uri = mlflow.get_registry_uri() mlflow.set_registry_uri("databricks-uc") ...
Configure MLflow client to register models to UC
configure_client_for_uc
python
mlflow/mlflow
tests/store/_unity_catalog/conftest.py
https://github.com/mlflow/mlflow/blob/master/tests/store/_unity_catalog/conftest.py
Apache-2.0
def test_create_registered_model_three_level_name_hint(store): """Test that creating a registered model with invalid name provides legacy registry hint.""" # Mock the _call_endpoint method to raise a RestException with # "specify all three levels" message original_error_message = "Model name must specif...
Test that creating a registered model with invalid name provides legacy registry hint.
test_create_registered_model_three_level_name_hint
python
mlflow/mlflow
tests/store/_unity_catalog/model_registry/test_unity_catalog_rest_store.py
https://github.com/mlflow/mlflow/blob/master/tests/store/_unity_catalog/model_registry/test_unity_catalog_rest_store.py
Apache-2.0
def test_create_registered_model_three_level_name_hint_with_period(store): """Test the hint works correctly when original error message ends with a period.""" original_error_message = "Model name must specify all three levels." rest_exception = RestException( {"error_code": "INVALID_PARAMETER_VALUE"...
Test the hint works correctly when original error message ends with a period.
test_create_registered_model_three_level_name_hint_with_period
python
mlflow/mlflow
tests/store/_unity_catalog/model_registry/test_unity_catalog_rest_store.py
https://github.com/mlflow/mlflow/blob/master/tests/store/_unity_catalog/model_registry/test_unity_catalog_rest_store.py
Apache-2.0
def test_create_registered_model_metastore_does_not_exist_hint(store): """ Test that creating a registered model when metastore doesn't exist provides legacy registry hint. """ # Mock the _call_endpoint method to raise a RestException with # "METASTORE_DOES_NOT_EXIST" message original_error_...
Test that creating a registered model when metastore doesn't exist provides legacy registry hint.
test_create_registered_model_metastore_does_not_exist_hint
python
mlflow/mlflow
tests/store/_unity_catalog/model_registry/test_unity_catalog_rest_store.py
https://github.com/mlflow/mlflow/blob/master/tests/store/_unity_catalog/model_registry/test_unity_catalog_rest_store.py
Apache-2.0
def test_create_registered_model_other_rest_exceptions_not_modified(store): """ Test that RestExceptions unrelated to bad UC model names are not modified and are re-raised as-is. """ original_error_message = "Some other error" rest_exception = RestException( {"error_code": "INTERNAL_ERRO...
Test that RestExceptions unrelated to bad UC model names are not modified and are re-raised as-is.
test_create_registered_model_other_rest_exceptions_not_modified
python
mlflow/mlflow
tests/store/_unity_catalog/model_registry/test_unity_catalog_rest_store.py
https://github.com/mlflow/mlflow/blob/master/tests/store/_unity_catalog/model_registry/test_unity_catalog_rest_store.py
Apache-2.0
def _assert_create_model_version_endpoints_called( request_mock, name, source, version, run_id=None, description=None, extra_headers=None, tags=None, model_version_dependencies=None, ): """ Asserts that endpoints related to the model version creation flow were called on the p...
Asserts that endpoints related to the model version creation flow were called on the provided `request_mock`
_assert_create_model_version_endpoints_called
python
mlflow/mlflow
tests/store/_unity_catalog/model_registry/test_unity_catalog_rest_store.py
https://github.com/mlflow/mlflow/blob/master/tests/store/_unity_catalog/model_registry/test_unity_catalog_rest_store.py
Apache-2.0
def test_link_prompt_version_to_model_success(store): """Test successful Unity Catalog linking with API call.""" with ( mock.patch.object(store, "_edit_endpoint_and_call") as mock_edit_call, mock.patch.object(store, "_get_endpoint_from_method") as mock_get_endpoint, mock.patch( ...
Test successful Unity Catalog linking with API call.
test_link_prompt_version_to_model_success
python
mlflow/mlflow
tests/store/_unity_catalog/model_registry/test_unity_catalog_rest_store.py
https://github.com/mlflow/mlflow/blob/master/tests/store/_unity_catalog/model_registry/test_unity_catalog_rest_store.py
Apache-2.0
def test_link_prompt_version_to_model_sets_tag(mock_get_tracking_store, store): """Test that linking a prompt version to a model sets the appropriate tag.""" # Setup mocks mock_tracking_store = mock.Mock() mock_get_tracking_store.return_value = mock_tracking_store # Mock the prompt version moc...
Test that linking a prompt version to a model sets the appropriate tag.
test_link_prompt_version_to_model_sets_tag
python
mlflow/mlflow
tests/store/_unity_catalog/model_registry/test_unity_catalog_rest_store.py
https://github.com/mlflow/mlflow/blob/master/tests/store/_unity_catalog/model_registry/test_unity_catalog_rest_store.py
Apache-2.0
def test_link_prompts_to_trace_success(store): """Test successful Unity Catalog linking prompts to a trace with API call.""" with ( mock.patch.object(store, "_edit_endpoint_and_call") as mock_edit_call, mock.patch.object(store, "_get_endpoint_from_method") as mock_get_endpoint, mock.pat...
Test successful Unity Catalog linking prompts to a trace with API call.
test_link_prompts_to_trace_success
python
mlflow/mlflow
tests/store/_unity_catalog/model_registry/test_unity_catalog_rest_store.py
https://github.com/mlflow/mlflow/blob/master/tests/store/_unity_catalog/model_registry/test_unity_catalog_rest_store.py
Apache-2.0
def test_link_prompt_version_to_run_success(store): """Test successful Unity Catalog linking prompt version to run with API call.""" with ( mock.patch.object(store, "_edit_endpoint_and_call") as mock_edit_call, mock.patch.object(store, "_get_endpoint_from_method") as mock_get_endpoint, ...
Test successful Unity Catalog linking prompt version to run with API call.
test_link_prompt_version_to_run_success
python
mlflow/mlflow
tests/store/_unity_catalog/model_registry/test_unity_catalog_rest_store.py
https://github.com/mlflow/mlflow/blob/master/tests/store/_unity_catalog/model_registry/test_unity_catalog_rest_store.py
Apache-2.0
def test_link_prompt_version_to_run_sets_tag(mock_get_tracking_store, store): """Test that linking a prompt version to a run sets the appropriate tag.""" # Setup mocks mock_tracking_store = mock.Mock() mock_get_tracking_store.return_value = mock_tracking_store # Mock the prompt version mock_pr...
Test that linking a prompt version to a run sets the appropriate tag.
test_link_prompt_version_to_run_sets_tag
python
mlflow/mlflow
tests/store/_unity_catalog/model_registry/test_unity_catalog_rest_store.py
https://github.com/mlflow/mlflow/blob/master/tests/store/_unity_catalog/model_registry/test_unity_catalog_rest_store.py
Apache-2.0
def test_proto_to_mlflow_prompt(): """Test that proto_to_mlflow_prompt correctly handles the decoupled tag architecture.""" # Test with version tags - the key behavior we care about proto_version = ProtoPromptVersion() proto_version.name = "test_prompt" proto_version.version = "1" proto_version...
Test that proto_to_mlflow_prompt correctly handles the decoupled tag architecture.
test_proto_to_mlflow_prompt
python
mlflow/mlflow
tests/store/_unity_catalog/registry/test_uc_prompt_utils.py
https://github.com/mlflow/mlflow/blob/master/tests/store/_unity_catalog/registry/test_uc_prompt_utils.py
Apache-2.0
def eval_input_fn(features, labels, batch_size): """An input function for evaluation or prediction""" features = dict(features) # Use only features when labels are null. inputs = features if labels is None else (features, labels) # Convert the inputs to a Dataset. dataset = tf.data.Dataset.fro...
An input function for evaluation or prediction
eval_input_fn
python
mlflow/mlflow
tests/tensorflow/iris_data_utils.py
https://github.com/mlflow/mlflow/blob/master/tests/tensorflow/iris_data_utils.py
Apache-2.0
def test_model_load_succeeds_with_missing_data_key_when_data_exists_at_default_path( tf_keras_model, model_path, data ): """ This is a backwards compatibility test to ensure that models saved in MLflow version <= 0.8.0 can be loaded successfully. These models are missing the `data` flavor configuration ...
This is a backwards compatibility test to ensure that models saved in MLflow version <= 0.8.0 can be loaded successfully. These models are missing the `data` flavor configuration key.
test_model_load_succeeds_with_missing_data_key_when_data_exists_at_default_path
python
mlflow/mlflow
tests/tensorflow/test_keras_model_export.py
https://github.com/mlflow/mlflow/blob/master/tests/tensorflow/test_keras_model_export.py
Apache-2.0
def test_save_model_with_tf_save_format(model_path): """Ensures that Keras models can be saved with SavedModel format. Using SavedModel format (save_format="tf") requires that the file extension is _not_ "h5". """ keras_model = mock.Mock(spec=tf.keras.Model) mlflow.tensorflow.save_model( ...
Ensures that Keras models can be saved with SavedModel format. Using SavedModel format (save_format="tf") requires that the file extension is _not_ "h5".
test_save_model_with_tf_save_format
python
mlflow/mlflow
tests/tensorflow/test_keras_model_export.py
https://github.com/mlflow/mlflow/blob/master/tests/tensorflow/test_keras_model_export.py
Apache-2.0
def test_save_and_load_model_with_tf_save_format(tf_keras_model, model_path, data): """Ensures that keras models saved with save_format="tf" can be loaded.""" mlflow.tensorflow.save_model( tf_keras_model, path=model_path, keras_model_kwargs={"save_format": "tf"} ) model_conf_path = os.path.join(...
Ensures that keras models saved with save_format="tf" can be loaded.
test_save_and_load_model_with_tf_save_format
python
mlflow/mlflow
tests/tensorflow/test_keras_model_export.py
https://github.com/mlflow/mlflow/blob/master/tests/tensorflow/test_keras_model_export.py
Apache-2.0
def test_load_without_save_format(tf_keras_model, model_path, data): """Ensures that keras models without save_format can still be loaded.""" mlflow.tensorflow.save_model( tf_keras_model, path=model_path, keras_model_kwargs={"save_format": "h5"} ) model_conf_path = os.path.join(model_path, "MLmo...
Ensures that keras models without save_format can still be loaded.
test_load_without_save_format
python
mlflow/mlflow
tests/tensorflow/test_keras_model_export.py
https://github.com/mlflow/mlflow/blob/master/tests/tensorflow/test_keras_model_export.py
Apache-2.0
def single_multidim_tensor_input_model(data): """ This is a model that requires a single input of shape (-1, 4, 3) """ x, y = data model = Sequential() # This decorator injects the decorated class or function into the Keras custom # object dictionary, so that it can be serialized and deseri...
This is a model that requires a single input of shape (-1, 4, 3)
single_multidim_tensor_input_model
python
mlflow/mlflow
tests/tensorflow/test_keras_pyfunc_model_works_with_all_input_types.py
https://github.com/mlflow/mlflow/blob/master/tests/tensorflow/test_keras_pyfunc_model_works_with_all_input_types.py
Apache-2.0
def multi_multidim_tensor_input_model(data): """ This is a model that requires 2 inputs: 'a' and 'b', input 'a' must be shape of (-1, 2, 3), input 'b' must be shape of (-1, 2, 5), """ x, y = data input_a = Input(shape=(2, 3), name="a") input_b = Input(shape=(2, 5), name="b") @regist...
This is a model that requires 2 inputs: 'a' and 'b', input 'a' must be shape of (-1, 2, 3), input 'b' must be shape of (-1, 2, 5),
multi_multidim_tensor_input_model
python
mlflow/mlflow
tests/tensorflow/test_keras_pyfunc_model_works_with_all_input_types.py
https://github.com/mlflow/mlflow/blob/master/tests/tensorflow/test_keras_pyfunc_model_works_with_all_input_types.py
Apache-2.0
def test_tf_keras_autolog_logs_metrics_for_single_epoch_training( random_train_data, random_one_hot_labels ): """ tf.Keras exhibits inconsistent epoch indexing behavior in comparison with other TF2 APIs (e.g., tf.Estimator). tf.Keras uses zero-indexing for epochs, while other APIs use one-indexing. ...
tf.Keras exhibits inconsistent epoch indexing behavior in comparison with other TF2 APIs (e.g., tf.Estimator). tf.Keras uses zero-indexing for epochs, while other APIs use one-indexing. Accordingly, this test verifies that metrics are produced in the boundary case where a model is trained for a single ...
test_tf_keras_autolog_logs_metrics_for_single_epoch_training
python
mlflow/mlflow
tests/tensorflow/test_tensorflow2_autolog.py
https://github.com/mlflow/mlflow/blob/master/tests/tensorflow/test_tensorflow2_autolog.py
Apache-2.0
def test_tf_keras_autolog_does_not_mutate_original_callbacks_list( tmp_path, random_train_data, random_one_hot_labels, positional ): """ TensorFlow autologging passes new callbacks to the `fit()` / `fit_generator()` function. If preexisting user-defined callbacks already exist, these new callbacks are a...
TensorFlow autologging passes new callbacks to the `fit()` / `fit_generator()` function. If preexisting user-defined callbacks already exist, these new callbacks are added to the user-specified ones. This test verifies that the new callbacks are added to the without permanently mutating the original li...
test_tf_keras_autolog_does_not_mutate_original_callbacks_list
python
mlflow/mlflow
tests/tensorflow/test_tensorflow2_autolog.py
https://github.com/mlflow/mlflow/blob/master/tests/tensorflow/test_tensorflow2_autolog.py
Apache-2.0
def test_autolog_text_vec_model(tmp_path): """ Verifies autolog successfully saves a model that can't be saved in the H5 format """ mlflow.tensorflow.autolog() train_samples = tf.convert_to_tensor(["this is an example", "another example"]) train_labels = np.array([0.4, 0.2]) model = get_tex...
Verifies autolog successfully saves a model that can't be saved in the H5 format
test_autolog_text_vec_model
python
mlflow/mlflow
tests/tensorflow/test_tensorflow2_autolog.py
https://github.com/mlflow/mlflow/blob/master/tests/tensorflow/test_tensorflow2_autolog.py
Apache-2.0
def test_fluent_autolog_with_tf_keras_logs_expected_content( random_train_data, random_one_hot_labels ): """ Guards against previously-exhibited issues where using the fluent `mlflow.autolog()` API with `tf.keras` Models did not work due to conflicting patches set by both the `mlflow.tensorflow.auto...
Guards against previously-exhibited issues where using the fluent `mlflow.autolog()` API with `tf.keras` Models did not work due to conflicting patches set by both the `mlflow.tensorflow.autolog()` and the `mlflow.keras.autolog()` APIs.
test_fluent_autolog_with_tf_keras_logs_expected_content
python
mlflow/mlflow
tests/tensorflow/test_tensorflow2_autolog.py
https://github.com/mlflow/mlflow/blob/master/tests/tensorflow/test_tensorflow2_autolog.py
Apache-2.0
def otel_collector(): """Start an OpenTelemetry collector in a Docker container.""" subprocess.run(["docker", "pull", "otel/opentelemetry-collector-contrib"], check=True) with ( tempfile.NamedTemporaryFile() as output_file, subprocess.Popen( [ "docker", ...
Start an OpenTelemetry collector in a Docker container.
otel_collector
python
mlflow/mlflow
tests/tracing/conftest.py
https://github.com/mlflow/mlflow/blob/master/tests/tracing/conftest.py
Apache-2.0
def create_mock_otel_span( trace_id: int, span_id: int, name: str = "test_span", parent_id: Optional[int] = None, start_time: Optional[int] = None, end_time: Optional[int] = None, ): """ Create a mock OpenTelemetry span for testing purposes. OpenTelemetry doesn't allow creating a sp...
Create a mock OpenTelemetry span for testing purposes. OpenTelemetry doesn't allow creating a span outside of a tracer. So here we create a mock span that extends ReadableSpan (data object) and exposes the necessary attributes for testing.
create_mock_otel_span
python
mlflow/mlflow
tests/tracing/helper.py
https://github.com/mlflow/mlflow/blob/master/tests/tracing/helper.py
Apache-2.0
def get_tracer_tracking_uri() -> Optional[str]: """Get current tracking URI configured as the trace export destination.""" from opentelemetry import trace tracer = _get_tracer(__name__) if isinstance(tracer, trace.ProxyTracer): tracer = tracer._tracer span_processor = tracer.span_processor....
Get current tracking URI configured as the trace export destination.
get_tracer_tracking_uri
python
mlflow/mlflow
tests/tracing/helper.py
https://github.com/mlflow/mlflow/blob/master/tests/tracing/helper.py
Apache-2.0
def reset_autolog_state(): """Reset autologging state to avoid interference between tests""" yield for flavor in FLAVOR_TO_MODULE_NAME: # 1. Remove post-import hooks (registered by global mlflow.autolog() function) mlflow.utils.import_hooks._post_import_hooks.pop(flavor, None) for flav...
Reset autologging state to avoid interference between tests
reset_autolog_state
python
mlflow/mlflow
tests/tracing/helper.py
https://github.com/mlflow/mlflow/blob/master/tests/tracing/helper.py
Apache-2.0
def score_in_model_serving(model_uri: str, model_input: dict): """ A helper function to emulate model prediction inside a Databricks model serving environment. This is highly simplified version, but captures important aspects for testing tracing: 1. Setting env vars that users set for enable tracing ...
A helper function to emulate model prediction inside a Databricks model serving environment. This is highly simplified version, but captures important aspects for testing tracing: 1. Setting env vars that users set for enable tracing in model serving 2. Load the model in a background thread
score_in_model_serving
python
mlflow/mlflow
tests/tracing/helper.py
https://github.com/mlflow/mlflow/blob/master/tests/tracing/helper.py
Apache-2.0
def skip_module_when_testing_trace_sdk(): """Skip the entire module if only mlflow-tracing package is installed""" if IS_TRACING_SDK_ONLY: pytest.skip( "Skipping test because it requires mlflow or mlflow-skinny to be installed.", allow_module_level=True, )
Skip the entire module if only mlflow-tracing package is installed
skip_module_when_testing_trace_sdk
python
mlflow/mlflow
tests/tracing/helper.py
https://github.com/mlflow/mlflow/blob/master/tests/tracing/helper.py
Apache-2.0
def test_log_feedback_with_exception_object(store, tracking_uri, legacy_api): """Test that log_feedback correctly accepts Exception objects.""" test_exception = ValueError("Test exception message") if legacy_api: mlflow.log_feedback( trace_id="1234", name="faithfulness", ...
Test that log_feedback correctly accepts Exception objects.
test_log_feedback_with_exception_object
python
mlflow/mlflow
tests/tracing/test_assessment.py
https://github.com/mlflow/mlflow/blob/master/tests/tracing/test_assessment.py
Apache-2.0
def test_update_current_trace_client_request_id_overwrites(): """Test that client_request_id can be overwritten by subsequent calls.""" from mlflow.tracing.trace_manager import InMemoryTraceManager with mlflow.start_span("overwrite_test") as span: # First set mlflow.update_current_trace(cli...
Test that client_request_id can be overwritten by subsequent calls.
test_update_current_trace_client_request_id_overwrites
python
mlflow/mlflow
tests/tracing/test_fluent.py
https://github.com/mlflow/mlflow/blob/master/tests/tracing/test_fluent.py
Apache-2.0
def test_update_current_trace_client_request_id_stringification(): """Test that client_request_id is stringified when it's not a string.""" from mlflow.tracing.trace_manager import InMemoryTraceManager test_cases = [ (123, "123"), (45.67, "45.67"), (True, "True"), (False, "F...
Test that client_request_id is stringified when it's not a string.
test_update_current_trace_client_request_id_stringification
python
mlflow/mlflow
tests/tracing/test_fluent.py
https://github.com/mlflow/mlflow/blob/master/tests/tracing/test_fluent.py
Apache-2.0
def test_update_current_trace_with_metadata(): """Test that update_current_trace correctly handles metadata parameter.""" @mlflow.trace def f(): mlflow.update_current_trace( metadata={ "mlflow.source.name": "inference.py", "mlflow.source.git.commit": "123...
Test that update_current_trace correctly handles metadata parameter.
test_update_current_trace_with_metadata
python
mlflow/mlflow
tests/tracing/test_fluent.py
https://github.com/mlflow/mlflow/blob/master/tests/tracing/test_fluent.py
Apache-2.0
def test_update_current_trace_should_not_raise_during_model_logging(): """ Tracing is disabled while model logging. When the model includes `update_current_trace` call, it should be no-op. """ class MyModel(mlflow.pyfunc.PythonModel): @mlflow.trace def predict(self, model_inputs): ...
Tracing is disabled while model logging. When the model includes `update_current_trace` call, it should be no-op.
test_update_current_trace_should_not_raise_during_model_logging
python
mlflow/mlflow
tests/tracing/test_fluent.py
https://github.com/mlflow/mlflow/blob/master/tests/tracing/test_fluent.py
Apache-2.0
def test_update_current_trace_state_none(): """Test that state=None doesn't change trace state.""" from mlflow.tracing.trace_manager import InMemoryTraceManager with mlflow.start_span("test_span") as span: # First set state to OK mlflow.update_current_trace(state="OK") # Then call ...
Test that state=None doesn't change trace state.
test_update_current_trace_state_none
python
mlflow/mlflow
tests/tracing/test_fluent.py
https://github.com/mlflow/mlflow/blob/master/tests/tracing/test_fluent.py
Apache-2.0
def test_update_current_trace_state_validation(): """Test that state validation only allows OK or ERROR.""" with mlflow.start_span("test_span"): # Valid states should work mlflow.update_current_trace(state="OK") mlflow.update_current_trace(state="ERROR") mlflow.update_current_tra...
Test that state validation only allows OK or ERROR.
test_update_current_trace_state_validation
python
mlflow/mlflow
tests/tracing/test_fluent.py
https://github.com/mlflow/mlflow/blob/master/tests/tracing/test_fluent.py
Apache-2.0
def test_span_record_exception_invalid_type(): """Test record_exception method with invalid parameter type.""" with mlflow.start_span("test_span") as span: with pytest.raises( MlflowException, match="The `exception` parameter must be an Exception instance or a string", ):...
Test record_exception method with invalid parameter type.
test_span_record_exception_invalid_type
python
mlflow/mlflow
tests/tracing/test_fluent.py
https://github.com/mlflow/mlflow/blob/master/tests/tracing/test_fluent.py
Apache-2.0
def test_combined_state_and_record_exception(): """Test using both status update and record_exception together.""" @mlflow.trace def test_function(): # Get current span and record exception span = mlflow.get_current_active_span() span.record_exception("Processing failed") #...
Test using both status update and record_exception together.
test_combined_state_and_record_exception
python
mlflow/mlflow
tests/tracing/test_fluent.py
https://github.com/mlflow/mlflow/blob/master/tests/tracing/test_fluent.py
Apache-2.0
def test_span_record_exception_no_op_span(): """Test that record_exception works gracefully with NoOpSpan.""" # This should not raise an exception from mlflow.entities.span import NoOpSpan no_op_span = NoOpSpan() no_op_span.record_exception("This should be ignored") # Should not create any tra...
Test that record_exception works gracefully with NoOpSpan.
test_span_record_exception_no_op_span
python
mlflow/mlflow
tests/tracing/test_fluent.py
https://github.com/mlflow/mlflow/blob/master/tests/tracing/test_fluent.py
Apache-2.0
def test_update_current_trace_state_isolation(): """Test that state update doesn't affect span status.""" with mlflow.start_span("test_span") as span: # Set span status to OK explicitly span.set_status("OK") # Update trace state to ERROR mlflow.update_current_trace(state="ERROR"...
Test that state update doesn't affect span status.
test_update_current_trace_state_isolation
python
mlflow/mlflow
tests/tracing/test_fluent.py
https://github.com/mlflow/mlflow/blob/master/tests/tracing/test_fluent.py
Apache-2.0
def test_size_bytes_in_trace_sent_to_mlflow_backend(monkeypatch): """Test that SIZE_BYTES is correctly set in the trace sent to MLflow backend via dual write.""" # Enable dual write monkeypatch.setenv("MLFLOW_ENABLE_TRACE_DUAL_WRITE_IN_MODEL_SERVING", "True") # Create spans and trace otel_span = cr...
Test that SIZE_BYTES is correctly set in the trace sent to MLflow backend via dual write.
test_size_bytes_in_trace_sent_to_mlflow_backend
python
mlflow/mlflow
tests/tracing/export/test_inference_table_exporter.py
https://github.com/mlflow/mlflow/blob/master/tests/tracing/export/test_inference_table_exporter.py
Apache-2.0
def test_prompt_linking_with_dual_write(monkeypatch): """Test that prompts are correctly linked when dual write to MLflow backend is enabled.""" # Enable dual write monkeypatch.setenv("MLFLOW_ENABLE_TRACE_DUAL_WRITE_IN_MODEL_SERVING", "True") # Create span and trace otel_span = create_mock_otel_spa...
Test that prompts are correctly linked when dual write to MLflow backend is enabled.
test_prompt_linking_with_dual_write
python
mlflow/mlflow
tests/tracing/export/test_inference_table_exporter.py
https://github.com/mlflow/mlflow/blob/master/tests/tracing/export/test_inference_table_exporter.py
Apache-2.0
def test_prompt_linking_disabled_without_dual_write(monkeypatch): """Test that prompt linking is not attempted when dual write is disabled.""" # Disable dual write monkeypatch.setenv("MLFLOW_ENABLE_TRACE_DUAL_WRITE_IN_MODEL_SERVING", "False") # Create span and trace otel_span = create_mock_otel_spa...
Test that prompt linking is not attempted when dual write is disabled.
test_prompt_linking_disabled_without_dual_write
python
mlflow/mlflow
tests/tracing/export/test_inference_table_exporter.py
https://github.com/mlflow/mlflow/blob/master/tests/tracing/export/test_inference_table_exporter.py
Apache-2.0
def test_prompt_linking_with_empty_prompts(monkeypatch): """Test that empty prompts list doesn't cause issues with dual write.""" # Enable dual write monkeypatch.setenv("MLFLOW_ENABLE_TRACE_DUAL_WRITE_IN_MODEL_SERVING", "True") # Create span and trace otel_span = create_mock_otel_span( name...
Test that empty prompts list doesn't cause issues with dual write.
test_prompt_linking_with_empty_prompts
python
mlflow/mlflow
tests/tracing/export/test_inference_table_exporter.py
https://github.com/mlflow/mlflow/blob/master/tests/tracing/export/test_inference_table_exporter.py
Apache-2.0
def test_prompt_linking_error_handling_with_dual_write(monkeypatch): """Test that prompt linking errors are handled gracefully with dual write enabled.""" # Enable dual write monkeypatch.setenv("MLFLOW_ENABLE_TRACE_DUAL_WRITE_IN_MODEL_SERVING", "True") # Create span and trace otel_span = create_moc...
Test that prompt linking errors are handled gracefully with dual write enabled.
test_prompt_linking_error_handling_with_dual_write
python
mlflow/mlflow
tests/tracing/export/test_inference_table_exporter.py
https://github.com/mlflow/mlflow/blob/master/tests/tracing/export/test_inference_table_exporter.py
Apache-2.0
def join_thread_by_name_prefix(prefix: str, timeout: float = 5.0): """Join thread by name prefix to avoid time.sleep in tests.""" for thread in threading.enumerate(): if thread != threading.main_thread() and thread.name.startswith(prefix): thread.join(timeout=timeout)
Join thread by name prefix to avoid time.sleep in tests.
join_thread_by_name_prefix
python
mlflow/mlflow
tests/tracing/export/test_mlflow_v3_exporter.py
https://github.com/mlflow/mlflow/blob/master/tests/tracing/export/test_mlflow_v3_exporter.py
Apache-2.0
def test_prompt_linking_in_mlflow_v3_exporter(is_async, monkeypatch): """Test that prompts are correctly linked when using MLflow v3 exporter.""" monkeypatch.setenv("DATABRICKS_HOST", "dummy-host") monkeypatch.setenv("DATABRICKS_TOKEN", "dummy-token") monkeypatch.setenv("MLFLOW_ENABLE_ASYNC_TRACE_LOGGIN...
Test that prompts are correctly linked when using MLflow v3 exporter.
test_prompt_linking_in_mlflow_v3_exporter
python
mlflow/mlflow
tests/tracing/export/test_mlflow_v3_exporter.py
https://github.com/mlflow/mlflow/blob/master/tests/tracing/export/test_mlflow_v3_exporter.py
Apache-2.0
def test_prompt_linking_with_empty_prompts_mlflow_v3(is_async, monkeypatch): """Test that empty prompts list doesn't cause issues with MLflow v3 exporter.""" monkeypatch.setenv("DATABRICKS_HOST", "dummy-host") monkeypatch.setenv("DATABRICKS_TOKEN", "dummy-token") monkeypatch.setenv("MLFLOW_ENABLE_ASYNC_...
Test that empty prompts list doesn't cause issues with MLflow v3 exporter.
test_prompt_linking_with_empty_prompts_mlflow_v3
python
mlflow/mlflow
tests/tracing/export/test_mlflow_v3_exporter.py
https://github.com/mlflow/mlflow/blob/master/tests/tracing/export/test_mlflow_v3_exporter.py
Apache-2.0
def test_prompt_linking_error_handling_mlflow_v3(monkeypatch): """Test that MLflow v3 exporter handles prompt linking errors gracefully.""" monkeypatch.setenv("DATABRICKS_HOST", "dummy-host") monkeypatch.setenv("DATABRICKS_TOKEN", "dummy-token") monkeypatch.setenv("MLFLOW_ENABLE_ASYNC_TRACE_LOGGING", "F...
Test that MLflow v3 exporter handles prompt linking errors gracefully.
test_prompt_linking_error_handling_mlflow_v3
python
mlflow/mlflow
tests/tracing/export/test_mlflow_v3_exporter.py
https://github.com/mlflow/mlflow/blob/master/tests/tracing/export/test_mlflow_v3_exporter.py
Apache-2.0
def test_on_end_preserves_user_set_trace_state(): """Test that explicitly set trace state is preserved when span ends.""" otel_span = create_mock_otel_span( name="foo", trace_id=_OTEL_TRACE_ID, span_id=1, parent_id=None, start_time=5_000_000, end_time=9_000_000, ...
Test that explicitly set trace state is preserved when span ends.
test_on_end_preserves_user_set_trace_state
python
mlflow/mlflow
tests/tracing/processor/test_inference_table_processor.py
https://github.com/mlflow/mlflow/blob/master/tests/tracing/processor/test_inference_table_processor.py
Apache-2.0
def test_on_end_updates_trace_state_when_in_progress(): """Test that trace state is updated from span when trace is still IN_PROGRESS.""" otel_span = create_mock_otel_span( name="foo", trace_id=_OTEL_TRACE_ID, span_id=1, parent_id=None, start_time=5_000_000, end_t...
Test that trace state is updated from span when trace is still IN_PROGRESS.
test_on_end_updates_trace_state_when_in_progress
python
mlflow/mlflow
tests/tracing/processor/test_inference_table_processor.py
https://github.com/mlflow/mlflow/blob/master/tests/tracing/processor/test_inference_table_processor.py
Apache-2.0
def _await_server_up_or_die(port, timeout=30): """Waits until the local flask server is listening on the given port.""" _logger.info(f"Awaiting server to be up on {LOCALHOST}:{port}") start_time = time.time() while time.time() - start_time < timeout: with socket.socket(socket.AF_INET, socket.SOC...
Waits until the local flask server is listening on the given port.
_await_server_up_or_die
python
mlflow/mlflow
tests/tracking/integration_test_utils.py
https://github.com/mlflow/mlflow/blob/master/tests/tracking/integration_test_utils.py
Apache-2.0
def _init_server(backend_uri, root_artifact_uri, extra_env=None, app="mlflow.server:app"): """ Launch a new REST server using the tracking store specified by backend_uri and root artifact directory specified by root_artifact_uri. :returns A tuple (url, process) containing the string URL of the server an...
Launch a new REST server using the tracking store specified by backend_uri and root artifact directory specified by root_artifact_uri. :returns A tuple (url, process) containing the string URL of the server and a handle to the server process (a multiprocessing.Process object).
_init_server
python
mlflow/mlflow
tests/tracking/integration_test_utils.py
https://github.com/mlflow/mlflow/blob/master/tests/tracking/integration_test_utils.py
Apache-2.0
def _send_rest_tracking_post_request(tracking_server_uri, api_path, json_payload, auth=None): """ Make a POST request to the specified MLflow Tracking API and retrieve the corresponding `requests.Response` object """ import requests url = tracking_server_uri + api_path return requests.post(...
Make a POST request to the specified MLflow Tracking API and retrieve the corresponding `requests.Response` object
_send_rest_tracking_post_request
python
mlflow/mlflow
tests/tracking/integration_test_utils.py
https://github.com/mlflow/mlflow/blob/master/tests/tracking/integration_test_utils.py
Apache-2.0
def tracking_uri(request, tmp_path): """Set an MLflow Tracking URI with different type of backend.""" if "MLFLOW_SKINNY" in os.environ and request.param == "sqlalchemy": pytest.skip("SQLAlchemy store is not available in skinny.") original_tracking_uri = mlflow.get_tracking_uri() if request.par...
Set an MLflow Tracking URI with different type of backend.
tracking_uri
python
mlflow/mlflow
tests/tracking/test_client.py
https://github.com/mlflow/mlflow/blob/master/tests/tracking/test_client.py
Apache-2.0
def test_update_registered_model(mock_registry_store): """ Update registered model no longer supports name change. """ expected_return_value = "some expected return value." mock_registry_store.rename_registered_model.return_value = expected_return_value expected_return_value_2 = "other expected ...
Update registered model no longer supports name change.
test_update_registered_model
python
mlflow/mlflow
tests/tracking/test_client.py
https://github.com/mlflow/mlflow/blob/master/tests/tracking/test_client.py
Apache-2.0
def test_create_model_version(mock_registry_store): """ Basic test for create model version. """ mock_registry_store.create_model_version.return_value = _default_model_version() res = MlflowClient(registry_uri="sqlite:///somedb.db").create_model_version( "orig name", "source", "run-id", tags...
Basic test for create model version.
test_create_model_version
python
mlflow/mlflow
tests/tracking/test_client.py
https://github.com/mlflow/mlflow/blob/master/tests/tracking/test_client.py
Apache-2.0
def test_update_model_version(mock_registry_store): """ Update registered model no longer support state changes. """ mock_registry_store.update_model_version.return_value = _default_model_version() res = MlflowClient(registry_uri="sqlite:///somedb.db").update_model_version( name="orig name",...
Update registered model no longer support state changes.
test_update_model_version
python
mlflow/mlflow
tests/tracking/test_client.py
https://github.com/mlflow/mlflow/blob/master/tests/tracking/test_client.py
Apache-2.0
def test_client_can_be_serialized_with_pickle(tmp_path): """ Verifies that instances of `MlflowClient` can be serialized using pickle, even if the underlying Tracking and Model Registry stores used by the client are not serializable using pickle """ class MockUnpickleableTrackingStore(SqlAlchemyTra...
Verifies that instances of `MlflowClient` can be serialized using pickle, even if the underlying Tracking and Model Registry stores used by the client are not serializable using pickle
test_client_can_be_serialized_with_pickle
python
mlflow/mlflow
tests/tracking/test_client.py
https://github.com/mlflow/mlflow/blob/master/tests/tracking/test_client.py
Apache-2.0
def registry_uri(request, tmp_path): """Set an MLflow Model Registry URI with different type of backend.""" if "MLFLOW_SKINNY" in os.environ and request.param == "sqlalchemy": pytest.skip("SQLAlchemy store is not available in skinny.") original_registry_uri = mlflow.get_registry_uri() if reque...
Set an MLflow Model Registry URI with different type of backend.
registry_uri
python
mlflow/mlflow
tests/tracking/test_client.py
https://github.com/mlflow/mlflow/blob/master/tests/tracking/test_client.py
Apache-2.0
def test_delete_prompt_version_no_auto_cleanup(tracking_uri): """Test that delete_prompt_version no longer automatically deletes prompts""" client = MlflowClient(tracking_uri=tracking_uri) # Create prompt and version client.register_prompt(name="test_prompt", template="Hello {{name}}!") # Verify p...
Test that delete_prompt_version no longer automatically deletes prompts
test_delete_prompt_version_no_auto_cleanup
python
mlflow/mlflow
tests/tracking/test_client.py
https://github.com/mlflow/mlflow/blob/master/tests/tracking/test_client.py
Apache-2.0
def test_delete_prompt_with_no_versions(tracking_uri): """Test that delete_prompt works when prompt has no versions""" client = MlflowClient(tracking_uri=tracking_uri) # Create prompt and version, then delete version client.register_prompt(name="empty_prompt", template="Hello {{name}}!") client.del...
Test that delete_prompt works when prompt has no versions
test_delete_prompt_with_no_versions
python
mlflow/mlflow
tests/tracking/test_client.py
https://github.com/mlflow/mlflow/blob/master/tests/tracking/test_client.py
Apache-2.0
def test_delete_prompt_complete_workflow(tracking_uri): """Test the complete workflow: create, add versions, delete versions, delete prompt""" client = MlflowClient(tracking_uri=tracking_uri) # Create prompt with multiple versions client.register_prompt(name="workflow_prompt", template="Version 1: {{na...
Test the complete workflow: create, add versions, delete versions, delete prompt
test_delete_prompt_complete_workflow
python
mlflow/mlflow
tests/tracking/test_client.py
https://github.com/mlflow/mlflow/blob/master/tests/tracking/test_client.py
Apache-2.0
def test_delete_prompt_version_behavior_consistency(tracking_uri): """Test that delete_prompt_version behavior is consistent across registry types""" client = MlflowClient(tracking_uri=tracking_uri) # Create multiple prompts with versions for i in range(3): prompt_name = f"consistency_test_{i}"...
Test that delete_prompt_version behavior is consistent across registry types
test_delete_prompt_version_behavior_consistency
python
mlflow/mlflow
tests/tracking/test_client.py
https://github.com/mlflow/mlflow/blob/master/tests/tracking/test_client.py
Apache-2.0
def test_delete_prompt_with_versions_unity_catalog_error(registry_uri): """Test that Unity Catalog throws error when deleting prompt with existing versions""" # Mock Unity Catalog behavior client = MlflowClient(registry_uri=registry_uri) # Mock the search_prompt_versions to return versions mock_re...
Test that Unity Catalog throws error when deleting prompt with existing versions
test_delete_prompt_with_versions_unity_catalog_error
python
mlflow/mlflow
tests/tracking/test_client.py
https://github.com/mlflow/mlflow/blob/master/tests/tracking/test_client.py
Apache-2.0
def test_link_prompt_version_to_model_smoke_test(tracking_uri): """Smoke test for linking a prompt version to a model - just verify the method can be called.""" client = MlflowClient(tracking_uri=tracking_uri) # Create an experiment and a run to have a proper context experiment_id = client.create_exper...
Smoke test for linking a prompt version to a model - just verify the method can be called.
test_link_prompt_version_to_model_smoke_test
python
mlflow/mlflow
tests/tracking/test_client.py
https://github.com/mlflow/mlflow/blob/master/tests/tracking/test_client.py
Apache-2.0
def test_link_prompts_to_trace_smoke_test(tracking_uri): """Smoke test for linking prompt versions to a trace - just verify the method can be called.""" client = MlflowClient(tracking_uri=tracking_uri) # Create an experiment and a run to have a proper context experiment_id = client.create_experiment("t...
Smoke test for linking prompt versions to a trace - just verify the method can be called.
test_link_prompts_to_trace_smoke_test
python
mlflow/mlflow
tests/tracking/test_client.py
https://github.com/mlflow/mlflow/blob/master/tests/tracking/test_client.py
Apache-2.0
def test_duplicated_log_image_with_step(): """ MLflow will save both files if there are multiple calls to log_image with the same key and step. """ import numpy as np image1 = np.random.randint(0, 256, size=(100, 100, 3), dtype=np.uint8) image2 = np.random.randint(0, 256, size=(100, 100, 3)...
MLflow will save both files if there are multiple calls to log_image with the same key and step.
test_duplicated_log_image_with_step
python
mlflow/mlflow
tests/tracking/test_log_image.py
https://github.com/mlflow/mlflow/blob/master/tests/tracking/test_log_image.py
Apache-2.0
def test_duplicated_log_image_with_timestamp(): """ MLflow will save both files if there are multiple calls to log_image with the same key, step, and timestamp. """ import numpy as np image1 = np.random.randint(0, 256, size=(100, 100, 3), dtype=np.uint8) image2 = np.random.randint(0, 256, s...
MLflow will save both files if there are multiple calls to log_image with the same key, step, and timestamp.
test_duplicated_log_image_with_timestamp
python
mlflow/mlflow
tests/tracking/test_log_image.py
https://github.com/mlflow/mlflow/blob/master/tests/tracking/test_log_image.py
Apache-2.0
def mlflow_client(request, tmp_path): """Provides an MLflow Tracking API client pointed at the local tracking server.""" if request.param == "file": backend_uri = tmp_path.joinpath("file").as_uri() elif request.param == "sqlalchemy": path = tmp_path.joinpath("sqlalchemy.db").as_uri() ...
Provides an MLflow Tracking API client pointed at the local tracking server.
mlflow_client
python
mlflow/mlflow
tests/tracking/test_rest_tracking.py
https://github.com/mlflow/mlflow/blob/master/tests/tracking/test_rest_tracking.py
Apache-2.0
def cli_env(mlflow_client): """Provides an environment for the MLflow CLI pointed at the local tracking server.""" return { "LC_ALL": "en_US.UTF-8", "LANG": "en_US.UTF-8", "MLFLOW_TRACKING_URI": mlflow_client.tracking_uri, }
Provides an environment for the MLflow CLI pointed at the local tracking server.
cli_env
python
mlflow/mlflow
tests/tracking/test_rest_tracking.py
https://github.com/mlflow/mlflow/blob/master/tests/tracking/test_rest_tracking.py
Apache-2.0
def create_test_runs_and_expected_data(experiment_id=None): """ Create a pair of runs and a corresponding data to expect when runs are searched for the same experiment. Returns: A tuple of a list and a dictionary """ start_times = [get_current_time_millis(), get_current_time_millis()] ...
Create a pair of runs and a corresponding data to expect when runs are searched for the same experiment. Returns: A tuple of a list and a dictionary
create_test_runs_and_expected_data
python
mlflow/mlflow
tests/tracking/fluent/test_fluent.py
https://github.com/mlflow/mlflow/blob/master/tests/tracking/fluent/test_fluent.py
Apache-2.0
def reset_experiment_id(): """ This fixture resets the active experiment id *after* the execution of the test case in which its included """ yield mlflow.tracking.fluent._active_experiment_id = None
This fixture resets the active experiment id *after* the execution of the test case in which its included
reset_experiment_id
python
mlflow/mlflow
tests/tracking/fluent/test_fluent.py
https://github.com/mlflow/mlflow/blob/master/tests/tracking/fluent/test_fluent.py
Apache-2.0
def test_search_runs_no_arguments(search_runs_output_format): """ When no experiment ID is specified, it should try to get the implicit one. """ mock_experiment_id = mock.Mock() experiment_id_patch = mock.patch( "mlflow.tracking.fluent._get_experiment_id", return_value=mock_experiment_id ...
When no experiment ID is specified, it should try to get the implicit one.
test_search_runs_no_arguments
python
mlflow/mlflow
tests/tracking/fluent/test_fluent.py
https://github.com/mlflow/mlflow/blob/master/tests/tracking/fluent/test_fluent.py
Apache-2.0
def test_search_runs_all_experiments(search_runs_output_format): """ When no experiment ID is specified but flag is passed, it should search all experiments. """ from mlflow.entities import Experiment mock_experiment_id = mock.Mock() mock_experiment = mock.Mock(Experiment) experiment_id_pat...
When no experiment ID is specified but flag is passed, it should search all experiments.
test_search_runs_all_experiments
python
mlflow/mlflow
tests/tracking/fluent/test_fluent.py
https://github.com/mlflow/mlflow/blob/master/tests/tracking/fluent/test_fluent.py
Apache-2.0
def test_search_runs_by_non_existing_experiment_name(): """When invalid experiment names are used (including None), it should return an empty collection. """ for name in [None, f"Random {random.randint(1, 1e6)}"]: assert search_runs(experiment_names=[name], output_format="list") == []
When invalid experiment names are used (including None), it should return an empty collection.
test_search_runs_by_non_existing_experiment_name
python
mlflow/mlflow
tests/tracking/fluent/test_fluent.py
https://github.com/mlflow/mlflow/blob/master/tests/tracking/fluent/test_fluent.py
Apache-2.0
def test_search_runs_by_experiment_id_and_name(): """When both experiment_ids and experiment_names are used, it should throw an exception""" err_msg = "Only experiment_ids or experiment_names can be used, but not both" with pytest.raises(MlflowException, match=err_msg): search_runs(experiment_ids=["...
When both experiment_ids and experiment_names are used, it should throw an exception
test_search_runs_by_experiment_id_and_name
python
mlflow/mlflow
tests/tracking/fluent/test_fluent.py
https://github.com/mlflow/mlflow/blob/master/tests/tracking/fluent/test_fluent.py
Apache-2.0
def test_paginate_lt_maxresults_onepage(): """ Number of runs is less than max_results and fits on one page, so we only need to fetch one page. """ runs = [create_run() for _ in range(5)] tokenized_runs = PagedList(runs, "") max_results = 50 max_per_page = 10 mocked_lambda = mock.Moc...
Number of runs is less than max_results and fits on one page, so we only need to fetch one page.
test_paginate_lt_maxresults_onepage
python
mlflow/mlflow
tests/tracking/fluent/test_fluent.py
https://github.com/mlflow/mlflow/blob/master/tests/tracking/fluent/test_fluent.py
Apache-2.0
def test_paginate_lt_maxresults_multipage(): """ Number of runs is less than max_results, but multiple pages are necessary to get all runs """ tokenized_runs = PagedList([create_run() for _ in range(10)], "token") no_token_runs = PagedList([create_run()], "") max_results = 50 max_per_page = ...
Number of runs is less than max_results, but multiple pages are necessary to get all runs
test_paginate_lt_maxresults_multipage
python
mlflow/mlflow
tests/tracking/fluent/test_fluent.py
https://github.com/mlflow/mlflow/blob/master/tests/tracking/fluent/test_fluent.py
Apache-2.0
def test_paginate_lt_maxresults_onepage_nonetoken(): """ Number of runs is less than max_results and fits on one page. The token passed back on the last page is None, not the emptystring """ runs = [create_run() for _ in range(5)] tokenized_runs = PagedList(runs, None) max_results = 50 m...
Number of runs is less than max_results and fits on one page. The token passed back on the last page is None, not the emptystring
test_paginate_lt_maxresults_onepage_nonetoken
python
mlflow/mlflow
tests/tracking/fluent/test_fluent.py
https://github.com/mlflow/mlflow/blob/master/tests/tracking/fluent/test_fluent.py
Apache-2.0
def test_paginate_eq_maxresults_blanktoken(): """ Runs returned are equal to max_results which are equal to a full number of pages. The server might send a token back, or they might not (depending on if they know if more runs exist). In this example, no token is sent back. Expected behavior is to NO...
Runs returned are equal to max_results which are equal to a full number of pages. The server might send a token back, or they might not (depending on if they know if more runs exist). In this example, no token is sent back. Expected behavior is to NOT query for more pages.
test_paginate_eq_maxresults_blanktoken
python
mlflow/mlflow
tests/tracking/fluent/test_fluent.py
https://github.com/mlflow/mlflow/blob/master/tests/tracking/fluent/test_fluent.py
Apache-2.0
def test_paginate_eq_maxresults_token(): """ Runs returned are equal to max_results which are equal to a full number of pages. The server might send a token back, or they might not (depending on if they know if more runs exist). In this example, a token IS sent back. Expected behavior is to NOT quer...
Runs returned are equal to max_results which are equal to a full number of pages. The server might send a token back, or they might not (depending on if they know if more runs exist). In this example, a token IS sent back. Expected behavior is to NOT query for more pages.
test_paginate_eq_maxresults_token
python
mlflow/mlflow
tests/tracking/fluent/test_fluent.py
https://github.com/mlflow/mlflow/blob/master/tests/tracking/fluent/test_fluent.py
Apache-2.0
def test_paginate_gt_maxresults_multipage(): """ Number of runs that fit search criteria is greater than max_results. Multiple pages expected. Expected to only get max_results number of results back. """ # should ask for and return the correct number of max_results full_page_runs = PagedList([cr...
Number of runs that fit search criteria is greater than max_results. Multiple pages expected. Expected to only get max_results number of results back.
test_paginate_gt_maxresults_multipage
python
mlflow/mlflow
tests/tracking/fluent/test_fluent.py
https://github.com/mlflow/mlflow/blob/master/tests/tracking/fluent/test_fluent.py
Apache-2.0
def test_paginate_gt_maxresults_onepage(): """ Number of runs that fit search criteria is greater than max_results. Only one page expected. Expected to only get max_results number of results back. """ runs = [create_run() for _ in range(10)] tokenized_runs = PagedList(runs, "abc") max_result...
Number of runs that fit search criteria is greater than max_results. Only one page expected. Expected to only get max_results number of results back.
test_paginate_gt_maxresults_onepage
python
mlflow/mlflow
tests/tracking/fluent/test_fluent.py
https://github.com/mlflow/mlflow/blob/master/tests/tracking/fluent/test_fluent.py
Apache-2.0
def test_delete_tag(): """ Confirm that fluent API delete tags actually works. """ mlflow.set_tag("a", "b") run = MlflowClient().get_run(mlflow.active_run().info.run_id) assert "a" in run.data.tags mlflow.delete_tag("a") run = MlflowClient().get_run(mlflow.active_run().info.run_id) a...
Confirm that fluent API delete tags actually works.
test_delete_tag
python
mlflow/mlflow
tests/tracking/fluent/test_fluent.py
https://github.com/mlflow/mlflow/blob/master/tests/tracking/fluent/test_fluent.py
Apache-2.0
def test_set_active_model_public_env_var(monkeypatch, is_in_databricks_serving): """Test that MLFLOW_ACTIVE_MODEL_ID (public env var) works correctly.""" with mock.patch( "mlflow.tracking.fluent.is_in_databricks_model_serving_environment", return_value=is_in_databricks_serving, ) as mock_is_...
Test that MLFLOW_ACTIVE_MODEL_ID (public env var) works correctly.
test_set_active_model_public_env_var
python
mlflow/mlflow
tests/tracking/fluent/test_fluent.py
https://github.com/mlflow/mlflow/blob/master/tests/tracking/fluent/test_fluent.py
Apache-2.0
def test_clear_active_model_clears_env_vars(monkeypatch): """Test that clear_active_model() properly clears environment variables.""" # Set both environment variables monkeypatch.setenv(_MLFLOW_ACTIVE_MODEL_ID.name, "legacy-model-id") monkeypatch.setenv(MLFLOW_ACTIVE_MODEL_ID.name, "public-model-id") ...
Test that clear_active_model() properly clears environment variables.
test_clear_active_model_clears_env_vars
python
mlflow/mlflow
tests/tracking/fluent/test_fluent.py
https://github.com/mlflow/mlflow/blob/master/tests/tracking/fluent/test_fluent.py
Apache-2.0
def reset_module_import(): """ Temporarily reset the module import state to simulate the module being not imported. """ original_modules = {} for module_name in FLAVOR_TO_MODULE_NAME.values(): original_modules[module_name] = sys.modules.get(module_name) try: yield finally: ...
Temporarily reset the module import state to simulate the module being not imported.
reset_module_import
python
mlflow/mlflow
tests/tracking/fluent/test_fluent_autolog.py
https://github.com/mlflow/mlflow/blob/master/tests/tracking/fluent/test_fluent_autolog.py
Apache-2.0
def join_thread_by_name_prefix(prefix: str): """Join any thread whose name starts with the given prefix.""" for t in threading.enumerate(): if t.name.startswith(prefix): t.join()
Join any thread whose name starts with the given prefix.
join_thread_by_name_prefix
python
mlflow/mlflow
tests/tracking/_model_registry/test_model_registry_fluent.py
https://github.com/mlflow/mlflow/blob/master/tests/tracking/_model_registry/test_model_registry_fluent.py
Apache-2.0
def mock_dbr_version(): """Mock DatabricksRuntimeVersion to simulate a supported client image.""" with mock.patch( "mlflow.utils.databricks_utils.DatabricksRuntimeVersion.parse", return_value=DatabricksRuntimeVersion( is_client_image=True, major=2, # Supported version ...
Mock DatabricksRuntimeVersion to simulate a supported client image.
mock_dbr_version
python
mlflow/mlflow
tests/tracking/_model_registry/test_model_registry_fluent.py
https://github.com/mlflow/mlflow/blob/master/tests/tracking/_model_registry/test_model_registry_fluent.py
Apache-2.0
def test_register_model_with_env_pack(tmp_path, mock_dbr_version): """Test that register_model correctly integrates with environment packing functionality.""" # Mock download_artifacts to return a path mock_artifacts_dir = tmp_path / "artifacts" mock_artifacts_dir.mkdir() (mock_artifacts_dir / "requ...
Test that register_model correctly integrates with environment packing functionality.
test_register_model_with_env_pack
python
mlflow/mlflow
tests/tracking/_model_registry/test_model_registry_fluent.py
https://github.com/mlflow/mlflow/blob/master/tests/tracking/_model_registry/test_model_registry_fluent.py
Apache-2.0
def test_register_model_with_env_pack_staging_failure(tmp_path, mock_dbr_version): """Test that register_model handles staging failure gracefully.""" # Mock download_artifacts to return a path mock_artifacts_dir = tmp_path / "artifacts" mock_artifacts_dir.mkdir() (mock_artifacts_dir / "requirements....
Test that register_model handles staging failure gracefully.
test_register_model_with_env_pack_staging_failure
python
mlflow/mlflow
tests/tracking/_model_registry/test_model_registry_fluent.py
https://github.com/mlflow/mlflow/blob/master/tests/tracking/_model_registry/test_model_registry_fluent.py
Apache-2.0
def test_load_prompt_with_link_to_model_disabled(): """Test load_prompt with link_to_model=False does not attempt linking.""" # Register a prompt mlflow.register_prompt(name="test_prompt", template="Hello, {{name}}!") # Create a logged model and set it as active with mlflow.start_run(): mo...
Test load_prompt with link_to_model=False does not attempt linking.
test_load_prompt_with_link_to_model_disabled
python
mlflow/mlflow
tests/tracking/_model_registry/test_model_registry_fluent.py
https://github.com/mlflow/mlflow/blob/master/tests/tracking/_model_registry/test_model_registry_fluent.py
Apache-2.0
def test_load_prompt_with_active_model_integration(): """Test load_prompt with active model integration using get_active_model_id.""" # Register a prompt mlflow.register_prompt(name="test_prompt", template="Hello, {{name}}!") # Test loading prompt with active model context with mlflow.start_run():...
Test load_prompt with active model integration using get_active_model_id.
test_load_prompt_with_active_model_integration
python
mlflow/mlflow
tests/tracking/_model_registry/test_model_registry_fluent.py
https://github.com/mlflow/mlflow/blob/master/tests/tracking/_model_registry/test_model_registry_fluent.py
Apache-2.0