Best Python code snippet using yandex-tank
term.py
Source:term.py  
1#!/usr/bin/env python2# -*- coding: utf-8 -*-3import random4import os5import struct6import platform7# https://gist.githubusercontent.com/jtriley/1108174/raw/6ec4c846427120aa342912956c7f717b586f1ddb/terminalsize.py8def consize(file=None):9    """ getTerminalSize()10     - get width and height of console11     originally retrieved from:12     http://stackoverflow.com/questions/566746/how-to-get-console-window-width-in-python13    """14    current_os = platform.system()15    tuple_xy = None16    if current_os == 'Windows':17        tuple_xy = _size_windows(file)18    if current_os in ['Linux', 'Darwin'] or current_os.startswith('CYGWIN'):19        tuple_xy = _size_linux(file)20    return tuple_xy or (None, None)21def _size_windows(file=None):22    try:23        from ctypes import windll, create_string_buffer24        h = windll.kernel32.GetStdHandle(-12)25        csbi = create_string_buffer(22)26        res = windll.kernel32.GetConsoleScreenBufferInfo(h, csbi)27        if res:28            (bufx, bufy, curx, cury, wattr,29             left, top, right, bottom,30             maxx, maxy) = struct.unpack("hhhhHhhhhhh", csbi.raw)31            sizex = right - left + 132            sizey = bottom - top + 133            return sizex, sizey34    except:35        pass36def _size_linux(file=None):37    def ioctl_GWINSZ(fd):38        try:39            import fcntl40            import termios41            cr = struct.unpack(42                'hh',43                fcntl.ioctl(fd, termios.TIOCGWINSZ, '1234'))44            return cr45        except:46            pass47    if file:48        cr = ioctl_GWINSZ(file.fileno())49    else:50        cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2)51        if not cr:52            try:53                fd = os.open(os.ctermid(), os.O_RDONLY)54                cr = ioctl_GWINSZ(fd)55                os.close(fd)56            except:57                pass58    if not cr:59        try:60            cr = (os.environ['LINES'], os.environ['COLUMNS'])61        except:62            return None63    return int(cr[1]), int(cr[0])64def colorize(s, color):65    if s is None:66        return ""67    if type(s) not in (str, unicode):68        s = str(s)69    res=s70    COLOR_STOP="\033[0m"71    if color.lower()=="random":72        color=random.choice(["blue","red","green","yellow"])73    if color.lower()=="blue":74        res="\033[34m"+s+COLOR_STOP75    elif color.lower()=="red":76        res="\033[31m"+s+COLOR_STOP77    elif color.lower()=="lightred":78        res="\033[31;1m"+s+COLOR_STOP79    elif color.lower()=="green":80        res="\033[32m"+s+COLOR_STOP81    elif color.lower()=="lightgreen":82        res="\033[32;1m"+s+COLOR_STOP83    elif color.lower()=="yellow":84        res="\033[33m"+s+COLOR_STOP85    elif color.lower()=="lightyellow":86        res="\033[1;33m"+s+COLOR_STOP87    elif color.lower()=="magenta":88        res="\033[35m"+s+COLOR_STOP89    elif color.lower()=="cyan":90        res="\033[36m"+s+COLOR_STOP91    elif color.lower()=="grey":92        res="\033[37m"+s+COLOR_STOP93    elif color.lower()=="darkgrey":94        res="\033[1;30m"+s+COLOR_STOP95    return res96def terminal_size():97    import fcntl, termios, struct98    h, w, hp, wp = struct.unpack('HHHH',99        fcntl.ioctl(0, termios.TIOCGWINSZ,100        struct.pack('HHHH', 0, 0, 0, 0)))...terminal.py
Source:terminal.py  
1class bcolors:2    """ bcolors: Facilitates printing colors on terminals with support for3    escape sequences. It was borrowed from the following stackoverflow answer:4    <http://stackoverflow.com/a/287944>5    """6    HEADER = '\033[95m'7    BLUE = '\033[94m'8    GREEN = '\033[92m'9    YELLOW = '\033[93m'10    RED = '\033[91m'11    ENDC = '\033[0m'12    def disable(self):13        self.HEADER = ''14        self.OKBLUE = ''15        self.OKGREEN = ''16        self.WARNING = ''17        self.FAIL = ''18        self.ENDC = ''19def get_term_size():20    """ get_term_size: Returns a tuple of the host's terminal width and size21    (in that order).  This code should be platform independent and was borrowed22    from the following stackoverflow answer:23    <http://stackoverflow.com/a/566752>24    """25    import os26    env = os.environ27    def ioctl_GWINSZ(fd):28        try:29            import fcntl, termios, struct, os30            cr = struct.unpack('hh', fcntl.ioctl(fd, termios.TIOCGWINSZ,31        '1234'))32        except:33            return34        return cr35    cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2)36    if not cr:37        try:38            fd = os.open(os.ctermid(), os.O_RDONLY)39            cr = ioctl_GWINSZ(fd)40            os.close(fd)41        except:42            pass43    if not cr:44        cr = (env.get('LINES', 25), env.get('COLUMNS', 80))45    return int(cr[1]), int(cr[0])46def clear_terminal():47    """ clear_terminal: Clears the terminal's window.48    """49    import sys...console.py
Source:console.py  
1import os2class colors:3    RED = '\033[91m'4    PINK = '\033[95m'5    BLUE = '\033[94m'6    CYAN = '\033[96m'7    GREEN = '\033[92m'8    WARNING = '\033[93m'9    FAIL = '\033[91m'10    ENDC = '\033[0m'11    BOLD = '\033[1m'12    UNDERLINE = '\033[4m'13def getTerminalSize():14    env = os.environ15    def ioctl_GWINSZ(fd):16        try:17            import fcntl, termios, struct, os18            cr = struct.unpack('hh', fcntl.ioctl(fd, termios.TIOCGWINSZ,19        '1234'))20        except:21            return22        return cr23    cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2)24    if not cr:25        try:26            fd = os.open(os.ctermid(), os.O_RDONLY)27            cr = ioctl_GWINSZ(fd)28            os.close(fd)29        except:30            pass31    if not cr:32        cr = (env.get('LINES', 25), env.get('COLUMNS', 80))...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!!
