def test_same_origin_of_different_nodes(self): # ideally we have one tree, therefor shared key # have identical origin (id of the origin env) foo = tree.TreeNode().get_node("/foo", True) root = foo.parent root.value = {'timeout': 1} bar = root.get_node("/bar", True) params1 = parameters.AvocadoParams([foo, bar], '/') self.assertEqual(params1.get('timeout'), 1) self.assertEqual(params1.get('timeout', '/foo/'), 1) self.assertEqual(params1.get('timeout', '/bar/'), 1) # Sometimes we get multiple trees, but if they claim the origin # is of the same path, let's trust it (even when the values # differ) # note: This is an artificial example which should not happen # in production. Anyway in json-variants-loader we do create # only leave-nodes without connecting the parents, which result # in same paths with different node objects. Let's make sure # they behave correctly. baz = tree.TreeNode().get_node("/baz", True) baz.parent.value = {'timeout': 2} params2 = parameters.AvocadoParams([foo, baz], '/') self.assertEqual(params2.get('timeout'), 1) self.assertEqual(params2.get('timeout', '/foo/'), 1) self.assertEqual(params2.get('timeout', '/baz/'), 2)
def setUp(self): yaml_path = os.path.join(BASEDIR, "tests/.data/mux-selftest-params.yaml") yaml_url = f"/:{yaml_path}" yamls = yaml_to_mux.create_from_yaml([yaml_url]) self.yamls = iter(mux.MuxTree(yamls)) self.params1 = parameters.AvocadoParams(next(self.yamls), ["/ch0/*", "/ch1/*"]) next(self.yamls) # Skip 2nd next(self.yamls) # and 3rd self.params2 = parameters.AvocadoParams(next(self.yamls), ["/ch1/*", "/ch0/*"])
def setUp(self): yamls = yaml_to_mux.create_from_yaml( ["/:" + PATH_PREFIX + 'selftests/.data/mux-selftest-params.yaml']) self.yamls = iter(mux.MuxTree(yamls)) self.params1 = parameters.AvocadoParams(next(self.yamls), 'Unittest1', ['/ch0/*', '/ch1/*']) next(self.yamls) # Skip 2nd next(self.yamls) # and 3rd self.params2 = parameters.AvocadoParams(next(self.yamls), 'Unittest2', ['/ch1/*', '/ch0/*'])
def setUp(self): yaml_path = os.path.join(BASEDIR, 'tests/.data/mux-selftest-params.yaml') yaml_url = '/:%s' % yaml_path yamls = yaml_to_mux.create_from_yaml([yaml_url]) self.yamls = iter(mux.MuxTree(yamls)) self.params1 = parameters.AvocadoParams(next(self.yamls), ['/ch0/*', '/ch1/*']) next(self.yamls) # Skip 2nd next(self.yamls) # and 3rd self.params2 = parameters.AvocadoParams(next(self.yamls), ['/ch1/*', '/ch0/*'])
def generate_vmimage_distro(): yaml_path = [ os.path.join(ROOT_PATH, 'selftests', 'pre_release', 'tests', 'vmimage.py.data', 'variants.yml') ] reference_dir_path = os.path.join(ROOT_PATH, 'docs', 'source', 'guides', 'writer', 'libs', 'data', 'vmimage') reference_path = os.path.join(reference_dir_path, 'supported_images.csv') config = {'yaml_to_mux.files': yaml_path, 'yaml_to_mux.inject': []} varianter = Varianter() varianter.parse(config) try: os.makedirs(reference_dir_path) except FileExistsError: pass with open(reference_path, 'w', encoding='utf-8') as reference: reference.write("Provider, Version, Architecture\n") for v in varianter.itertests(): vmimage_params = parameters.AvocadoParams(v['variant'], ['/run/*']) vmimage_name = vmimage_params.get('name') vmimage_version = vmimage_params.get('version') vmimage_arch = vmimage_params.get('arch', path='*/architectures/*') distro_arch_path = f'/run/distro/{vmimage_name}/{vmimage_arch}/*' vmimage_arch = vmimage_params.get('arch', path=distro_arch_path, default=vmimage_arch) reference.write(f"{str(vmimage_name)},{str(vmimage_version)}," f"{str(vmimage_arch)}\n")
def discover(self, reference, which_tests=loader.DiscoverMode.DEFAULT): tests = [] try: root = mux.apply_filters(create_from_yaml([reference], False), getattr(self.args, "mux_suite_only", []), getattr(self.args, "mux_suite_out", [])) except Exception: return [] mux_tree = mux.MuxTree(root) for variant in mux_tree: params = parameters.AvocadoParams(variant, ["/run/*"], output.LOG_JOB.name) references = params.get("test_reference") if not isinstance(references, (list, tuple)): references = [references] for reference in references: test_loader = self._get_loader(params) if not test_loader: continue _tests = test_loader.discover(reference, which_tests) self._extra_type_label_mapping.update( test_loader.get_full_type_label_mapping()) self._extra_decorator_mapping.update( test_loader.get_full_decorator_mapping()) name_prefix = params.get("mux_suite_test_name_prefix") if _tests: if isinstance(name_prefix, list): name_prefix = "".join(name_prefix) for tst in _tests: if name_prefix: tst[1]["name"] = name_prefix + tst[1]["name"] tst[1]["params"] = (variant, ["/run/*"]) tests.extend(_tests) return tests
def discover(self, reference, which_tests=loader.DEFAULT): tests = [] try: root = mux.apply_filters(create_from_yaml([reference], False), getattr(self.args, "mux_suite_only", []), getattr(self.args, "mux_suite_out", [])) except Exception: return [] mux_tree = mux.MuxTree(root) for variant in mux_tree: params = parameters.AvocadoParams(variant, ["/run/*"], output.LOG_UI.name) reference = params.get("test_reference") test_loader = self._get_loader(params) if not test_loader: continue _tests = test_loader.discover(reference, which_tests) self._extra_type_label_mapping.update( test_loader.get_full_type_label_mapping()) self._extra_decorator_mapping.update( test_loader.get_full_decorator_mapping()) if _tests: for tst in _tests: tst[1]["params"] = (variant, ["/run/*"]) tests.extend(_tests) return tests
def test_greedy_path_to_re(self): params = parameters.AvocadoParams([tree.TreeNode()], ['/run']) self.assertEqual(params._greedy_path_to_re('').pattern, '^$') self.assertEqual(params._greedy_path_to_re('/').pattern, '/$') self.assertEqual( params._greedy_path_to_re('/foo/bar').pattern, '/foo/bar$') self.assertEqual( params._greedy_path_to_re('foo/bar').pattern, 'foo/bar$') self.assertEqual( params._greedy_path_to_re('/*/foo').pattern, '/[^/]*/foo$') self.assertEqual(params._greedy_path_to_re('foo/*').pattern, 'foo/') self.assertEqual(params._greedy_path_to_re('/foo/*').pattern, '/foo/')
def test_greedy_path_to_re(self): params = parameters.AvocadoParams([tree.TreeNode()], ["/run"]) self.assertEqual(params._greedy_path_to_re("").pattern, "^$") self.assertEqual(params._greedy_path_to_re("/").pattern, "/$") self.assertEqual( params._greedy_path_to_re("/foo/bar").pattern, "/foo/bar$") self.assertEqual( params._greedy_path_to_re("foo/bar").pattern, "foo/bar$") self.assertEqual( params._greedy_path_to_re("/*/foo").pattern, "/[^/]*/foo$") self.assertEqual(params._greedy_path_to_re("foo/*").pattern, "foo/") self.assertEqual(params._greedy_path_to_re("/foo/*").pattern, "/foo/")
def __init__(self, methodName='test', name=None, params=None, base_logdir=None, config=None, runner_queue=None, tags=None): """ Initializes the test. :param methodName: Name of the main method to run. For the sake of compatibility with the original unittest class, you should not set this. :param name: Pretty name of the test name. For normal tests, written with the avocado API, this should not be set. This is reserved for internal Avocado use, such as when running random executables as tests. :type name: :class:`avocado.core.test.TestID` :param base_logdir: Directory where test logs should go. If None provided a temporary directory will be created. :param config: the job configuration, usually set by command line options and argument parsing :type config: dict """ self.__phase = 'INIT' def record_and_warn(*args, **kwargs): """ Record call to this function and log warning """ if not self.__log_warn_used: self.__log_warn_used = True return original_log_warn(*args, **kwargs) if name is not None: self.__name = name else: self.__name = TestID(0, self.__class__.__name__) self.__tags = tags self._config = config or settings.as_dict() self.__base_logdir = base_logdir self.__base_logdir_tmp = None if self.__base_logdir is None: prefix = 'avocado_test_' self.__base_logdir_tmp = tempfile.TemporaryDirectory(prefix=prefix) self.__base_logdir = self.__base_logdir_tmp.name self.__logfile = os.path.join(self.logdir, 'debug.log') self._stdout_file = os.path.join(self.logdir, 'stdout') self._stderr_file = os.path.join(self.logdir, 'stderr') self._output_file = os.path.join(self.logdir, 'output') self._logging_handlers = {} self.__outputdir = utils_path.init_dir(self.logdir, 'data') self.__log = LOG_JOB original_log_warn = self.log.warning self.__log_warn_used = False self.log.warn = self.log.warning = record_and_warn self.log.info('INIT %s', self.name) paths = ['/test/*'] if params is None: params = [] elif isinstance(params, tuple): params, paths = params[0], params[1] self.__params = parameters.AvocadoParams(params, paths, self.__log.name) default_timeout = getattr(self, "timeout", None) self.timeout = self.params.get("timeout", default=default_timeout) self.__status = None self.__fail_reason = None self.__fail_class = None self.__traceback = None self.__skip_test = False # Are initialized lazily self.__cache_dirs = None self.__base_tmpdir = None self.__workdir = None self.__running = False self.paused = False self.paused_msg = '' self.__runner_queue = runner_queue self.log.debug("Test metadata:") if self.filename: self.log.debug(" filename: %s", self.filename) try: teststmpdir = self.teststmpdir except EnvironmentError: pass else: self.log.debug(" teststmpdir: %s", teststmpdir) unittest.TestCase.__init__(self, methodName=methodName) TestData.__init__(self)