Пример #1
0
 def setUp(self):    # pylint: disable=invalid-name
     """ things to be run when tests are started. """
     self.pool = ha.create_worker_pool(0)
     self.bus = ha.EventBus(self.pool)
     self.states = ha.StateMachine(self.bus)
     self.states.set("light.Bowl", "on")
     self.states.set("switch.AC", "off")
Пример #2
0
 def setUp(self):  # pylint: disable=invalid-name
     """ things to be run when tests are started. """
     self.pool = ha.create_worker_pool(0)
     self.bus = ha.EventBus(self.pool)
     self.states = ha.StateMachine(self.bus)
     self.states.set("light.Bowl", "on")
     self.states.set("switch.AC", "off")
Пример #3
0
    def __init__(self, remote_api, local_api=None):
        if not remote_api.validate_api():
            raise ha.HomeAssistantError(
                "Remote API not valid: {}".format(remote_api.status))

        self.remote_api = remote_api
        self.local_api = local_api

        self._pool = pool = ha.create_worker_pool()

        self.bus = EventBus(remote_api, pool)
        self.services = ha.ServiceRegistry(self.bus, pool)
        self.states = StateMachine(self.bus, self.remote_api)
Пример #4
0
    def __init__(self, remote_api, local_api=None):
        if not remote_api.validate_api():
            raise ha.HomeAssistantError(
                "Remote API at {}:{} not valid: {}".format(
                    remote_api.host, remote_api.port, remote_api.status))

        self.remote_api = remote_api
        self.local_api = local_api

        self._pool = pool = ha.create_worker_pool()

        self.bus = EventBus(remote_api, pool)
        self.services = ha.ServiceRegistry(self.bus, pool)
        self.states = StateMachine(self.bus, self.remote_api)
Пример #5
0
    def test_exception_during_job(self):
        pool = ha.create_worker_pool(1)

        def malicious_job(_):
            raise Exception("Test breaking worker pool")

        calls = []

        def register_call(_):
            calls.append(1)

        pool.add_job(ha.JobPriority.EVENT_DEFAULT, (malicious_job, None))
        pool.add_job(ha.JobPriority.EVENT_DEFAULT, (register_call, None))
        pool.block_till_done()
        self.assertEqual(1, len(calls))
Пример #6
0
    def test_exception_during_job(self):
        pool = ha.create_worker_pool(1)

        def malicious_job(_):
            raise Exception("Test breaking worker pool")

        calls = []

        def register_call(_):
            calls.append(1)

        pool.add_job(ha.JobPriority.EVENT_DEFAULT, (malicious_job, None))
        pool.add_job(ha.JobPriority.EVENT_DEFAULT, (register_call, None))
        pool.block_till_done()
        self.assertEqual(1, len(calls))
Пример #7
0
 def setUp(self):  # pylint: disable=invalid-name
     """ things to be run when tests are started. """
     self.pool = ha.create_worker_pool()
     self.bus = ha.EventBus(self.pool)
     self.services = ha.ServiceRegistry(self.bus, self.pool)
     self.services.register("test_domain", "test_service", lambda x: len)
Пример #8
0
 def setUp(self):     # pylint: disable=invalid-name
     """ things to be run when tests are started. """
     self.pool = ha.create_worker_pool()
     self.bus = ha.EventBus(self.pool)
     self.services = ha.ServiceRegistry(self.bus, self.pool)
     self.services.register("test_domain", "test_service", lambda x: len)
Пример #9
0
 def setUp(self):     # pylint: disable=invalid-name
     """ things to be run when tests are started. """
     self.bus = ha.EventBus(ha.create_worker_pool(0))
     self.bus.listen('test_event', lambda x: len)
Пример #10
0
 def setUp(self):  # pylint: disable=invalid-name
     """ things to be run when tests are started. """
     self.bus = ha.EventBus(ha.create_worker_pool(0))
     self.bus.listen('test_event', lambda x: len)