def test_dunder_uri(self): # See issue #319 # The __uri__ method to convert an object to a URI # was returning a str, not a URIRef sa = sbol2.SequenceAnnotation('test_sa') comp = sbol2.Component('test_comp') sa.component = comp expected = rdflib.URIRef(comp.identity) self.assertEqual(expected, sa.properties[sbol2.SBOL_COMPONENT_PROPERTY][0])
def test_containers(self): # Note: Alphabetical Order x = sbol.Activity() x = sbol.CombinatorialDerivation() x = sbol.Component() x = sbol.ComponentDefinition() x = sbol.Document() x = sbol.Interaction() x = sbol.Module() x = sbol.ModuleDefinition() x = sbol.Participation() x = sbol.SequenceAnnotation()
def test_add_remove_role(self): c = sbol2.Component('c1') self.assertEqual([], c.roles) c.addRole(sbol2.SO_PROMOTER) self.assertEqual([sbol2.SO_PROMOTER], c.roles) c.addRole(sbol2.SO_MISC) self.assertEqual([sbol2.SO_PROMOTER, sbol2.SO_MISC], c.roles) c.addRole(sbol2.SO_CDS) self.assertEqual([sbol2.SO_PROMOTER, sbol2.SO_MISC, sbol2.SO_CDS], c.roles) c.removeRole(1) self.assertEqual([sbol2.SO_PROMOTER, sbol2.SO_CDS], c.roles)
def test_recursive_add(self): # Make sure that when an object gets added to a document # all of its child objects also get added. cd = sbol2.ComponentDefinition('cd') comp = sbol2.Component('cd_c') cd.components.add(comp) # Use of cd.sequence is dubious because the sequence attribute # isn't really there in SBOL 2.3. But it's the test case that # found the bug with recursive addition of objects, so we use it. seq = sbol2.Sequence('cd_seq') cd.sequence = seq doc = sbol2.Document() doc.addComponentDefinition(cd) # The cd and sequence should be in the document # The component is not top level, so doesn't get added self.assertEqual(2, len(doc))
def test_role(self): c = sbol2.Component('c1') self.assertTrue(hasattr(c, 'identity')) self.assertEqual(None, c.roleIntegration) self.assertEqual([], c.roles) c.roles = [sbol2.SO_PROMOTER] # The SBOL 2.3.0 spec says that if a component has roles then # it MUST have a roleIntegration. There is a validator that should # set roleIntegration if not set self.assertNotEqual(None, c.roleIntegration) self.assertEqual(sbol2.SBOL_ROLE_INTEGRATION_MERGE, c.roleIntegration) c.roleIntegration = sbol2.SBOL_ROLE_INTEGRATION_OVERRIDE c.roles = [] # It is ok to have a roleIntegration even if there are no roles self.assertEqual(sbol2.SBOL_ROLE_INTEGRATION_OVERRIDE, c.roleIntegration)
def test_delete_downstream(self): doc = sbol2.Document() gene = sbol2.ComponentDefinition("BB0001") promoter = sbol2.ComponentDefinition("R0010") rbs = sbol2.ComponentDefinition("B0032") cds = sbol2.ComponentDefinition("E0040") terminator = sbol2.ComponentDefinition("B0012") doc.addComponentDefinition([gene, promoter, rbs, cds, terminator]) gene.assemblePrimaryStructure([promoter, rbs, cds, terminator]) primary_structure_components = gene.getPrimaryStructureComponents() c_promoter = primary_structure_components[0] c_rbs = primary_structure_components[1] c_cds = primary_structure_components[2] c_terminator = primary_structure_components[3] gene.deleteDownstreamComponent(c_rbs) primary_structure = gene.getPrimaryStructure() primary_structure = [cd.identity for cd in primary_structure] valid_primary_structure = [ promoter.identity, rbs.identity, terminator.identity ] self.assertEqual(primary_structure, valid_primary_structure) # Test deletion when the target Component is the last Component gene.deleteDownstreamComponent(c_rbs) primary_structure = gene.getPrimaryStructure() primary_structure = [cd.identity for cd in primary_structure] valid_primary_structure = [promoter.identity, rbs.identity] self.assertEqual(primary_structure, valid_primary_structure) # Test failure when user tries to delete Component upstream of the first # Component with self.assertRaises(ValueError): gene.deleteDownstreamComponent(c_cds) # Test failure when the user supplies a Component that isn't part of the # primary structure with self.assertRaises(ValueError): gene.deleteDownstreamComponent(sbol2.Component())