19
19
from google import showcase
20
20
21
21
22
- metadata = (("showcase-trailer" , "hello world" ),)
22
+ _METADATA = (("showcase-trailer" , "hello world" ),)
23
23
24
24
25
25
def test_unary_stream (echo ):
26
26
content = 'The hail in Wales falls mainly on the snails.'
27
27
responses = echo .expand ({
28
28
'content' : content ,
29
- }, metadata = metadata )
29
+ }, metadata = _METADATA )
30
30
31
31
# Consume the response and ensure it matches what we expect.
32
32
# with pytest.raises(exceptions.NotFound) as exc:
@@ -38,11 +38,11 @@ def test_unary_stream(echo):
38
38
(metadata .key , metadata .value )
39
39
for metadata in responses .trailing_metadata ()
40
40
]
41
- assert metadata [0 ] in response_metadata
41
+ assert _METADATA [0 ] in response_metadata
42
42
else :
43
- showcase_header = f"X-Showcase-Request-{ metadata [0 ][0 ]} "
43
+ showcase_header = f"X-Showcase-Request-{ _METADATA [0 ][0 ]} "
44
44
assert showcase_header in responses ._response .headers
45
- assert responses ._response .headers [showcase_header ] == metadata [0 ][1 ]
45
+ assert responses ._response .headers [showcase_header ] == _METADATA [0 ][1 ]
46
46
47
47
48
48
def test_stream_unary (echo ):
@@ -75,7 +75,7 @@ def test_stream_stream(echo):
75
75
requests = []
76
76
requests .append (showcase .EchoRequest (content = "hello" ))
77
77
requests .append (showcase .EchoRequest (content = "world!" ))
78
- responses = echo .chat (iter (requests ), metadata = metadata )
78
+ responses = echo .chat (iter (requests ), metadata = _METADATA )
79
79
80
80
contents = []
81
81
for response in responses :
@@ -86,7 +86,7 @@ def test_stream_stream(echo):
86
86
(metadata .key , metadata .value )
87
87
for metadata in responses .trailing_metadata ()
88
88
]
89
- assert metadata [0 ] in response_metadata
89
+ assert _METADATA [0 ] in response_metadata
90
90
91
91
92
92
def test_stream_stream_passing_dict (echo ):
@@ -95,7 +95,7 @@ def test_stream_stream_passing_dict(echo):
95
95
return
96
96
97
97
requests = [{'content' : 'hello' }, {'content' : 'world!' }]
98
- responses = echo .chat (iter (requests ), metadata = metadata )
98
+ responses = echo .chat (iter (requests ), metadata = _METADATA )
99
99
100
100
contents = []
101
101
for response in responses :
@@ -106,7 +106,7 @@ def test_stream_stream_passing_dict(echo):
106
106
(metadata .key , metadata .value )
107
107
for metadata in responses .trailing_metadata ()
108
108
]
109
- assert metadata [0 ] in response_metadata
109
+ assert _METADATA [0 ] in response_metadata
110
110
111
111
112
112
if os .environ .get ("GAPIC_PYTHON_ASYNC" , "true" ) == "true" :
@@ -117,7 +117,7 @@ async def test_async_unary_stream_reader(async_echo):
117
117
content = 'The hail in Wales falls mainly on the snails.'
118
118
call = await async_echo .expand ({
119
119
'content' : content ,
120
- }, metadata = metadata )
120
+ }, metadata = _METADATA )
121
121
122
122
# Consume the response and ensure it matches what we expect.
123
123
# with pytest.raises(exceptions.NotFound) as exc:
@@ -127,14 +127,14 @@ async def test_async_unary_stream_reader(async_echo):
127
127
assert ground_truth == 'snails.'
128
128
129
129
trailing_metadata = await call .trailing_metadata ()
130
- assert metadata [0 ] in trailing_metadata .items ()
130
+ assert _METADATA [0 ] in trailing_metadata .items ()
131
131
132
132
@pytest .mark .asyncio
133
133
async def test_async_unary_stream_async_generator (async_echo ):
134
134
content = 'The hail in Wales falls mainly on the snails.'
135
135
call = await async_echo .expand ({
136
136
'content' : content ,
137
- }, metadata = metadata )
137
+ }, metadata = _METADATA )
138
138
139
139
# Consume the response and ensure it matches what we expect.
140
140
# with pytest.raises(exceptions.NotFound) as exc:
@@ -145,7 +145,7 @@ async def test_async_unary_stream_async_generator(async_echo):
145
145
assert ground_truth == 'snails.'
146
146
147
147
trailing_metadata = await call .trailing_metadata ()
148
- assert metadata [0 ] in trailing_metadata .items ()
148
+ assert _METADATA [0 ] in trailing_metadata .items ()
149
149
150
150
@pytest .mark .asyncio
151
151
async def test_async_stream_unary_iterable (async_echo ):
@@ -187,7 +187,7 @@ async def test_async_stream_unary_passing_dict(async_echo):
187
187
188
188
@pytest .mark .asyncio
189
189
async def test_async_stream_stream_reader_writier (async_echo ):
190
- call = await async_echo .chat (metadata = metadata )
190
+ call = await async_echo .chat (metadata = _METADATA )
191
191
await call .write (showcase .EchoRequest (content = "hello" ))
192
192
await call .write (showcase .EchoRequest (content = "world!" ))
193
193
await call .done_writing ()
@@ -199,7 +199,7 @@ async def test_async_stream_stream_reader_writier(async_echo):
199
199
assert contents == ['hello' , 'world!' ]
200
200
201
201
trailing_metadata = await call .trailing_metadata ()
202
- assert metadata [0 ] in trailing_metadata .items ()
202
+ assert _METADATA [0 ] in trailing_metadata .items ()
203
203
204
204
@pytest .mark .asyncio
205
205
async def test_async_stream_stream_async_generator (async_echo ):
@@ -208,7 +208,7 @@ async def async_generator():
208
208
yield showcase .EchoRequest (content = "hello" )
209
209
yield showcase .EchoRequest (content = "world!" )
210
210
211
- call = await async_echo .chat (async_generator (), metadata = metadata )
211
+ call = await async_echo .chat (async_generator (), metadata = _METADATA )
212
212
213
213
contents = []
214
214
async for response in call :
@@ -221,12 +221,12 @@ async def async_generator():
221
221
@pytest .mark .asyncio
222
222
async def test_async_stream_stream_passing_dict (async_echo ):
223
223
requests = [{'content' : 'hello' }, {'content' : 'world!' }]
224
- call = await async_echo .chat (iter (requests ), metadata = metadata )
224
+ call = await async_echo .chat (iter (requests ), metadata = _METADATA )
225
225
226
226
contents = []
227
227
async for response in call :
228
228
contents .append (response .content )
229
229
assert contents == ['hello' , 'world!' ]
230
230
231
231
trailing_metadata = await call .trailing_metadata ()
232
- assert metadata [0 ] in trailing_metadata .items ()
232
+ assert _METADATA [0 ] in trailing_metadata .items ()
0 commit comments