@@ -3599,3 +3599,169 @@ def test_execute_evaluation_adds_creation_timestamp(
3599
3599
3600
3600
assert result .metadata is not None
3601
3601
assert result .metadata .creation_timestamp == mock_now
3602
+
3603
+
3604
+ class TestEvaluationDataset :
3605
+ """Contains set of tests for the EvaluationDataset class methods."""
3606
+
3607
+ @mock .patch .object (_evals_utils , "GcsUtils" )
3608
+ def test_load_from_observability_eval_cases (self , mock_gcs_utils ):
3609
+ """Tests that load_from_observability_eval_cases reads data from GCS."""
3610
+
3611
+ def read_file_contents_side_effect (src : str ) -> str :
3612
+ if src == "gs://project/input.json" :
3613
+ return "input"
3614
+ elif src == "gs://project/output.json" :
3615
+ return "output"
3616
+ elif src == "gs://project/system_instruction.json" :
3617
+ return "system_instruction"
3618
+ else :
3619
+ return ""
3620
+
3621
+ mock_gcs_utils .return_value .read_file_contents .side_effect = (
3622
+ read_file_contents_side_effect
3623
+ )
3624
+
3625
+ eval_cases = [
3626
+ vertexai_genai_types .ObservabilityEvalCase (
3627
+ input_src = "gs://project/input.json" ,
3628
+ output_src = "gs://project/output.json" ,
3629
+ system_instruction_src = "gs://project/system_instruction.json" ,
3630
+ )
3631
+ ]
3632
+ result = (
3633
+ vertexai_genai_types .EvaluationDataset .load_from_observability_eval_cases (
3634
+ eval_cases
3635
+ )
3636
+ )
3637
+
3638
+ mock_gcs_utils .return_value .read_file_contents .assert_has_calls (
3639
+ [
3640
+ mock .call ("gs://project/input.json" ),
3641
+ mock .call ("gs://project/output.json" ),
3642
+ mock .call ("gs://project/system_instruction.json" ),
3643
+ ],
3644
+ any_order = True ,
3645
+ )
3646
+ assert result .eval_dataset_df is not None
3647
+ pd .testing .assert_frame_equal (
3648
+ result .eval_dataset_df ,
3649
+ pd .DataFrame (
3650
+ {
3651
+ "format" : ["observability" ],
3652
+ "request" : ["input" ],
3653
+ "response" : ["output" ],
3654
+ "system_instruction" : ["system_instruction" ],
3655
+ }
3656
+ ),
3657
+ )
3658
+
3659
+ @mock .patch .object (_evals_utils , "GcsUtils" )
3660
+ def test_load_from_observability_eval_cases_no_system_instruction (
3661
+ self , mock_gcs_utils
3662
+ ):
3663
+ """Tests load_from_observability_eval_cases works without system_instruction."""
3664
+
3665
+ def read_file_contents_side_effect (src : str ) -> str :
3666
+ if src == "gs://project/input.json" :
3667
+ return "input"
3668
+ elif src == "gs://project/output.json" :
3669
+ return "output"
3670
+ elif src == "gs://project/system_instruction.json" :
3671
+ return "system_instruction"
3672
+ else :
3673
+ return ""
3674
+
3675
+ mock_gcs_utils .return_value .read_file_contents .side_effect = (
3676
+ read_file_contents_side_effect
3677
+ )
3678
+
3679
+ eval_cases = [
3680
+ vertexai_genai_types .ObservabilityEvalCase (
3681
+ input_src = "gs://project/input.json" ,
3682
+ output_src = "gs://project/output.json" ,
3683
+ )
3684
+ ]
3685
+ result = (
3686
+ vertexai_genai_types .EvaluationDataset .load_from_observability_eval_cases (
3687
+ eval_cases
3688
+ )
3689
+ )
3690
+
3691
+ mock_gcs_utils .return_value .read_file_contents .assert_has_calls (
3692
+ [
3693
+ mock .call ("gs://project/input.json" ),
3694
+ mock .call ("gs://project/output.json" ),
3695
+ ],
3696
+ any_order = True ,
3697
+ )
3698
+ assert result .eval_dataset_df is not None
3699
+ pd .testing .assert_frame_equal (
3700
+ result .eval_dataset_df ,
3701
+ pd .DataFrame (
3702
+ {
3703
+ "format" : ["observability" ],
3704
+ "request" : ["input" ],
3705
+ "response" : ["output" ],
3706
+ "system_instruction" : ["" ],
3707
+ }
3708
+ ),
3709
+ )
3710
+
3711
+ @mock .patch .object (_evals_utils , "GcsUtils" )
3712
+ def test_load_from_observability_eval_cases_multiple_cases (self , mock_gcs_utils ):
3713
+ """Test load_from_observability_eval_cases can handle multiple cases."""
3714
+
3715
+ def read_file_contents_side_effect (src : str ) -> str :
3716
+ if src == "gs://project/input_1.json" :
3717
+ return "input_1"
3718
+ elif src == "gs://project/input_2.json" :
3719
+ return "input_2"
3720
+ elif src == "gs://project/output_1.json" :
3721
+ return "output_1"
3722
+ elif src == "gs://project/output_2.json" :
3723
+ return "output_2"
3724
+ elif src == "gs://project/system_instruction_1.json" :
3725
+ return "system_instruction_1"
3726
+ elif src == "gs://project/system_instruction_2.json" :
3727
+ return "system_instruction_2"
3728
+ else :
3729
+ return ""
3730
+
3731
+ mock_gcs_utils .return_value .read_file_contents .side_effect = (
3732
+ read_file_contents_side_effect
3733
+ )
3734
+
3735
+ eval_cases = [
3736
+ vertexai_genai_types .ObservabilityEvalCase (
3737
+ input_src = "gs://project/input_1.json" ,
3738
+ output_src = "gs://project/output_1.json" ,
3739
+ system_instruction_src = "gs://project/system_instruction_1.json" ,
3740
+ ),
3741
+ vertexai_genai_types .ObservabilityEvalCase (
3742
+ input_src = "gs://project/input_2.json" ,
3743
+ output_src = "gs://project/output_2.json" ,
3744
+ system_instruction_src = "gs://project/system_instruction_2.json" ,
3745
+ ),
3746
+ ]
3747
+ result = (
3748
+ vertexai_genai_types .EvaluationDataset .load_from_observability_eval_cases (
3749
+ eval_cases
3750
+ )
3751
+ )
3752
+
3753
+ assert result .eval_dataset_df is not None
3754
+ pd .testing .assert_frame_equal (
3755
+ result .eval_dataset_df ,
3756
+ pd .DataFrame (
3757
+ {
3758
+ "format" : ["observability" , "observability" ],
3759
+ "request" : ["input_1" , "input_2" ],
3760
+ "response" : ["output_1" , "output_2" ],
3761
+ "system_instruction" : [
3762
+ "system_instruction_1" ,
3763
+ "system_instruction_2" ,
3764
+ ],
3765
+ }
3766
+ ),
3767
+ )
0 commit comments