Skip to content

Commit

Permalink
Fix style errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryan Bartley committed Oct 15, 2023
1 parent 9bd4921 commit 6e2ea5e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion sbol3/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ def assign_document(x: Identified):

# Update any external references to this object
# replacing stub SBOLObjects with this one
self._resolve_references(obj)
self._resolve_references(obj)
return obj

def _add_all(self, objects: pytyping.Sequence[TopLevel]) -> pytyping.Sequence[TopLevel]:
Expand Down
7 changes: 5 additions & 2 deletions sbol3/object.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def find(self, search_string: str) -> Optional['SBOLObject']:

def _resolve_references(self, new_obj):
NEW_OBJ = new_obj

def resolve_references(x):
for property_id, references in x._referenced_objects.items():
needs_updating = False
Expand All @@ -118,6 +119,7 @@ def resolve_references(x):
if needs_updating:
references.remove(ref_obj)
references.append(new_obj)

self.traverse(resolve_references)

def copy(self, target_doc=None, target_namespace=None):
Expand Down Expand Up @@ -180,19 +182,20 @@ def copy(self, target_doc=None, target_namespace=None):
if referenced_obj:
new_obj._referenced_objects[property_uri].append(referenced_obj)
else:
new_obj._referenced_objects[property_uri].append(SBOLObject(o.identity))
new_obj._referenced_objects[property_uri].append(SBOLObject(o.identity))
else:
# If the copy does not belong to a Document, then treat all references
# like external references
for property_uri, object_store in self._referenced_objects.items():
for o in object_store:
new_obj._referenced_objects[property_uri].append(SBOLObject(o.identity))
new_obj._referenced_objects[property_uri].append(SBOLObject(o.identity))

return new_obj

def lookup(self):
return self


def replace_namespace(old_uri, target_namespace, rdf_type):

# Flag as not working to ensure nobody calls this function thinking
Expand Down
2 changes: 1 addition & 1 deletion sbol3/refobj_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def __init__(self, property_owner: Any, property_uri: str,

def __setitem__(self, key: Union[int, slice], value: Any) -> None:
replaced_obj = self._storage()[self.property_uri].__getitem__(key)
replaced_obj._references.remove(self.property_owner)
replaced_obj._references.remove(self.property_owner)
super().__setitem__(key, value)

def __delitem__(self, key: Union[int, slice]) -> None:
Expand Down
18 changes: 10 additions & 8 deletions test/test_referenced_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ def test_uri_assignment_not_resolved(self):
component.sequences.append(sequence.identity)
self.assertNotEqual(sequence, component.sequences[0])
self.assertTrue(type(component.sequences[0]) is sbol3.SBOLObject)


def test_instance_append(self):
# Test assignment to a ReferencedObject attribute with an
Expand Down Expand Up @@ -203,7 +202,7 @@ def test_equality(self):
foo = sbol3.SBOLObject('foo')
self.assertEqual(foo, foo.identity)
self.assertEqual(foo.identity, foo)

def test_singleton_property_reference_counter(self):
sbol3.set_namespace('https://github.com/synbiodex/pysbol3')
doc = sbol3.Document()
Expand All @@ -227,7 +226,7 @@ def test_list_property_reference_counter(self):
self.assertListEqual(seq1._references, [])
doc.add(component)
doc.add(seq1)

# Test that the reference counter is working
component.sequences = [seq1.identity]
self.assertListEqual(seq1._references, [component])
Expand Down Expand Up @@ -269,7 +268,7 @@ def setUp(self) -> None:
file_format=TestExternalReferences.TEST_FORMAT)

def test_parse_external_reference(self):
# When parsing a document, if we encounter a reference to an object
# When parsing a document, if we encounter a reference to an object
# not in this document, create a stub object using SBOLObject
component = self.doc.find('toggle_switch')
model = component.models[0]
Expand All @@ -278,11 +277,14 @@ def test_parse_external_reference(self):
self.assertListEqual(model._references, [component])

def test_serialize_external_reference(self):
# When serializing a document, if we encounter a reference to an object
# When serializing a document, if we encounter a reference to an object
# not in this document, serialize it as a URI

roundtrip_doc = sbol3.Document()
roundtrip_doc.read_string(self.doc.write_string(file_format=TestExternalReferences.TEST_FORMAT), file_format=TestExternalReferences.TEST_FORMAT)
roundtrip_doc.read_string(
self.doc.write_string(file_format=TestExternalReferences.TEST_FORMAT),
file_format=TestExternalReferences.TEST_FORMAT
)
component = roundtrip_doc.find('toggle_switch')
model = component.models[0]

Expand All @@ -300,7 +302,7 @@ def test_update(self):
self.assertEqual(model.identity, 'https://sbolstandard.org/examples/model1')
self.doc.add(model)

# Check whether dereferencing now returns a Model
# Check whether dereferencing now returns a Model
# instead of SBOLObject
model = component.models[0]
self.assertFalse(type(model) is sbol3.SBOLObject)
Expand All @@ -318,7 +320,7 @@ def test_remove(self):
model = component.models[0]
self.assertFalse(type(model) is sbol3.Model)
self.assertTrue(type(model) is sbol3.SBOLObject)


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

0 comments on commit 6e2ea5e

Please sign in to comment.