Example #1
0
 def test_list_wrapping(self):
     # Ensure that at least certain properties handle automatic list
     # wrapping and are typed to do so.
     # See https://github.com/SynBioDex/pySBOL3/issues/301
     sbol3.set_namespace('https://github.com/synbiodex/pysbol3')
     instance_uri = 'https://example.org/instance'
     seq1 = sbol3.Sequence('seq1')
     test_loc = sbol3.EntireSequence(seq1)
     seq2 = sbol3.Sequence('seq2')
     test_source_loc = sbol3.EntireSequence(seq1)
     subcomp1 = sbol3.SubComponent(instance_of=instance_uri,
                                   locations=test_loc,
                                   source_locations=test_source_loc)
     self.assertEqual([test_loc], subcomp1.locations)
     self.assertEqual([test_source_loc], subcomp1.source_locations)
Example #2
0
 def test_cloning_with_children(self):
     # This test does not use `sbol3.set_namespace` as the other
     # cloning unit tests do. This is on purpose to verify that
     # cloning does not rely on the default namespace.
     doc = sbol3.Document()
     namespace = 'https://github.com/synbiodex/pysbol3'
     c1_identity = posixpath.join(namespace, 'c1')
     c2_identity = posixpath.join(namespace, 'c2')
     s1_identity = posixpath.join(namespace, 's1')
     c1 = sbol3.Component(c1_identity, sbol3.SBO_DNA)
     doc.add(c1)
     seq1 = sbol3.Sequence(s1_identity)
     doc.add(seq1)
     c1.sequences.append(seq1)
     sc1 = sbol3.SubComponent(c1)
     es1 = sbol3.EntireSequence(seq1)
     sc1.source_locations.append(es1)
     c1.features = [sc1]
     c2 = c1.clone(c2_identity)
     self.assertEqual(c2_identity, c2.identity)
     self.assertIsNone(c2.document)
     # Check on the SubComponent
     sc2 = c2.features[0]
     self.assertIsInstance(sc2, sbol3.SubComponent)
     self.assertNotEqual(sc1.identity, sc2.identity)
     self.assertTrue(sc2.identity.startswith(c2.identity))
     # Ensure that the reference was updated properly
     self.assertEqual(c2.identity, sc2.instance_of)
     self.assertIsNone(sc2.document)
     es2 = sc2.source_locations[0]
     self.assertIsInstance(es2, sbol3.EntireSequence)
     self.assertNotEqual(es1.identity, es2.identity)
     self.assertTrue(es2.identity.startswith(c2.identity))
     self.assertEqual(es1.sequence, es2.sequence)
     self.assertIsNone(es2.document)
Example #3
0
 def test_list_wrapping(self):
     # Ensure that at least certain properties handle automatic list
     # wrapping and are typed to do so.
     # See https://github.com/SynBioDex/pySBOL3/issues/301
     sbol3.set_namespace('https://github.com/synbiodex/pysbol3')
     seq = sbol3.Sequence('seq1')
     test_loc = sbol3.EntireSequence(seq)
     seq_feat1 = sbol3.SequenceFeature(locations=test_loc)
     self.assertEqual([test_loc], seq_feat1.locations)
Example #4
0
 def test_list_wrapping(self):
     # Ensure that at least certain properties handle automatic list
     # wrapping and are typed to do so.
     # See https://github.com/SynBioDex/pySBOL3/issues/301
     sbol3.set_namespace('https://github.com/synbiodex/pysbol3')
     test_type = sbol3.SBO_DNA
     seq = sbol3.Sequence('seq1')
     test_loc = sbol3.EntireSequence(seq)
     lsc = sbol3.LocalSubComponent(types=test_type, locations=test_loc)
     self.assertEqual([test_type], lsc.types)
     self.assertEqual([test_loc], lsc.locations)
Example #5
0
 def test_cascade_identity(self):
     # Test that updating identity of an owned object cascades
     # to child owned objects
     sbol3.set_namespace('https://github.com/synbiodex/pysbol3')
     c1 = sbol3.Component('c1', sbol3.SBO_DNA)
     seq = sbol3.Sequence('seq1')
     loc = sbol3.EntireSequence(seq)
     seq_feature = sbol3.SequenceFeature([loc])
     c1.features.append(seq_feature)
     self.assertIsNotNone(seq_feature.identity)
     # identity should cascade down to the location after it
     # is set on the sequence feature
     self.assertIsNotNone(loc.identity)
