Spaces:
Running
Running
Test for input ordering.
Browse files
lynxkite-graph-analytics/tests/test_lynxkite_ops.py
CHANGED
|
@@ -92,5 +92,73 @@ async def test_execute_operation_inputs_correct_cast():
|
|
| 92 |
assert all([node.data.error is None for node in ws.nodes])
|
| 93 |
|
| 94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
if __name__ == "__main__":
|
| 96 |
pytest.main()
|
|
|
|
| 92 |
assert all([node.data.error is None for node in ws.nodes])
|
| 93 |
|
| 94 |
|
| 95 |
+
async def test_multiple_inputs():
|
| 96 |
+
"""Make sure each input goes to the right argument."""
|
| 97 |
+
op = ops.op_registration("test")
|
| 98 |
+
|
| 99 |
+
@op("One")
|
| 100 |
+
def one():
|
| 101 |
+
return 1
|
| 102 |
+
|
| 103 |
+
@op("Two")
|
| 104 |
+
def two():
|
| 105 |
+
return 2
|
| 106 |
+
|
| 107 |
+
@op("Smaller?", view="visualization")
|
| 108 |
+
def is_smaller(a, b):
|
| 109 |
+
return a < b
|
| 110 |
+
|
| 111 |
+
ws = workspace.Workspace(env="test")
|
| 112 |
+
ws.nodes.append(
|
| 113 |
+
workspace.WorkspaceNode(
|
| 114 |
+
id="one",
|
| 115 |
+
type="cool",
|
| 116 |
+
data=workspace.WorkspaceNodeData(title="One", params={}),
|
| 117 |
+
position=workspace.Position(x=0, y=0),
|
| 118 |
+
)
|
| 119 |
+
)
|
| 120 |
+
ws.nodes.append(
|
| 121 |
+
workspace.WorkspaceNode(
|
| 122 |
+
id="two",
|
| 123 |
+
type="cool",
|
| 124 |
+
data=workspace.WorkspaceNodeData(title="Two", params={}),
|
| 125 |
+
position=workspace.Position(x=100, y=0),
|
| 126 |
+
)
|
| 127 |
+
)
|
| 128 |
+
ws.nodes.append(
|
| 129 |
+
workspace.WorkspaceNode(
|
| 130 |
+
id="smaller",
|
| 131 |
+
type="cool",
|
| 132 |
+
data=workspace.WorkspaceNodeData(title="Smaller?", params={}),
|
| 133 |
+
position=workspace.Position(x=200, y=0),
|
| 134 |
+
)
|
| 135 |
+
)
|
| 136 |
+
ws.edges = [
|
| 137 |
+
workspace.WorkspaceEdge(
|
| 138 |
+
id="one",
|
| 139 |
+
source="one",
|
| 140 |
+
target="smaller",
|
| 141 |
+
sourceHandle="output",
|
| 142 |
+
targetHandle="a",
|
| 143 |
+
),
|
| 144 |
+
workspace.WorkspaceEdge(
|
| 145 |
+
id="two",
|
| 146 |
+
source="two",
|
| 147 |
+
target="smaller",
|
| 148 |
+
sourceHandle="output",
|
| 149 |
+
targetHandle="b",
|
| 150 |
+
),
|
| 151 |
+
]
|
| 152 |
+
|
| 153 |
+
await execute(ws)
|
| 154 |
+
|
| 155 |
+
assert ws.nodes[-1].data.display is True
|
| 156 |
+
# Flip the inputs.
|
| 157 |
+
ws.edges[0].targetHandle = "b"
|
| 158 |
+
ws.edges[1].targetHandle = "a"
|
| 159 |
+
await execute(ws)
|
| 160 |
+
assert ws.nodes[-1].data.display is False
|
| 161 |
+
|
| 162 |
+
|
| 163 |
if __name__ == "__main__":
|
| 164 |
pytest.main()
|