Skip to content

Commit ca70d5d

Browse files
committed
Atest for plugin API
1 parent 54f59e3 commit ca70d5d

File tree

10 files changed

+76
-6
lines changed

10 files changed

+76
-6
lines changed

atest/plugin_api/MyPlugin.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from robot.api.deco import keyword # noqa F401
2+
3+
4+
class MyPlugin:
5+
6+
@keyword
7+
def plugin_keyword(self):
8+
return 2

atest/plugin_api/MyPluginBase.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from robot.api.deco import keyword # noqa F401
2+
3+
from PluginWithBaseLib import BaseClass
4+
5+
6+
class MyPluginBase(BaseClass):
7+
8+
@keyword
9+
def base_plugin_keyword(self):
10+
return "40"

atest/plugin_api/PluginLib.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from robot.api.deco import keyword # noqa F401
2+
3+
from robotlibcore import DynamicCore, PluginParser
4+
5+
6+
class PluginLib(DynamicCore):
7+
8+
def __init__(self, plugins):
9+
plugin_parser = PluginParser()
10+
parsed_plugins = plugin_parser.parse_plugins(plugins)
11+
self._plugin_keywords = plugin_parser.get_plugin_keywords(plugins)
12+
DynamicCore.__init__(self, parsed_plugins)
13+
14+
@keyword
15+
def foo(self):
16+
return 1

atest/plugin_api/PluginWithBaseLib.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from robot.api.deco import keyword # noqa F401
2+
3+
from robotlibcore import DynamicCore, PluginParser
4+
5+
6+
class BaseClass:
7+
def method(self):
8+
return 1
9+
10+
11+
class PluginWithBaseLib(DynamicCore):
12+
13+
def __init__(self, plugins):
14+
plugin_parser = PluginParser(BaseClass)
15+
parsed_plugins = plugin_parser.parse_plugins(plugins)
16+
self._plugin_keywords = plugin_parser.get_plugin_keywords(plugins)
17+
DynamicCore.__init__(self, parsed_plugins)
18+
19+
@keyword
20+
def base_keyword(self):
21+
return "42"

atest/plugin_api/__init__.py

Whitespace-only changes.

atest/plugin_api/plugin_api.robot

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
*** Test Cases ***
2+
Plugin Test
3+
Import Library ${CURDIR}/PluginLib.py plugins=${CURDIR}/MyPlugin.py
4+
${value} = Foo
5+
Should Be Equal ${value} ${1}
6+
${value} = Plugin Keyword
7+
Should Be Equal ${value} ${2}
8+
9+
Plugins With Base Class
10+
Import Library ${CURDIR}/PluginWithBaseLib.py plugins=${CURDIR}/MyPluginBase.py
11+
${value} = Base Plugin Keyword
12+
Should Be Equal ${value} 40
13+
${value} = Base Keyword
14+
Should Be Equal ${value} 42
15+
16+
Pugins With No Base Class
17+
Run Keyword And Expect Error
18+
... *PluginError: Plugin does not inherit <class 'PluginWithBaseLib.BaseClass'>
19+
... Import Library ${CURDIR}/PluginWithBaseLib.py plugins=${CURDIR}/MyPlugin.py

src/robotlibcore.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,6 @@ def get_keyword_types(self, name):
124124
raise ValueError('Keyword "%s" not found.' % name)
125125
return spec.argument_types
126126

127-
def parse_plugins(self, plugins: str) -> typing.List:
128-
pass
129-
130127
def __get_keyword(self, keyword_name):
131128
if keyword_name == "__init__":
132129
return self.__init__
@@ -285,7 +282,7 @@ def __init__(self, argument_specification=None, documentation=None, argument_typ
285282

286283

287284
class PluginParser:
288-
def __init__(self, base_class: typing.Any):
285+
def __init__(self, base_class: typing.Optional[typing.Any] = None):
289286
self._base_class = base_class
290287

291288
def parse_plugins(self, plugins: str) -> typing.List:

utest/helpers/__init__.py

Whitespace-only changes.

utest/test_plugin_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
@pytest.fixture(scope="module")
88
def plugin_parser() -> PluginParser:
9-
return PluginParser(None)
9+
return PluginParser()
1010

1111

1212
def test_no_plugins_parsing(plugin_parser):

utest/test_robotlibcore.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ def test_dir():
6666
"multi_line_doc",
6767
"not_keyword_in_main",
6868
"one_line_doc",
69-
"parse_plugins",
7069
"run_keyword",
7170
"tags",
7271
"varargs_and_kwargs",

0 commit comments

Comments
 (0)