Skip to content

Commit c8e8a49

Browse files
committed
Removing overly broad mock.Mock() in vision.
1 parent 09ae157 commit c8e8a49

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

vision/unit_tests/test__gax.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ def _make_one(self, *args, **kwargs):
3333
return self._get_target_class()(*args, **kwargs)
3434

3535
def test_ctor(self):
36-
client = mock.Mock()
36+
client = mock.Mock(
37+
_credentials=_make_credentials(),
38+
spec=['_credentials'],
39+
)
3740
with mock.patch('google.cloud.vision._gax.image_annotator_client.'
3841
'ImageAnnotatorClient'):
3942
api = self._make_one(client)

vision/unit_tests/test_batch.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def test_ctor(self):
4040
from google.cloud.vision.feature import FeatureTypes
4141
from google.cloud.vision.image import Image
4242

43-
client = mock.Mock()
43+
client = mock.Mock(spec=[])
4444
image = Image(client, source_uri='gs://images/imageone.jpg')
4545
face_feature = Feature(FeatureTypes.FACE_DETECTION, 5)
4646
logo_feature = Feature(FeatureTypes.LOGO_DETECTION, 3)
@@ -66,8 +66,13 @@ def test_batch_from_client(self):
6666
image_two = client.image(source_uri='gs://images/imagtwo.jpg')
6767
face_feature = Feature(FeatureTypes.FACE_DETECTION, 5)
6868
logo_feature = Feature(FeatureTypes.LOGO_DETECTION, 3)
69-
client._vision_api_internal = mock.Mock()
70-
client._vision_api_internal.annotate.return_value = True
69+
70+
# Make mocks.
71+
annotate = mock.Mock(return_value=True, spec=[])
72+
vision_api = mock.Mock(annotate=annotate, spec=['annotate'])
73+
client._vision_api_internal = vision_api
74+
75+
# Actually call the partially-mocked method.
7176
batch = client.batch()
7277
batch.add_image(image_one, [face_feature])
7378
batch.add_image(image_two, [logo_feature, face_feature])

vision/unit_tests/test_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ def test_annotate_with_preset_api(self):
5151
vision_api = client._vision_api
5252
vision_api._connection = _Connection()
5353

54-
api = mock.Mock()
55-
api.annotate.return_value = mock.sentinel.annotated
54+
annotate = mock.Mock(return_value=mock.sentinel.annotated, spec=[])
55+
api = mock.Mock(annotate=annotate, spec=['annotate'])
5656

5757
client._vision_api_internal = api
5858
client._vision_api.annotate()
59-
api.annotate.assert_called_once_with()
59+
annotate.assert_called_once_with()
6060

6161
def test_make_gax_client(self):
6262
from google.cloud.vision._gax import _GAPICVisionAPI

0 commit comments

Comments
 (0)