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)
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)
def register_components(self, component_manager): logger.debug("Registering sut with ip '{ip}'".format(ip=self._ip)) sut = component_manager.get_unique_class_for_entity(self._entity) sut.ip = self._ip sut.reset_started_timeout = self._reset_started_timeout sut.reset_done_timeout = self._reset_done_timeout cans = set(self._add_cans) cans.add(self._entity) component(name='Sut', scope='session', can=cans)(sut)
def register_components(self, component_manager): @requires(sut='Sut', can=[self._entity]) class ZnailComponentInstance(ZnailComponent): def __init__(self, sut): pass if self._ip: component(name='Znail')(ZnailComponentInstance, component_manager) ZnailComponentInstance.ip = self.ip ZnailComponentInstance.port = self.port ZnailComponentInstance.timeout = self.timeout
def register_components(self, component_manager): if self._enabled: port = component_manager.get_unique_class_for_entity(self._entity) add_properties(port, 'serial', { 'prompt': self._prompt, 'timeout': self._timeout, }) register_component = component(name='SerialPort', scope='session', can={self._entity}) register_component(port, component_manager)
def register_firefox_webdriver_component(component_manager, headless=True): from selenium import webdriver from selenium.webdriver.firefox.options import Options _verify_that_firefox_is_installed() _verify_that_firefox_is_the_minimum_required_version() def firefox_webdriver(): options = Options() if headless is True: options.add_argument('-headless') return webdriver.Firefox(executable_path=_get_geckodriver_path(), firefox_options=options) register_webdriver_component = component(name='Webdriver', can=['firefox']) register_firefox_webdriver_component = component(name='FirefoxWebdriver') register_webdriver_component(firefox_webdriver, component_manager) register_firefox_webdriver_component(firefox_webdriver, component_manager)
def test_requires_on_command_callable(self): with patch('sys.argv', ['test', 'noop']): with Application( ApplicationConfiguration( 'test', application_context=ApplicationContext.EXTENDABLE) ) as app: class Component(object): def get_value(self): return 3 component('Component')(Component, app.component_manager) app.command = REQUIRES_COMMAND exit_code = app.execute_command() self.assertEqual( exit_code, 3, 'exit code should be one if command returns one')
def register_components(self, component_manager): if self._env == 'docker': DockerEnv.root = self._root component(name='Env', scope='session')(DockerEnv, component_manager=component_manager)
def register_components(self, component_manager): if self._env == 'host': component(name='Env', scope='session')(HostEnv, component_manager=component_manager)