Skip to content

Commit

Permalink
Update test to assert Jinja2 {% include ... %} works as expected
Browse files Browse the repository at this point in the history
  • Loading branch information
yvan-sraka committed Jan 2, 2025
1 parent df0eb2c commit f11f10c
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions tests/test_prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,10 @@ def args_prompt(fn):


@pytest.fixture
def temp_prompt_file():
def temp_prompt_files():
# Create a temporary directory
with tempfile.TemporaryDirectory() as test_dir:
# Create a temporary prompt file
# Create the first temporary prompt file
prompt_file_path = os.path.join(test_dir, "prompt.txt")
with open(prompt_file_path, "w") as f:
f.write(
Expand All @@ -331,18 +331,27 @@ def temp_prompt_file():
- A: {{ example.answer }}
{% endfor %}
Now please answer the following question:
{% include 'additional.txt' %}
"""
)

# Create the second temporary prompt file to be included
additional_file_path = os.path.join(test_dir, "additional.txt")
with open(additional_file_path, "w") as f:
f.write(
"""Now please answer the following question:
Q: {{ question }}
A:
"""
)

yield prompt_file_path


def test_prompt_from_file(temp_prompt_file):
def test_prompt_from_file(temp_prompt_files):
# Create a Prompt instance from the file
template = Prompt.from_file(temp_prompt_file)
template = Prompt.from_file(temp_prompt_files)

# Define example data
examples = [
Expand Down

0 comments on commit f11f10c

Please sign in to comment.