Skip to content

Commit

Permalink
Merge pull request #160 from tcmitchell/159-compliant-naming
Browse files Browse the repository at this point in the history
Fix compliant name cascading
  • Loading branch information
tcmitchell authored Feb 2, 2021
2 parents cd034bd + 4612111 commit 8ba05e5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
3 changes: 2 additions & 1 deletion sbol3/identified.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import rdflib

from . import *
from .utils import parse_class_name


class Identified(SBOLObject):
Expand Down Expand Up @@ -86,7 +87,7 @@ def _update_identity(self, identity: str, display_id: str) -> None:
new_display_id = child.display_id
else:
# Generate a display id based on type and number
type_name = child.type_uri[len(SBOL3_NS):]
type_name = parse_class_name(child.type_uri)
counter_value = self.counter_value(type_name)
new_display_id = f'{type_name}{counter_value}'
new_identity = posixpath.join(self.identity, new_display_id)
Expand Down
21 changes: 21 additions & 0 deletions test/test_varcomp.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,27 @@ def test_round_trip1(self):
vf2 = doc2.find(vf1.identity)
self.assertIsInstance(vf2, sbol3.VariableFeature)

def test_round_trip2(self):
# See https://github.com/SynBioDex/pySBOL3/issues/159
sbol3.set_namespace('https://github.com/synbiodex/pysbol3')
doc1 = sbol3.Document()
comp1 = sbol3.Component('comp1', sbol3.SBO_DNA)
doc1.add(comp1)
cd1 = sbol3.CombinatorialDerivation('cd1', comp1)
self.assertEqual(comp1.identity, cd1.template)
doc1.add(cd1)
vf1 = sbol3.VariableFeature()
hour = 'https://identifiers.org/ncit:C25529'
m1 = sbol3.Measure(32, hour)
vf1.variant_measure.append(m1)
cd1.variable_features.append(vf1)
self.assertTrue(vf1.identity.startswith(cd1.identity))
# Ensure that Measure m1 is valid. The bug tested here was that it
# had been assigned an invalid displayId.
# Note: validate() currently returns None if an object is valid,
# and raises an exception if the object is not valid.
self.assertIsNone(m1.validate())


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

0 comments on commit 8ba05e5

Please sign in to comment.