Skip to content

robot.utils.recommendations

RecommendationFinder

RecommendationFinder(normalizer=None)
Source code in src/robot/utils/recommendations.py
def __init__(self, normalizer=None):
    self.normalizer = normalizer or (lambda x: x)

find

find(name, candidates, max_matches=10)

Return a list of close matches to name from candidates.

Source code in src/robot/utils/recommendations.py
def find(self, name, candidates, max_matches=10):
    """Return a list of close matches to `name` from `candidates`."""
    if not name or not candidates:
        return []
    norm_name = self.normalizer(name)
    norm_candidates = self._get_normalized_candidates(candidates)
    cutoff = self._calculate_cutoff(norm_name)
    norm_matches = difflib.get_close_matches(
        norm_name, norm_candidates, n=max_matches, cutoff=cutoff
    )
    return self._get_original_candidates(norm_matches, norm_candidates)

format

format(message, recommendations)

Add recommendations to the given message.

The recommendation string looks like::

1
2
3
4
<message> Did you mean:
    <recommendations[0]>
    <recommendations[1]>
    <recommendations[2]>
Source code in src/robot/utils/recommendations.py
def format(self, message, recommendations):
    """Add recommendations to the given message.

    The recommendation string looks like::

        <message> Did you mean:
            <recommendations[0]>
            <recommendations[1]>
            <recommendations[2]>
    """
    if recommendations:
        message += " Did you mean:"
        for rec in recommendations:
            message += "\n    %s" % rec
    return message