Robot Framework Integrated Development Environment (RIDE)
notfound.py
Go to the documentation of this file.
1 # Copyright 2008-2015 Nokia Networks
2 # Copyright 2016- Robot Framework Foundation
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 
16 from functools import partial
17 
18 from robotide.lib.robot.errors import VariableError
19 from robotide.lib.robot.utils import (is_dict_like, is_list_like, normalize,
20  RecommendationFinder)
21 
22 
23 
27 def variable_not_found(name, candidates, msg=None, deco_braces=True):
28  if msg is None:
29  msg = "Variable '%s' not found." % name
30  candidates = _decorate_candidates(name[0], candidates, deco_braces)
31  normalizer = partial(normalize, ignore='$@%&*{}_', caseless=True,
32  spaceless=True)
33  finder = RecommendationFinder(normalizer)
34  recommendations = finder.find_recommendations(name, candidates)
35  msg = finder.format_recommendations(msg, recommendations)
36  raise VariableError(msg)
37 
38 
39 def _decorate_candidates(identifier, candidates, deco_braces=True):
40  template = '%s{%s}' if deco_braces else '%s%s'
41  is_included = {'$': lambda value: True,
42  '@': is_list_like,
43  '&': is_dict_like,
44  '%': lambda value: True}[identifier]
45  return [template % (identifier, name)
46  for name in candidates if is_included(candidates[name])]
Used when no keyword is found or there is more than one match.
Definition: errors.py:75
def variable_not_found(name, candidates, msg=None, deco_braces=True)
Raise DataError for missing variable name.
Definition: notfound.py:27
def _decorate_candidates(identifier, candidates, deco_braces=True)
Definition: notfound.py:39