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||expect_request||Expect 'request_bytes' to be sent, and reply with 'response_bytes'.|
|Method||expect_disconnect||Expect the client to call medium.disconnect().|
|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.|
|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_line||Read bytes from this request's response until a newline byte.|
|Method||_report_activity||Notify that this medium has activity.|
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()
Will both satisfy medium.expect_request('abcd', ...). Thus tests using this should not break due to irrelevant changes in protocol implementations.
|Parameters||allow_partial_read||if 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.|
The default implementation does nothing.