@@ -117,6 +117,7 @@ def test_create_schema_model_valid_data(
117117 )
118118 assert schema_instance .entities ["AGE" ]["description" ] == "Age of a person in years."
119119
120+ assert schema_instance .relations
120121 assert (
121122 schema_instance .relations ["EMPLOYED_BY" ]["description" ]
122123 == "Indicates employment relationship."
@@ -134,6 +135,7 @@ def test_create_schema_model_valid_data(
134135 {"description" : "" , "name" : "end_time" , "type" : "LOCAL_DATETIME" },
135136 ]
136137
138+ assert schema_instance .potential_schema
137139 assert schema_instance .potential_schema == potential_schema
138140
139141
@@ -159,6 +161,7 @@ def test_create_schema_model_missing_description(
159161
160162 assert schema_instance .entities ["ORGANIZATION" ]["description" ] == ""
161163 assert schema_instance .entities ["AGE" ]["description" ] == ""
164+ assert schema_instance .relations
162165 assert schema_instance .relations ["ORGANIZED_BY" ]["description" ] == ""
163166 assert schema_instance .relations ["ATTENDED_BY" ]["description" ] == ""
164167
@@ -242,6 +245,7 @@ async def test_run_method(
242245 )
243246 assert schema .entities ["AGE" ]["description" ] == "Age of a person in years."
244247
248+ assert schema .relations
245249 assert (
246250 schema .relations ["EMPLOYED_BY" ]["description" ]
247251 == "Indicates employment relationship."
@@ -255,6 +259,7 @@ async def test_run_method(
255259 == "Indicates attendance at an event."
256260 )
257261
262+ assert schema .potential_schema
258263 assert schema .potential_schema == potential_schema
259264
260265
@@ -327,6 +332,7 @@ def test_create_schema_model_missing_properties(
327332 schema_instance .entities ["AGE" ]["properties" ] == []
328333 ), "Expected empty properties for AGE"
329334
335+ assert schema_instance .relations
330336 assert (
331337 schema_instance .relations ["EMPLOYED_BY" ]["properties" ] == []
332338 ), "Expected empty properties for EMPLOYED_BY"
@@ -336,3 +342,80 @@ def test_create_schema_model_missing_properties(
336342 assert (
337343 schema_instance .relations ["ATTENDED_BY" ]["properties" ] == []
338344 ), "Expected empty properties for ATTENDED_BY"
345+
346+
347+ def test_create_schema_model_no_potential_schema (
348+ schema_builder : SchemaBuilder ,
349+ valid_entities : list [SchemaEntity ],
350+ valid_relations : list [SchemaRelation ],
351+ ) -> None :
352+ schema_instance = schema_builder .create_schema_model (
353+ valid_entities , valid_relations
354+ )
355+
356+ assert (
357+ schema_instance .entities ["PERSON" ]["description" ]
358+ == "An individual human being."
359+ )
360+ assert schema_instance .entities ["PERSON" ]["properties" ] == [
361+ {"description" : "" , "name" : "birth date" , "type" : "ZONED_DATETIME" },
362+ {"description" : "" , "name" : "name" , "type" : "STRING" },
363+ ]
364+ assert (
365+ schema_instance .entities ["ORGANIZATION" ]["description" ]
366+ == "A structured group of people with a common purpose."
367+ )
368+ assert schema_instance .entities ["AGE" ]["description" ] == "Age of a person in years."
369+
370+ assert schema_instance .relations
371+ assert (
372+ schema_instance .relations ["EMPLOYED_BY" ]["description" ]
373+ == "Indicates employment relationship."
374+ )
375+ assert (
376+ schema_instance .relations ["ORGANIZED_BY" ]["description" ]
377+ == "Indicates organization responsible for an event."
378+ )
379+ assert (
380+ schema_instance .relations ["ATTENDED_BY" ]["description" ]
381+ == "Indicates attendance at an event."
382+ )
383+ assert schema_instance .relations ["EMPLOYED_BY" ]["properties" ] == [
384+ {"description" : "" , "name" : "start_time" , "type" : "LOCAL_DATETIME" },
385+ {"description" : "" , "name" : "end_time" , "type" : "LOCAL_DATETIME" },
386+ ]
387+
388+
389+ def test_create_schema_model_no_relations_or_potential_schema (
390+ schema_builder : SchemaBuilder ,
391+ valid_entities : list [SchemaEntity ],
392+ ) -> None :
393+ schema_instance = schema_builder .create_schema_model (valid_entities )
394+
395+ assert (
396+ schema_instance .entities ["PERSON" ]["description" ]
397+ == "An individual human being."
398+ )
399+ assert schema_instance .entities ["PERSON" ]["properties" ] == [
400+ {"description" : "" , "name" : "birth date" , "type" : "ZONED_DATETIME" },
401+ {"description" : "" , "name" : "name" , "type" : "STRING" },
402+ ]
403+ assert (
404+ schema_instance .entities ["ORGANIZATION" ]["description" ]
405+ == "A structured group of people with a common purpose."
406+ )
407+ assert schema_instance .entities ["AGE" ]["description" ] == "Age of a person in years."
408+
409+
410+ def test_create_schema_model_missing_relations (
411+ schema_builder : SchemaBuilder ,
412+ valid_entities : list [SchemaEntity ],
413+ potential_schema : list [tuple [str , str , str ]],
414+ ) -> None :
415+ with pytest .raises (SchemaValidationError ) as exc_info :
416+ schema_builder .create_schema_model (
417+ entities = valid_entities , potential_schema = potential_schema
418+ )
419+ assert "Relations must also be provided when using a potential schema." in str (
420+ exc_info .value
421+ ), "Should fail due to missing relations"
0 commit comments