def test_stream_creation_invalid_workflow(self): with assert_raises_regexp( ValueError, 'Sequential workflow inputs and outputs ' + 'are not compatible. Workflow is invalid.'): ZMQStream('some_stream', 'input_stream', [ PacketHandler(input_type=int, output_type=str, packet='CCSDS_HEADER'), PacketHandler(input_type=int, packet='CCSDS_HEADER') ], zmq_args={'zmq_context': self.broker.context})
class TestStream(object): broker = Broker() stream = ZMQStream('some_stream', ['input_stream'], [ PacketHandler(input_type=int, output_type=str, packet='CCSDS_HEADER') ], zmq_args={'zmq_context': broker.context}) def setUp(self): self.stream.handlers = [ PacketHandler(input_type=int, output_type=str, packet='CCSDS_HEADER') ] def test_stream_creation(self): assert self.stream.name is 'some_stream' assert self.stream.inputs == ['input_stream'] assert len(self.stream.handlers) == 1 assert type(self.stream.handlers[0]) == PacketHandler assert self.stream.context == self.broker.context assert type(self.stream.pub) == zmq.green.core._Socket assert type(self.stream.sub) == zmq.green.core._Socket def test_repr(self): assert self.stream.__repr__() == '<ZMQStream name=some_stream>' @mock.patch.object(PacketHandler, 'handle') def test_process(self, execute_handler_mock): self.stream.process('input_data') execute_handler_mock.assert_called_with('input_data') def test_valid_workflow_one_handler(self): assert self.stream.valid_workflow() is True def test_valid_workflow_more_handlers(self): self.stream.handlers.append( PacketHandler(input_type=str, packet='CCSDS_HEADER')) assert self.stream.valid_workflow() is True def test_invalid_workflow_more_handlers(self): self.stream.handlers.append( PacketHandler(input_type=int, packet='CCSDS_HEADER')) assert self.stream.valid_workflow() is False def test_stream_creation_invalid_workflow(self): with assert_raises_regexp( ValueError, 'Sequential workflow inputs and outputs ' + 'are not compatible. Workflow is invalid.'): ZMQStream('some_stream', 'input_stream', [ PacketHandler(input_type=int, output_type=str, packet='CCSDS_HEADER'), PacketHandler(input_type=int, packet='CCSDS_HEADER') ], zmq_args={'zmq_context': self.broker.context})
class TestHandlerClassWithInputOutputTypes(object): handler = PacketHandler(packet='CCSDS_HEADER', input_type='int', output_type='str') def test_handler_creation(self): assert self.handler.input_type is 'int' assert self.handler.output_type is 'str' @mock.patch('ait.core.server.handler.PacketHandler.handle', return_value='SpecialReturn') def test_execute_handler_returns_handle_return_on_input(self, handle_mock): returned = self.handler.handle('2') assert returned == 'SpecialReturn'
class TestHandlerClassWithoutInputOutputTypes(object): handler = PacketHandler(packet='CCSDS_HEADER') def test_handler_default_params(self): assert self.handler.input_type is None assert self.handler.output_type is None @mock.patch('ait.core.server.handler.PacketHandler.handle', return_value='SpecialReturn') def test_execute_handler_returns_handle_return_on_input(self, handle_mock): returned = self.handler.handle('2') assert returned == 'SpecialReturn' def test_handler_repr(self): assert self.handler.__repr__() == '<handler.PacketHandler>'
def test_invalid_workflow_more_handlers(self): self.stream.handlers.append( PacketHandler(input_type=int, packet='CCSDS_HEADER')) assert self.stream.valid_workflow() is False
def setUp(self): self.stream.handlers = [ PacketHandler(input_type=int, output_type=str, packet='CCSDS_HEADER') ]