Spaces:
Sleeping
Sleeping
Download test_json_extractor.py from baljot07/studiq-backend: direct link, hf CLI and curl.
- Browser
- Download file 1.13 kB
-
https://huggingface.co/spaces/baljot07/studiq-backend/resolve/main/test_json_extractor.py
- Command line
-
hf download hf://spaces/baljot07/studiq-backend/test_json_extractor.py
-
curl -L -o test_json_extractor.py https://huggingface.co/spaces/baljot07/studiq-backend/resolve/main/test_json_extractor.py
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() | |