示例#1
0
 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})
示例#2
0
 def test_stream_creation_invalid_workflow(self):
     with pytest.raises(ValueError):
         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},
         )
示例#3
0
 def setup_method(self):
     self.broker = Broker()
     self.stream = ZMQStream(
         "some_stream",
         ["input_stream"],
         [
             PacketHandler(
                 input_type=int, output_type=str, packet="CCSDS_HEADER")
         ],
         zmq_args={"zmq_context": self.broker.context},
     )
     self.stream.handlers = [
         PacketHandler(input_type=int,
                       output_type=str,
                       packet="CCSDS_HEADER")
     ]
示例#4
0
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})
示例#5
0
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.handlers.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'
示例#6
0
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.handlers.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"
示例#7
0
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.handlers.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>'
示例#8
0
 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
示例#9
0
 def setUp(self):
     self.stream.handlers = [
         PacketHandler(input_type=int,
                       output_type=str,
                       packet='CCSDS_HEADER')
     ]
示例#10
0
 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