예제 #1
0
    def setUp(self):
        self.component_manager = ComponentManager()
        self.component_manager.clear_component_registry()
        component(scope='session')(TestTestRunnerComponents.Verifier)
        self.load_components()
        self.verifier = TestTestRunnerComponents.Verifier()
        self.parent_scope = Scope('session', None)
        self.parent_scope.register_instance(
            _InstanceId(TestTestRunnerComponents.Verifier, ()), self.verifier)
        self.run_queue = []
        self.messagebus = Mock()

        def send_request(message_id,
                         endpoint_id=None,
                         entities=None,
                         data=None):
            futures = Mock()
            if message_id == SCHEDULE_NEXT_TEST:
                future = Mock()
                if self.run_queue:
                    future.result.return_value = self.run_queue.pop(0)
                else:
                    future.result.return_value = None

                futures.wait.return_value = [future]
            return futures

        self.messagebus.send_request.side_effect = send_request
        self.tr = TestRunner(self.messagebus,
                             Factory(self.component_manager),
                             'suite-name',
                             parent_scope=self.parent_scope)
예제 #2
0
    def init_component_handling(self, components):
        self.component_registry = create_registry()
        self.component_manager = ComponentManager(self.component_registry)
        self.component_factory = Factory(self.component_manager)
        self.messagebus = MessageBus(self.component_factory, Scope('session'))

        components.append(
            ComponentMock(name='ComponentFactory',
                          mock=self.component_factory))
        components.append(
            ComponentMock(name='MessageBus', mock=self.messagebus))
        components.append(ComponentMock(name='Config', mock=self.config))
        components.append(
            ComponentMock(name='ComponentManager',
                          mock=self.component_manager))
        components.append(
            ComponentMock(name='ExtensionManager', mock=MagicMock()))
        for comp in components:
            if type(comp) == ComponentMock:
                component(name=comp.name,
                          scope=comp.scope,
                          can=comp.can,
                          provided_by_extension=comp.provided_by_extension)(
                              comp, self.component_manager)
            else:
                self.component_manager.register_component(comp)
예제 #3
0
    def setUp(self):
        self.run_queue = []
        messagebus = Mock()

        def send_request(message_id,
                         endpoint_id=None,
                         entities=None,
                         data=None):
            futures = Mock()
            if message_id == SCHEDULE_NEXT_TEST:
                future = Mock()
                if self.run_queue:
                    future.result.return_value = self.run_queue.pop(0)
                else:
                    future.result.return_value = None

                futures.wait.return_value = [future]
            return futures

        messagebus.send_request.side_effect = send_request

        self.tr = TestRunner(messagebus=messagebus,
                             component_factory=Factory(ComponentManager()),
                             suite_name='suite-name')
        self.tr.QUEUE_TIMEOUT_SECONDS = 1
        self.tr.EXECUTION_PAUSED_TIMEOUT_SECONDS = 1
예제 #4
0
 def test_fail_when_no_serial_connection_is_registered_to_send_command(self):
     messagebus = MessageBus(Factory(ComponentManager(COMPONENT_REGISTRY)))
     messagebus.define_endpoints_and_messages({SERIAL_ENDPOINT: [LOG_LINE_RECEIVED]})
     client = SerialClient(messagebus, 'entity')
     with self.assertRaises(SerialError) as error:
         client.send_line('line', timeout=1)
         assert 'No serial connection' in error.msg
예제 #5
0
    def test_enabling_remote_client_registers_component(self):
        component_manager = ComponentManager()
        component_manager.clear_component_registry()

        config = ConfigManager()
        config.set(REMOTE_CLIENT_ENABLED, True)

        with ExtensionTestHarness(RemoteClientExtension, config=config):
            self.assertIn('RemoteClient', component_manager.COMPONENT_REGISTRY)
예제 #6
0
 def setUp(self):
     self.messagebus = MessageBus(Factory(ComponentManager({})))
     self.endpoint = MOCK_ENDPOINT
     self.sut = Mock()
     self.sut.entity = 'entity'
     self.config = Mock()
     self.config.get = MagicMock(side_effect=config_get_log_sources)
     self.messagebus.define_endpoints_and_messages(
         {self.endpoint: [LOG_LINE_RECEIVED]})
