Skip to content

Commit 917ef56

Browse files
committed
test: add more tests for transform flow
1 parent 97ea7a9 commit 917ef56

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

python/cocoindex/tests/test_transform_flow.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,25 @@ def __call__(self, text: str) -> str:
166166
return f"{text}{self.spec.suffix}"
167167

168168

169+
class GpuAppendSuffixWithAnalyzePrepare(cocoindex.op.FunctionSpec):
170+
suffix: str
171+
172+
173+
@cocoindex.op.executor_class(gpu=True)
174+
class GpuAppendSuffixWithAnalyzePrepareExecutor:
175+
spec: GpuAppendSuffixWithAnalyzePrepare
176+
suffix: str
177+
178+
def analyze(self) -> Any:
179+
return str
180+
181+
def prepare(self) -> None:
182+
self.suffix = self.spec.suffix
183+
184+
def __call__(self, text: str) -> str:
185+
return f"{text}{self.suffix}"
186+
187+
169188
def test_gpu_function() -> None:
170189
@cocoindex.transform_flow()
171190
def transform_flow(text: cocoindex.DataSlice[str]) -> cocoindex.DataSlice[str]:
@@ -174,3 +193,15 @@ def transform_flow(text: cocoindex.DataSlice[str]) -> cocoindex.DataSlice[str]:
174193
result = transform_flow.eval("Hello")
175194
expected = "Hello world!"
176195
assert result == expected, f"Expected {expected}, got {result}"
196+
197+
@cocoindex.transform_flow()
198+
def transform_flow_with_analyze_prepare(
199+
text: cocoindex.DataSlice[str],
200+
) -> cocoindex.DataSlice[str]:
201+
return text.transform(gpu_append_world).transform(
202+
GpuAppendSuffixWithAnalyzePrepare(suffix="!!")
203+
)
204+
205+
result = transform_flow_with_analyze_prepare.eval("Hello")
206+
expected = "Hello world!!"
207+
assert result == expected, f"Expected {expected}, got {result}"

0 commit comments

Comments
 (0)