How to use _format_err method in tavern

Best Python code snippet using tavern

parser.py

Source:parser.py Github

copy

Full Screen

...190 try:191 # Check if any unreplaced macros192 self._validate_macros_in_txt(pvname)193 except MacroError as e:194 return ReqParseError(self._format_err(195 (self._curr_line_n, self._curr_line), e))196 else:197 pvs.append(pvname)198 elif self._curr_line.startswith('!'):199 # Calling another req file200 split_line = self._curr_line[1:].split(',', maxsplit=1)201 if len(split_line) > 1:202 macro_txt = split_line[1].strip()203 if macro_txt.startswith(('\"', '\'')):204 quote_type = macro_txt[0]205 else:206 return ReqFileFormatError(207 self._format_err(208 (self._curr_line_n, self._curr_line),209 'Syntax error. Macro argument must be quoted'))210 if not macro_txt.endswith(quote_type):211 return ReqFileFormatError(212 self._format_err(213 (self._curr_line_n, self._curr_line),214 'Syntax error. Macro argument must be quoted'))215 macro_txt = SnapshotPv.macros_substitution(216 macro_txt[1:-1], self._macros)217 try:218 # Check for any unreplaced macros219 self._validate_macros_in_txt(macro_txt)220 macros = parse_macros(macro_txt)221 except MacroError as e:222 return ReqParseError(223 self._format_err(224 (self._curr_line_n, self._curr_line), e))225 else:226 macros = {}227 path = os.path.join(228 os.path.dirname(self._path),229 split_line[0])230 msg = self._check_looping(path)231 if msg:232 return ReqFileInfLoopError(233 self._format_err(234 (self._curr_line_n, self._curr_line), msg))235 try:236 sub_f = SnapshotReqFile(237 path, parent=self, macros=macros)238 includes.append(sub_f)239 except OSError as e:240 return OSError(241 self._format_err(242 (self._curr_line, self._curr_line_n), e))243 return (pvs, metadata, includes)244 @staticmethod245 def __normalize_key_values(metadata: dict) -> dict:246 # Ensure backward compatibility - some keys previously were using "-" instead of "_"247 # To further support these keys (e.g. "rgx-filters", "force-labels"248 # we normalize them to "rgx_filters", "force_labels"249 if 'labels' in metadata and 'force-labels' in metadata['labels'].keys():250 metadata['labels']['force_labels'] = metadata['labels'].pop(251 'force-labels')252 if 'filters' in metadata and 'rgx-filters' in metadata['filters'].keys():253 metadata['filters']['rgx_filters'] = metadata['filters'].pop(254 'rgx-filters')255 return metadata256 def _extract_pvs_from_req(self):257 try:258 list_of_pvs = self._file_data.split('\n')259 except Exception as e:260 return ReqParseError(e)261 else:262 return list_of_pvs263 264 def _extract_pvs_from_yaml(self):265 try:266 list_of_pvs = []267 for ioc_name in self._file_data.keys():268 for pv_name in self._file_data[ioc_name]:269 list_of_pvs.append(ioc_name+":"+pv_name)270 return list_of_pvs271 except Exception as e:272 msg = f"{self._path}: Could not parse YML file."273 return JsonParseError(msg)274 def _extract_pvs_from_json(self):275 try:276 list_of_pvs = []277 for ioc_name in self._file_data.keys():278 for pv_name in self._file_data[ioc_name]:279 list_of_pvs.append(ioc_name+":"+pv_name)280 return list_of_pvs281 except Exception as e:282 msg = f"{self._path}: Could not parse Json file."283 return JsonParseError(msg)284 def _format_err(self, line: tuple, msg: str):285 return '{} [line {}: {}]: {}'.format(286 self._trace, line[0], line[1], msg)287 def _validate_macros_in_txt(self, txt: str):288 invalid_macros = []289 macro_rgx = re.compile('\$\(.*?\)') # find all of type $()290 raw_macros = macro_rgx.findall(txt)291 for raw_macro in raw_macros:292 if raw_macro not in self._macros.values(293 ) and raw_macro[2:-1] not in self._c_macros:294 # There are unknown macros which were not substituted295 invalid_macros.append(raw_macro)296 if invalid_macros:297 raise MacroError(298 'Following macros were not defined: {}'.format(...

Full Screen

Full Screen

dict_util.py

Source:dict_util.py Github

copy

Full Screen

...151 def full_err():152 """Get error in the format:153 a["b"]["c"] = 4, b["b"]["c"] = {'key': 'value'}154 """155 def _format_err(which):156 return "{}{}".format(which, "".join('["{}"]'.format(key) for key in keys))157 e_formatted = _format_err("expected")158 a_formatted = _format_err("actual")159 return "{} = '{}', {} = '{}'".format(e_formatted, expected_val,160 a_formatted, actual_val)161 # Check required because of python 2/3 unicode compatability when loading yaml162 if isinstance(actual_val, ustr):163 actual_type = str164 else:165 actual_type = type(actual_val)166 if expected_val == ANYTHING:167 # Match anything. We could just early exit here but having the debug168 # logging below is useful169 expected_matches = True170 elif isinstance(expected_val, TypeSentinel):171 # If the 'expected' type is actually just a sentinel for another type,172 # then it should match...

Full Screen

Full Screen

analysis.py

Source:analysis.py Github

copy

Full Screen

...74 else:75 mag = "%d" % round(mag, -order)76 err = "%d" % round(err, -order)77 return "%s%s%s" % (mag, sep, err)78def _format_err(row):79 out = {}80 for var in row.index.levels[0]:81 out[var] = format_mag_err(row[var]["mean"], row[var]["sem"])82 return out83def df_agg_mean(df, group_cols, raw=False):84 """85 Aggregate a dataframe to summarize it with the mean and its error86 Args:87 df (pd.DataFrame): The dataframe.88 group_cols (list of str): Columns used as index for the aggregation.89 raw (bool): If False, the result is a table of strings representing the number with its error. If True,90 the columns will an additional level providing both the mean and its error (sem).91 Returns:92 pd.DataFrame: The summarizing dataframe...

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 tavern 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