-
Notifications
You must be signed in to change notification settings - Fork 78
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 #38 from jlowin/deco-tests
Add decorator tests for flow
- Loading branch information
Showing
6 changed files
with
155 additions
and
3,407 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,10 +1,20 @@ | ||
import pytest | ||
from controlflow.settings import temporary_settings | ||
from prefect.testing.utilities import prefect_test_harness | ||
|
||
from .fixtures import * | ||
|
||
|
||
@pytest.fixture(autouse=True, scope="session") | ||
def temp_settings(): | ||
def temp_controlflow_settings(): | ||
with temporary_settings(enable_global_flow=False, max_task_iterations=3): | ||
yield | ||
|
||
|
||
@pytest.fixture(autouse=True, scope="session") | ||
def prefect_test_fixture(): | ||
""" | ||
Run Prefect against temporary sqlite database | ||
""" | ||
with prefect_test_harness(): | ||
yield |
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,54 @@ | ||
import pytest | ||
from controlflow import Task | ||
from controlflow.decorators import flow | ||
|
||
|
||
@pytest.mark.usefixtures("mock_controller") | ||
class TestFlowDecorator: | ||
def test_flow_decorator(self): | ||
@flow | ||
def test_flow(): | ||
return 1 | ||
|
||
result = test_flow() | ||
assert result == 1 | ||
|
||
def test_flow_decorator_runs_all_tasks(self): | ||
tasks: list[Task] = [] | ||
|
||
@flow | ||
def test_flow(): | ||
task = Task( | ||
"say hello", | ||
result_type=str, | ||
result="Task completed successfully", | ||
) | ||
tasks.append(task) | ||
|
||
result = test_flow() | ||
assert result is None | ||
assert tasks[0].is_successful() | ||
assert tasks[0].result == "Task completed successfully" | ||
|
||
def test_flow_decorator_resolves_all_tasks(self): | ||
@flow | ||
def test_flow(): | ||
task1 = Task("say hello", result="hello") | ||
task2 = Task("say goodbye", result="goodbye") | ||
task3 = Task("say goodnight", result="goodnight") | ||
return dict(a=task1, b=[task2], c=dict(x=dict(y=[[task3]]))) | ||
|
||
result = test_flow() | ||
assert result == dict( | ||
a="hello", b=["goodbye"], c=dict(x=dict(y=[["goodnight"]])) | ||
) | ||
|
||
def test_manually_run_task_in_flow(self): | ||
@flow | ||
def test_flow(): | ||
task = Task("say hello", result="hello") | ||
task.run() | ||
return task.result | ||
|
||
result = test_flow() | ||
assert result == "hello" |