Best Python code snippet using avocado_python
varianter_pict.py
Source:varianter_pict.py  
...92        pass93def run_pict(binary, parameter_file, order):94    cmd = f"{binary} {parameter_file} /o:{order}"95    return process.run(cmd, shell=True).stdout_text96def parse_pict_output(output):97    variants = []98    lines = output.splitlines()99    header = lines[0]100    headers = header.split("\t")101    for line in lines[1:]:102        variants.append(dict(zip(headers, line.split("\t"))))103    return (headers, variants)104class VarianterPict(Varianter):105    """106    Processes the pict file into variants107    """108    name = "pict"109    description = "PICT based Varianter"110    def initialize(self, config):111        self.variants = None  # pylint: disable=W0201112        error = False113        subcommand = config.get("subcommand", "run")114        namespace = f"{subcommand}.pict_parameter_file"115        pict_parameter_file = config.get(namespace)116        if pict_parameter_file is None:117            return118        else:119            pict_parameter_file = os.path.expanduser(pict_parameter_file)120            if not os.access(pict_parameter_file, os.R_OK):121                LOG_UI.error(122                    "pict parameter file '%s' could not be found or " "is not readable",123                    pict_parameter_file,124                )125                error = True126        pict_binary = config.get(f"{subcommand}.pict_binary")127        if pict_binary is None:128            LOG_UI.error(129                "pict binary could not be found in $PATH. Please set "130                "its location with --pict-binary or put it in your "131                "$PATH"132            )133            error = True134        else:135            pict_binary = os.path.expanduser(pict_binary)136            if not os.access(pict_binary, os.R_OK | os.X_OK):137                LOG_UI.error(138                    "pict binary '%s' can not be executed, please check "139                    "the option given with --pict-binary and/or the file "140                    "permissions",141                    pict_binary,142                )143                error = True144        if error:145            if subcommand == "run":146                sys.exit(exit_codes.AVOCADO_JOB_FAIL)147            else:148                sys.exit(exit_codes.AVOCADO_FAIL)149        path_namespace = f"{subcommand}.pict_parameter_path"150        self.parameter_path = config.get(path_namespace)  # pylint: disable=W0201151        order_namespace = f"{subcommand}.pict_combinations_order"152        output = run_pict(pict_binary, pict_parameter_file, config.get(order_namespace))153        self.headers, self.variants = parse_pict_output(output)  # pylint: disable=W0201154    def __iter__(self):155        if self.variants is None:156            return157        variant_ids = []158        for variant in self.variants:159            base_id = "-".join([variant.get(key) for key in self.headers])160            variant_ids.append(161                base_id + "-" + hashlib.sha1(base_id.encode()).hexdigest()[:4]162            )163        for vid, variant in zip(variant_ids, self.variants):164            variant_tree_nodes = []165            for key, val in variant.items():166                variant_tree_nodes.append(TreeNode(key, {key: val}))167            yield {...__init__.py
Source:__init__.py  
...60        pass61def run_pict(binary, parameter_file, order):62    cmd = "%s %s /o:%s" % (binary, parameter_file, order)63    return process.system_output(cmd, shell=True)64def parse_pict_output(output):65    variants = []66    lines = output.splitlines()67    header = lines[0]68    headers = header.split('\t')69    for line in lines[1:]:70        variants.append(dict(zip(headers, line.split('\t'))))71    return (headers, variants)72class VarianterPict(Varianter):73    """74    Processes the pict file into variants75    """76    name = 'pict'77    description = "PICT based Varianter"78    def initialize(self, args):79        self.variants = None80        error = False81        pict_parameter_file = getattr(args, "pict_parameter_file", None)82        if pict_parameter_file is None:83            return84        else:85            pict_parameter_file = os.path.expanduser(pict_parameter_file)86            if not os.access(pict_parameter_file, os.R_OK):87                LOG_UI.error("pict parameter file '%s' could not be found or "88                             "is not readable", pict_parameter_file)89                error = True90        pict_binary = getattr(args, "pict_binary", None)91        if pict_binary is None:92            LOG_UI.error("pict binary could not be found in $PATH. Please set "93                         "its location with --pict-binary or put it in your "94                         "$PATH")95            error = True96        else:97            pict_binary = os.path.expanduser(pict_binary)98            if not os.access(pict_binary, os.R_OK | os.X_OK):99                LOG_UI.error("pict binary '%s' can not be executed, please check "100                             "the option given with --pict-binary and/or the file "101                             "permissions", pict_binary)102                error = True103        if error:104            if args.subcommand == 'run':105                sys.exit(exit_codes.AVOCADO_JOB_FAIL)106            else:107                sys.exit(exit_codes.AVOCADO_FAIL)108        self.parameter_path = getattr(args, "pict_parameter_path")109        output = run_pict(pict_binary,110                          pict_parameter_file,111                          getattr(args, "pict_order_of_combinations"))112        self.headers, self.variants = parse_pict_output(output)113    def __iter__(self):114        if self.variants is None:115            return116        variant_ids = []117        for variant in self.variants:118            base_id = "-".join([variant.get(key) for key in self.headers])119            variant_ids.append(base_id + '-' +120                               hashlib.sha1(base_id).hexdigest()[:4])121        for vid, variant in itertools.izip(variant_ids, self.variants):122            variant_tree_nodes = []123            for key, val in variant.items():124                variant_tree_nodes.append(TreeNode(key, {key: val}))125            yield {"variant_id": vid,126                   "variant": variant_tree_nodes,...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
