Robot Framework
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 robot.errors import VariableError
19 from robot.utils import is_dict_like, is_list_like, normalize, RecommendationFinder
20 
21 
22 
26 def variable_not_found(name, candidates, message=None, deco_braces=True):
27  candidates = _decorate_candidates(name[0], candidates, deco_braces)
28  normalizer = partial(normalize, ignore='$@&%{}_')
29  message = RecommendationFinder(normalizer).find_and_format(
30  name, candidates,
31  message=message or "Variable '%s' not found." % name
32  )
33  raise VariableError(message)
34 
35 
36 def _decorate_candidates(identifier, candidates, deco_braces=True):
37  template = '%s{%s}' if deco_braces else '%s%s'
38  is_included = {'$': lambda value: True,
39  '@': is_list_like,
40  '&': is_dict_like,
41  '%': lambda value: True}[identifier]
42  return [template % (identifier, name)
43  for name in candidates if is_included(candidates[name])]
Used when variable does not exist.
Definition: errors.py:72
def variable_not_found(name, candidates, message=None, deco_braces=True)
Raise DataError for missing variable name.
Definition: notfound.py:26
def _decorate_candidates(identifier, candidates, deco_braces=True)
Definition: notfound.py:36