@@ -37,25 +37,53 @@ def test_annotation(self):
3737 from google .cloud .vision .feature import FeatureTypes
3838 from google .cloud .vision .image import Image
3939
40- client = mock .Mock ()
40+ client = mock .Mock (spec_set = [] )
4141 feature = Feature (FeatureTypes .LABEL_DETECTION , 5 )
4242 image_content = b'abc 1 2 3'
4343 image = Image (client , content = image_content )
4444 with mock .patch ('google.cloud.vision._gax.image_annotator_client.'
4545 'ImageAnnotatorClient' ):
46- api = self ._make_one (client )
46+ gax_api = self ._make_one (client )
4747
48- api ._api = mock .Mock ()
49- mock_response = mock .Mock (responses = ['mock response data' ])
50- api ._api .batch_annotate_images .return_value = mock_response
48+ mock_response = {
49+ 'batch_annotate_images.return_value' :
50+ mock .Mock (responses = ['mock response data' ]),
51+ }
52+
53+ gax_api ._annotator_client = mock .Mock (
54+ spec_set = ['batch_annotate_images' ], ** mock_response )
5155
5256 with mock .patch ('google.cloud.vision._gax.Annotations' ) as mock_anno :
53- api .annotate (image , [feature ])
57+ gax_api .annotate (image , [feature ])
5458 mock_anno .from_pb .assert_called_with ('mock response data' )
55- api ._api .batch_annotate_images .assert_called ()
59+ gax_api ._annotator_client .batch_annotate_images .assert_called ()
60+
61+ def test_annotate_no_results (self ):
62+ from google .cloud .vision .feature import Feature
63+ from google .cloud .vision .feature import FeatureTypes
64+ from google .cloud .vision .image import Image
65+
66+ client = mock .Mock (spec_set = [])
67+ feature = Feature (FeatureTypes .LABEL_DETECTION , 5 )
68+ image_content = b'abc 1 2 3'
69+ image = Image (client , content = image_content )
70+ with mock .patch ('google.cloud.vision._gax.image_annotator_client.'
71+ 'ImageAnnotatorClient' ):
72+ gax_api = self ._make_one (client )
73+
74+ mock_response = {
75+ 'batch_annotate_images.return_value' : mock .Mock (responses = []),
76+ }
77+
78+ gax_api ._annotator_client = mock .Mock (
79+ spec_set = ['batch_annotate_images' ], ** mock_response )
80+ with mock .patch ('google.cloud.vision._gax.Annotations' ):
81+ self .assertIsNone (gax_api .annotate (image , [feature ]))
82+
83+ gax_api ._annotator_client .batch_annotate_images .assert_called ()
5684
5785
58- class TestToGAPICFeature (unittest .TestCase ):
86+ class Test__to_gapic_feature (unittest .TestCase ):
5987 def _call_fut (self , feature ):
6088 from google .cloud .vision ._gax import _to_gapic_feature
6189 return _to_gapic_feature (feature )
@@ -72,7 +100,7 @@ def test__to_gapic_feature(self):
72100 self .assertEqual (feature_pb .max_results , 5 )
73101
74102
75- class TestToGAPICImage (unittest .TestCase ):
103+ class Test__to_gapic_image (unittest .TestCase ):
76104 def _call_fut (self , image ):
77105 from google .cloud .vision ._gax import _to_gapic_image
78106 return _to_gapic_image (image )
0 commit comments