Best Python code snippet using yandex-tank
screen.py
Source:screen.py  
...112        self.default_final = '{{{:}:>{len}}}'113        self.last_reshaped = time.time()114        self.old_shape = {}115        self.reshape_delay = reshape_delay116    def __delimiter_gen(self):117        for d in self.delimiters:118            yield d119        while True:120            yield self.delimiters[-1]121    def __prepare(self, data):122        prepared = []123        shape = {}124        for line in data:125            new = {}126            for f in line:127                if f in self.template:128                    new[f] = self.template[f]['tpl'].format(line[f])129                    if f not in shape:130                        shape[f] = len(new[f])131                    else:132                        shape[f] = max(shape[f], len(new[f]))133            prepared.append(new)134        return (prepared, shape)135    def __update_shape(self, shape):136        def change_shape():137            self.last_reshaped = time.time()138            self.old_shape = shape139        if set(shape.keys()) != set(self.old_shape.keys()):140            change_shape()141            return shape142        else:143            for f in shape:144                if shape[f] > self.old_shape[f]:145                    change_shape()146                    return shape147                elif shape[f] < self.old_shape[f]:148                    if time.time() > (self.last_reshaped + self.reshape_delay):149                        change_shape()150                        return shape151        return self.old_shape152    def render_table(self, data, fields):153        prepared, shape = self.__prepare(data)154        headers = {}155        for f in shape:156            if 'header' in self.template[f]:157                headers[f] = self.template[f]['header']158                shape[f] = max(shape[f], len(headers[f]))159            else:160                headers[f] = ''161        shape = self.__update_shape(shape)162        has_headers = any(headers.values())163        delimiter_gen = self.__delimiter_gen()164        row_tpl = ''165        for num, field in enumerate(fields):166            if 'final' in self.template[field]:167                final = self.template[field]['final']168            else:169                final = self.default_final170            row_tpl += final.format(field, len=shape[field])171            if num < len(fields) - 1:172                row_tpl += next(delimiter_gen)173        result = []174        if has_headers:175            result.append(176                (row_tpl.format(**headers),))177        for line in prepared:...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!!
