def test_create_from_instance(self): """Tests create_from_instance gets all InstanceSubscriptionHandles.""" bundle = subscription_bundle.create_from_instance(self) self.assertEqual(len(bundle.subscriptions), 2) keys = bundle.subscriptions.keys() self.assertIn(self.instance_listener_1.subscription, keys) self.assertIn(self.instance_listener_2.subscription, keys)
def test_subscribe_instance_bundles(self): """Tests that @subscribe bundles register only instance listeners.""" test_run_config = mobly_config_parser.TestRunConfig() test_run_config.testbed_name = '' test_run_config.log_path = '' test_object = TestClass(test_run_config) bundle = subscription_bundle.create_from_instance(test_object) bundle.register() event_bus.post(Event()) self.assertEqual(len(TestClass.instance_event_received), 1) self.assertEqual(len(TestClass.static_event_received), 0)
def __init__(self, logger_cls, logger_args, logger_kwargs): """Constructs a proxy for the given logger class. The logger class will later be constructed using the triggering event, along with the args and kwargs passed here. This will also register any methods decorated with event subscriptions that may have been defined in a subclass. It is the subclass's responsibility to unregister them once the logger is finished. Args: logger_cls: The class object for the underlying logger. logger_args: The position args for the logger constructor. logger_kwargs: The keyword args for the logger constructor. """ self._logger_cls = logger_cls self._logger_args = logger_args self._logger_kwargs = logger_kwargs self._logger = None bundle = subscription_bundle.create_from_instance(self) bundle.register() self.__initialized = True
def register_test_class_event_subscriptions(self): self.class_subscriptions = subscription_bundle.create_from_instance( self) self.class_subscriptions.register()
def init_replacement(self, *args, **kwargs): old_init(self, *args, **kwargs) subscription_bundle.create_from_instance(self).register()