15
15
import http .client
16
16
import json
17
17
18
- import grpc
19
18
import mock
19
+ import pytest
20
20
import requests
21
21
22
+ try :
23
+ import grpc
24
+ except ImportError :
25
+ grpc = None
26
+
22
27
from google .api_core import exceptions
23
28
24
29
@@ -151,6 +156,7 @@ def test_from_http_response_json_unicode_content():
151
156
assert exception .errors == ["1" , "2" ]
152
157
153
158
159
+ @pytest .mark .skipif (grpc is None , reason = "No grpc" )
154
160
def test_from_grpc_status ():
155
161
message = "message"
156
162
exception = exceptions .from_grpc_status (grpc .StatusCode .OUT_OF_RANGE , message )
@@ -162,6 +168,7 @@ def test_from_grpc_status():
162
168
assert exception .errors == []
163
169
164
170
171
+ @pytest .mark .skipif (grpc is None , reason = "No grpc" )
165
172
def test_from_grpc_status_as_int ():
166
173
message = "message"
167
174
exception = exceptions .from_grpc_status (11 , message )
@@ -173,6 +180,7 @@ def test_from_grpc_status_as_int():
173
180
assert exception .errors == []
174
181
175
182
183
+ @pytest .mark .skipif (grpc is None , reason = "No grpc" )
176
184
def test_from_grpc_status_with_errors_and_response ():
177
185
message = "message"
178
186
response = mock .sentinel .response
@@ -187,13 +195,15 @@ def test_from_grpc_status_with_errors_and_response():
187
195
assert exception .response == response
188
196
189
197
198
+ @pytest .mark .skipif (grpc is None , reason = "No grpc" )
190
199
def test_from_grpc_status_unknown_code ():
191
200
message = "message"
192
201
exception = exceptions .from_grpc_status (grpc .StatusCode .OK , message )
193
202
assert exception .grpc_status_code == grpc .StatusCode .OK
194
203
assert exception .message == message
195
204
196
205
206
+ @pytest .mark .skipif (grpc is None , reason = "No grpc" )
197
207
def test_from_grpc_error ():
198
208
message = "message"
199
209
error = mock .create_autospec (grpc .Call , instance = True )
@@ -211,6 +221,7 @@ def test_from_grpc_error():
211
221
assert exception .response == error
212
222
213
223
224
+ @pytest .mark .skipif (grpc is None , reason = "No grpc" )
214
225
def test_from_grpc_error_non_call ():
215
226
message = "message"
216
227
error = mock .create_autospec (grpc .RpcError , instance = True )
0 commit comments