Best Python code snippet using autotest_python
topic_common.py
Source:topic_common.py  
...439            return440        twrap = textwrap.TextWrapper(initial_indent='\t',441                                     subsequent_indent='\t')442        print twrap.fill(', '.join(values))443    def __conv_value(self, type, value):444        return KEYS_CONVERT.get(type, str)(value)445    def print_fields_std(self, items, keys, title=None):446        """Print the keys in each item, one on each line"""447        if not items:448            return449        if title:450            print title451        for item in items:452            for key in keys:453                print '%s: %s' % (KEYS_TO_NAMES_EN[key],454                                  self.__conv_value(key,455                                                    _get_item_key(item, key)))456    def print_fields_parse(self, items, keys, title=None):457        """Print the keys in each item as comma458        separated name=value"""459        for item in items:460            values = ['%s=%s' % (KEYS_TO_NAMES_EN[key],461                                  self.__conv_value(key,462                                                    _get_item_key(item, key)))463                      for key in keys464                      if self.__conv_value(key,465                                           _get_item_key(item, key)) != '']466            print self.parse_delim.join(values)467    def __find_justified_fmt(self, items, keys):468        """Find the max length for each field."""469        lens = {}470        # Don't justify the last field, otherwise we have blank471        # lines when the max is overlaps but the current values472        # are smaller473        if not items:474            print "No results"475            return476        for key in keys[:-1]:477            lens[key] = max(len(self.__conv_value(key,478                                                  _get_item_key(item, key)))479                            for item in items)480            lens[key] = max(lens[key], len(KEYS_TO_NAMES_EN[key]))481        lens[keys[-1]] = 0482        return '  '.join(["%%-%ds" % lens[key] for key in keys])483    def print_table_std(self, items, keys_header, sublist_keys=()):484        """Print a mix of header and lists in a user readable485        format486        The headers are justified, the sublist_keys are wrapped."""487        if not items:488            return489        fmt = self.__find_justified_fmt(items, keys_header)490        header = tuple(KEYS_TO_NAMES_EN[key] for key in keys_header)491        print fmt % header492        for item in items:493            values = tuple(self.__conv_value(key,494                                             _get_item_key(item, key))495                           for key in keys_header)496            print fmt % values497            if sublist_keys:498                for key in sublist_keys:499                    self.print_wrapped(KEYS_TO_NAMES_EN[key],500                                       _get_item_key(item, key))501                print '\n'502    def print_table_parse(self, items, keys_header, sublist_keys=()):503        """Print a mix of header and lists in a user readable504        format"""505        for item in items:506            values = ['%s=%s' % (KEYS_TO_NAMES_EN[key],507                                 self.__conv_value(key, _get_item_key(item, key)))508                      for key in keys_header509                      if self.__conv_value(key,510                                           _get_item_key(item, key)) != '']511            if sublist_keys:512                [values.append('%s=%s'% (KEYS_TO_NAMES_EN[key],513                                         ','.join(_get_item_key(item, key))))514                 for key in sublist_keys515                 if len(_get_item_key(item, key))]516            print self.parse_delim.join(values)517    def print_by_ids_std(self, items, title=None, line_before=False):518        """Prints ID & names of items in a user readable form"""519        if not items:520            return521        if line_before:522            print523        if title:524            print title + ':'525        self.print_table_std(items, keys_header=['id', 'name'])526    def print_by_ids_parse(self, items, title=None, line_before=False):527        """Prints ID & names of items in a parseable format"""528        if not items:529            return530        if title:531            print title + '=',532        values = []533        for item in items:534            values += ['%s=%s' % (KEYS_TO_NAMES_EN[key],535                                  self.__conv_value(key,536                                                    _get_item_key(item, key)))537                       for key in ['id', 'name']538                       if self.__conv_value(key,539                                            _get_item_key(item, key)) != '']540        print self.parse_delim.join(values)541    def print_list_std(self, items, key):542        """Print a wrapped list of results"""543        if not items:544            return545        print ' '.join(_get_item_key(item, key) for item in items)546    def print_list_parse(self, items, key):547        """Print a wrapped list of results"""548        if not items:549            return550        print '%s=%s' % (KEYS_TO_NAMES_EN[key],...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!!
