Skip to content

Commit

Permalink
Merge pull request #358 from tcmitchell/357-no-identity
Browse files Browse the repository at this point in the history
Add check for uninitialized identity
  • Loading branch information
tcmitchell authored Nov 30, 2021
2 parents 4115159 + 5368441 commit 0b87e64
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions sbol3/refobj_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ def to_user(self, value: Any) -> str:
@staticmethod
def from_user(value: Any) -> rdflib.URIRef:
if isinstance(value, SBOLObject):
# see https://github.com/SynBioDex/pySBOL3/issues/357
if value.identity is None:
# The SBOLObject has an uninitialized identity
msg = f'Cannot set reference to {value}.'
msg += ' Object identity is uninitialized.'
raise ValueError(msg)
value = value.identity
if not isinstance(value, str):
raise TypeError(f'Expecting string, got {type(value)}')
Expand Down
9 changes: 9 additions & 0 deletions test/test_referenced_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,15 @@ def test_adding_referenced_objects(self):
# to get back to the original instance via document lookup
self.assertEqual(execution.identity, foo.members[0].lookup().identity)

def test_no_identity_exception(self):
# See https://github.com/SynBioDex/pySBOL3/issues/357
sbol3.set_namespace('https://github.com/SynBioDex/pySBOL3')
collection = sbol3.Collection('foo_collection')
subc = sbol3.SubComponent(instance_of='https://github.com/SynBioDex/pySBOL3/c1')
exc_regex = r'Object identity is uninitialized\.$'
with self.assertRaisesRegex(ValueError, exc_regex):
collection.members.append(subc)


if __name__ == '__main__':
unittest.main()

0 comments on commit 0b87e64

Please sign in to comment.