@@ -337,3 +337,72 @@ def test_classification_relationship_restrictions():
337
337
data = {"global_key" : "test_key" }, annotations = [relationship ]
338
338
)
339
339
list (NDJsonConverter .serialize ([label ]))
340
+
341
+
342
+ def test_relationship_readonly_default_none ():
343
+ """Test that relationship readonly field defaults to None when not specified."""
344
+ source = ObjectAnnotation (
345
+ name = "e1" ,
346
+ value = TextEntity (start = 10 , end = 12 ),
347
+ )
348
+ target = ObjectAnnotation (
349
+ name = "e2" ,
350
+ value = TextEntity (start = 30 , end = 35 ),
351
+ )
352
+
353
+ relationship = RelationshipAnnotation (
354
+ name = "rel" ,
355
+ value = Relationship (
356
+ source = source ,
357
+ target = target ,
358
+ type = Relationship .Type .UNIDIRECTIONAL ,
359
+ ),
360
+ )
361
+ assert relationship .value .readonly is None
362
+
363
+
364
+ def test_relationship_readonly_explicit_false ():
365
+ """Test that relationship readonly field can be explicitly set to False."""
366
+ source = ObjectAnnotation (
367
+ name = "e1" ,
368
+ value = TextEntity (start = 10 , end = 12 ),
369
+ )
370
+ target = ObjectAnnotation (
371
+ name = "e2" ,
372
+ value = TextEntity (start = 30 , end = 35 ),
373
+ )
374
+
375
+ relationship = RelationshipAnnotation (
376
+ name = "rel" ,
377
+ value = Relationship (
378
+ source = source ,
379
+ target = target ,
380
+ type = Relationship .Type .UNIDIRECTIONAL ,
381
+ readonly = False ,
382
+ ),
383
+ )
384
+ assert relationship .value .readonly is False
385
+
386
+
387
+ def test_relationship_readonly_explicit_true ():
388
+ """Test that setting relationship readonly=True triggers a warning."""
389
+ source = ObjectAnnotation (
390
+ name = "e1" ,
391
+ value = TextEntity (start = 10 , end = 12 ),
392
+ )
393
+ target = ObjectAnnotation (
394
+ name = "e2" ,
395
+ value = TextEntity (start = 30 , end = 35 ),
396
+ )
397
+
398
+ with pytest .warns (UserWarning , match = "Creating a relationship with readonly=True is in beta.*" ):
399
+ relationship = RelationshipAnnotation (
400
+ name = "rel" ,
401
+ value = Relationship (
402
+ source = source ,
403
+ target = target ,
404
+ type = Relationship .Type .UNIDIRECTIONAL ,
405
+ readonly = True ,
406
+ ),
407
+ )
408
+ assert relationship .value .readonly is True
0 commit comments