class TestInMemoryBufferedStreamWriter(object): SAMPLE_IMAGE = object() ANOTHER_SAMPLE_IMAGE = object() SAMPLE_TIMEOUT = 0 SAMPLE_BUFFER_SIZE = 2 def setup(self): self._stream_writer = InMemoryBufferedStreamWriter(self.SAMPLE_BUFFER_SIZE) def test_given_image_written_to_buffer_when_getting_image_then_image_is_returned(self): self._stream_writer.write(self.SAMPLE_IMAGE) image = self._stream_writer.get() assert_is(image, self.SAMPLE_IMAGE) def test_given_images_written_to_buffer_when_getting_images_then_images_are_returned_in_order(self): self._stream_writer.write(self.SAMPLE_IMAGE) self._stream_writer.write(self.ANOTHER_SAMPLE_IMAGE) image_1 = self._stream_writer.get() image_2 = self._stream_writer.get() assert_is(image_1, self.SAMPLE_IMAGE) assert_is(image_2, self.ANOTHER_SAMPLE_IMAGE) @raises(Empty) def test_given_empty_buffer_when_getting_image_then_nothing_is_returned(self): image = self._stream_writer.get(self.SAMPLE_TIMEOUT)
def setup(self): self._stream_writer = InMemoryBufferedStreamWriter(self.SAMPLE_BUFFER_SIZE)