def test_filter_only(self): exp = (('intel', 'scsi'), ('intel', 'virtio')) act = tuple(multiplexer.multiplex_yamls(['examples/mux-selftest.yaml'], ('/hw/cpu/intel', '/distro/fedora', '/hw'))) self.assertEqual(act, exp)
def test_filter_out(self): act = tuple( multiplexer.multiplex_yamls( ['examples/mux-selftest.yaml'], None, ('/hw/cpu/intel', '/distro/fedora', '/distro'))) self.assertEqual(len(act), 4) self.assertEqual(len(act[0]), 3) str_act = str(act) self.assertIn('amd', str_act) self.assertIn('prod', str_act) self.assertNotIn('intel', str_act) self.assertNotIn('fedora', str_act)
def test_filter_out(self): act = tuple(multiplexer.multiplex_yamls(['examples/mux-selftest.yaml'], None, ('/hw/cpu/intel', '/distro/fedora', '/distro'))) self.assertEqual(len(act), 4) self.assertEqual(len(act[0]), 3) str_act = str(act) self.assertIn('amd', str_act) self.assertIn('prod', str_act) self.assertNotIn('intel', str_act) self.assertNotIn('fedora', str_act)
def run(self, args): view = output.View(app_args=args) multiplex_files = args.multiplex_files if args.tree: view.notify(event='message', msg='Config file tree structure:') t = tree.create_from_yaml(multiplex_files) t = tree.apply_filters(t, args.filter_only, args.filter_out) view.notify(event='minor', msg=t.get_ascii(attributes=args.attr)) sys.exit(exit_codes.AVOCADO_ALL_OK) try: variants = multiplexer.multiplex_yamls(multiplex_files, args.filter_only, args.filter_out, args.debug) except IOError, details: view.notify(event='error', msg="%s: '%s'" % (details.strerror, details.filename)) sys.exit(exit_codes.AVOCADO_JOB_FAIL)
def run(self, args): view = output.View(app_args=args) multiplex_files = tuple(os.path.abspath(_) for _ in args.multiplex_files) for path in multiplex_files: if not os.path.isfile(path): view.notify(event='error', msg='Invalid multiplex file %s' % path) sys.exit(exit_codes.AVOCADO_JOB_FAIL) if args.tree: view.notify(event='message', msg='Config file tree structure:') t = tree.create_from_yaml(multiplex_files) t = tree.apply_filters(t, args.filter_only, args.filter_out) view.notify(event='minor', msg=t.get_ascii()) sys.exit(exit_codes.AVOCADO_ALL_OK) variants = multiplexer.multiplex_yamls(multiplex_files, args.filter_only, args.filter_out, args.debug) view.notify(event='message', msg='Variants generated:') for (index, tpl) in enumerate(variants): if not args.debug: paths = ', '.join([x.path for x in tpl]) else: color = output.term_support.LOWLIGHT cend = output.term_support.ENDC paths = ', '.join(["%s%s@%s%s" % (_.name, color, _.yaml, cend) for _ in tpl]) view.notify(event='minor', msg='\nVariant %s: %s' % (index + 1, paths)) if args.contents: env = {} for node in tpl: env.update(node.environment) for k in sorted(env.keys()): view.notify(event='minor', msg=' %s: %s' % (k, env[k])) sys.exit(exit_codes.AVOCADO_ALL_OK)
def run(self, args): view = output.View(app_args=args) multiplex_files = tuple( os.path.abspath(_) for _ in args.multiplex_files) for path in multiplex_files: if not os.path.isfile(path): view.notify(event='error', msg='Invalid multiplex file %s' % path) sys.exit(exit_codes.AVOCADO_JOB_FAIL) if args.tree: view.notify(event='message', msg='Config file tree structure:') t = tree.create_from_yaml(multiplex_files) t = tree.apply_filters(t, args.filter_only, args.filter_out) view.notify(event='minor', msg=t.get_ascii()) sys.exit(exit_codes.AVOCADO_ALL_OK) variants = multiplexer.multiplex_yamls(multiplex_files, args.filter_only, args.filter_out, args.debug) view.notify(event='message', msg='Variants generated:') for (index, tpl) in enumerate(variants): if not args.debug: paths = ', '.join([x.path for x in tpl]) else: color = output.term_support.LOWLIGHT cend = output.term_support.ENDC paths = ', '.join( ["%s%s@%s%s" % (_.name, color, _.yaml, cend) for _ in tpl]) view.notify(event='minor', msg='\nVariant %s: %s' % (index + 1, paths)) if args.contents: env = {} for node in tpl: env.update(node.environment) for k in sorted(env.keys()): view.notify(event='minor', msg=' %s: %s' % (k, env[k])) sys.exit(exit_codes.AVOCADO_ALL_OK)
def test_create_variants(self): from_file = multiplexer.multiplex_yamls(['examples/mux-selftest.yaml']) self.assertEqual(self.mux_full, tuple(from_file))
def _run(self, urls=None, multiplex_files=None): """ Unhandled job method. Runs a list of test URLs to its completion. :param urls: String with tests to run. :param multiplex_files: File that multiplexes a given test url. :return: Integer with overall job status. See :mod:`avocado.core.exit_codes` for more information. :raise: Any exception (avocado crashed), or :class:`avocado.core.exceptions.JobBaseException` errors, that configure a job failure. """ params_list = [] if urls is None: if self.args and self.args.url: urls = self.args.url else: if isinstance(urls, str): urls = urls.split() if urls is not None: for url in urls: params_list.append({'id': url}) else: e_msg = "Empty test ID. A test path or alias must be provided" raise exceptions.OptionValidationError(e_msg) if multiplex_files is None: if self.args and self.args.multiplex_files is not None: multiplex_files = self.args.multiplex_files else: multiplex_files = multiplex_files if multiplex_files is not None: for mux_file in multiplex_files: if not os.path.exists(mux_file): e_msg = "Multiplex file %s doesn't exist." % (mux_file) raise exceptions.OptionValidationError(e_msg) params_list = [] if urls is not None: for url in urls: try: variants = multiplexer.multiplex_yamls(multiplex_files, self.args.filter_only, self.args.filter_out) except SyntaxError: variants = None if variants: tag = 1 for variant in variants: env = {} for t in variant: env.update(dict(t.environment)) env.update({'tag': tag}) env.update({'id': url}) params_list.append(env) tag += 1 else: params_list.append({'id': url}) if not params_list: e_msg = "Test(s) with empty parameter list or the number of variants is zero" raise exceptions.OptionValidationError(e_msg) if self.args is not None: self.args.test_result_total = len(params_list) self._make_test_result() self._make_test_runner() self._make_test_loader() self.view.start_file_logging(self.logfile, self.loglevel, self.unique_id) self.view.logfile = self.logfile failures = self.test_runner.run_suite(params_list) self.view.stop_file_logging() # If it's all good so far, set job status to 'PASS' if self.status == 'RUNNING': self.status = 'PASS' # Let's clean up test artifacts if self.args is not None: if self.args.archive: filename = self.logdir + '.zip' archive.create(filename, self.logdir) if not self.args.keep_tmp_files: data_dir.clean_tmp_files() tests_status = not bool(failures) if tests_status: return exit_codes.AVOCADO_ALL_OK else: return exit_codes.AVOCADO_TESTS_FAIL
class TestAvocadoParams(unittest.TestCase): yamls = multiplexer.multiplex_yamls( ['examples/mux-selftest-params.' 'yaml']) params1 = multiplexer.AvocadoParams(yamls.next(), 'Unittest1', 1, ['/ch0/*', '/ch1/*'], {}) yamls.next() # Skip 2nd yamls.next() # and 3rd params2 = multiplexer.AvocadoParams(yamls.next(), 'Unittest2', 1, ['/ch1/*', '/ch0/*'], {}) def test_pickle(self): params = pickle.dumps(self.params1, 2) # protocol == 2 params = pickle.loads(params) self.assertEqual(self.params1, params) def test_basic(self): self.assertEqual(self.params1, self.params1) self.assertNotEqual(self.params1, self.params2) repr(self.params1) str(self.params1) str(multiplexer.AvocadoParams([], 'Unittest', None, [], {})) self.assertEqual(26, sum([1 for _ in self.params1.iteritems()])) def test_get_old_api(self): self.assertEqual(self.params1.get('unique1'), 'unique1') self.assertEqual(self.params1.get('missing'), None) self.assertEqual(self.params1.get('missing', 'aaa'), 'aaa') self.assertEqual(self.params1.root, 'root') def test_get_abs_path(self): # /ch0/ is not leaf thus it's not queryable self.assertEqual(self.params1.get('root', '/ch0/', 'bbb'), 'bbb') self.assertEqual(self.params1.get('unique1', '/ch0/*', 'ccc'), 'unique1') self.assertEqual(self.params2.get('unique1', '/ch0/*', 'ddd'), 'unique1-2') self.assertEqual(self.params1.get('unique3', '/ch0/*', 'eee'), 'unique3') # unique3 is not in self.params2 self.assertEqual(self.params2.get('unique3', '/ch0/*', 'fff'), 'fff') # Use the leaf self.assertEqual( self.params1.get('unique1', '/ch0/ch0.1/ch0.1.1/ch0.1.1.1/', 'ggg'), 'unique1') # '/ch0/ch0.1/ch0.1.1/' is in the tree, but not in current variant self.assertEqual( self.params2.get('unique1', '/ch0/ch0.1/ch0.1.1/ch0.1.1.1/', 'hhh'), 'hhh') def test_get_greedy_path(self): self.assertEqual(self.params1.get('unique1', '/*/*/*/ch0.1.1.1/', 111), 'unique1') # not in this level (-1) self.assertEqual(self.params1.get('unique1', '/*/*/ch0.1.1.1/', 222), 222) # not in this level (+1) self.assertEqual( self.params1.get('unique1', '/*/*/*/*/ch0.1.1.1/', 333), 333) self.assertEqual(self.params1.get('unique1', '/ch*/c*1/*0*/*1/', 444), 'unique1') # '/ch0/ch0.1/ch0.1.1/' is in the tree, but not in current variant self.assertEqual(self.params2.get('unique1', '/ch*/c*1/*0*/*1/', 555), 555) self.assertEqual(self.params2.get('unique1', '/ch*/c*1/*', 666), 'unique1-2') self.assertEqual(self.params1.get('unique4', '/ch1*/*', 777), 'other_unique') self.assertEqual(self.params1.get('unique2', '/ch1*/*', 888), 'unique2') # path matches nothing self.assertEqual(self.params1.get('root', '', 999), 999) def test_get_rel_path(self): self.assertEqual(self.params1.get('root', default='iii'), 'root') self.assertEqual(self.params1.get('unique1', '*', 'jjj'), 'unique1') self.assertEqual(self.params2.get('unique1', '*', 'kkk'), 'unique1-2') self.assertEqual(self.params1.get('unique3', '*', 'lll'), 'unique3') # unique3 is not in self.params2 self.assertEqual(self.params2.get('unique3', default='mmm'), 'mmm') # Use the leaf self.assertEqual(self.params1.get('unique1', '*/ch0.1.1.1/', 'nnn'), 'unique1') # '/ch0/ch0.1/ch0.1.1/' is in the tree, but not in current variant self.assertEqual(self.params2.get('unique1', '*/ch0.1.1.1/', 'ooo'), 'ooo') def test_get_clashes(self): # One inherited, the other is new self.assertRaisesRegexp(ValueError, r"'clash1'.* \['/ch0/ch0.1/ch0.1.1" r"/ch0.1.1.1=>equal', '/ch0=>equal'\]", self.params1.get, 'clash1', default='nnn') # Only inherited ones self.assertEqual(self.params2.get('clash1', default='ooo'), 'equal') # Booth of different origin self.assertRaisesRegexp(ValueError, r"'clash2'.* \['/ch11=>equal', " r"'/ch111=>equal'\]", self.params1.get, 'clash2', path='/*') # Filter-out the clash self.assertEqual(self.params1.get('clash2', path='/ch11/*'), 'equal') # simple clash in params1 self.assertRaisesRegexp(ValueError, r"'clash3'.* \['/ch0=>also equal'," r" '/ch0/ch0.1/ch0.1.2=>also equal'\]", self.params1.get, 'clash3', default='nnn') # params2 is sliced the other way around so it returns before the clash self.assertEqual(self.params2.get('clash3', default='nnn'), 'also equal')