def test_manual_singular(): """Exercise ManualPipe's single-link handling.""" print('Testing Piped Singular Event Link with Manual Synchronization:') chunked_stream_link = ChunkedStreamLink() pipe = ManualPipe(chunked_stream_link, chunked_stream_link) # Read/write on links write_bottom_chunked_buffers(chunked_stream_link) pipe.sync() assert_bottom_events(chunked_stream_link) write_top_events(chunked_stream_link) pipe.sync() result = chunked_stream_link.to_write() print('Chunked Stream Link wrote to stream: {}'.format(result)) assert result == HIGHER_CHUNKED_STREAM # Read/write on pipe write_bottom_chunked_buffers(pipe) pipe.sync() assert_bottom_events(pipe) write_top_events(pipe) pipe.sync() result = pipe.to_write() print('Chunked Stream Link wrote to stream: {}'.format(result)) assert result == HIGHER_CHUNKED_STREAM
def test_manual_pipe_composition(): """Exercise ManualPipe nested composition.""" print('Testing Nesting of Piped Event Links with Manual Synchronization:') chunked_stream_link = ChunkedStreamLink() upper_event_link = EventLink() outer_pipe = ManualPipe(ManualPipe(chunked_stream_link, EventLink()), ManualPipe(EventLink(), upper_event_link)) # Read/write on links write_bottom_chunked_buffers(chunked_stream_link) outer_pipe.sync() assert_bottom_events(upper_event_link) write_top_events(upper_event_link) outer_pipe.sync() result = chunked_stream_link.to_write() print('Chunked Stream Link wrote to stream: {}'.format(result)) assert result == HIGHER_CHUNKED_STREAM # Read/write on pipe write_bottom_chunked_buffers(outer_pipe) outer_pipe.sync() assert_bottom_events(outer_pipe) write_top_events(outer_pipe) outer_pipe.sync() result = outer_pipe.to_write() print('Chunked Stream Link wrote to stream: {}'.format(result)) assert result == HIGHER_CHUNKED_STREAM
def make_pipeline_delayed(pipeline_type): """Make a short pipeline.""" pipeline = pipeline_type(StreamLink(), ChunkedStreamLink(), DelayedEventLink(), EventLink(), EventLink()) assert isinstance(pipeline.bottom, StreamLink) assert isinstance(pipeline.top, EventLink) return pipeline
def test_manual_pipe_clocked(): """Exercise ManualPipe's clock functionality.""" print('Testing Piped Clocked Event Links with Manual Synchronization:') pipe = ManualPipe(ChunkedStreamLink(), DelayedEventLink()) print('On deadline:') assert pipe.update_clock(0) is None write_bottom_chunked_buffers(pipe) assert pipe.sync().requested_time == 1.0 assert_clock_request_event_received(pipe, 1.0) assert pipe.update_clock(0.5).requested_time == 1.0 assert not pipe.has_receive() assert pipe.update_clock(0.99).requested_time == 1.0 assert not pipe.has_receive() assert pipe.update_clock(1.0) is None assert_bottom_events(pipe) print('After deadline:') assert pipe.update_clock(0) is None write_top_events(pipe) assert pipe.update_clock(0.5) == 1.0 assert not pipe.to_write() assert pipe.update_clock(0.75) == 1.0 assert not pipe.to_write() assert pipe.update_clock(1.5) is None result = pipe.to_write() assert result == HIGHER_CHUNKED_STREAM
def test_automatic_pipe_clocked(): """Exercise AutomaticPipe's clock functionality.""" print('Testing Piped Clocked Event Links with Automatic Synchronization:') pipe = AutomaticPipe(ChunkedStreamLink(), DelayedEventLink()) assert pipe.update_clock(0) is None write_bottom_chunked_buffers(pipe) assert_clock_request_event_received(pipe, 1.0) assert pipe.update_clock(0.5).requested_time == 1.0 assert not pipe.has_receive() assert pipe.update_clock(0.99).requested_time == 1.0 assert not pipe.has_receive() assert pipe.update_clock(1.0) is None assert_bottom_events(pipe) print('Resetting clock...') assert pipe.update_clock(0) is None print('Writing top events...') write_top_events(pipe) print('Wrote top events!') assert pipe.update_clock(0.5) == 1.0 assert not pipe.to_write() assert pipe.update_clock(0.75) == 1.0 assert not pipe.to_write() assert pipe.update_clock(1.5) is None result = pipe.to_write() assert result == HIGHER_CHUNKED_STREAM
def make_pipeline_long(pipeline_type): """Make a long pipeline.""" pipeline = pipeline_type(StreamLink(), StreamLink(), StreamLink(), ChunkedStreamLink(), EventLink(), EventLink(), EventLink()) assert isinstance(pipeline.bottom, StreamLink) assert isinstance(pipeline.top, EventLink) return pipeline
def make_pipeline_short(pipeline_type): """Make a short pipeline.""" pipeline = pipeline_type( ChunkedStreamLink(), EventLink(), ) assert isinstance(pipeline.bottom, ChunkedStreamLink) assert isinstance(pipeline.top, EventLink) return pipeline
def make_pipeline_loopback(pipeline_factory): """Make a long pipeline with a loopback at the top.""" manual_pipeline = pipeline_factory(StreamLink(), StreamLink(), StreamLink(), ChunkedStreamLink(), EventLink(), EventLink(), EventLink(), TopLoopbackLink()) assert isinstance(manual_pipeline.bottom, StreamLink) assert isinstance(manual_pipeline.top, TopLoopbackLink) return manual_pipeline
def test_automatic_pipe(): """Exercise AutomaticPipe's interface.""" print('Testing Piped Event Links with Automatic Synchronization:') chunked_stream_link = ChunkedStreamLink() event_link = EventLink() pipe = AutomaticPipe(chunked_stream_link, event_link) # Read/write on links write_bottom_chunked_buffers(chunked_stream_link) assert_bottom_events(event_link) write_top_events(event_link) result = chunked_stream_link.to_write() print('Chunked Stream Link wrote to stream: {}'.format(result)) assert result == HIGHER_CHUNKED_STREAM # Read/write on pipe write_bottom_chunked_buffers(pipe) assert_bottom_events(pipe) write_top_events(pipe) result = pipe.to_write() print('Chunked Stream Link wrote to stream: {}'.format(result)) assert result == HIGHER_CHUNKED_STREAM
def make_pipeline_singular(pipeline_type): """Make a singular pipeline.""" pipeline = pipeline_type(ChunkedStreamLink()) assert isinstance(pipeline.bottom, ChunkedStreamLink) assert isinstance(pipeline.top, ChunkedStreamLink) return pipeline
def test_chunked_stream_link(): """Exercise ChunkedStreamLink's interface.""" print('Testing Chunked Stream Link:') chunked_stream_link = ChunkedStreamLink() chunked_stream_link.to_read(LOWER_CHUNKED_BUFFERS[0]) chunked_stream_link.to_read(LOWER_CHUNKED_BUFFERS[1] + LOWER_CHUNKED_BUFFERS[2]) assert chunked_stream_link.has_receive() for (i, event) in enumerate(chunked_stream_link.receive_all()): print('Chunked Stream Link received from stream: {}'.format(event)) assert event.data == LOWER_BUFFERS[i] for event in HIGHER_BUFFERS: chunked_stream_link.send(event) result = chunked_stream_link.to_write() print('Chunked Stream Link wrote to stream: {}'.format(result)) assert result == HIGHER_CHUNKED_STREAM print('Testing Chunked Stream Link without chunk starting delimiters:') chunked_stream_link = ChunkedStreamLink(begin_chunk_separator=False) chunked_stream_link.to_read(LOWER_CHUNKED_BUFFERS[0]) chunked_stream_link.to_read(LOWER_CHUNKED_BUFFERS[1] + LOWER_CHUNKED_BUFFERS[2]) assert chunked_stream_link.has_receive() for (i, event) in enumerate(chunked_stream_link.receive_all()): print('Chunked Stream Link received from stream: {}'.format(event)) assert event.data == LOWER_BUFFERS[i] for event in HIGHER_BUFFERS: chunked_stream_link.send(event) result = chunked_stream_link.to_write() print('Chunked Stream Link wrote to stream: {}'.format(result)) assert result == HIGHER_CHUNKED_STREAM_MINIMAL