Best Python code snippet using robotframework
cmdline.py
Source:cmdline.py  
...80        sys.argv.append('-h')81    args = parser.parse_args()82    if args.err:83        for i in range(len(args.err)):84            args.err[i] = system_decode(args.err[i])85    if args.suc:86        for i in range(len(args.suc)):87            args.suc[i] = system_decode(args.suc[i])88    if args.rtxt:89        args.rtxt = system_decode(args.rtxt)90    if args.rntxt:91        args.rntxt = system_decode(args.rntxt)92    check_args(args)93    self.args = args94    if self.args.debug:95        self.args.t = 1    # thread set to 1 in debug mode96        self.lock.acquire()97        print '*' * self.console_width98        print '[Parsed Arguments]\n'99        pprint.pprint(self.args.__dict__)100        print '\n' + '*' * self.console_width101        self.lock.release()102    self.request_thread_count = self.args.t103def check_args(args):104    if not args.f and not args.u:105        msg = 'Both RequestFILE and RequestURL were not set!\n' + \...robotpath.py
Source:robotpath.py  
...48       That includes Windows and also OSX in default configuration.49    4. Turn ``c:`` into ``c:\\`` on Windows instead of keeping it as ``c:``.50    """51    if not is_unicode(path):52        path = system_decode(path)53    path = unic(path)  # Handles NFC normalization on OSX54    path = os.path.normpath(path)55    if case_normalize and CASE_INSENSITIVE_FILESYSTEM:56        path = path.lower()57    if WINDOWS and len(path) == 2 and path[1] == ':':58        return path + '\\'59    return path60def abspath(path, case_normalize=False):61    """Replacement for os.path.abspath with some enhancements and bug fixes.62    1. Non-Unicode paths are converted to Unicode using file system encoding.63    2. Optionally lower-case paths on case-insensitive file systems.64       That includes Windows and also OSX in default configuration.65    3. Turn ``c:`` into ``c:\\`` on Windows instead of ``c:\\current\\path``.66    4. Handle non-ASCII characters on working directory with Python < 2.6.5:67       http://bugs.python.org/issue342668    """69    path = normpath(path, case_normalize)70    return normpath(_abspath(path), case_normalize)71def get_link_path(target, base):72    """Returns a relative path to ``target`` from ``base``.73    If ``base`` is an existing file, then its parent directory is considered to74    be the base. Otherwise ``base`` is assumed to be a directory.75    The returned path is URL encoded. On Windows returns an absolute path with76    ``file:`` prefix if the target is on a different drive.77    """78    path = _get_link_path(target, base)79    url = path_to_url(path)80    if os.path.isabs(path):81        url = 'file:' + url82    return url83def _get_link_path(target, base):84    target = abspath(target)85    base = abspath(base)86    if os.path.isfile(base):87        base = os.path.dirname(base)88    if base == target:89        return '.'90    base_drive, base_path = os.path.splitdrive(base)91    # Target and base on different drives92    if os.path.splitdrive(target)[0] != base_drive:93        return target94    common_len = len(_common_path(base, target))95    if base_path == os.sep:96        return target[common_len:]97    if common_len == len(base_drive) + len(os.sep):98        common_len -= len(os.sep)99    dirs_up = os.sep.join([os.pardir] * base[common_len:].count(os.sep))100    path = os.path.join(dirs_up, target[common_len + len(os.sep):])101    return os.path.normpath(path)102def _common_path(p1, p2):103    """Returns the longest path common to p1 and p2.104    Rationale: as os.path.commonprefix is character based, it doesn't consider105    path separators as such, so it may return invalid paths:106    commonprefix(('/foo/bar/', '/foo/baz.txt')) -> '/foo/ba' (instead of /foo)107    """108    while p1 and p2:109        if p1 == p2:110            return p1111        if len(p1) > len(p2):112            p1 = os.path.dirname(p1)113        else:114            p2 = os.path.dirname(p2)115    return ''116def find_file(path, basedir='.', file_type=None):117    path = os.path.normpath(path.replace('/', os.sep))118    if os.path.isabs(path):119        ret = _find_absolute_path(path)120    else:121        ret = _find_relative_path(path, basedir)122    if ret:123        return ret124    default = file_type or 'File'125    file_type = {'Library': 'Test library',126                 'Variables': 'Variable file',127                 'Resource': 'Resource file'}.get(file_type, default)128    raise DataError("%s '%s' does not exist." % (file_type, path))129def _find_absolute_path(path):130    if _is_valid_file(path):131        return path132    return None133def _find_relative_path(path, basedir):134    for base in [basedir] + sys.path:135        if not (base and os.path.isdir(base)):136            continue137        if not is_unicode(base):138            base = system_decode(base)139        ret = os.path.abspath(os.path.join(base, path))140        if _is_valid_file(ret):141            return ret142    return None143def _is_valid_file(path):144    return os.path.isfile(path) or \...encodings.py
Source:encodings.py  
...3import sys4def system_encode(s):5    charset = sys.stdout.encoding6    return s.encode(charset, 'ignore')7def system_decode(s):8    charset = sys.stdout.encoding...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!!
