Skip to content

Commit

Permalink
Fix broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
klntsky committed Nov 18, 2024
1 parent 6e3df26 commit f0d5d2b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
7 changes: 4 additions & 3 deletions python/src/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,10 @@ async def _eval_ast(ast):
# short-curcuit the evaluation: if the condition text is literally
# 'true' or 'false', then use it to dispatch into the :if branch.
# That way we can use FFI functions with :if statements
prompt_result = "" if condition not in ["false", "true"] \
else condition
MAX_RETRIES = 3
prompt_result = (
"" if condition not in ["false", "true"] else condition
)
MAX_RETRIES = 3 # TODO: move to config
retries = 0
prompt = IF_PROMPT + condition
while prompt_result != "true" and prompt_result != "false":
Expand Down
26 changes: 23 additions & 3 deletions python/tests/test_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,36 @@
@pytest.mark.asyncio
async def test_parameters():
prompt = "[:foo][:foo]"
await metaprompt(prompt, Config(parameters={"foo": "bar"})) == "barbar"
assert (
await metaprompt(prompt, Config(parameters={"foo": "bar"})) == "barbar"
)


@pytest.mark.asyncio
async def test_assign1():
prompt = "[:foo=bar][:foo][:foo]"
await metaprompt(prompt) == "barbar"
assert await metaprompt(prompt) == "barbar"


@pytest.mark.asyncio
async def test_assign2():
prompt = "[:foo=bar][:foo=[:foo][:foo]][:foo]"
await metaprompt(prompt) == "barbar"
assert await metaprompt(prompt) == "barbar"


@pytest.mark.asyncio
async def test_if_1():
prompt = "[:if false :then foo :else bar]"
assert await metaprompt(prompt) == " bar"


@pytest.mark.asyncio
async def test_if_2():
prompt = "[:if true :then foo :else bar]"
assert await metaprompt(prompt) == " foo "


@pytest.mark.asyncio
async def test_if_3():
prompt = "[:v1=tr][:v2=ue][:if [:v1][:v2] :then foo :else bar]"
assert await metaprompt(prompt) == " foo "

0 comments on commit f0d5d2b

Please sign in to comment.