b.t.t.MockMedium(medium.SmartClientMedium) : class documentation

Part of bzrlib.tests.test_smart_transport View In Hierarchy

A mock medium that can be used to test _SmartClient.

It can be given a series of requests to expect (and responses it should return for them). It can also be told when the client is expected to disconnect a medium. Expectations must be satisfied in the order they are given, or else an AssertionError will be raised.

Typical use looks like:

medium = MockMedium()
medium.expect_request(...)
medium.expect_request(...)
medium.expect_request(...)
Method __init__ Undocumented
Method expect_request Expect 'request_bytes' to be sent, and reply with 'response_bytes'.
Method expect_disconnect Expect the client to call medium.disconnect().
Method get_request Undocumented
Method disconnect If this medium maintains a persistent connection, close it.
Method _assertEvent Raise AssertionError unless observed_event matches the next expected

Inherited from SmartClientMedium:

Method protocol_version Find out if 'hello' smart request works.
Method should_probe Should RemoteBzrDirFormat.probe_transport send a smart request on
Method remote_path_from_transport Convert transport into a path suitable for using in a request.
Method _is_remote_before Is it possible the remote side supports RPCs for a given version?
Method _remember_remote_is_before Tell this medium that the remote side is older the given version.

Inherited from SmartMedium (via SmartClientMedium):

Method read_bytes Read some bytes from this medium.
Method _push_back Return unused bytes to the medium, because they belong to the next
Method _get_push_back_buffer Undocumented
Method _read_bytes Undocumented
Method _get_line Read bytes from this request's response until a newline byte.
Method _report_activity Notify that this medium has activity.
def __init__(self):
Undocumented
def expect_request(self, request_bytes, response_bytes, allow_partial_read=False):
Expect 'request_bytes' to be sent, and reply with 'response_bytes'.

No assumption is made about how many times accept_bytes should be called to send the request. Similarly, no assumption is made about how many times read_bytes/read_line are called by protocol code to read a response. e.g.:

request.accept_bytes('ab')
request.accept_bytes('cd')
request.finished_writing()

and:

request.accept_bytes('abcd')
request.finished_writing()

Will both satisfy medium.expect_request('abcd', ...). Thus tests using this should not break due to irrelevant changes in protocol implementations.

Parametersallow_partial_readif True, no assertion is raised if a response is not fully read. Setting this is useful when the client is expected to disconnect without needing to read the complete response. Default is False.
def expect_disconnect(self):
Expect the client to call medium.disconnect().
def _assertEvent(self, observed_event):
Raise AssertionError unless observed_event matches the next expected event.
See Alsoexpect_request
expect_disconnect
def get_request(self):
Undocumented
def disconnect(self):
If this medium maintains a persistent connection, close it.

The default implementation does nothing.

API Documentation for Bazaar, generated by pydoctor at 2022-06-16 00:25:16.