Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion python/dotpromptz/tests/dotpromptz/dotprompt_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@
import pytest

from dotpromptz.dotprompt import Dotprompt, _identify_partials
from dotpromptz.typing import ModelConfigT, ParsedPrompt, PromptMetadata, ToolDefinition
from dotpromptz.typing import (ModelConfigT, ParsedPrompt, PromptMetadata,
ToolDefinition, PromptInputConfig, DataArgument)
from handlebarrz import HelperFn



@pytest.fixture
def mock_handlebars() -> Generator[Mock, None, None]:
"""Create a mock Handlebars instance."""
Expand Down Expand Up @@ -143,6 +145,25 @@ def test_define_tool(mock_handlebars: Mock) -> None:
# Ensure chaining works.
assert result == dotprompt

class TestCompileRender(IsolatedAsyncioTestCase):
async def test_compile_render_mock(self) -> str:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test should be in YAML instead so that we can compare behavior against the Go and JS implementations.

"""should compile a template string into a render function."""
dotprompt = Dotprompt()
template_source = 'hello {{name}} ({{@state.name}}, {{@auth.email}})'

render_fn = dotprompt._handlebars.compile(template_source)

result = render_fn(
data=DataArgument[dict[str, Any]](
input={'name': 'foo'},
context={'auth': {'email': '[email protected]'}},
),
options=PromptMetadata(input=PromptInputConfig()),)

assert result == "hello foo (bar, [email protected])" # No input provided, so name is empty string.




@patch('dotpromptz.dotprompt.parse_document')
def test_parse(mock_parse_document: Mock, mock_handlebars: Mock) -> None:
Expand Down