Example #6
0
 def test_list_wrapping(self):
     # Ensure that at least certain properties handle automatic list
     # wrapping and are typed to do so.
     # See https://github.com/SynBioDex/pySBOL3/issues/301
     sbol3.set_namespace('https://github.com/synbiodex/pysbol3')
     seq = sbol3.Sequence('seq1')
     test_loc = sbol3.EntireSequence(seq)
     variable_uri = 'https://example.org/variable'
     var_coll_uri = 'https://example.org/collection'
     var_feat1 = sbol3.VariableFeature(cardinality=sbol3.SBOL_ZERO_OR_MORE,
                                       variable=variable_uri,
                                       variant_collections=var_coll_uri)
     self.assertEqual([var_coll_uri], var_feat1.variant_collections)
Example #7
0
 def test_overwrite_identity(self):
     sbol3.set_namespace('https://github.com/synbiodex/pysbol3')
     c1 = sbol3.Component('c1', sbol3.SBO_DNA)
     seq = sbol3.Sequence('seq1')
     loc = sbol3.EntireSequence(seq)
     seq_feature = sbol3.SequenceFeature([loc])
     c1.features.append(seq_feature)
     self.assertIsNotNone(seq_feature.identity)
     # identity should cascade down to the location after it
     # is set on the sequence feature
     self.assertIsNotNone(loc.identity)
     old_sf_identity = seq_feature.identity
     old_loc_identity = loc.identity
     c2 = sbol3.Component('c2', sbol3.SBO_DNA)
     # Try adding the same object to a different parent
     # This should cause an error because the object is
     # still parented by c1.
     # See https://github.com/SynBioDex/pySBOL3/issues/178
     with self.assertRaises(ValueError):
         c2.features.append(seq_feature)
     self.assertEqual(old_loc_identity, loc.identity)
     self.assertEqual(old_sf_identity, seq_feature.identity)
Example #8
0
 def test_create(self):
     es1 = sbol3.EntireSequence(sbol3.PYSBOL3_MISSING)
     locations = [es1]
     sf = sbol3.SequenceFeature(locations)
     self.assertEqual(locations, sf.locations)
Example #9
0
 def test_identified_constructors(self):
     # I don't remember why I wanted this test.
     # Test all of the Identified constructors.
     args_map = {
         'Association': ['https://example.com/fake'],
         'ComponentReference':
         ['https://example.com/fake', 'https://example.com/fake'],
         'Constraint': [
             'https://example.com/restriction',
             'https://example.com/subject', 'https://example.com/object'
         ],
         'CustomIdentified': ['https://example.com/fake'],
         'Cut': ['https://example.com/fake', 1],
         'EntireSequence': ['https://example.com/fake'],
         'ExternallyDefined': [['https://example.com/fake'],
                               'https://example.com/fake'],
         'Interaction': [['https://example.com/fake']],
         'LocalSubComponent': [['https://example.com/fake']],
         'Measure': [1.0, OM_KILOGRAM],
         'Participation': [[sbol3.SBO_INHIBITOR],
                           'https://example.com/fake'],
         'Range': ['https://example.com/fake', 1, 2],
         'SequenceFeature':
         [[sbol3.EntireSequence('https://example.com/fake')]],
         'SubComponent': ['https://example.com/fake'],
         'Usage': ['https://example.com/fake'],
         'VariableFeature':
         [sbol3.SBOL_ONE_OR_MORE, 'https://example.com/fake']
     }
     skip_list = [sbol3.Identified, sbol3.Feature, sbol3.Location]
     abstract_list = [
         sbol3.CustomIdentified, sbol3.TopLevel, sbol3.CustomTopLevel
     ]
     for name in dir(sbol3):
         item = getattr(sbol3, name)
         if not isinstance(item, type):
             continue
         if issubclass(item, sbol3.TopLevel):
             if item not in abstract_list:
                 self.assertTrue(hasattr(item, 'accept'),
                                 f'{str(item)} has no accept attribute')
             continue
         if not issubclass(item, sbol3.Identified):
             continue
         if item in skip_list:
             continue
         arg_list = []
         if name in args_map:
             arg_list = args_map[name]
         try:
             item(*arg_list)
         except TypeError as e:
             self.fail('Unable to construct sbol3.%s: %s' % (name, e))
         except sbol3.ValidationError as e:
             self.fail('Constructed invalid sbol3.%s: %s' % (name, e))
         if item in abstract_list:
             # Skip over abstract classes when checking for the
             # accept method
             continue
         self.assertTrue(hasattr(item, 'accept'),
                         f'{str(item)} has no accept attribute')
Example #10
0
 def test_creation(self):
     # EntireSequence has no properties, so there isn't much to test here
     es = sbol3.EntireSequence(sbol3.PYSBOL3_MISSING)
     self.assertIsNotNone(es)
     self.assertEqual(sbol3.SBOL_ENTIRE_SEQUENCE, es.type_uri)