@@ -431,6 +431,16 @@ def types_reasoning_engine_mock():
431
431
yield types_reasoning_engine_mock
432
432
433
433
434
+ @pytest .fixture (scope = "function" )
435
+ def get_gca_resource_mock ():
436
+ with mock .patch .object (
437
+ base .VertexAiResourceNoun ,
438
+ "_get_gca_resource" ,
439
+ ) as get_gca_resource_mock :
440
+ get_gca_resource_mock .return_value = _TEST_REASONING_ENGINE_OBJ
441
+ yield get_gca_resource_mock
442
+
443
+
434
444
class InvalidCapitalizeEngineWithoutQuerySelf :
435
445
"""A sample Reasoning Engine with an invalid query method."""
436
446
@@ -533,15 +543,14 @@ def test_create_reasoning_engine(
533
543
tarfile_open_mock ,
534
544
cloudpickle_dump_mock ,
535
545
get_reasoning_engine_mock ,
546
+ get_gca_resource_mock ,
536
547
):
537
- test_reasoning_engine = reasoning_engines .ReasoningEngine .create (
548
+ reasoning_engines .ReasoningEngine .create (
538
549
self .test_app ,
539
550
display_name = _TEST_REASONING_ENGINE_DISPLAY_NAME ,
540
551
requirements = _TEST_REASONING_ENGINE_REQUIREMENTS ,
541
552
extra_packages = [_TEST_REASONING_ENGINE_EXTRA_PACKAGE_PATH ],
542
553
)
543
- # Manually set _gca_resource here to prevent the mocks from propagating.
544
- test_reasoning_engine ._gca_resource = _TEST_REASONING_ENGINE_OBJ
545
554
create_reasoning_engine_mock .assert_called_with (
546
555
parent = _TEST_PARENT ,
547
556
reasoning_engine = _TEST_INPUT_REASONING_ENGINE_OBJ ,
@@ -595,20 +604,19 @@ def test_create_reasoning_engine_requirements_from_file(
595
604
tarfile_open_mock ,
596
605
cloudpickle_dump_mock ,
597
606
get_reasoning_engine_mock ,
607
+ get_gca_resource_mock ,
598
608
):
599
609
with mock .patch (
600
610
"builtins.open" ,
601
611
mock .mock_open (read_data = "google-cloud-aiplatform==1.29.0" ),
602
612
) as mock_file :
603
- test_reasoning_engine = reasoning_engines .ReasoningEngine .create (
613
+ reasoning_engines .ReasoningEngine .create (
604
614
self .test_app ,
605
615
display_name = _TEST_REASONING_ENGINE_DISPLAY_NAME ,
606
616
requirements = "requirements.txt" ,
607
617
extra_packages = [_TEST_REASONING_ENGINE_EXTRA_PACKAGE_PATH ],
608
618
)
609
619
mock_file .assert_called_with ("requirements.txt" )
610
- # Manually set _gca_resource here to prevent the mocks from propagating.
611
- test_reasoning_engine ._gca_resource = _TEST_REASONING_ENGINE_OBJ
612
620
create_reasoning_engine_mock .assert_called_with (
613
621
parent = _TEST_PARENT ,
614
622
reasoning_engine = _TEST_INPUT_REASONING_ENGINE_OBJ ,
@@ -808,15 +816,14 @@ def test_delete_after_create_reasoning_engine(
808
816
cloudpickle_dump_mock ,
809
817
get_reasoning_engine_mock ,
810
818
delete_reasoning_engine_mock ,
819
+ get_gca_resource_mock ,
811
820
):
812
821
test_reasoning_engine = reasoning_engines .ReasoningEngine .create (
813
822
self .test_app ,
814
823
display_name = _TEST_REASONING_ENGINE_DISPLAY_NAME ,
815
824
requirements = _TEST_REASONING_ENGINE_REQUIREMENTS ,
816
825
extra_packages = [_TEST_REASONING_ENGINE_EXTRA_PACKAGE_PATH ],
817
826
)
818
- # Manually set _gca_resource here to prevent the mocks from propagating.
819
- test_reasoning_engine ._gca_resource = _TEST_REASONING_ENGINE_OBJ
820
827
create_reasoning_engine_mock .assert_called_with (
821
828
parent = _TEST_PARENT ,
822
829
reasoning_engine = _TEST_INPUT_REASONING_ENGINE_OBJ ,
@@ -834,10 +841,9 @@ def test_delete_after_get_reasoning_engine(
834
841
self ,
835
842
get_reasoning_engine_mock ,
836
843
delete_reasoning_engine_mock ,
844
+ get_gca_resource_mock ,
837
845
):
838
846
test_reasoning_engine = reasoning_engines .ReasoningEngine (_TEST_RESOURCE_ID )
839
- # Manually set _gca_resource here to prevent the mocks from propagating.
840
- test_reasoning_engine ._gca_resource = _TEST_REASONING_ENGINE_OBJ
841
847
get_reasoning_engine_mock .assert_called_with (
842
848
name = _TEST_REASONING_ENGINE_RESOURCE_NAME ,
843
849
retry = _TEST_RETRY ,
@@ -852,10 +858,9 @@ def test_query_reasoning_engine(
852
858
get_reasoning_engine_mock ,
853
859
query_reasoning_engine_mock ,
854
860
to_dict_mock ,
861
+ get_gca_resource_mock ,
855
862
):
856
863
test_reasoning_engine = reasoning_engines .ReasoningEngine (_TEST_RESOURCE_ID )
857
- # Manually set _gca_resource here to prevent the mocks from propagating.
858
- test_reasoning_engine ._gca_resource = _TEST_REASONING_ENGINE_OBJ
859
864
get_reasoning_engine_mock .assert_called_with (
860
865
name = _TEST_REASONING_ENGINE_RESOURCE_NAME ,
861
866
retry = _TEST_RETRY ,
@@ -866,10 +871,12 @@ def test_query_reasoning_engine(
866
871
)
867
872
to_dict_mock .assert_called_once ()
868
873
869
- def test_operation_schemas (self , get_reasoning_engine_mock ):
874
+ def test_operation_schemas (
875
+ self ,
876
+ get_reasoning_engine_mock ,
877
+ get_gca_resource_mock ,
878
+ ):
870
879
test_reasoning_engine = reasoning_engines .ReasoningEngine (_TEST_RESOURCE_ID )
871
- # Manually set _gca_resource here to prevent the mocks from propagating.
872
- test_reasoning_engine ._gca_resource = _TEST_REASONING_ENGINE_OBJ
873
880
test_reasoning_engine ._operation_schemas = (
874
881
_TEST_REASONING_ENGINE_OPERATION_SCHEMAS
875
882
)
0 commit comments