Robot Framework Integrated Development Environment (RIDE)
runkwregister.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 import inspect
17 import warnings
18 
19 from robotide.lib.robot.utils import NormalizedDict, PY3
20 
21 
23 
24  def __init__(self):
25  self._libs_libs = {}
26 
27  def register_run_keyword(self, libname, keyword, args_to_process=None,
28  deprecation_warning=True):
29  if deprecation_warning:
30  warnings.warn(self._deprecation_warning_deprecation_warning(), UserWarning)
31  if args_to_process is None:
32  args_to_process = self._get_args_from_method_get_args_from_method(keyword)
33  keyword = keyword.__name__
34  if libname not in self._libs_libs:
35  self._libs_libs[libname] = NormalizedDict(ignore=['_'])
36  self._libs_libs[libname][keyword] = int(args_to_process)
37 
39  return ("The API to register run keyword variants and to disable "
40  "variable resolving in keyword arguments will change in Robot "
41  "Framework 3.1. For more information see issue #2190 <"
42  "https://github.com/robotframework/robotframework/issues/2190"
43  ">. Use with 'deprecation_warning=False' to avoid related "
44  "deprecation warnings.")
45 
46  def get_args_to_process(self, libname, kwname):
47  if libname in self._libs_libs and kwname in self._libs_libs[libname]:
48  return self._libs_libs[libname][kwname]
49  return -1
50 
51  def is_run_keyword(self, libname, kwname):
52  return self.get_args_to_processget_args_to_process(libname, kwname) >= 0
53 
54  def _get_args_from_method(self, method):
55  if PY3:
56  raise RuntimeError('Cannot determine arguments to process '
57  'automatically in Python 3.')
58  if inspect.ismethod(method):
59  return method.__code__.co_argcount - 1
60  elif inspect.isfunction(method):
61  return method.__code__.co_argcount
62  raise ValueError('Needs function or method')
63 
64 
65 RUN_KW_REGISTER = _RunKeywordRegister()
def register_run_keyword(self, libname, keyword, args_to_process=None, deprecation_warning=True)