diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5e193d5..c372362 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,5 +38,7 @@ jobs: run: hatch run types:check - name: Run tests + coverage run: hatch run test:cov + - name: Run example tests + run: hatch run test:examples - name: Build distribution run: hatch build diff --git a/examples/src/__init__.py b/examples/src/__init__.py new file mode 100644 index 0000000..3f5aece --- /dev/null +++ b/examples/src/__init__.py @@ -0,0 +1,3 @@ +"""AWS Durable Functions Python Examples.""" + +__version__ = "0.1.0" diff --git a/examples/src/hello_world.py b/examples/src/hello_world.py new file mode 100644 index 0000000..9a9c016 --- /dev/null +++ b/examples/src/hello_world.py @@ -0,0 +1,10 @@ +from typing import Any + +from aws_durable_execution_sdk_python.context import DurableContext +from aws_durable_execution_sdk_python.execution import durable_handler + + +@durable_handler +def handler(_event: Any, _context: DurableContext) -> str: + """Simple hello world durable function.""" + return "Hello World!" diff --git a/examples/test/__init__.py b/examples/test/__init__.py new file mode 100644 index 0000000..46dbb82 --- /dev/null +++ b/examples/test/__init__.py @@ -0,0 +1 @@ +"""Integration tests for AWS Durable Functions Python Examples.""" diff --git a/examples/test/test_hello_world.py b/examples/test/test_hello_world.py new file mode 100644 index 0000000..bbc869e --- /dev/null +++ b/examples/test/test_hello_world.py @@ -0,0 +1,21 @@ +"""Integration tests for example durable functions.""" + +from aws_durable_execution_sdk_python.execution import InvocationStatus + +from aws_durable_execution_sdk_python_testing.runner import ( + DurableFunctionTestResult, + DurableFunctionTestRunner, +) +from src import hello_world + + +class TestExamples: + """Integration tests for examples.""" + + def test_hello_world(self): + """Test hello world example.""" + with DurableFunctionTestRunner(handler=hello_world.handler) as runner: + result: DurableFunctionTestResult = runner.run(input="test", timeout=10) + + assert result.status is InvocationStatus.SUCCEEDED # noqa: S101 + assert result.result == '"Hello World!"' # noqa: S101 diff --git a/pyproject.toml b/pyproject.toml index fd5f1c6..d2e75b1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -53,9 +53,12 @@ dependencies = [ "coverage[toml]", "pytest", "pytest-cov", + "aws_durable_execution_sdk_python @ git+ssh://git@github.com/aws/aws-durable-execution-sdk-python.git" ] [tool.hatch.envs.test.scripts] +test = "pytest tests/ -v" +examples = "pytest examples/test/ -v" cov="pytest --cov-report=term-missing --cov-config=pyproject.toml --cov=src/aws_durable_execution_sdk_python_testing --cov=tests --cov-fail-under=99" [tool.hatch.envs.types]