def iterable_suites(obj): """Create an iterable suites object.""" suites = [obj] if not isinstance(obj, collections.abc.Iterable) else obj # If multiple objects from one test suite class are added into a Multitest, # it's better provide naming function to avoid duplicate test suite names. name_counts = collections.Counter( # After calling `get_testsuite_name` each test suite object has # an attribute `name` of string type (value has been verified) mtest_suite.get_testsuite_name(suite) for suite in suites ) dupe_names = {k for k, v in name_counts.items() if v > 1} if len(dupe_names) > 0: raise ValueError( 'Duplicate test suite name found: "{}".' " Consider customizing test suite names with argument `name`" " in @testsuite decorator.".format(", ".join(dupe_names)) ) for suite in suites: mtest_suite.set_testsuite_testcases(suite) return suites
def iterable_suites(obj): """Create an iterable suites object.""" suites = [obj] if not isinstance(obj, collections.Iterable) else obj for suite in suites: mtest_suite.set_testsuite_testcases(suite) return suites
def update_suites(self, suite_instances): """ Update suite objects to new classes. :param suite_instances: Mapping of module and class name to test suite instances. :type suite_instances: ``Dict[str, Dict[str, List[Any]]`` """ for suite_cls in self._iter_suites(): for suite_obj in suite_instances[self.name].get( suite_cls.__name__, []): suite_obj.__class__ = suite_cls suite.set_testsuite_testcases(suite_obj)
def _update_suites(module, module_suites): """ Update suite objects to new classes. :param module: Module to update suite object for. :type module: ``types.ModuleType`` :param module_suites: Suites in the corresponding module. :type module_suites: ``Dict`` """ for attr_name in dir(module): attr = getattr(module, attr_name) if _is_testsuite(attr): for suite_obj in module_suites.get(attr.__name__, []): suite_obj.__class__ = attr suite.set_testsuite_testcases(suite_obj)
def update_suites(self, suite_instances): """ Update suite objects to new classes. :param suite_instances: Mapping of module and class name to test suite instances. :type suite_instances: ``Dict[str, Dict[str, List[Any]]`` """ if self.name not in suite_instances: return module_suites = self._module_suites(suite_instances[self.name]) for attr in self._iter_attrs(): if _is_testsuite(attr): for suite_obj in module_suites.get(attr.__name__, []): suite_obj.__class__ = attr suite.set_testsuite_testcases(suite_obj)
def iterable_suites(obj): """Create an iterable suites object.""" suites = [obj] if not isinstance(obj, collections.Iterable) else obj # No duplicate names of test suites are allowed, if there is any, user # should use `custom_name` argument of @testsuite for customization suite_names = [mtest_suite.get_testsuite_name(suite) for suite in suites] for name in suite_names: validation.validate_display_name(name, defaults.MAX_TESTSUITE_NAME_LENGTH, "Test suite name") suite_name_counts = collections.Counter(suite_names) dupe_names = {k for k, v in suite_name_counts.items() if v > 1} if len(dupe_names) > 0: raise ValueError( "Duplicate test suite name found: {}. Consider using `custom_name`" " argument in @testsuite decorator.".format(", ".join(dupe_names))) for suite in suites: mtest_suite.set_testsuite_testcases(suite) return suites