14
14
15
15
import unittest
16
16
17
+ import mock
18
+
17
19
18
20
class TestGAXClient (unittest .TestCase ):
19
21
def _get_target_class (self ):
@@ -23,7 +25,62 @@ def _get_target_class(self):
23
25
def _make_one (self , * args , ** kwargs ):
24
26
return self ._get_target_class ()(* args , ** kwargs )
25
27
26
- def test_gax_not_implemented (self ):
28
+ def test_ctor (self ):
29
+ client = mock .Mock ()
30
+ with mock .patch ('google.cloud.vision._gax.image_annotator_client.'
31
+ 'ImageAnnotatorClient' ):
32
+ api = self ._make_one (client )
33
+ self .assertIs (api ._client , client )
34
+
35
+
36
+ class TestToGAPICFeature (unittest .TestCase ):
37
+ def _call_fut (self , feature ):
38
+ from google .cloud .vision ._gax import _to_gapic_feature
39
+ return _to_gapic_feature (feature )
40
+
41
+ def test__to_gapic_feature (self ):
42
+ from google .cloud .vision .feature import Feature
43
+ from google .cloud .vision .feature import FeatureTypes
44
+ from google .cloud .grpc .vision .v1 import image_annotator_pb2
45
+
46
+ feature = Feature (FeatureTypes .LABEL_DETECTION , 5 )
47
+ feature_pb = self ._call_fut (feature )
48
+ self .assertIsInstance (feature_pb , image_annotator_pb2 .Feature )
49
+ self .assertEqual (feature_pb .type , 4 )
50
+ self .assertEqual (feature_pb .max_results , 5 )
51
+
52
+
53
+ class TestToGAPICImage (unittest .TestCase ):
54
+ def _call_fut (self , image ):
55
+ from google .cloud .vision ._gax import _to_gapic_image
56
+ return _to_gapic_image (image )
57
+
58
+ def test__to_gapic_image_content (self ):
59
+ import base64
60
+ from google .cloud .vision .image import Image
61
+ from google .cloud .grpc .vision .v1 import image_annotator_pb2
62
+
63
+ image_content = b'abc 1 2 3'
64
+ b64_content = base64 .b64encode (image_content )
65
+ client = object ()
66
+ image = Image (client , content = image_content )
67
+ image_pb = self ._call_fut (image )
68
+ self .assertIsInstance (image_pb , image_annotator_pb2 .Image )
69
+ self .assertEqual (image_pb .content , b64_content )
70
+
71
+ def test__to_gapic_image_uri (self ):
72
+ from google .cloud .vision .image import Image
73
+ from google .cloud .grpc .vision .v1 import image_annotator_pb2
74
+
75
+ image_uri = 'gs://1234/34.jpg'
27
76
client = object ()
28
- with self .assertRaises (NotImplementedError ):
29
- self ._make_one (client = client )
77
+ image = Image (client , source_uri = image_uri )
78
+ image_pb = self ._call_fut (image )
79
+ self .assertIsInstance (image_pb , image_annotator_pb2 .Image )
80
+ self .assertEqual (image_pb .source .gcs_image_uri , image_uri )
81
+
82
+ def test__to_gapic_with_empty_image (self ):
83
+ image = mock .Mock (
84
+ content = None , source = None , spec = ['content' , 'source' ])
85
+ with self .assertRaises (ValueError ):
86
+ self ._call_fut (image )
0 commit comments