Spaces:
Sleeping

studiq-backend / test_json_extractor.py
StudIQ Deploy Bot
Deploy from GitHub bd6593ee823738a18ac58cff1ff96835532a69af
4518498
Raw History Blame Contribute Delete
1.13 kB
from app.services.syllabus_service import extract_json_from_response
def run_tests():
test_cases = [
# 1. Clean JSON
'{"course": "BCA", "semester": 1}',
# 2. Markdown block
'```json\n{"course": "BCA", "semester": 1}\n```',
# 3. Markdown block with raw backticks
'```\n{"course": "BCA", "semester": 1}\n```',
# 4. Leading and trailing conversational text
'Here is the requested syllabus:\n\n```json\n{"course": "BCA", "semester": 1}\n```\nLet me know if you need anything else!',
# 5. Nested objects with extra text
'Sure, the JSON is {\n "course": "BCA",\n "semester": 1,\n "topic_tree": []\n} - hope this helps!',
# 6. JSON Array
'```json\n[{"course": "BCA", "semester": 1}]\n```'
]
for idx, case in enumerate(test_cases, 1):
try:
res = extract_json_from_response(case)
print(f"Test Case {idx}: SUCCESS -> {res}")
except Exception as e:
print(f"Test Case {idx}: FAILED -> {e}")
if __name__ == "__main__":
run_tests()