Beispiel #1
0
    def __init__(self, indexer=count(), methodName='runTest',
                 base_work_dir=ROTEST_WORK_DIR, save_state=True,
                 force_initialize=False, config=None, parent=None,
                 run_data=None, enable_debug=True, resource_manager=None,
                 skip_init=False):

        super(TestCase, self).__init__(indexer, methodName, save_state,
                                       force_initialize, config, parent,
                                       enable_debug, resource_manager,
                                       skip_init)

        self.skip_reason = None
        self.skip_determined = False

        name = self.get_name(methodName)
        core_log.debug("Initializing %r test-case", name)

        core_log.debug("Creating database entry for %r test-case", name)
        self.work_dir = get_work_dir(base_work_dir, name, self)
        self.data = CaseData(name=name, run_data=run_data)

        core_log.debug("Initialized %r test-case successfully", name)

        if self.resource_manager is None:
            self.resource_manager = self.create_resource_manager()
            self._is_client_local = True
Beispiel #2
0
    def __init__(self,
                 indexer=count(),
                 base_work_dir=ROTEST_WORK_DIR,
                 save_state=True,
                 force_initialize=False,
                 config=None,
                 parent=None,
                 run_data=None,
                 enable_debug=True,
                 resource_manager=None,
                 skip_init=False,
                 is_main=True):

        test_method_name = self.get_test_method_name()
        super(AbstractFlowComponent,
              self).__init__(indexer, test_method_name, save_state,
                             force_initialize, config, parent, enable_debug,
                             resource_manager, skip_init)

        self._pipes = {}
        self.is_main = is_main

        name = self.get_name()
        core_log.debug("Initializing %r flow-component", name)

        core_log.debug("Creating database entry for %r test-block", name)
        self.work_dir = get_work_dir(base_work_dir, name)
        self.data = CaseData(name=name, run_data=run_data)

        if self.resource_manager is None:
            self.resource_manager = self.create_resource_manager()
            self._is_client_local = True
Beispiel #3
0
    def set_work_dir(self, resource_name, containing_work_dir):
        """Set the work directory under the given case's work directory.

        Args:
            resource_name (str): name of resource.
            containing_work_dir (str): root work directory.
        """
        self.work_dir = get_work_dir(containing_work_dir, resource_name, None)
Beispiel #4
0
    def set_work_dir(self, resource_name, containing_work_dir):
        """Set the work directory under the given case's work directory.

        Args:
            resource_name (str): name of resource.
            containing_work_dir (str): root work directory.
        """
        self.work_dir = get_work_dir(containing_work_dir, resource_name)

        for resource in self.get_sub_resources():
            resource.set_work_dir(resource.name, self.work_dir)
Beispiel #5
0
    def __init__(self,
                 base_work_dir=ROTEST_WORK_DIR,
                 save_state=True,
                 config=None,
                 indexer=count(),
                 parent=None,
                 run_data=None,
                 enable_debug=False,
                 skip_init=False,
                 resource_manager=None):
        """Initialize 'components' & add them to the suite.

        Validates & initializes the TestSuite components & data object.

        Args:
            base_work_dir (str): the base directory of the tests.
            save_state (bool): flag to determine if storing the states of
                resources is required.
            config (AttrDict): dictionary of configurations.
            indexer (iterator): the generator of test indexes.
            parent (TestSuite): container of this test.
            run_data (RunData): test run data object.
            enable_debug (bool): whether to enable entering ipdb debugging mode
                upon any exception in a test statement.
            skip_init (bool): True to skip resources initialization and
                validation of resources.
            resource_manager (ClientResourceManager): tests' client resource
                manager instance, leave None to create a new one for the test.

        Raises:
            AttributeError: if components tuple is empty.
            TypeError: in case components tuple contains anything other than
                classes inheriting from :class:`rotest.core.case.TestCase`,
                :class:`rotest.core.suite.TestSuite`.
        """
        self._tags = None
        self.parent = parent
        name = self.get_name()
        self.identifier = indexer.next()
        self.resource_manager = resource_manager
        self.parents_count = self._get_parents_count()

        core_log.debug("Initializing %r test-suite", name)
        if len(self.components) == 0:
            raise AttributeError("%s: Components tuple can't be empty" % name)

        core_log.debug("Creating database entry for %r test-suite", name)
        self.work_dir = get_work_dir(base_work_dir, name)
        self.data = SuiteData(name=name, run_data=run_data)

        tests = []
        for test_component in self.components:

            if issubclass(test_component, TestCase):
                for method_name in test_component.load_test_method_names():
                    test_item = test_component(
                        parent=self,
                        config=config,
                        indexer=indexer,
                        run_data=run_data,
                        skip_init=skip_init,
                        save_state=save_state,
                        methodName=method_name,
                        enable_debug=enable_debug,
                        base_work_dir=self.work_dir,
                        resource_manager=resource_manager)

                    core_log.debug("Adding %r to %r", test_item, self.data)
                    tests.append(test_item)

            elif issubclass(test_component, TestFlow):
                test_item = test_component(parent=self,
                                           config=config,
                                           indexer=indexer,
                                           run_data=run_data,
                                           skip_init=skip_init,
                                           save_state=save_state,
                                           enable_debug=enable_debug,
                                           base_work_dir=self.work_dir,
                                           resource_manager=resource_manager)

                core_log.debug("Adding %r to %r", test_item, self.data)
                tests.append(test_item)

            elif issubclass(test_component, TestSuite):
                test_item = test_component(parent=self,
                                           config=config,
                                           indexer=indexer,
                                           run_data=run_data,
                                           skip_init=skip_init,
                                           save_state=save_state,
                                           enable_debug=enable_debug,
                                           base_work_dir=self.work_dir,
                                           resource_manager=resource_manager)

                core_log.debug("Adding %r to %r", test_item, self.data)
                tests.append(test_item)

            else:
                raise TypeError("Components under TestSuite must be classes "
                                "inheriting from TestCase or TestSuite, "
                                "got %r" % test_component)

        core_log.debug("Initialized %r test-suite successfully", self.data)
        super(TestSuite, self).__init__(tests)