How to use _is_abspath method in avocado

Best Python code snippet using avocado_python

paths.py

Source:paths.py Github

copy

Full Screen

...8import os9import sys10NT = sys.platform == 'win32'11if NT:12 def _is_abspath(path: str):13 if os.path.isabs(path):14 return True15 rp = path.rpartition(':')16 if rp[0]:17 # path like 'c:' should be abspath18 return True19 return False20 def _get_normpath(path: str):21 val = str(path) # avoid recursion22 if val.endswith(':'):23 val += os.path.sep # c: -> c:\24 return os.path.normpath(os.path.normcase(val))25 def _join(path, *others):26 if not isinstance(path, str):27 raise TypeError28 if path.endswith(':'):29 path += os.path.sep30 return os.path.join(path, *others)31else:32 def _is_abspath(path: str):33 return os.path.isabs(path)34 def _get_normpath(path: str):35 val = str(path) # avoid recursion36 return os.path.normpath(os.path.normcase(val))37 def _join(path, *others):38 return os.path.join(path, *others)39class PathComponent(str):40 def __init__(self, *args):41 self._normpath: str = None42 def __repr__(self):43 return '{}(\'{}\')'.format(type(self).__name__, self)44 def __eq__(self, other):45 if other is self:46 return True47 if isinstance(other, PathComponent):48 return self.normalcase == other.normalcase49 if isinstance(other, str):50 return self.normalcase == _get_normpath(other)51 return False52 def __hash__(self):53 return hash(self.normalcase)54 @property55 def normalcase(self):56 '''57 get normcase path which create by `os.path.normcase()`.58 '''59 if self._normpath is None:60 self._normpath = _get_normpath(self)61 return self._normpath62class Name(PathComponent):63 '''64 the name part of path.65 '''66 def __init__(self, val):67 super().__init__(val)68 self._pure_name = None69 self._ext = None70 def __ensure_pure_name(self):71 if self._pure_name is None:72 pn, ext = os.path.splitext(self)73 self._pure_name = PathComponent(pn)74 self._ext = PathComponent(ext)75 @property76 def pure_name(self) -> PathComponent:77 ''' get name without ext from path. '''78 self.__ensure_pure_name()79 return self._pure_name80 @property81 def ext(self) -> PathComponent:82 ''' get ext from path. '''83 self.__ensure_pure_name()84 return self._ext85 def replace_pure_name(self, val):86 if not isinstance(val, str):87 raise TypeError88 return Name(val + self.ext)89 def replace_ext(self, val):90 if not isinstance(val, str):91 raise TypeError92 return Name(self.pure_name + val)93class Path(PathComponent):94 join = staticmethod(_join)95 def __new__(cls, value):96 if not isinstance(value, str):97 raise TypeError98 if cls is Path:99 if _is_abspath(value):100 cls = _AbsPath101 else:102 cls = _RelPath103 path = str.__new__(cls, value)104 return path105 def __init__(self, val):106 super().__init__(val)107 # sub attrs108 self._dirname = None109 self._name = None110 @staticmethod111 def from_cwd():112 ''' get `Path` from `os.getcwd()` '''113 return Path(os.getcwd())...

Full Screen

Full Screen

parameters.py

Source:parameters.py Github

copy

Full Screen

...95 else:96 suffix = '$'97 return re.compile(path.replace('*', '[^/]*') + suffix)98 @staticmethod99 def _is_abspath(path):100 """ Is this an absolute or relative path? """101 if path.pattern and path.pattern[0] == '/':102 return True103 else:104 return False105 def get(self, key, path=None, default=None):106 """107 Retrieve value associated with key from params108 :param key: Key you're looking for109 :param path: namespace ['*']110 :param default: default value when not found111 :raise KeyError: In case of multiple different values (params clash)112 """113 if path is None: # default path is any relative path114 path = '*'115 try:116 return self._cache[(key, path, default)]117 except (KeyError, TypeError):118 # KeyError - first query119 # TypeError - unable to hash120 value = self._get(key, path, default)121 if self._logger_name is not None:122 logger = logging.getLogger(self._logger_name)123 logger.debug("PARAMS (key=%s, path=%s, default=%s) => %r",124 key, path, default, value)125 try:126 self._cache[(key, path, default)] = value127 except TypeError:128 pass129 return value130 def _get(self, key, path, default):131 """132 Actual params retrieval133 :param key: key you're looking for134 :param path: namespace135 :param default: default value when not found136 :raise KeyError: In case of multiple different values (params clash)137 """138 path_re = self._greedy_path_to_re(path)139 for param in self._rel_paths:140 try:141 return param.get_or_die(path_re, key)142 except NoMatchError:143 pass144 if self._is_abspath(path_re):145 try:146 return self._abs_path.get_or_die(path_re, key)147 except NoMatchError:148 pass149 return default150 def objects(self, key, path=None):151 """152 Return the names of objects defined using a given key.153 :param key: The name of the key whose value lists the objects154 (e.g. 'nics').155 """156 return self.get(path, key, "").split()157 def iteritems(self):158 """...

Full Screen

Full Screen

service.py

Source:service.py Github

copy

Full Screen

...80 return False81 with open(actual_path, 'w') as f:82 f.write('')83 return True84 def _is_abspath(self, path):85 return '/' == path[0] if path else False86 def _resolve_path(self, path):87 if self._is_abspath(path):88 return path89 return os.path.join(self.base_path, path)90 def _sanitize_path(self, path):91 return self.__illegal_pattern.sub('', path)92class BroadcastService(object):93 def __init__(self, WebSocketInterfaceClass):94 self.WebSocketInterfaceClass = WebSocketInterfaceClass95 def broadcast(self, message):96 channels = self.WebSocketInterfaceClass._channel_table97 for object_hash in channels:98 channel = channels[object_hash]...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run avocado automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful