Best Python code snippet using avocado_python
...101 suffix (:data:`SUFFIX`) that has to be accounted for.102 """103 max_length = utils_path.get_max_file_name_length(self.filename)104 return max_length - len(self.SUFFIX)105 def _check_valid_data_source(self, source):106 """107 Utility to check if user chose a specific data source108 :param source: either None for no specific selection or a source name109 :type source: None or str110 :raises: ValueError111 """112 if source is not None and source not in self.DATA_SOURCES:113 msg = "Data file source requested (%s) is not one of: %s"114 msg %= (source, ", ".join(self.DATA_SOURCES))115 raise ValueError(msg)116 def _get_datadir(self, source):117 path_components = self._data_sources_mapping.get(source)118 if path_components is None:119 return120 # evaluate lazily, needed when the class changes its own121 # information such as its datadir122 path_components = [func() for func in path_components]123 if None in path_components:124 return125 # if path components are absolute paths, let's believe that126 # they have already been treated (such as the entries that127 # return the self.datadir). If not, let's split the path128 # components so that they can be treated in the next loop129 split_path_components = 130 for path_component in path_components:131 if not os.path.isabs(path_component):132 split_path_components += path_component.split(os.path.sep)133 else:134 split_path_components.append(path_component)135 # now, make sure each individual path component can be represented136 # in the filesystem. again, if it's an absolute path, do nothing137 paths = 138 for path in split_path_components:139 if os.path.isabs(path):140 paths.append(path)141 else:142 paths.append(astring.string_to_safe_path(path))143 return os.path.join(*paths)144 def get_data(self, filename, source=None, must_exist=True):145 """146 Retrieves the path to a given data file.147 This implementation looks for data file in one of the sources148 defined by the :attr:`DATA_SOURCES` attribute.149 :param filename: the name of the data file to be retrieved150 :type filename: str151 :param source: one of the defined data sources. If not set,152 all of the :attr:`DATA_SOURCES` will be attempted153 in the order they are defined154 :type source: str155 :param must_exist: whether the existence of a file is checked for156 :type must_exist: bool157 :rtype: str or None158 """159 log_fmt = "DATA (filename=%s) => %s (%s)"160 if source is None:161 sources = self.DATA_SOURCES162 else:163 self._check_valid_data_source(source)164 sources = [source]165 for attempt_source in sources:166 datadir = self._get_datadir(attempt_source)167 if datadir is not None:168 # avoid returning a slash after the data directory name169 # when a file was not requested (thus return the data170 # directory itself)171 if not filename:172 path = datadir173 else:174 path = os.path.join(datadir, filename)175 if not must_exist:176 self.log.debug(177 log_fmt,...
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.