Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide some stability in dependent names #368

Merged
merged 1 commit into from
Jan 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sbol3/identified.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def _update_identity(self, identity: str, display_id: str) -> None:
new_identity = posixpath.join(self.identity, new_display_id)
child._update_identity(new_identity, new_display_id)

def counter_value(self, type_name: str):
def counter_value(self, type_name: str) -> int:
result = 0
for _, objects in self._owned_objects.items():
for sibling in objects:
Expand Down
7 changes: 6 additions & 1 deletion sbol3/ownedobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ def item_added(self, item: Any) -> None:
# raise ValueError(f'Item {item} does not have a display_id')
type_name = parse_class_name(item.type_uri)
counter_value = self.property_owner.counter_value(type_name)
new_display_id = f'{type_name}{counter_value}'
# Provide stability across clone and copy
# If an item already has a display_id, use it, otherwise mint a new one
if item.display_id:
new_display_id = item.display_id
else:
new_display_id = f'{type_name}{counter_value}'
new_url = posixpath.join(self.property_owner.identity, new_display_id)
for sibling in self._storage()[self.property_uri]:
if sibling == item:
Expand Down
2 changes: 1 addition & 1 deletion sbol3/toplevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def erase_identity_traverser(x):
return
identity_map[x.identity] = x
x._identity = None
x._display_id = None
# x._display_id = None
x.document = None
return erase_identity_traverser

Expand Down
19 changes: 19 additions & 0 deletions test/test_toplevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,25 @@ def test_split_identity(self):
expected = namespace, path, name
self.assertEqual(expected, c3.split_identity())

def test_clone_bad_rename(self):
# Tests that the dependent objects have consistent renaming
namespace = 'https://github.com/synbiodex/pysbol3'
sbol3.set_namespace(namespace)
name = 'c1'
c1 = sbol3.Component(name, types=[sbol3.SBO_DNA])
lsc1 = sbol3.LocalSubComponent(types=[sbol3.SBO_DNA])
lsc2 = sbol3.LocalSubComponent(types=[sbol3.SBO_DNA])
c1.features = [lsc1, lsc2]
self.assertEqual('LocalSubComponent1', lsc1.display_id)
self.assertEqual('LocalSubComponent2', lsc2.display_id)
c1.features.remove(lsc1)
self.assertListEqual([lsc2], list(c1.features))
self.assertEqual('LocalSubComponent2', lsc2.display_id)
self.assertIsNotNone(c1.find('LocalSubComponent2'))
clone_name = 'c1_prime'
c1_prime = c1.clone(posixpath.join(namespace, clone_name))
self.assertIsNotNone(c1_prime.find('LocalSubComponent2'))


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