From b687e2ff9655c7a8d0e58262565ef90f814d6be3 Mon Sep 17 00:00:00 2001 From: Matej Aleksandrov Date: Mon, 16 Nov 2026 15:19:29 -0800 Subject: [PATCH] Migrate usage of mock to unittest.mock PiperOrigin-RevId: 1023162695 --- .../core/experimental/tests/unit/models_entry_point_test.py | 3 ++- .../core/experimental/tests/unit/models_test.py | 3 ++- .../core/tests/integration/run_on_notebook_test.py | 2 +- .../core/tests/integration/run_on_script_test.py | 2 +- .../tensorflow_cloud/core/tests/unit/containerize_test.py | 2 +- src/python/tensorflow_cloud/core/tests/unit/deploy_test.py | 2 +- .../tensorflow_cloud/core/tests/unit/preprocess_test.py | 2 +- src/python/tensorflow_cloud/tuner/tests/unit/tuner_test.py | 4 ++-- .../tensorflow_cloud/tuner/tests/unit/vizier_client_test.py | 3 ++- .../utils/tests/unit/google_api_client_test.py | 3 ++- src/python/tensorflow_cloud/utils/tests/unit/tf_utils_test.py | 4 +++- 11 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/python/tensorflow_cloud/core/experimental/tests/unit/models_entry_point_test.py b/src/python/tensorflow_cloud/core/experimental/tests/unit/models_entry_point_test.py index 64bcfe94..554c236a 100644 --- a/src/python/tensorflow_cloud/core/experimental/tests/unit/models_entry_point_test.py +++ b/src/python/tensorflow_cloud/core/experimental/tests/unit/models_entry_point_test.py @@ -13,8 +13,9 @@ # limitations under the License. """Tests for the models experimental module.""" +from unittest import mock + from absl.testing import absltest -import mock import tensorflow as tf from tensorflow_cloud.core.experimental import models_entry_point diff --git a/src/python/tensorflow_cloud/core/experimental/tests/unit/models_test.py b/src/python/tensorflow_cloud/core/experimental/tests/unit/models_test.py index 5ee64fea..456981b4 100644 --- a/src/python/tensorflow_cloud/core/experimental/tests/unit/models_test.py +++ b/src/python/tensorflow_cloud/core/experimental/tests/unit/models_test.py @@ -14,9 +14,10 @@ """Tests for the models experimental module.""" import os +from unittest import mock import uuid + from absl.testing import absltest -import mock import tensorflow as tf from tensorflow_cloud.core import machine_config diff --git a/src/python/tensorflow_cloud/core/tests/integration/run_on_notebook_test.py b/src/python/tensorflow_cloud/core/tests/integration/run_on_notebook_test.py index f4a3c177..31952c6e 100644 --- a/src/python/tensorflow_cloud/core/tests/integration/run_on_notebook_test.py +++ b/src/python/tensorflow_cloud/core/tests/integration/run_on_notebook_test.py @@ -14,7 +14,7 @@ """Integration tests for calling tfc.run on a notebook with keras.""" import os -import mock +from unittest import mock import tensorflow as tf import tensorflow_cloud as tfc diff --git a/src/python/tensorflow_cloud/core/tests/integration/run_on_script_test.py b/src/python/tensorflow_cloud/core/tests/integration/run_on_script_test.py index e956947c..8626438d 100644 --- a/src/python/tensorflow_cloud/core/tests/integration/run_on_script_test.py +++ b/src/python/tensorflow_cloud/core/tests/integration/run_on_script_test.py @@ -14,7 +14,7 @@ """Integration tests for calling tfc.run on a script with keras.""" import os -import mock +from unittest import mock import tensorflow as tf import tensorflow_cloud as tfc diff --git a/src/python/tensorflow_cloud/core/tests/unit/containerize_test.py b/src/python/tensorflow_cloud/core/tests/unit/containerize_test.py index 3ac57969..71ad132e 100644 --- a/src/python/tensorflow_cloud/core/tests/unit/containerize_test.py +++ b/src/python/tensorflow_cloud/core/tests/unit/containerize_test.py @@ -15,11 +15,11 @@ import os import tempfile +from unittest import mock import uuid from absl.testing import absltest import docker -import mock from tensorflow_cloud.core import containerize from tensorflow_cloud.core import docker_config diff --git a/src/python/tensorflow_cloud/core/tests/unit/deploy_test.py b/src/python/tensorflow_cloud/core/tests/unit/deploy_test.py index 774b13c0..065079b5 100644 --- a/src/python/tensorflow_cloud/core/tests/unit/deploy_test.py +++ b/src/python/tensorflow_cloud/core/tests/unit/deploy_test.py @@ -14,11 +14,11 @@ """Tests for the cloud deploy module.""" import io +from unittest import mock from absl.testing import absltest from googleapiclient import discovery from googleapiclient import errors -import mock from tensorflow_cloud.core import deploy from tensorflow_cloud.core import gcp diff --git a/src/python/tensorflow_cloud/core/tests/unit/preprocess_test.py b/src/python/tensorflow_cloud/core/tests/unit/preprocess_test.py index bb2d97ff..6d35e61c 100644 --- a/src/python/tensorflow_cloud/core/tests/unit/preprocess_test.py +++ b/src/python/tensorflow_cloud/core/tests/unit/preprocess_test.py @@ -14,9 +14,9 @@ """Tests for the cloud preprocessing module.""" import os +from unittest import mock from absl.testing import absltest -import mock from tensorflow_cloud.core import machine_config from tensorflow_cloud.core import preprocess diff --git a/src/python/tensorflow_cloud/tuner/tests/unit/tuner_test.py b/src/python/tensorflow_cloud/tuner/tests/unit/tuner_test.py index 26e10631..9c59968d 100644 --- a/src/python/tensorflow_cloud/tuner/tests/unit/tuner_test.py +++ b/src/python/tensorflow_cloud/tuner/tests/unit/tuner_test.py @@ -15,14 +15,14 @@ import os import time +from unittest import mock + from keras_tuner.engine import hypermodel as hypermodel_module from keras_tuner.engine import hyperparameters as hp_module from keras_tuner.engine import oracle as oracle_module from keras_tuner.engine import trial as trial_module from keras_tuner.engine import tuner as super_tuner -import mock - import tensorflow as tf from tensorboard.plugins.hparams import api as hparams_api from tensorflow_cloud.core import deploy diff --git a/src/python/tensorflow_cloud/tuner/tests/unit/vizier_client_test.py b/src/python/tensorflow_cloud/tuner/tests/unit/vizier_client_test.py index 65a00dc3..ddb71c66 100644 --- a/src/python/tensorflow_cloud/tuner/tests/unit/vizier_client_test.py +++ b/src/python/tensorflow_cloud/tuner/tests/unit/vizier_client_test.py @@ -13,9 +13,10 @@ # limitations under the License. """Tests for vizier_client.""" +from unittest import mock + from googleapiclient import errors import httplib2 -import mock import tensorflow as tf from tensorflow_cloud.tuner import vizier_client diff --git a/src/python/tensorflow_cloud/utils/tests/unit/google_api_client_test.py b/src/python/tensorflow_cloud/utils/tests/unit/google_api_client_test.py index 8652dd90..8a9fe54d 100644 --- a/src/python/tensorflow_cloud/utils/tests/unit/google_api_client_test.py +++ b/src/python/tensorflow_cloud/utils/tests/unit/google_api_client_test.py @@ -15,11 +15,12 @@ import json import os +from unittest import mock + from googleapiclient import discovery from googleapiclient import errors from googleapiclient import http as googleapiclient_http import httplib2 -import mock import tensorflow as tf from tensorflow_cloud import version from tensorflow_cloud.utils import google_api_client diff --git a/src/python/tensorflow_cloud/utils/tests/unit/tf_utils_test.py b/src/python/tensorflow_cloud/utils/tests/unit/tf_utils_test.py index 9418408f..ad1b6b7b 100644 --- a/src/python/tensorflow_cloud/utils/tests/unit/tf_utils_test.py +++ b/src/python/tensorflow_cloud/utils/tests/unit/tf_utils_test.py @@ -13,8 +13,10 @@ # limitations under the License. """Unit test for tf_utils module.""" -import mock +from unittest import mock + import tensorflow as tf + from tensorboard.backend.event_processing import directory_watcher from tensorboard.backend.event_processing import event_file_loader from tensorboard.backend.event_processing import io_wrapper