23
23
from unittest .mock import patch
24
24
25
25
import cloudpickle
26
+ from google import auth
26
27
from google .api_core import exceptions
28
+ from google .auth import credentials as auth_credentials
27
29
from google .cloud import aiplatform
28
30
from google .cloud .aiplatform import utils
29
31
from google .cloud .aiplatform .compat .services import (
30
32
job_service_client_v1beta1 as job_service_client ,
33
+ tensorboard_service_client ,
31
34
)
32
35
from google .cloud .aiplatform .compat .types import (
33
36
custom_job_v1beta1 as gca_custom_job_compat ,
89
92
_TEST_EXPERIMENT = "test-experiment"
90
93
_TEST_EXPERIMENT_RUN = "test-experiment-run"
91
94
_TEST_SERVICE_ACCOUNT = f"{ _TEST_PROJECT_NUMBER } [email protected] "
95
+ _TEST_CREDENTIALS = mock .Mock (spec = auth_credentials .AnonymousCredentials ())
92
96
93
97
# dataset constants
94
98
dataset = load_iris ()
@@ -707,6 +711,25 @@ def aiplatform_autolog_mock():
707
711
yield aiplatform_autolog_mock
708
712
709
713
714
+ @pytest .fixture (scope = "module" )
715
+ def google_auth_mock ():
716
+ with mock .patch .object (auth , "default" ) as auth_mock :
717
+ auth_mock .return_value = (
718
+ auth_credentials .AnonymousCredentials (),
719
+ "test-project" ,
720
+ )
721
+ yield auth_mock
722
+
723
+
724
+ @pytest .fixture
725
+ def get_tensorboard_mock ():
726
+ with patch .object (
727
+ tensorboard_service_client .TensorboardServiceClient , "get_tensorboard"
728
+ ) as get_tensorboard_mock :
729
+ get_tensorboard_mock .return_value = _TEST_DEFAULT_TENSORBOARD_GCA
730
+ yield get_tensorboard_mock
731
+
732
+
710
733
# unittest `assert_any_call` method doesn't work when arguments contain `np.ndarray`
711
734
# https://stackoverflow.com/questions/56644729/mock-assert-mock-calls-with-a-numpy-array-as-argument-raises-valueerror-and-np
712
735
# tentatively runtime patch `assert_any_call` to solve this issue
@@ -1636,6 +1659,7 @@ def test_remote_training_keras_distributed_no_cuda_no_worker_pool_specs(
1636
1659
"get_artifact_not_found_mock" ,
1637
1660
"update_context_mock" ,
1638
1661
"mock_autolog_disabled" ,
1662
+ "get_tensorboard_mock" ,
1639
1663
)
1640
1664
def test_remote_training_sklearn_with_experiment (
1641
1665
self ,
@@ -1647,6 +1671,7 @@ def test_remote_training_sklearn_with_experiment(
1647
1671
location = _TEST_LOCATION ,
1648
1672
staging_bucket = _TEST_BUCKET_NAME ,
1649
1673
experiment = _TEST_EXPERIMENT ,
1674
+ credentials = _TEST_CREDENTIALS ,
1650
1675
)
1651
1676
vertexai .preview .init (remote = True )
1652
1677
@@ -1720,6 +1745,7 @@ def test_remote_training_sklearn_with_experiment(
1720
1745
"update_context_mock" ,
1721
1746
"aiplatform_autolog_mock" ,
1722
1747
"mock_autolog_enabled" ,
1748
+ "get_tensorboard_mock" ,
1723
1749
)
1724
1750
def test_remote_training_sklearn_with_experiment_autolog_enabled (
1725
1751
self ,
@@ -1731,6 +1757,7 @@ def test_remote_training_sklearn_with_experiment_autolog_enabled(
1731
1757
location = _TEST_LOCATION ,
1732
1758
staging_bucket = _TEST_BUCKET_NAME ,
1733
1759
experiment = _TEST_EXPERIMENT ,
1760
+ credentials = _TEST_CREDENTIALS ,
1734
1761
)
1735
1762
vertexai .preview .init (remote = True , autolog = True )
1736
1763
@@ -1926,6 +1953,7 @@ def test_initialize_existing_persistent_resource_service_account_mismatch(self):
1926
1953
"aiplatform_autolog_mock" ,
1927
1954
"mock_autolog_enabled" ,
1928
1955
"persistent_resource_running_mock" ,
1956
+ "get_tensorboard_mock" ,
1929
1957
)
1930
1958
def test_remote_training_sklearn_with_persistent_cluster_no_service_account_and_experiment_error (
1931
1959
self ,
@@ -1935,6 +1963,7 @@ def test_remote_training_sklearn_with_persistent_cluster_no_service_account_and_
1935
1963
location = _TEST_LOCATION ,
1936
1964
staging_bucket = _TEST_BUCKET_NAME ,
1937
1965
experiment = _TEST_EXPERIMENT ,
1966
+ credentials = _TEST_CREDENTIALS ,
1938
1967
)
1939
1968
vertexai .preview .init (
1940
1969
remote = True , autolog = True , cluster = _TEST_PERSISTENT_RESOURCE_CONFIG
@@ -1966,6 +1995,7 @@ def test_remote_training_sklearn_with_persistent_cluster_no_service_account_and_
1966
1995
"persistent_resource_service_account_running_mock" ,
1967
1996
"mock_timestamped_unique_name" ,
1968
1997
"mock_get_custom_job" ,
1998
+ "get_tensorboard_mock" ,
1969
1999
)
1970
2000
def test_remote_training_sklearn_with_persistent_cluster_and_experiment_autologging (
1971
2001
self ,
@@ -1977,6 +2007,7 @@ def test_remote_training_sklearn_with_persistent_cluster_and_experiment_autologg
1977
2007
location = _TEST_LOCATION ,
1978
2008
staging_bucket = _TEST_BUCKET_NAME ,
1979
2009
experiment = _TEST_EXPERIMENT ,
2010
+ credentials = _TEST_CREDENTIALS ,
1980
2011
)
1981
2012
vertexai .preview .init (
1982
2013
remote = True ,
0 commit comments