Spaces:
Paused
Paused
Create test_app.py
Browse files- test_app.py +43 -0
test_app.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pytest
|
| 2 |
+
from app import is_this_prompt_a_list, respond
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
def test_is_this_prompt_a_list_with_list_request():
|
| 6 |
+
"""Test that 'tell me ten css class names' is correctly identified as a list"""
|
| 7 |
+
result = is_this_prompt_a_list("tell me ten css class names")
|
| 8 |
+
assert result == True, "Expected 'tell me ten css class names' to be identified as a list"
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def test_is_this_prompt_a_list_with_story_request():
|
| 12 |
+
"""Test that 'tell me a tall tale' is correctly identified as NOT a list"""
|
| 13 |
+
result = is_this_prompt_a_list("tell me a tall tale")
|
| 14 |
+
assert result == False, "Expected 'tell me a tall tale' to be identified as a story (not a list)"
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def test_respond_generates_acrostic_with_dash():
|
| 18 |
+
"""Test that respond generates output starting with '- G' for acrostic 'good dog'"""
|
| 19 |
+
# Get the generator and consume it to get the final response
|
| 20 |
+
response_gen = respond(
|
| 21 |
+
"give me seven great names for a dog",
|
| 22 |
+
[],
|
| 23 |
+
"You are a friendly Chatbot.",
|
| 24 |
+
"good dog",
|
| 25 |
+
512,
|
| 26 |
+
0.2,
|
| 27 |
+
0.95
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
# Get the final response by consuming the generator
|
| 31 |
+
final_response = None
|
| 32 |
+
for response in response_gen:
|
| 33 |
+
final_response = response
|
| 34 |
+
|
| 35 |
+
# Check that we got some output
|
| 36 |
+
assert final_response is not None, "Expected some response output"
|
| 37 |
+
assert len(final_response) > 0, "Expected non-empty response"
|
| 38 |
+
|
| 39 |
+
# Check that the last non-empty line starts with "* G" (acrostic format with dash)
|
| 40 |
+
lines = [line for line in final_response.split("\n") if line.strip()]
|
| 41 |
+
assert len(lines) > 0, "Expected at least one non-empty line"
|
| 42 |
+
last_line = lines[-1]
|
| 43 |
+
assert last_line[0:3] == "* G", f"Expected last line to start with '- G', but got: '{last_line[0:3]}'"
|