예제 #1
0
    def test_broadcast(self):
        communicator = kiwipy.LocalCommunicator()

        messages = []

        def on_broadcast_receive(_comm, body, sender, subject, correlation_id):
            messages.append({
                'body': body,
                'subject': subject,
                'sender': sender,
                'correlation_id': correlation_id
            })

        communicator.add_broadcast_subscriber(on_broadcast_receive)
        proc = test_utils.DummyProcess(communicator=communicator)
        proc.execute()

        expected_subjects = []
        for i, state in enumerate(
                test_utils.DummyProcess.EXPECTED_STATE_SEQUENCE):
            from_state = test_utils.DummyProcess.EXPECTED_STATE_SEQUENCE[
                i - 1].value if i != 0 else None
            expected_subjects.append("state_changed.{}.{}".format(
                from_state, state.value))

        for i, message in enumerate(messages):
            self.assertEqual(message['subject'], expected_subjects[i])
예제 #2
0
파일: test_local.py 프로젝트: unkcpz/kiwipy
 def create_communicator(self):
     return kiwipy.LocalCommunicator()