14 """Objects for use in testing gRPC Python-using application code."""
24 """Fixture for a unary-unary RPC invoked by a system under test.
26 Enables users to "play server" for the RPC.
31 """Sends the RPC's initial metadata to the system under test.
34 initial_metadata: The RPC's initial metadata to be "sent" to
35 the system under test.
37 raise NotImplementedError()
41 """Blocks until the system under test has cancelled the RPC."""
42 raise NotImplementedError()
45 def terminate(self, response, trailing_metadata, code, details):
46 """Terminates the RPC.
49 response: The response for the RPC.
50 trailing_metadata: The RPC's trailing metadata.
51 code: The RPC's status code.
52 details: The RPC's status details.
54 raise NotImplementedError()
58 """Fixture for a unary-stream RPC invoked by a system under test.
60 Enables users to "play server" for the RPC.
65 """Sends the RPC's initial metadata to the system under test.
68 initial_metadata: The RPC's initial metadata to be "sent" to
69 the system under test.
71 raise NotImplementedError()
75 """Sends a response to the system under test.
78 response: A response message to be "sent" to the system under test.
80 raise NotImplementedError()
84 """Blocks until the system under test has cancelled the RPC."""
85 raise NotImplementedError()
88 def terminate(self, trailing_metadata, code, details):
89 """Terminates the RPC.
92 trailing_metadata: The RPC's trailing metadata.
93 code: The RPC's status code.
94 details: The RPC's status details.
96 raise NotImplementedError()
100 """Fixture for a stream-unary RPC invoked by a system under test.
102 Enables users to "play server" for the RPC.
107 """Sends the RPC's initial metadata to the system under test.
110 initial_metadata: The RPC's initial metadata to be "sent" to
111 the system under test.
113 raise NotImplementedError()
117 """Draws one of the requests added to the RPC by the system under test.
119 This method blocks until the system under test has added to the RPC
120 the request to be returned.
122 Successive calls to this method return requests in the same order in
123 which the system under test added them to the RPC.
126 A request message added to the RPC by the system under test.
128 raise NotImplementedError()
132 """Blocks until the system under test has closed the request stream."""
133 raise NotImplementedError()
137 """Blocks until the system under test has cancelled the RPC."""
138 raise NotImplementedError()
141 def terminate(self, response, trailing_metadata, code, details):
142 """Terminates the RPC.
145 response: The response for the RPC.
146 trailing_metadata: The RPC's trailing metadata.
147 code: The RPC's status code.
148 details: The RPC's status details.
150 raise NotImplementedError()
154 """Fixture for a stream-stream RPC invoked by a system under test.
156 Enables users to "play server" for the RPC.
161 """Sends the RPC's initial metadata to the system under test.
164 initial_metadata: The RPC's initial metadata to be "sent" to the
167 raise NotImplementedError()
171 """Draws one of the requests added to the RPC by the system under test.
173 This method blocks until the system under test has added to the RPC
174 the request to be returned.
176 Successive calls to this method return requests in the same order in
177 which the system under test added them to the RPC.
180 A request message added to the RPC by the system under test.
182 raise NotImplementedError()
186 """Sends a response to the system under test.
189 response: A response messages to be "sent" to the system under test.
191 raise NotImplementedError()
195 """Blocks until the system under test has closed the request stream."""
196 raise NotImplementedError()
200 """Blocks until the system under test has cancelled the RPC."""
201 raise NotImplementedError()
205 """Terminates the RPC.
208 trailing_metadata: The RPC's trailing metadata.
209 code: The RPC's status code.
210 details: The RPC's status details.
212 raise NotImplementedError()
216 """A grpc.Channel double with which to test a system that invokes RPCs."""
220 """Draws an RPC currently being made by the system under test.
222 If the given descriptor does not identify any RPC currently being made
223 by the system under test, this method blocks until the system under
224 test invokes such an RPC.
227 method_descriptor: A descriptor.MethodDescriptor describing a
228 unary-unary RPC method.
231 A (invocation_metadata, request, unary_unary_channel_rpc) tuple of
232 the RPC's invocation metadata, its request, and a
233 UnaryUnaryChannelRpc with which to "play server" for the RPC.
235 raise NotImplementedError()
239 """Draws an RPC currently being made by the system under test.
241 If the given descriptor does not identify any RPC currently being made
242 by the system under test, this method blocks until the system under
243 test invokes such an RPC.
246 method_descriptor: A descriptor.MethodDescriptor describing a
247 unary-stream RPC method.
250 A (invocation_metadata, request, unary_stream_channel_rpc) tuple of
251 the RPC's invocation metadata, its request, and a
252 UnaryStreamChannelRpc with which to "play server" for the RPC.
254 raise NotImplementedError()
258 """Draws an RPC currently being made by the system under test.
260 If the given descriptor does not identify any RPC currently being made
261 by the system under test, this method blocks until the system under
262 test invokes such an RPC.
265 method_descriptor: A descriptor.MethodDescriptor describing a
266 stream-unary RPC method.
269 A (invocation_metadata, stream_unary_channel_rpc) tuple of the RPC's
270 invocation metadata and a StreamUnaryChannelRpc with which to "play
273 raise NotImplementedError()
277 """Draws an RPC currently being made by the system under test.
279 If the given descriptor does not identify any RPC currently being made
280 by the system under test, this method blocks until the system under
281 test invokes such an RPC.
284 method_descriptor: A descriptor.MethodDescriptor describing a
285 stream-stream RPC method.
288 A (invocation_metadata, stream_stream_channel_rpc) tuple of the RPC's
289 invocation metadata and a StreamStreamChannelRpc with which to
290 "play server" for the RPC.
292 raise NotImplementedError()
296 """Fixture for a unary-unary RPC serviced by a system under test.
298 Enables users to "play client" for the RPC.
303 """Accesses the initial metadata emitted by the system under test.
305 This method blocks until the system under test has added initial
306 metadata to the RPC (or has provided one or more response messages or
307 has terminated the RPC, either of which will cause gRPC Python to
308 synthesize initial metadata for the RPC).
311 The initial metadata for the RPC.
313 raise NotImplementedError()
317 """Cancels the RPC."""
318 raise NotImplementedError()
322 """Blocks until the system under test has terminated the RPC.
325 A (response, trailing_metadata, code, details) sequence with the RPC's
326 response, trailing metadata, code, and details.
328 raise NotImplementedError()
332 """Fixture for a unary-stream RPC serviced by a system under test.
334 Enables users to "play client" for the RPC.
339 """Accesses the initial metadata emitted by the system under test.
341 This method blocks until the system under test has added initial
342 metadata to the RPC (or has provided one or more response messages or
343 has terminated the RPC, either of which will cause gRPC Python to
344 synthesize initial metadata for the RPC).
347 The initial metadata for the RPC.
349 raise NotImplementedError()
353 """Draws one of the responses added to the RPC by the system under test.
355 Successive calls to this method return responses in the same order in
356 which the system under test added them to the RPC.
359 A response message added to the RPC by the system under test.
361 raise NotImplementedError()
365 """Cancels the RPC."""
366 raise NotImplementedError()
370 """Blocks until the system under test has terminated the RPC.
373 A (trailing_metadata, code, details) sequence with the RPC's trailing
374 metadata, code, and details.
376 raise NotImplementedError()
380 """Fixture for a stream-unary RPC serviced by a system under test.
382 Enables users to "play client" for the RPC.
387 """Accesses the initial metadata emitted by the system under test.
389 This method blocks until the system under test has added initial
390 metadata to the RPC (or has provided one or more response messages or
391 has terminated the RPC, either of which will cause gRPC Python to
392 synthesize initial metadata for the RPC).
395 The initial metadata for the RPC.
397 raise NotImplementedError()
401 """Sends a request to the system under test.
404 request: A request message for the RPC to be "sent" to the system
407 raise NotImplementedError()
411 """Indicates the end of the RPC's request stream."""
412 raise NotImplementedError()
416 """Cancels the RPC."""
417 raise NotImplementedError()
421 """Blocks until the system under test has terminated the RPC.
424 A (response, trailing_metadata, code, details) sequence with the RPC's
425 response, trailing metadata, code, and details.
427 raise NotImplementedError()
431 """Fixture for a stream-stream RPC serviced by a system under test.
433 Enables users to "play client" for the RPC.
438 """Accesses the initial metadata emitted by the system under test.
440 This method blocks until the system under test has added initial
441 metadata to the RPC (or has provided one or more response messages or
442 has terminated the RPC, either of which will cause gRPC Python to
443 synthesize initial metadata for the RPC).
446 The initial metadata for the RPC.
448 raise NotImplementedError()
452 """Sends a request to the system under test.
455 request: A request message for the RPC to be "sent" to the system
458 raise NotImplementedError()
462 """Indicates the end of the RPC's request stream."""
463 raise NotImplementedError()
467 """Draws one of the responses added to the RPC by the system under test.
469 Successive calls to this method return responses in the same order in
470 which the system under test added them to the RPC.
473 A response message added to the RPC by the system under test.
475 raise NotImplementedError()
479 """Cancels the RPC."""
480 raise NotImplementedError()
484 """Blocks until the system under test has terminated the RPC.
487 A (trailing_metadata, code, details) sequence with the RPC's trailing
488 metadata, code, and details.
490 raise NotImplementedError()
493 class Server(six.with_metaclass(abc.ABCMeta)):
494 """A server with which to test a system that services RPCs."""
499 """Invokes an RPC to be serviced by the system under test.
502 method_descriptor: A descriptor.MethodDescriptor describing a unary-unary
504 invocation_metadata: The RPC's invocation metadata.
505 request: The RPC's request.
506 timeout: A duration of time in seconds for the RPC or None to
507 indicate that the RPC has no time limit.
510 A UnaryUnaryServerRpc with which to "play client" for the RPC.
512 raise NotImplementedError()
517 """Invokes an RPC to be serviced by the system under test.
520 method_descriptor: A descriptor.MethodDescriptor describing a unary-stream
522 invocation_metadata: The RPC's invocation metadata.
523 request: The RPC's request.
524 timeout: A duration of time in seconds for the RPC or None to
525 indicate that the RPC has no time limit.
528 A UnaryStreamServerRpc with which to "play client" for the RPC.
530 raise NotImplementedError()
535 """Invokes an RPC to be serviced by the system under test.
538 method_descriptor: A descriptor.MethodDescriptor describing a stream-unary
540 invocation_metadata: The RPC's invocation metadata.
541 timeout: A duration of time in seconds for the RPC or None to
542 indicate that the RPC has no time limit.
545 A StreamUnaryServerRpc with which to "play client" for the RPC.
547 raise NotImplementedError()
552 """Invokes an RPC to be serviced by the system under test.
555 method_descriptor: A descriptor.MethodDescriptor describing a stream-stream
557 invocation_metadata: The RPC's invocation metadata.
558 timeout: A duration of time in seconds for the RPC or None to
559 indicate that the RPC has no time limit.
562 A StreamStreamServerRpc with which to "play client" for the RPC.
564 raise NotImplementedError()
567 class Time(six.with_metaclass(abc.ABCMeta)):
568 """A simulation of time.
570 Implementations needn't be connected with real time as provided by the
571 Python interpreter, but as long as systems under test use
572 RpcContext.is_active and RpcContext.time_remaining for querying RPC liveness
573 implementations may be used to change passage of time in tests.
578 """Accesses the current test time.
581 The current test time (over which this object has authority).
583 raise NotImplementedError()
587 """Adds a behavior to be called after some time.
590 behavior: A behavior to be called with no arguments.
591 delay: A duration of time in seconds after which to call the behavior.
594 A grpc.Future with which the call of the behavior may be cancelled
595 before it is executed.
597 raise NotImplementedError()
601 """Adds a behavior to be called at a specific time.
604 behavior: A behavior to be called with no arguments.
605 time: The test time at which to call the behavior.
608 A grpc.Future with which the call of the behavior may be cancelled
609 before it is executed.
611 raise NotImplementedError()
615 """Blocks for some length of test time.
618 duration: A duration of test time in seconds for which to block.
620 raise NotImplementedError()
624 """Blocks until some test time.
627 time: The test time until which to block.
629 raise NotImplementedError()
633 """Creates a Time backed by the Python interpreter's time.
635 The returned instance will be "strict" with respect to callbacks
636 submitted to it: it will ensure that all callbacks registered to
637 be called at time t have been called before it describes the time
638 as having advanced beyond t.
641 A Time backed by the "system" (Python interpreter's) time.
643 from grpc_testing
import _time
648 """Creates a Time that can be manipulated by test code.
650 The returned instance maintains an internal representation of time
651 independent of real time. This internal representation only advances
652 when user code calls the instance's sleep_for and sleep_until methods.
654 The returned instance will be "strict" with respect to callbacks
655 submitted to it: it will ensure that all callbacks registered to
656 be called at time t have been called before it describes the time
657 as having advanced beyond t.
660 A Time that simulates the passage of time.
662 from grpc_testing
import _time
667 """Creates a Channel for use in tests of a gRPC Python-using system.
670 service_descriptors: An iterable of descriptor.ServiceDescriptors
671 describing the RPCs that will be made on the returned Channel by the
673 time: A Time to be used for tests.
676 A Channel for use in tests.
678 from grpc_testing
import _channel
679 return _channel.testing_channel(service_descriptors, time)
683 """Creates a Server for use in tests of a gRPC Python-using system.
686 descriptors_to_servicers: A dictionary from descriptor.ServiceDescriptors
687 defining RPC services to servicer objects (usually instances of classes
688 that implement "Servicer" interfaces defined in generated "_pb2_grpc"
689 modules) implementing those services.
690 time: A Time to be used for tests.
693 A Server for use in tests.
695 from grpc_testing
import _server
696 return _server.server_from_dictionary(descriptors_to_servicers, time)