Best Python code snippet using yandex-tank
screen.py
Source:screen.py  
...630        self.last_dist = data["overall"]["proto_code"]["count"]631        for code, count in self.last_dist.items():632            self.total_count += count633            self.overall_dist[code] += count634    def __code_color(self, code):635        colors = {(200, 299): self.screen.markup.GREEN,636                  (300, 399): self.screen.markup.CYAN,637                  (400, 499): self.screen.markup.YELLOW,638                  (500, 599): self.screen.markup.RED}639        if code in self.last_dist:640            for left, right in colors:641                if left <= int(code) <= right:642                    return colors[(left, right)]643            return self.screen.markup.MAGENTA644        else:645            return ''646    def __code_descr(self, code):647        if int(code) in util.HTTP:648            return util.HTTP[int(code)]649        else:650            return 'N/A'651    def render(self, expected_width=None):652        prepared = [(self.screen.markup.WHITE, self.title)]653        if not self.overall_dist:654            prepared.append(('',))655        else:656            data = []657            for code, count in sorted(self.overall_dist.items()):658                if code in self.last_dist:659                    last_count = self.last_dist[code]660                else:661                    last_count = 0662                data.append({663                    'count': count,664                    'last': last_count,665                    'percent': 100 * safe_div(count, self.total_count),666                    'code': code,667                    'description': self.__code_descr(code)668                })669            table = self.formatter.render_table(data, ['count', 'last', 'percent', 'code', 'description'])670            for num, line in enumerate(data):671                color = self.__code_color(line['code'])672                prepared.append((color, table[num][0]))673        self.width, self.lines = self.fill_rectangle(prepared)674class CurrentNetBlock(AbstractBlock):675    ''' NET codes with highlight'''676    def __init__(self, screen):677        AbstractBlock.__init__(self, screen)678        self.overall_dist = defaultdict(int)679        self.title = 'Net codes:'680        self.total_count = 0681        template = {682            'count':       {'tpl': '{:>,}'},  # noqa: E241683            'last':        {'tpl': '+{:>,}'},  # noqa: E241684            'percent':     {'tpl': '{:>.2f}%'},  # noqa: E241685            'code':        {'tpl': '{:>2}', 'final': '{{{:}:<{len}}}'},  # noqa: E241686            'description': {'tpl': '{:<10}', 'final': '{{{:}:<{len}}}'}687        }688        delimiters = [' ', '  ', ' : ', ' ']689        self.formatter = TableFormatter(template, delimiters)690    def add_second(self, data):691        self.last_dist = data["overall"]["net_code"]["count"]692        for code, count in self.last_dist.items():693            self.total_count += count694            self.overall_dist[code] += count695    def __code_descr(self, code):696        if int(code) in util.NET:697            return util.NET[int(code)]698        else:699            return 'N/A'700    def __code_color(self, code):701        if code in self.last_dist:702            if int(code) == 0:703                return self.screen.markup.GREEN704            elif int(code) == 314:705                return self.screen.markup.MAGENTA706            else:707                return self.screen.markup.RED708        else:709            return ''710    def render(self, expected_width=None):711        prepared = [(self.screen.markup.WHITE, self.title)]712        if not self.overall_dist:713            prepared.append(('',))714        else:715            data = []716            for code, count in sorted(self.overall_dist.items()):717                if code in self.last_dist:718                    last_count = self.last_dist[code]719                else:720                    last_count = 0721                data.append({722                    'count': count,723                    'last': last_count,724                    'percent': 100 * safe_div(count, self.total_count),725                    'code': code,726                    'description': self.__code_descr(code)727                })728            table = self.formatter.render_table(data, ['count', 'last', 'percent', 'code', 'description'])729            for num, line in enumerate(data):730                color = self.__code_color(line['code'])731                prepared.append((color, table[num][0]))732        self.width, self.lines = self.fill_rectangle(prepared)733class AnswSizesBlock(AbstractBlock):734    ''' Answer and response sizes, if available '''735    def __init__(self, screen, sizes_max_spark=120):736        AbstractBlock.__init__(self, screen)737        self.sparkline = Sparkline(sizes_max_spark)738        self.overall = {'count': 0, 'Response': 0, 'Request': 0}739        self.last = {'count': 0, 'Response': 0, 'Request': 0}740        self.title = 'Average Sizes (all/last), bytes:'741        template = {742            'name': {'tpl': '{:>}'},743            'avg': {'tpl': '{:>,.1f}'},744            'last_avg': {'tpl': '{:>,.1f}'}...qr_code.py
Source:qr_code.py  
1#!/usr/bin/env python32"""! QR code generator animation script."""3import numpy as np4import qrcode5from src.animate import Animate6class QRCode(Animate):7    """! QR code generator animation class.8    @image html qr_code.QRCode.png width=256px9    Animation displaying a static QR-code-encoded-text.10    """11    __CODE_COLOR = (0xFF, 0xFF, 0xFF)12    def __init__(self, shape: tuple, *args: list, **kwargs: dict):13        super().__init__(shape)14        self.__text = kwargs["text"]15        assert self.__text != "", "Text is empty."16    def draw(self):17        qr_code = qrcode.QRCode(18            version=1,19            # error_correction=qrcode.constants.ERROR_CORRECT_L,20            box_size=1,21            border=0,22        )23        qr_code.add_data(self.__text)24        qr_code.make(fit=True)25        qr_pil = qr_code.make_image(fill_color=self.__CODE_COLOR, back_color=(0, 0, 0))26        qr_np = np.array(qr_pil)27        assert (28            qr_np.shape <= self._screen.shape29        ), f"[{self.__class__.__name__}] QR code too large."30        # Center the code on the screen.31        offset_y = (self._screen.shape[0] - qr_np.shape[0]) // 232        offset_x = (self._screen.shape[1] - qr_np.shape[1]) // 233        self._screen[34            offset_y : qr_np.shape[1] + offset_y, offset_x : qr_np.shape[0] + offset_x35        ] = qr_np...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!!
