def recommend_similar_keywords(self, name): """Return keyword names similar to `name`.""" candidates = self._get_candidates('.' in name) normalizer = lambda name: candidates.get(name, name).lower().replace( '_', ' ') finder = RecommendationFinder(normalizer) return finder.find_recommendations(name, candidates)
def _get_non_existing_setting_message(self, name, normalized): if normalized in TestCaseFileSettings.names: is_resource = isinstance(self, ResourceFileSettings) return "Setting '%s' is not allowed in %s file." % ( name, 'resource' if is_resource else 'suite initialization') return RecommendationFinder(normalize).find_and_format( name=normalized, candidates=tuple(self.settings) + tuple(self.aliases), message="Non-existing setting '%s'." % name)
def recommend_similar_keywords(self, name, message): """Return keyword names similar to `name`.""" candidates = self._get_candidates('.' in name) finder = RecommendationFinder( lambda name: normalize(candidates.get(name, name), ignore='_')) return finder.find_and_format(name, candidates, message, check_missing_argument_separator=True)
def variable_not_found(name, candidates, message=None, deco_braces=True): """Raise DataError for missing variable name. Return recommendations for similar variable names if any are found. """ candidates = _decorate_candidates(name[0], candidates, deco_braces) normalizer = partial(normalize, ignore='$@&%{}_') message = RecommendationFinder(normalizer).find_and_format( name, candidates, message=message or "Variable '%s' not found." % name) raise VariableError(message)
def raise_not_found(name, candidates, msg=None): """Raise DataError for missing variable name. Return recommendations for similar variable names if any are found. """ if msg is None: msg = "Variable '%s' not found." % name candidates = _decorate_candidates(name[0], candidates) normalizer = partial(normalize, ignore='$@%&*{}_', caseless=True, spaceless=True) finder = RecommendationFinder(normalizer) recommendations = finder.find_recommendations(name, candidates) msg = finder.format_recommendations(msg, recommendations) raise DataError(msg)
def raise_not_found(name, candidates, msg=None, env_vars=False): """Raise DataError for missing variable name. Return recommendations for similar variable names if any are found. """ if msg is None: msg = "Variable '%s' not found." % name if env_vars: candidates = list(candidates) + ['%%{%s}' % ev for ev in get_env_vars()] normalizer = partial(normalize, ignore='$@%&*{}_', caseless=True, spaceless=True) finder = RecommendationFinder(normalizer) recommendations = finder.find_recommendations(name, candidates) msg = finder.format_recommendations(msg, recommendations) raise DataError(msg)
def format_recommendations(message, recommendations): return RecommendationFinder().format(message, recommendations)
def recommend_similar_keywords(self, name): """Return keyword names similar to `name`.""" candidates = self._get_candidates('.' in name) finder = RecommendationFinder( lambda name: normalize(candidates.get(name, name), ignore='_')) return finder.find(name, candidates)