@@ -10635,25 +10635,33 @@ async def test_create_evaluation_run_async_passes_allow_cross_region_model(self)
1063510635 return_value = self .mock_response
1063610636 )
1063710637 async_evals_module = evals .AsyncEvals (api_client_ = self .mock_api_client )
10638-
10639- await async_evals_module .create_evaluation_run (
10640- dataset = agentplatform_genai_types .EvaluationRunDataSource (
10641- evaluation_set = "projects/123/locations/us-central1/evaluationSets/789"
10642- ),
10643- metrics = [
10644- agentplatform_genai_types .EvaluationRunMetric (
10645- metric = "general_quality_v1" ,
10646- metric_config = agentplatform_genai_types .UnifiedMetric (
10647- predefined_metric_spec = genai_types .PredefinedMetricSpec (
10648- metric_spec_name = "general_quality_v1" ,
10649- )
10650- ),
10651- )
10652- ],
10653- dest = "gs://test-bucket/output" ,
10654- config = {"allow_cross_region_model" : True },
10638+ experiment = agentplatform_genai_types .EvaluationExperiment (
10639+ name = "projects/123/locations/us-central1/evaluationExperiments/e1"
1065510640 )
1065610641
10642+ with mock .patch .object (
10643+ async_evals_module ,
10644+ "create_evaluation_experiment" ,
10645+ new = mock .AsyncMock (return_value = experiment ),
10646+ ):
10647+ await async_evals_module .create_evaluation_run (
10648+ dataset = agentplatform_genai_types .EvaluationRunDataSource (
10649+ evaluation_set = "projects/123/locations/us-central1/evaluationSets/789"
10650+ ),
10651+ metrics = [
10652+ agentplatform_genai_types .EvaluationRunMetric (
10653+ metric = "general_quality_v1" ,
10654+ metric_config = agentplatform_genai_types .UnifiedMetric (
10655+ predefined_metric_spec = genai_types .PredefinedMetricSpec (
10656+ metric_spec_name = "general_quality_v1" ,
10657+ )
10658+ ),
10659+ )
10660+ ],
10661+ dest = "gs://test-bucket/output" ,
10662+ config = {"allow_cross_region_model" : True },
10663+ )
10664+
1065710665 self .mock_api_client .async_request .assert_called_once ()
1065810666 call_args = self .mock_api_client .async_request .call_args
1065910667 request_body = call_args [0 ][2 ] # Third positional arg is the request dict
@@ -12414,3 +12422,86 @@ def test_uses_provided_experiment_without_creating(self):
1241412422 request_body .get ("evaluationExperiment" )
1241512423 == "projects/123/locations/us-central1/evaluationExperiments/existing"
1241612424 )
12425+
12426+
12427+ class TestAsyncCreateEvaluationRunAutoExperiment :
12428+
12429+ def setup_method (self , method ):
12430+ self .mock_api_client = mock .MagicMock ()
12431+ self .mock_api_client .vertexai = True
12432+ self .mock_response = mock .MagicMock ()
12433+ self .mock_response .body = json .dumps (
12434+ {
12435+ "name" : "projects/123/locations/us-central1/evaluationRuns/456" ,
12436+ "displayName" : "test_run" ,
12437+ "state" : "PENDING" ,
12438+ "evaluationExperiment" : (
12439+ "projects/123/locations/us-central1/evaluationExperiments/e1"
12440+ ),
12441+ }
12442+ )
12443+ self .mock_api_client .async_request = mock .AsyncMock (
12444+ return_value = self .mock_response
12445+ )
12446+ self .dataset = agentplatform_genai_types .EvaluationRunDataSource (
12447+ evaluation_set = "projects/123/locations/us-central1/evaluationSets/789"
12448+ )
12449+ self .metrics = [
12450+ agentplatform_genai_types .EvaluationRunMetric (
12451+ metric = "general_quality_v1" ,
12452+ metric_config = agentplatform_genai_types .UnifiedMetric (
12453+ predefined_metric_spec = genai_types .PredefinedMetricSpec (
12454+ metric_spec_name = "general_quality_v1" ,
12455+ )
12456+ ),
12457+ )
12458+ ]
12459+
12460+ @pytest .mark .asyncio
12461+ async def test_async_auto_creates_experiment_when_not_provided (self ):
12462+ async_evals_module = evals .AsyncEvals (api_client_ = self .mock_api_client )
12463+ experiment = agentplatform_genai_types .EvaluationExperiment (
12464+ name = "projects/123/locations/us-central1/evaluationExperiments/e1"
12465+ )
12466+ with mock .patch .object (
12467+ async_evals_module ,
12468+ "create_evaluation_experiment" ,
12469+ new = mock .AsyncMock (return_value = experiment ),
12470+ ) as mock_create_exp :
12471+ await async_evals_module .create_evaluation_run (
12472+ dataset = self .dataset ,
12473+ metrics = self .metrics ,
12474+ dest = "gs://test-bucket/output" ,
12475+ display_name = "my_run" ,
12476+ )
12477+
12478+ mock_create_exp .assert_awaited_once ()
12479+ request_body = self .mock_api_client .async_request .call_args [0 ][2 ]
12480+ assert (
12481+ request_body .get ("evaluationExperiment" )
12482+ == "projects/123/locations/us-central1/evaluationExperiments/e1"
12483+ )
12484+
12485+ @pytest .mark .asyncio
12486+ async def test_async_uses_provided_experiment_without_creating (self ):
12487+ async_evals_module = evals .AsyncEvals (api_client_ = self .mock_api_client )
12488+ with mock .patch .object (
12489+ async_evals_module ,
12490+ "create_evaluation_experiment" ,
12491+ new = mock .AsyncMock (),
12492+ ) as mock_create_exp :
12493+ await async_evals_module .create_evaluation_run (
12494+ dataset = self .dataset ,
12495+ metrics = self .metrics ,
12496+ dest = "gs://test-bucket/output" ,
12497+ evaluation_experiment = (
12498+ "projects/123/locations/us-central1/evaluationExperiments/existing"
12499+ ),
12500+ )
12501+
12502+ mock_create_exp .assert_not_awaited ()
12503+ request_body = self .mock_api_client .async_request .call_args [0 ][2 ]
12504+ assert (
12505+ request_body .get ("evaluationExperiment" )
12506+ == "projects/123/locations/us-central1/evaluationExperiments/existing"
12507+ )
0 commit comments