Skip to content

Commit e7c31d1

Browse files
committed
Document expected return values of a pluging action
1 parent 5dfd223 commit e7c31d1

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

cmem_plugin_base/dataintegration/description.py

+4
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ class PluginAction:
104104
They can be triggered from the plugin UI.
105105
Each action is based on a method on the plugin class. Besides the self parameter,
106106
the method can have one additional parameter of type PluginContext.
107+
The return value of the method will be converted to a string and displayed in the UI.
108+
The string may use Markdown formatting.
109+
The method may return None, in which case no output will be displayed.
110+
It may raise an exception to signal an error to the user.
107111
108112
:param name: The name of the method.
109113
:param label: A human-readable label of the action

tests/test_description.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,18 @@ def get_project(self, context: PluginContext) -> str:
102102

103103
# There should be two actions
104104
assert len(plugin.actions) == 2
105+
action1 = plugin.actions[0]
106+
action2 = plugin.actions[1]
105107

106108
# Check first action
107-
action = plugin.actions[0]
108-
assert action.name == "get_name"
109-
assert action.label == "Get name"
110-
assert action.description == "Returns the supplied name"
109+
assert action1.name == "get_name"
110+
assert action1.label == "Get name"
111+
assert action1.description == "Returns the supplied name"
111112

112113
# Call actions on a plugin instance
113114
plugin_instance = MyWorkflowPlugin("My Name")
114-
assert action.execute(plugin_instance, TestPluginContext()) == "My Name"
115-
assert action.execute(plugin_instance, TestPluginContext(project_id="movies")) == "movies"
115+
assert action1.execute(plugin_instance, TestPluginContext()) == "My Name"
116+
assert action2.execute(plugin_instance, TestPluginContext(project_id="movies")) == "movies"
116117

117118

118119
if __name__ == "__main__":

0 commit comments

Comments
 (0)