Skip to content

Commit

Permalink
Removing overly broad mock.Mock() in vision.
Browse files Browse the repository at this point in the history
  • Loading branch information
dhermes committed Mar 1, 2017
1 parent 09ae157 commit c8e8a49
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
5 changes: 4 additions & 1 deletion vision/unit_tests/test__gax.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 8 additions & 3 deletions vision/unit_tests/test_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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])
Expand Down
6 changes: 3 additions & 3 deletions vision/unit_tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c8e8a49

Please sign in to comment.