From c8e8a49b041f07d5adcd746bef76e430ffafc468 Mon Sep 17 00:00:00 2001 From: Danny Hermes Date: Thu, 23 Feb 2017 13:55:41 -0800 Subject: [PATCH] Removing overly broad mock.Mock() in vision. --- vision/unit_tests/test__gax.py | 5 ++++- vision/unit_tests/test_batch.py | 11 ++++++++--- vision/unit_tests/test_client.py | 6 +++--- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/vision/unit_tests/test__gax.py b/vision/unit_tests/test__gax.py index ee73cbdce0b2..b2c0ea5ab430 100644 --- a/vision/unit_tests/test__gax.py +++ b/vision/unit_tests/test__gax.py @@ -33,7 +33,10 @@ def _make_one(self, *args, **kwargs): return self._get_target_class()(*args, **kwargs) def test_ctor(self): - client = mock.Mock() + client = mock.Mock( + _credentials=_make_credentials(), + spec=['_credentials'], + ) with mock.patch('google.cloud.vision._gax.image_annotator_client.' 'ImageAnnotatorClient'): api = self._make_one(client) diff --git a/vision/unit_tests/test_batch.py b/vision/unit_tests/test_batch.py index a1acaf4efe33..bda1148eca7e 100644 --- a/vision/unit_tests/test_batch.py +++ b/vision/unit_tests/test_batch.py @@ -40,7 +40,7 @@ def test_ctor(self): from google.cloud.vision.feature import FeatureTypes from google.cloud.vision.image import Image - client = mock.Mock() + client = mock.Mock(spec=[]) image = Image(client, source_uri='gs://images/imageone.jpg') face_feature = Feature(FeatureTypes.FACE_DETECTION, 5) logo_feature = Feature(FeatureTypes.LOGO_DETECTION, 3) @@ -66,8 +66,13 @@ def test_batch_from_client(self): image_two = client.image(source_uri='gs://images/imagtwo.jpg') face_feature = Feature(FeatureTypes.FACE_DETECTION, 5) logo_feature = Feature(FeatureTypes.LOGO_DETECTION, 3) - client._vision_api_internal = mock.Mock() - client._vision_api_internal.annotate.return_value = True + + # Make mocks. + annotate = mock.Mock(return_value=True, spec=[]) + vision_api = mock.Mock(annotate=annotate, spec=['annotate']) + client._vision_api_internal = vision_api + + # Actually call the partially-mocked method. batch = client.batch() batch.add_image(image_one, [face_feature]) batch.add_image(image_two, [logo_feature, face_feature]) diff --git a/vision/unit_tests/test_client.py b/vision/unit_tests/test_client.py index 7cd7fb21e229..952621f776a8 100644 --- a/vision/unit_tests/test_client.py +++ b/vision/unit_tests/test_client.py @@ -51,12 +51,12 @@ def test_annotate_with_preset_api(self): vision_api = client._vision_api vision_api._connection = _Connection() - api = mock.Mock() - api.annotate.return_value = mock.sentinel.annotated + annotate = mock.Mock(return_value=mock.sentinel.annotated, spec=[]) + api = mock.Mock(annotate=annotate, spec=['annotate']) client._vision_api_internal = api client._vision_api.annotate() - api.annotate.assert_called_once_with() + annotate.assert_called_once_with() def test_make_gax_client(self): from google.cloud.vision._gax import _GAPICVisionAPI