File tree Expand file tree Collapse file tree 5 files changed +31
-9
lines changed Expand file tree Collapse file tree 5 files changed +31
-9
lines changed Original file line number Diff line number Diff line change @@ -31,13 +31,17 @@ def check_readonly(self):
31
31
@model_validator (mode = "after" )
32
32
def validate_source_fields (self ):
33
33
if self .source is None and self .source_ontology_name is None :
34
- raise ValueError ("Either source or source_ontology_name must be provided" )
34
+ raise ValueError (
35
+ "Either source or source_ontology_name must be provided"
36
+ )
35
37
return self
36
38
37
39
@model_validator (mode = "after" )
38
40
def validate_source_consistency (self ):
39
41
if self .source is not None and self .source_ontology_name is not None :
40
- raise ValueError ("Only one of 'source' or 'source_ontology_name' may be provided" )
42
+ raise ValueError (
43
+ "Only one of 'source' or 'source_ontology_name' may be provided"
44
+ )
41
45
return self
42
46
43
47
Original file line number Diff line number Diff line change @@ -230,7 +230,10 @@ def _create_relationship_annotations(
230
230
f"Unable to create relationship with invalid source. For PDF targets, "
231
231
f"source must be ObjectAnnotation or ClassificationAnnotation. Got: { type (source )} "
232
232
)
233
- if source is None and annotation .value .source_ontology_name is None :
233
+ if (
234
+ source is None
235
+ and annotation .value .source_ontology_name is None
236
+ ):
234
237
raise ValueError (
235
238
"Unable to create relationship - either source or source_ontology_name must be provided"
236
239
)
Original file line number Diff line number Diff line change @@ -53,7 +53,9 @@ def from_common(
53
53
name = annotation .name ,
54
54
dataRow = DataRow (id = data .uid , global_key = data .global_key ),
55
55
relationship = _Relationship (
56
- source = str (relationship .source ._uuid ) if relationship .source else None ,
56
+ source = str (relationship .source ._uuid )
57
+ if relationship .source
58
+ else None ,
57
59
target = str (relationship .target ._uuid ),
58
60
sourceOntologyName = relationship .source_ontology_name ,
59
61
type = relationship .type .value ,
Original file line number Diff line number Diff line change @@ -437,7 +437,10 @@ def test_relationship_missing_source_validation():
437
437
value = TextEntity (start = 30 , end = 35 ),
438
438
)
439
439
440
- with pytest .raises (ValueError , match = "Either source or source_ontology_name must be provided" ):
440
+ with pytest .raises (
441
+ ValueError ,
442
+ match = "Either source or source_ontology_name must be provided" ,
443
+ ):
441
444
RelationshipAnnotation (
442
445
name = "rel" ,
443
446
value = Relationship (
@@ -458,7 +461,10 @@ def test_relationship_both_sources_validation():
458
461
value = TextEntity (start = 30 , end = 35 ),
459
462
)
460
463
461
- with pytest .raises (ValueError , match = "Only one of 'source' or 'source_ontology_name' may be provided" ):
464
+ with pytest .raises (
465
+ ValueError ,
466
+ match = "Only one of 'source' or 'source_ontology_name' may be provided" ,
467
+ ):
462
468
RelationshipAnnotation (
463
469
name = "rel" ,
464
470
value = Relationship (
Original file line number Diff line number Diff line change @@ -383,7 +383,8 @@ def test_source_ontology_name_relationship():
383
383
384
384
# Verify relationship with source_ontology_name
385
385
assert (
386
- ontology_rel_serialized ["relationship" ]["sourceOntologyName" ] == "Person"
386
+ ontology_rel_serialized ["relationship" ]["sourceOntologyName" ]
387
+ == "Person"
387
388
)
388
389
assert (
389
390
ontology_rel_serialized ["relationship" ]["target" ]
@@ -404,7 +405,10 @@ def test_source_ontology_name_relationship():
404
405
)
405
406
assert False , "Expected ValueError for providing both source and source_ontology_name"
406
407
except Exception as e :
407
- assert "Value error, Only one of 'source' or 'source_ontology_name' may be provided" in str (e )
408
+ assert (
409
+ "Value error, Only one of 'source' or 'source_ontology_name' may be provided"
410
+ in str (e )
411
+ )
408
412
409
413
# Test that providing neither source nor source_ontology_name raises an error
410
414
try :
@@ -417,4 +421,7 @@ def test_source_ontology_name_relationship():
417
421
)
418
422
assert False , "Expected ValueError for providing neither source nor source_ontology_name"
419
423
except Exception as e :
420
- assert "Value error, Either source or source_ontology_name must be provided" in str (e )
424
+ assert (
425
+ "Value error, Either source or source_ontology_name must be provided"
426
+ in str (e )
427
+ )
You can’t perform that action at this time.
0 commit comments