예제 #7
0
    def setUp(self):
        self.messagebus = MessageBus(Factory(ComponentManager({})))
        self.sut = MagicMock()
        self.sut.entity = 'entity1'
        config = Mock()

        self.messagebus.define_endpoints_and_messages({
            MOCK_ENDPOINT: [SUT_RESET_EXPECTED],
            SUTEVENTSCOMPONENT_ENDPOINT: [SUT_RESET_EXPECTED, SUT_RESET_DONE]
        })
        self.sut_events = SutEvents(self.messagebus, config, self.sut)
예제 #8
0
 def setUp(self):
     ComponentManager().clear_component_registry()
예제 #9
0
    def __init__(self,
                 application_config,
                 entry_points=['zaf.addons', 'zaf.local_addons'],
                 signalhandler=None):
        root_logger = logging.getLogger()
        # Default config for rootlogger to not spam until logger is correctly configured
        root_logger.setLevel(logging.INFO)

        self.app_config = application_config
        self.signalhandler = signalhandler
        self.entry_points = entry_points
        self.extension_manager = ExtensionManager()
        self.component_manager = ComponentManager()
        self.component_factory = Factory(self.component_manager)
        self.session_scope = self.component_factory.enter_scope('session')
        self.messagebus = MessageBus(self.component_factory,
                                     self.session_scope)
        self.messagebus.define_endpoints_and_messages(
            {APPLICATION_ENDPOINT: [BEFORE_COMMAND, AFTER_COMMAND]})
        self.config = ConfigManager()
        self.command = None
        self._exit_code = 1
        self.app_config.apply_configuration(self.config)

        @component(name='MessageBus', scope='session')
        def messagebus():
            """
            Access the message bus.

            The message bus can be used to register dispatchers to specific
            endpoints, message_ids and entities and to send requests and events
            to the registered dispatchers.
            """
            return self.messagebus

        @component(name='ComponentFactory', scope='session')
        def component_factory():
            """
            Access the component factory.

            The component factory can be used to call callables inside a scope
            and have the correct components instantiated in the scope.
            """
            return self.component_factory

        @component(name='ComponentManager', scope='session')
        def component_manager():
            """
            Access the component manager.

            The component manager can be used to find out what components are
            available.
            """
            return self.component_manager

        @component(name='Config', scope='session')
        def config():
            """
            Access the Config Manager.

            The Config components gives full access to all the config.
            """
            return self.config

        @component(name='ExtensionManager', scope='session')
        def extension_manager():
            """
            Access the extension manager.

            The extension manager can be used to find out what extensions are
            loaded.
            """
            return self.extension_manager
예제 #10
0
 def setUp(self):
     self.component_manager = ComponentManager()
     self.component_manager.clear_component_registry()
     self.load_components()
예제 #11
0
 def setUp(self):
     self.component_manager = ComponentManager(create_registry(),
                                               create_entity_map())
예제 #12
0
 def setUp(self):
     component_manager = ComponentManager()
     component_manager.clear_component_registry()
     self.registry = component_manager.COMPONENT_REGISTRY
     self.builder = DependencyGraphBuilder(self.registry)
예제 #13
0
 def setUp(self):
     self.component_manager = ComponentManager(create_registry(),
                                               create_entity_map())
     self.registry = self.component_manager.COMPONENT_REGISTRY
     self.builder = DependencyGraphBuilder(self.registry)
     self.scope = Scope('scope')
