DP_PRACA/test_graph_builder.py
2026-12-04 09:22:31 +01:00

35 lines
1017 B
Python

import unittest
from graph_builder import _json_response
class JsonResponseTests(unittest.TestCase):
def test_parses_object_with_trailing_text(self):
text = '{"entities":[{"name":"Python","type":"language"}],"relations":[]}\nExtra text'
result = _json_response(text)
self.assertEqual(result["entities"][0]["name"], "Python")
def test_parses_object_from_markdown_fence(self):
text = '```json\n{"entities":[],"relations":[]}\n```'
result = _json_response(text)
self.assertEqual(result, {"entities": [], "relations": []})
def test_selects_object_with_graph_schema(self):
text = 'Status {"status":"ok"}\nResult: {"entities":[],"relations":[]}'
result = _json_response(text)
self.assertEqual(result, {"entities": [], "relations": []})
def test_rejects_response_without_schema(self):
with self.assertRaises(ValueError):
_json_response('{"status":"ok"}')
if __name__ == "__main__":
unittest.main()