render-lab-test-utils 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,11 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.py[cod]
4
+ .pytest_cache/
5
+ .mypy_cache/
6
+ .ruff_cache/
7
+ dist/
8
+ *.egg-info/
9
+ .env
10
+ .env.*
11
+ !.env.example
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Render Lab
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,34 @@
1
+ Metadata-Version: 2.5
2
+ Name: render-lab-test-utils
3
+ Version: 0.1.0
4
+ Summary: Registration-free test contexts for Render tasks
5
+ License-Expression: MIT
6
+ License-File: LICENSE
7
+ Requires-Python: >=3.12
8
+ Requires-Dist: render==1.0.1
9
+ Description-Content-Type: text/markdown
10
+
11
+ # render-lab-test-utils
12
+
13
+ Registration-free test contexts for `render==1.0.1`. No credentials or network.
14
+
15
+ ```python
16
+ from render_lab_test_utils import fake_ctx, local_ctx
17
+
18
+ ctx = fake_ctx() # Any unexpected ctx.run fails loudly.
19
+ # await some_impl(ctx, input, deps=fakes)
20
+
21
+ ctx = local_ctx() # Execute task.func(ctx, ...) recursively in this process.
22
+ # await ctx.run(composed_task, input)
23
+ ```
24
+
25
+ `fake_ctx(override)` accepts a context stub implementing async `run`. This replaces
26
+ TypeScript's partial-object override with Python's structural TaskContext protocol.
27
+ `local_ctx` supports synchronous and asynchronous task bodies and keyword inputs.
28
+ It checks wiring and results; it does not prove durable dispatch, retries, or timeouts.
29
+
30
+ ## Installation
31
+
32
+ ```sh
33
+ pip install render-lab-test-utils==0.1.0
34
+ ```
@@ -0,0 +1,24 @@
1
+ # render-lab-test-utils
2
+
3
+ Registration-free test contexts for `render==1.0.1`. No credentials or network.
4
+
5
+ ```python
6
+ from render_lab_test_utils import fake_ctx, local_ctx
7
+
8
+ ctx = fake_ctx() # Any unexpected ctx.run fails loudly.
9
+ # await some_impl(ctx, input, deps=fakes)
10
+
11
+ ctx = local_ctx() # Execute task.func(ctx, ...) recursively in this process.
12
+ # await ctx.run(composed_task, input)
13
+ ```
14
+
15
+ `fake_ctx(override)` accepts a context stub implementing async `run`. This replaces
16
+ TypeScript's partial-object override with Python's structural TaskContext protocol.
17
+ `local_ctx` supports synchronous and asynchronous task bodies and keyword inputs.
18
+ It checks wiring and results; it does not prove durable dispatch, retries, or timeouts.
19
+
20
+ ## Installation
21
+
22
+ ```sh
23
+ pip install render-lab-test-utils==0.1.0
24
+ ```
@@ -0,0 +1,16 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.27,<2"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "render-lab-test-utils"
7
+ version = "0.1.0"
8
+ description = "Registration-free test contexts for Render tasks"
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ license-files = ["LICENSE"]
12
+ requires-python = ">=3.12"
13
+ dependencies = ["render==1.0.1"]
14
+
15
+ [tool.hatch.build.targets.wheel]
16
+ packages = ["src/render_lab_test_utils"]
@@ -0,0 +1,42 @@
1
+ """Registration-free contexts for unit and composition tests."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import inspect
6
+ from typing import TYPE_CHECKING, cast
7
+
8
+ if TYPE_CHECKING:
9
+ from render import TaskContext
10
+ from render.workflows.task import TaskDefinition
11
+
12
+
13
+ class LocalContext:
14
+ """Execute raw task functions recursively, without durability or retries."""
15
+
16
+ async def run[**P, R](self, task: TaskDefinition[P, R], *args: P.args, **kwargs: P.kwargs) -> R:
17
+ if not callable(getattr(task, "func", None)):
18
+ raise TypeError(f"local_ctx: {getattr(task, 'name', task)} is not a task definition")
19
+ result = task.func(self, *args, **kwargs)
20
+ if inspect.isawaitable(result):
21
+ return cast(R, await result)
22
+ return result
23
+
24
+
25
+ class FakeContext:
26
+ """Fail any unstubbed chained dispatch."""
27
+
28
+ async def run[**P, R](self, task: TaskDefinition[P, R], *args: P.args, **kwargs: P.kwargs) -> R:
29
+ raise RuntimeError(
30
+ f'unexpected ctx.run("{getattr(task, "name", "unknown")}") '
31
+ "- stub it via fake_ctx(override)"
32
+ )
33
+
34
+
35
+ def fake_ctx(override: TaskContext | None = None) -> TaskContext:
36
+ """Return a failing context, or an explicit context stub implementing run."""
37
+ return override if override is not None else FakeContext()
38
+
39
+
40
+ def local_ctx() -> TaskContext:
41
+ """Return a context that runs chained task bodies in the current process."""
42
+ return LocalContext()
@@ -0,0 +1,33 @@
1
+ from types import SimpleNamespace
2
+
3
+ import pytest
4
+ from render import Workflows
5
+ from render_lab_test_utils import fake_ctx, local_ctx
6
+
7
+
8
+ async def test_unexpected_dispatch_and_override():
9
+ with pytest.raises(RuntimeError, match=r'unexpected ctx.run\("demo.leaf"\)'):
10
+ await fake_ctx().run(SimpleNamespace(name="demo.leaf"))
11
+ override = local_ctx()
12
+ assert fake_ctx(override) is override
13
+
14
+
15
+ async def test_recursive_sync_and_async_bodies_receive_same_context():
16
+ app = Workflows()
17
+ seen = []
18
+
19
+ @app.task(name="testutils.leaf")
20
+ def leaf(ctx, value):
21
+ seen.append(ctx)
22
+ return value + 1
23
+
24
+ @app.task(name="testutils.parent")
25
+ async def parent(ctx, value):
26
+ seen.append(ctx)
27
+ return await ctx.run(leaf, value=value)
28
+
29
+ ctx = local_ctx()
30
+ assert await ctx.run(parent, 3) == 4
31
+ assert seen == [ctx, ctx]
32
+ with pytest.raises(TypeError, match="not a task definition"):
33
+ await ctx.run(SimpleNamespace(name="bad"))