def test_filter_only(self): exp = (['intel', 'scsi'], ['intel', 'virtio']) act = multiplexer.yaml2tree( ["/:" + PATH_PREFIX + 'examples/mux-selftest.yaml'], ('/hw/cpu/intel', '/distro/fedora', '/hw')) act = tuple(multiplexer.MuxTree(act)) self.assertEqual(act, exp)
def test_filter_only(self): exp = (['intel', 'scsi'], ['intel', 'virtio']) act = multiplexer.yaml2tree(["/:" + PATH_PREFIX + 'examples/mux-selftest.yaml'], ('/hw/cpu/intel', '/distro/fedora', '/hw')) act = tuple(multiplexer.MuxTree(act)) self.assertEqual(act, exp)
def setUp(self): yamls = multiplexer.yaml2tree(["/:" + PATH_PREFIX + 'examples/mux-selftest-params.yaml']) self.yamls = iter(multiplexer.MuxTree(yamls)) self.params1 = multiplexer.AvocadoParams(self.yamls.next(), 'Unittest1', ['/ch0/*', '/ch1/*'], {}) self.yamls.next() # Skip 2nd self.yamls.next() # and 3rd self.params2 = multiplexer.AvocadoParams(self.yamls.next(), 'Unittest2', ['/ch1/*', '/ch0/*'], {})
def setUp(self): yamls = multiplexer.yaml2tree( ["/:" + PATH_PREFIX + 'examples/mux-selftest-params.yaml']) self.yamls = iter(multiplexer.MuxTree(yamls)) self.params1 = multiplexer.AvocadoParams(self.yamls.next(), 'Unittest1', ['/ch0/*', '/ch1/*'], {}) self.yamls.next() # Skip 2nd self.yamls.next() # and 3rd self.params2 = multiplexer.AvocadoParams(self.yamls.next(), 'Unittest2', ['/ch1/*', '/ch0/*'], {})
def test_filter_out(self): act = multiplexer.yaml2tree( ["/:" + PATH_PREFIX + 'examples/mux-selftest.yaml'], None, ('/hw/cpu/intel', '/distro/fedora', '/distro')) act = tuple(multiplexer.MuxTree(act)) 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 = multiplexer.yaml2tree(["/:" + PATH_PREFIX + 'examples/mux-selftest.yaml'], None, ('/hw/cpu/intel', '/distro/fedora', '/distro')) act = tuple(multiplexer.MuxTree(act)) 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): self._activate(args) view = output.View(app_args=args) err = None if args.tree and args.debug: err = "Option --tree is incompatible with --debug." elif not args.tree and args.inherit: err = "Option --inherit can be only used with --tree" if err: view.notify(event="minor", msg=self.parser.format_help()) view.notify(event="error", msg=err) sys.exit(exit_codes.AVOCADO_FAIL) try: mux_tree = multiplexer.yaml2tree(args.multiplex_files, args.filter_only, args.filter_out, args.debug) except IOError, details: view.notify(event='error', msg=details.strerror) sys.exit(exit_codes.AVOCADO_JOB_FAIL)
def test_create_variants(self): from_file = multiplexer.yaml2tree( ["/:" + PATH_PREFIX + 'examples/mux-selftest.yaml']) from_file = multiplexer.MuxTree(from_file) self.assertEqual(self.mux_full, tuple(from_file))
def run(self, args): self._activate(args) log = logging.getLogger("avocado.app") err = None if args.tree and args.debug: err = "Option --tree is incompatible with --debug." elif not args.tree and args.inherit: err = "Option --inherit can be only used with --tree" if err: log.error(err) sys.exit(exit_codes.AVOCADO_FAIL) try: mux_tree = multiplexer.yaml2tree(args.multiplex_files, args.filter_only, args.filter_out, args.debug) except IOError as details: log.error(details.strerror) sys.exit(exit_codes.AVOCADO_JOB_FAIL) if args.system_wide: mux_tree.merge(args.default_multiplex_tree) mux_tree.merge(self._from_args_tree) if args.tree: if args.contents: verbose = 1 else: verbose = 0 if args.inherit: verbose += 2 use_utf8 = settings.get_value("runner.output", "utf8", key_type=bool, default=None) log.debug(tree.tree_view(mux_tree, verbose, use_utf8)) sys.exit(exit_codes.AVOCADO_ALL_OK) variants = multiplexer.MuxTree(mux_tree) log.info('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, getattr(_, 'yaml', "Unknown"), cend) for _ in tpl]) log.debug('%sVariant %s: %s', '\n' if args.contents else '', index + 1, paths) if args.contents: env = set() for node in tpl: for key, value in node.environment.iteritems(): origin = node.environment_origin[key].path env.add(("%s:%s" % (origin, key), str(value))) if not env: continue fmt = ' %%-%ds => %%s' % max([len(_[0]) for _ in env]) for record in sorted(env): log.debug(fmt, *record) sys.exit(exit_codes.AVOCADO_ALL_OK)
class TestAvocadoParams(unittest.TestCase): yamls = multiplexer.yaml2tree( ["/:" + PATH_PREFIX + 'examples/mux-selftest-params.yaml']) yamls = iter(multiplexer.MuxTree(yamls)) 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(15, sum([1 for _ in self.params1.iteritems()])) 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') # evaluated from right self.assertEqual(self.params1.get('unique1', '/*/*/ch0.1.1.1/', 222), 'unique1') # path too long so can't match from right 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.1b/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')