예제 #14
0
    def test_multiple_request_dispatchers_triggered_by_applicable_requests(
            self):
        messagebus = MessageBus(Factory(ComponentManager()))

        request_target = EndpointId('request_target', '')
        request_target2 = EndpointId('request_target2', '')
        request_target_entity1 = 'target_entity1'
        request_target_entity2 = 'target_entity2'

        sent_to_all = MessageId('request_to_all', '')
        sent_to_target = MessageId('request_to_target', '')
        sent_to_entity1 = MessageId('request_to_entity1', '')

        messagebus.define_endpoint(request_target)
        messagebus.define_endpoint(request_target2)

        messagebus.define_message(sent_to_all, request_target)
        messagebus.define_message(sent_to_target, request_target)
        messagebus.define_message(sent_to_entity1, request_target)

        messagebus.define_message(sent_to_all, request_target2)
        messagebus.define_message(sent_to_target, request_target2)
        messagebus.define_message(sent_to_entity1, request_target2)

        received = {
            request_target: [],
            request_target2: [],
            request_target_entity1: [],
            request_target_entity2: []
        }

        def target1(message):
            received[request_target].append(message.message_id)

        messagebus.register_dispatcher(
            create_dispatcher(target1),
            [sent_to_all, sent_to_target, sent_to_entity1], [request_target])

        def target2(message):
            received[request_target2].append(message.message_id)

        messagebus.register_dispatcher(
            create_dispatcher(target2),
            [sent_to_all, sent_to_target, sent_to_entity1], [request_target2])

        def target_entity1(message):
            received[request_target_entity1].append(message.message_id)

        messagebus.register_dispatcher(
            create_dispatcher(target_entity1),
            [sent_to_all, sent_to_target, sent_to_entity1], [request_target],
            [request_target_entity1])

        def target_entity2(message):
            received[request_target_entity2].append(message.message_id)

        messagebus.register_dispatcher(
            create_dispatcher(target_entity2),
            [sent_to_all, sent_to_target, sent_to_entity1], [request_target],
            [request_target_entity2])

        messagebus.send_request(sent_to_all)
        messagebus.send_request(sent_to_target, request_target)
        messagebus.send_request(sent_to_entity1, request_target,
                                request_target_entity1)

        self.assertEqual(received[request_target],
                         [sent_to_all, sent_to_target])
        self.assertEqual(received[request_target2], [sent_to_all])
        self.assertEqual(received[request_target_entity1],
                         [sent_to_all, sent_to_target, sent_to_entity1])
        self.assertEqual(received[request_target_entity2],
                         [sent_to_all, sent_to_target])
예제 #15
0
    def test_multiple_message_dispatchers_triggered_by_applicable_messages(
            self):
        messagebus = MessageBus(Factory(ComponentManager()))

        message_endpoint = EndpointId('message_endpoint', '')
        message_endpoint2 = EndpointId('message_endpoint2', '')
        message_endpoint_entity1 = 'endpoint_entity1'
        message_endpoint_entity2 = 'endpoint_entity2'

        sent_from_endpoint = MessageId('sent_from_endpoint', '')
        sent_from_entity1 = MessageId('sent_from_entity1', '')

        messagebus.define_endpoint(message_endpoint)
        messagebus.define_endpoint(message_endpoint2)
        messagebus.define_message(sent_from_endpoint, message_endpoint)
        messagebus.define_message(sent_from_entity1, message_endpoint)
        messagebus.define_message(sent_from_endpoint, message_endpoint2)
        messagebus.define_message(sent_from_entity1, message_endpoint2)

        received = {
            message_endpoint: [],
            message_endpoint2: [],
            message_endpoint_entity1: [],
            message_endpoint_entity2: []
        }

        def endpoint1(message):
            received[message_endpoint].append(message.message_id)

        messagebus.register_dispatcher(create_dispatcher(endpoint1),
                                       [sent_from_endpoint, sent_from_entity1],
                                       [message_endpoint])

        def endpoint2(message):
            received[message_endpoint2].append(message.message_id)

        messagebus.register_dispatcher(create_dispatcher(endpoint2),
                                       [sent_from_endpoint, sent_from_entity1],
                                       [message_endpoint2])

        def endpoint_entity1(message):
            received[message_endpoint_entity1].append(message.message_id)

        messagebus.register_dispatcher(create_dispatcher(endpoint_entity1),
                                       [sent_from_endpoint, sent_from_entity1],
                                       [message_endpoint],
                                       [message_endpoint_entity1])

        def endpoint_entity2(message):
            received[message_endpoint_entity2].append(message.message_id)

        messagebus.register_dispatcher(create_dispatcher(endpoint_entity2),
                                       [sent_from_endpoint, sent_from_entity1],
                                       [message_endpoint],
                                       [message_endpoint_entity2])

        messagebus.trigger_event(sent_from_endpoint, message_endpoint)
        messagebus.trigger_event(sent_from_entity1, message_endpoint,
                                 message_endpoint_entity1)

        self.assertEqual(received[message_endpoint],
                         [sent_from_endpoint, sent_from_entity1])
        self.assertEqual(received[message_endpoint2], [])
        self.assertEqual(received[message_endpoint_entity1],
                         [sent_from_entity1])
        self.assertEqual(received[message_endpoint_entity2], [])