-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #639 from writer/chore-workflows-tests2
chore: Refactor and workflows tests
- Loading branch information
Showing
39 changed files
with
825 additions
and
701 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from writer.blocks.addtostatelist import AddToStateList | ||
from writer.blocks.calleventhandler import CallEventHandler | ||
from writer.blocks.foreach import ForEach | ||
from writer.blocks.httprequest import HTTPRequest | ||
from writer.blocks.logmessage import LogMessage | ||
from writer.blocks.parsejson import ParseJSON | ||
from writer.blocks.returnvalue import ReturnValue | ||
from writer.blocks.runworkflow import RunWorkflow | ||
from writer.blocks.setstate import SetState | ||
from writer.blocks.writeraddchatmessage import WriterAddChatMessage | ||
from writer.blocks.writerchat import WriterChat | ||
from writer.blocks.writerclassification import WriterClassification | ||
from writer.blocks.writercompletion import WriterCompletion | ||
from writer.blocks.writerinitchat import WriterInitChat | ||
from writer.blocks.writernocodeapp import WriterNoCodeApp | ||
|
||
SetState.register("workflows_setstate") | ||
WriterClassification.register("workflows_writerclassification") | ||
WriterCompletion.register("workflows_writercompletion") | ||
HTTPRequest.register("workflows_httprequest") | ||
RunWorkflow.register("workflows_runworkflow") | ||
WriterNoCodeApp.register("workflows_writernocodeapp") | ||
ForEach.register("workflows_foreach") | ||
LogMessage.register("workflows_logmessage") | ||
WriterChat.register("workflows_writerchat") | ||
WriterAddChatMessage.register("workflows_writeraddchatmessage") | ||
ParseJSON.register("workflows_parsejson") | ||
CallEventHandler.register("workflows_calleventhandler") | ||
AddToStateList.register("workflows_addtostatelist") | ||
ReturnValue.register("workflows_returnvalue") | ||
WriterInitChat.register("workflows_writerinitchat") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from typing import TYPE_CHECKING, Any, Dict, Type | ||
|
||
import writer.evaluator | ||
|
||
if TYPE_CHECKING: | ||
from writer.core_ui import Component | ||
from writer.ss_types import InstancePath | ||
from writer.workflows import WorkflowRunner | ||
|
||
WorkflowBlock_T = Type["WorkflowBlock"] | ||
block_map:Dict[str, WorkflowBlock_T] = {} | ||
|
||
class WorkflowBlock: | ||
|
||
@classmethod | ||
def register(cls, type: str): | ||
block_map[type] = cls | ||
|
||
def __init__(self, component: "Component", runner: "WorkflowRunner", execution_environment: Dict): | ||
self.outcome = None | ||
self.component = component | ||
self.runner = runner | ||
self.execution_time_in_seconds = -1.0 | ||
self.execution_environment = execution_environment | ||
self.result = None | ||
self.return_value = None | ||
self.instance_path: InstancePath = [{"componentId": self.component.id, "instanceNumber": 0}] | ||
self.evaluator = writer.evaluator.Evaluator(runner.session.session_state, runner.session.session_component_tree) | ||
|
||
def _get_field(self, field_key: str, as_json=False, default_field_value=None): | ||
if default_field_value is None: | ||
if as_json: | ||
default_field_value = "{}" | ||
else: | ||
default_field_value = "" | ||
value = self.evaluator.evaluate_field(self.instance_path, field_key, as_json, default_field_value, self.execution_environment) | ||
return value | ||
|
||
def _set_state(self, expr: str, value: Any): | ||
self.evaluator.set_state(expr, self.instance_path, value, base_context=self.execution_environment) | ||
|
||
def run(self): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/writer/workflows_blocks/httprequest.py → src/writer/blocks/httprequest.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/writer/workflows_blocks/parsejson.py → src/writer/blocks/parsejson.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
src/writer/workflows_blocks/returnvalue.py → src/writer/blocks/returnvalue.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.