def test_XMLToken_create(self): token = libsbml.XMLToken() self.assert_(token != None) _dummyList = [token] _dummyList[:] = [] del _dummyList triple = libsbml.XMLTriple("attr", "uri", "prefix") token = libsbml.XMLToken(triple) self.assert_(token != None) self.assert_(("attr" != token.getName()) == False) self.assert_(("prefix" != token.getPrefix()) == False) self.assert_(("uri" != token.getURI()) == False) _dummyList = [token] _dummyList[:] = [] del _dummyList attr = libsbml.XMLAttributes() self.assert_(attr != None) attr.add("attr2", "value") token = libsbml.XMLToken(triple, attr) self.assert_(token != None) returnattr = token.getAttributes() self.assert_(("attr2" != returnattr.getName(0)) == False) _dummyList = [token] _dummyList[:] = [] del _dummyList _dummyList = [triple] _dummyList[:] = [] del _dummyList _dummyList = [attr] _dummyList[:] = [] del _dummyList pass
def test_Node_assignmentOperator(self): att = libsbml.XMLAttributes() t = libsbml.XMLTriple("sarah", "http://foo.org/", "bar") token = libsbml.XMLToken(t,att,3,4) node = libsbml.XMLNode(token) child = libsbml.XMLNode() node.addChild(child) self.assert_( node.getNumChildren() == 1 ) self.assert_( node.getName() == "sarah" ) self.assert_( node.getURI() == "http://foo.org/" ) self.assert_( node.getPrefix() == "bar" ) self.assert_( node.isEnd() == False ) self.assert_( node.isEOF() == False ) self.assert_( node.getLine() == 3 ) self.assert_( node.getColumn() == 4 ) node2 = libsbml.XMLNode() node2 = node self.assert_( node2.getNumChildren() == 1 ) self.assert_( node2.getName() == "sarah" ) self.assert_( node2.getURI() == "http://foo.org/" ) self.assert_( node2.getPrefix() == "bar" ) self.assert_( node2.isEnd() == False ) self.assert_( node2.isEOF() == False ) self.assert_( node2.getLine() == 3 ) self.assert_( node2.getColumn() == 4 ) t = None token = None node = None node2 = None pass
def test_XMLNode_clearNamespaces(self): triple = libsbml.XMLTriple("test", "", "") attr = libsbml.XMLAttributes() node = libsbml.XMLNode(triple, attr) i = node.addNamespace("http://test1.org/", "test1") self.assert_(i == libsbml.LIBSBML_OPERATION_SUCCESS) nms = node.getNamespaces() self.assert_(nms.getLength() == 1) i = node.addNamespace("http://test2.org/", "test2") self.assert_(i == libsbml.LIBSBML_OPERATION_SUCCESS) nms = node.getNamespaces() self.assert_(nms.getLength() == 2) i = node.clearNamespaces() self.assert_(i == libsbml.LIBSBML_OPERATION_SUCCESS) nms = node.getNamespaces() self.assert_(nms.getLength() == 0) _dummyList = [triple] _dummyList[:] = [] del _dummyList _dummyList = [attr] _dummyList[:] = [] del _dummyList _dummyList = [node] _dummyList[:] = [] del _dummyList pass
def test_XMLAttributes_remove1(self): xa = libsbml.XMLAttributes() xt2 = libsbml.XMLTriple("name2", "http://name2.org/", "p2") i = xa.add("name1", "val1", "http://name1.org/", "p1") self.assert_(i == libsbml.LIBSBML_OPERATION_SUCCESS) i = xa.add(xt2, "val2") self.assert_(i == libsbml.LIBSBML_OPERATION_SUCCESS) i = xa.add("noprefix", "val3") self.assert_(i == libsbml.LIBSBML_OPERATION_SUCCESS) i = xa.add("name4", "val4", "http://name4.org/", "p1") self.assert_(i == libsbml.LIBSBML_OPERATION_SUCCESS) self.assert_(xa.getLength() == 4) i = xa.remove(4) self.assert_(i == libsbml.LIBSBML_INDEX_EXCEEDS_SIZE) i = xa.remove(3) self.assert_(i == libsbml.LIBSBML_OPERATION_SUCCESS) self.assert_(xa.getLength() == 3) i = xa.remove("noprefix") self.assert_(i == libsbml.LIBSBML_OPERATION_SUCCESS) self.assert_(xa.getLength() == 2) i = xa.remove(xt2) self.assert_(i == libsbml.LIBSBML_OPERATION_SUCCESS) self.assert_(xa.getLength() == 1) i = xa.remove("name1", "http://name1.org/") self.assert_(i == libsbml.LIBSBML_OPERATION_SUCCESS) self.assert_(xa.getLength() == 0) _dummyList = [xa] _dummyList[:] = [] del _dummyList _dummyList = [xt2] _dummyList[:] = [] del _dummyList pass
def test_XMLNode_removeNamespaces(self): triple = libsbml.XMLTriple("test","","") attr = libsbml.XMLAttributes() node = libsbml.XMLNode(triple,attr) i = node.addNamespace( "http://test1.org/", "test1") self.assert_( i == libsbml.LIBSBML_OPERATION_SUCCESS ) nms = node.getNamespaces() self.assert_( nms.getLength() == 1 ) i = node.addNamespace( "http://test2.org/", "test2") self.assert_( i == libsbml.LIBSBML_OPERATION_SUCCESS ) nms = node.getNamespaces() self.assert_( nms.getLength() == 2 ) i = node.removeNamespace(7) self.assert_( i == libsbml.LIBSBML_INDEX_EXCEEDS_SIZE ) nms = node.getNamespaces() self.assert_( nms.getLength() == 2 ) i = node.removeNamespace( "name7") self.assert_( i == libsbml.LIBSBML_INDEX_EXCEEDS_SIZE ) nms = node.getNamespaces() self.assert_( nms.getLength() == 2 ) i = node.removeNamespace(0) self.assert_( i == libsbml.LIBSBML_OPERATION_SUCCESS ) nms = node.getNamespaces() self.assert_( nms.getLength() == 1 ) i = node.removeNamespace( "test2") self.assert_( i == libsbml.LIBSBML_OPERATION_SUCCESS ) nms = node.getNamespaces() self.assert_( nms.getLength() == 0 ) _dummyList = [ triple ]; _dummyList[:] = []; del _dummyList _dummyList = [ attr ]; _dummyList[:] = []; del _dummyList _dummyList = [ node ]; _dummyList[:] = []; del _dummyList pass
def test_XMLNode_clearAttributes(self): triple = libsbml.XMLTriple("test","","") attr = libsbml.XMLAttributes() node = libsbml.XMLNode(triple,attr) xt2 = libsbml.XMLTriple("name3", "http://name3.org/", "p3") xt1 = libsbml.XMLTriple("name5", "http://name5.org/", "p5") i = node.addAttr( "name1", "val1") self.assert_( i == libsbml.LIBSBML_OPERATION_SUCCESS ) self.assert_( node.getAttributes().getLength() == 1 ) i = node.addAttr( "name2", "val2", "http://name1.org/", "p1") self.assert_( i == libsbml.LIBSBML_OPERATION_SUCCESS ) self.assert_( node.getAttributes().getLength() == 2 ) i = node.addAttr(xt2, "val2") self.assert_( i == libsbml.LIBSBML_OPERATION_SUCCESS ) self.assert_( node.getAttributes().getLength() == 3 ) i = node.addAttr( "name4", "val4") self.assert_( i == libsbml.LIBSBML_OPERATION_SUCCESS ) self.assert_( node.getAttributes().getLength() == 4 ) i = node.clearAttributes() self.assert_( i == libsbml.LIBSBML_OPERATION_SUCCESS ) self.assert_( node.getAttributes().getLength() == 0 ) _dummyList = [ xt1 ]; _dummyList[:] = []; del _dummyList _dummyList = [ xt2 ]; _dummyList[:] = []; del _dummyList _dummyList = [ triple ]; _dummyList[:] = []; del _dummyList _dummyList = [ attr ]; _dummyList[:] = []; del _dummyList _dummyList = [ node ]; _dummyList[:] = []; del _dummyList pass
def test_XMLNode_namespace_add(self): triple = libsbml.XMLTriple("test", "", "") attr = libsbml.XMLAttributes() node = libsbml.XMLNode(triple, attr) self.assert_(node.getNamespacesLength() == 0) self.assert_(node.isNamespacesEmpty() == True) node.addNamespace("http://test1.org/", "test1") self.assert_(node.getNamespacesLength() == 1) self.assert_(node.isNamespacesEmpty() == False) node.addNamespace("http://test2.org/", "test2") self.assert_(node.getNamespacesLength() == 2) self.assert_(node.isNamespacesEmpty() == False) node.addNamespace("http://test1.org/", "test1a") self.assert_(node.getNamespacesLength() == 3) self.assert_(node.isNamespacesEmpty() == False) node.addNamespace("http://test1.org/", "test1a") self.assert_(node.getNamespacesLength() == 3) self.assert_(node.isNamespacesEmpty() == False) self.assert_( (node.getNamespaceIndex("http://test1.org/") == -1) == False) _dummyList = [node] _dummyList[:] = [] del _dummyList _dummyList = [triple] _dummyList[:] = [] del _dummyList _dummyList = [attr] _dummyList[:] = [] del _dummyList pass
def test_XMLToken_newSetters_setNamespaces1(self): triple = libsbml.XMLTriple("test", "", "") attr = libsbml.XMLAttributes() token = libsbml.XMLToken(triple, attr) ns = libsbml.XMLNamespaces() self.assert_(token.getNamespacesLength() == 0) self.assert_(token.isNamespacesEmpty() == True) ns.add("http://test1.org/", "test1") i = token.setNamespaces(ns) self.assert_(i == libsbml.LIBSBML_OPERATION_SUCCESS) self.assert_(token.getNamespacesLength() == 1) self.assert_(token.isNamespacesEmpty() == False) _dummyList = [attr] _dummyList[:] = [] del _dummyList _dummyList = [triple] _dummyList[:] = [] del _dummyList _dummyList = [token] _dummyList[:] = [] del _dummyList _dummyList = [ns] _dummyList[:] = [] del _dummyList pass
def test_XMLAttributes_copy(self): att1 = libsbml.XMLAttributes() att1.add("xmlns", "http://foo.org/") self.assert_(att1.getLength() == 1) self.assert_(att1.isEmpty() == False) self.assert_(att1.getIndex("xmlns") == 0) self.assert_(att1.getName(0) == "xmlns") self.assert_(att1.getValue("xmlns") == "http://foo.org/") att2 = libsbml.XMLAttributes(att1) self.assert_(att2.getLength() == 1) self.assert_(att2.isEmpty() == False) self.assert_(att2.getIndex("xmlns") == 0) self.assert_(att2.getName(0) == "xmlns") self.assert_(att2.getValue("xmlns") == "http://foo.org/") att2 = None att1 = None pass
def test_XMLToken_namespace_get(self): triple = libsbml.XMLTriple("test", "", "") attr = libsbml.XMLAttributes() token = libsbml.XMLToken(triple, attr) token.addNamespace("http://test1.org/", "test1") token.addNamespace("http://test2.org/", "test2") token.addNamespace("http://test3.org/", "test3") token.addNamespace("http://test4.org/", "test4") token.addNamespace("http://test5.org/", "test5") token.addNamespace("http://test6.org/", "test6") token.addNamespace("http://test7.org/", "test7") token.addNamespace("http://test8.org/", "test8") token.addNamespace("http://test9.org/", "test9") self.assert_(token.getNamespacesLength() == 9) self.assert_(token.getNamespaceIndex("http://test1.org/") == 0) self.assert_(("test2" != token.getNamespacePrefix(1)) == False) self.assert_(( "test1" != token.getNamespacePrefix("http://test1.org/")) == False) self.assert_( ("http://test2.org/" != token.getNamespaceURI(1)) == False) self.assert_( ("http://test2.org/" != token.getNamespaceURI("test2")) == False) self.assert_(token.getNamespaceIndex("http://test1.org/") == 0) self.assert_(token.getNamespaceIndex("http://test2.org/") == 1) self.assert_(token.getNamespaceIndex("http://test5.org/") == 4) self.assert_(token.getNamespaceIndex("http://test9.org/") == 8) self.assert_(token.getNamespaceIndex("http://testX.org/") == -1) self.assert_(token.hasNamespaceURI("http://test1.org/") != False) self.assert_(token.hasNamespaceURI("http://test2.org/") != False) self.assert_(token.hasNamespaceURI("http://test5.org/") != False) self.assert_(token.hasNamespaceURI("http://test9.org/") != False) self.assert_(token.hasNamespaceURI("http://testX.org/") == False) self.assert_(token.getNamespaceIndexByPrefix("test1") == 0) self.assert_(token.getNamespaceIndexByPrefix("test5") == 4) self.assert_(token.getNamespaceIndexByPrefix("test9") == 8) self.assert_(token.getNamespaceIndexByPrefix("testX") == -1) self.assert_(token.hasNamespacePrefix("test1") != False) self.assert_(token.hasNamespacePrefix("test5") != False) self.assert_(token.hasNamespacePrefix("test9") != False) self.assert_(token.hasNamespacePrefix("testX") == False) self.assert_( token.hasNamespaceNS("http://test1.org/", "test1") != False) self.assert_( token.hasNamespaceNS("http://test5.org/", "test5") != False) self.assert_( token.hasNamespaceNS("http://test9.org/", "test9") != False) self.assert_( token.hasNamespaceNS("http://testX.org/", "testX") == False) _dummyList = [token] _dummyList[:] = [] del _dummyList _dummyList = [triple] _dummyList[:] = [] del _dummyList _dummyList = [attr] _dummyList[:] = [] del _dummyList pass
def test_XMLNode_removeAttributes(self): triple = libsbml.XMLTriple("test", "", "") attr = libsbml.XMLAttributes() node = libsbml.XMLNode(triple, attr) xt2 = libsbml.XMLTriple("name3", "http://name3.org/", "p3") xt1 = libsbml.XMLTriple("name5", "http://name5.org/", "p5") i = node.addAttr("name1", "val1") self.assert_(i == libsbml.LIBSBML_OPERATION_SUCCESS) self.assert_(node.getAttributes().getLength() == 1) i = node.addAttr("name2", "val2", "http://name1.org/", "p1") self.assert_(i == libsbml.LIBSBML_OPERATION_SUCCESS) self.assert_(node.getAttributes().getLength() == 2) i = node.addAttr(xt2, "val2") self.assert_(i == libsbml.LIBSBML_OPERATION_SUCCESS) self.assert_(node.getAttributes().getLength() == 3) i = node.addAttr("name4", "val4") self.assert_(i == libsbml.LIBSBML_OPERATION_SUCCESS) self.assert_(node.getAttributes().getLength() == 4) i = node.removeAttr(7) self.assert_(i == libsbml.LIBSBML_INDEX_EXCEEDS_SIZE) i = node.removeAttr("name7") self.assert_(i == libsbml.LIBSBML_INDEX_EXCEEDS_SIZE) i = node.removeAttr("name7", "namespaces7") self.assert_(i == libsbml.LIBSBML_INDEX_EXCEEDS_SIZE) i = node.removeAttr(xt1) self.assert_(i == libsbml.LIBSBML_INDEX_EXCEEDS_SIZE) self.assert_(node.getAttributes().getLength() == 4) i = node.removeAttr(3) self.assert_(i == libsbml.LIBSBML_OPERATION_SUCCESS) self.assert_(node.getAttributes().getLength() == 3) i = node.removeAttr("name1") self.assert_(i == libsbml.LIBSBML_OPERATION_SUCCESS) self.assert_(node.getAttributes().getLength() == 2) i = node.removeAttr("name2", "http://name1.org/") self.assert_(i == libsbml.LIBSBML_OPERATION_SUCCESS) self.assert_(node.getAttributes().getLength() == 1) i = node.removeAttr(xt2) self.assert_(i == libsbml.LIBSBML_OPERATION_SUCCESS) self.assert_(node.getAttributes().getLength() == 0) _dummyList = [xt1] _dummyList[:] = [] del _dummyList _dummyList = [xt2] _dummyList[:] = [] del _dummyList _dummyList = [triple] _dummyList[:] = [] del _dummyList _dummyList = [attr] _dummyList[:] = [] del _dummyList _dummyList = [node] _dummyList[:] = [] del _dummyList pass
def test_XMLNode_addChild2(self): triple = libsbml.XMLTriple("test","","") attr = libsbml.XMLAttributes() node = libsbml.XMLNode(triple,attr) node2 = libsbml.XMLNode() i = node.addChild(node2) self.assert_( i == libsbml.LIBSBML_OPERATION_SUCCESS ) self.assert_( node.getNumChildren() == 1 ) _dummyList = [ triple ]; _dummyList[:] = []; del _dummyList _dummyList = [ attr ]; _dummyList[:] = []; del _dummyList _dummyList = [ node ]; _dummyList[:] = []; del _dummyList _dummyList = [ node2 ]; _dummyList[:] = []; del _dummyList pass
def _setThresholdXml(self, value): """ Uses the value to update the internal libsbml.XMLNode structure. If there is a reference to an existing XML node (from loading the file) it is used. Otherwise, it's created. @since: 2011-05-23 """ if not self.thresholdNode: # have to create the XML node thresholdNodeTriplet = libsbml.XMLTriple(XML_SCALE, XML_THRESHOLD_NAMESPACE, "") thresholdNodeAttribute = libsbml.XMLAttributes() thresholdNodeAttribute.add(XML_THRESHOLD_VALUE, str(value)) self.thresholdNode = libsbml.XMLNode(thresholdNodeTriplet, thresholdNodeAttribute) namespace = libsbml.XMLNamespaces() # seems to be necessary to do this again namespace.add(XML_THRESHOLD_NAMESPACE) self.thresholdNode.setNamespaces(namespace) self.Item.appendAnnotation(self.thresholdNode) else: thresholdNodeAttribute = libsbml.XMLAttributes() thresholdNodeAttribute.add(XML_THRESHOLD_VALUE, str(value)) self.thresholdNode.setAttributes(thresholdNodeAttribute)
def test_Constraint_setMessage(self): text = libsbml.XMLNode.convertStringToXMLNode(" Some text ",None) triple = libsbml.XMLTriple("p", "http://www.w3.org/1999/xhtml", "") att = libsbml.XMLAttributes() xmlns = libsbml.XMLNamespaces() xmlns.add( "http://www.w3.org/1999/xhtml", "") p = libsbml.XMLNode(triple,att,xmlns) p.addChild(text) triple1 = libsbml.XMLTriple("message", "", "") att1 = libsbml.XMLAttributes() node = libsbml.XMLNode(triple1,att1) node.addChild(p) self.C.setMessage(node) self.assert_( self.C.getMessage() != node ) self.assert_( self.C.isSetMessage() == True ) self.C.setMessage(self.C.getMessage()) self.assert_( self.C.getMessage() != node ) self.assert_( self.C.getMessageString() != None ) self.C.unsetMessage() self.assertEqual( False, self.C.isSetMessage() ) if (self.C.getMessage() != None): pass _dummyList = [ node ]; _dummyList[:] = []; del _dummyList pass
def test_XMLToken_namespace_remove(self): triple = libsbml.XMLTriple("test", "", "") attr = libsbml.XMLAttributes() token = libsbml.XMLToken(triple, attr) token.addNamespace("http://test1.org/", "test1") token.addNamespace("http://test2.org/", "test2") token.addNamespace("http://test3.org/", "test3") token.addNamespace("http://test4.org/", "test4") token.addNamespace("http://test5.org/", "test5") self.assert_(token.getNamespacesLength() == 5) token.removeNamespace(4) self.assert_(token.getNamespacesLength() == 4) token.removeNamespace(3) self.assert_(token.getNamespacesLength() == 3) token.removeNamespace(2) self.assert_(token.getNamespacesLength() == 2) token.removeNamespace(1) self.assert_(token.getNamespacesLength() == 1) token.removeNamespace(0) self.assert_(token.getNamespacesLength() == 0) token.addNamespace("http://test1.org/", "test1") token.addNamespace("http://test2.org/", "test2") token.addNamespace("http://test3.org/", "test3") token.addNamespace("http://test4.org/", "test4") token.addNamespace("http://test5.org/", "test5") self.assert_(token.getNamespacesLength() == 5) token.removeNamespace(0) self.assert_(token.getNamespacesLength() == 4) token.removeNamespace(0) self.assert_(token.getNamespacesLength() == 3) token.removeNamespace(0) self.assert_(token.getNamespacesLength() == 2) token.removeNamespace(0) self.assert_(token.getNamespacesLength() == 1) token.removeNamespace(0) self.assert_(token.getNamespacesLength() == 0) _dummyList = [token] _dummyList[:] = [] del _dummyList _dummyList = [triple] _dummyList[:] = [] del _dummyList _dummyList = [attr] _dummyList[:] = [] del _dummyList pass
def test_XMLNode_namespace_remove(self): triple = libsbml.XMLTriple("test", "", "") attr = libsbml.XMLAttributes() node = libsbml.XMLNode(triple, attr) node.addNamespace("http://test1.org/", "test1") node.addNamespace("http://test2.org/", "test2") node.addNamespace("http://test3.org/", "test3") node.addNamespace("http://test4.org/", "test4") node.addNamespace("http://test5.org/", "test5") self.assert_(node.getNamespacesLength() == 5) node.removeNamespace(4) self.assert_(node.getNamespacesLength() == 4) node.removeNamespace(3) self.assert_(node.getNamespacesLength() == 3) node.removeNamespace(2) self.assert_(node.getNamespacesLength() == 2) node.removeNamespace(1) self.assert_(node.getNamespacesLength() == 1) node.removeNamespace(0) self.assert_(node.getNamespacesLength() == 0) node.addNamespace("http://test1.org/", "test1") node.addNamespace("http://test2.org/", "test2") node.addNamespace("http://test3.org/", "test3") node.addNamespace("http://test4.org/", "test4") node.addNamespace("http://test5.org/", "test5") self.assert_(node.getNamespacesLength() == 5) node.removeNamespace(0) self.assert_(node.getNamespacesLength() == 4) node.removeNamespace(0) self.assert_(node.getNamespacesLength() == 3) node.removeNamespace(0) self.assert_(node.getNamespacesLength() == 2) node.removeNamespace(0) self.assert_(node.getNamespacesLength() == 1) node.removeNamespace(0) self.assert_(node.getNamespacesLength() == 0) _dummyList = [node] _dummyList[:] = [] del _dummyList _dummyList = [triple] _dummyList[:] = [] del _dummyList _dummyList = [attr] _dummyList[:] = [] del _dummyList pass
def test_XMLToken_namespace_set_clear(self): triple = libsbml.XMLTriple("test", "", "") attr = libsbml.XMLAttributes() token = libsbml.XMLToken(triple, attr) ns = libsbml.XMLNamespaces() self.assert_(token.getNamespacesLength() == 0) self.assert_(token.isNamespacesEmpty() == True) ns.add("http://test1.org/", "test1") ns.add("http://test2.org/", "test2") ns.add("http://test3.org/", "test3") ns.add("http://test4.org/", "test4") ns.add("http://test5.org/", "test5") token.setNamespaces(ns) self.assert_(token.getNamespacesLength() == 5) self.assert_(token.isNamespacesEmpty() == False) self.assert_(("test1" != token.getNamespacePrefix(0)) == False) self.assert_(("test2" != token.getNamespacePrefix(1)) == False) self.assert_(("test3" != token.getNamespacePrefix(2)) == False) self.assert_(("test4" != token.getNamespacePrefix(3)) == False) self.assert_(("test5" != token.getNamespacePrefix(4)) == False) self.assert_( ("http://test1.org/" != token.getNamespaceURI(0)) == False) self.assert_( ("http://test2.org/" != token.getNamespaceURI(1)) == False) self.assert_( ("http://test3.org/" != token.getNamespaceURI(2)) == False) self.assert_( ("http://test4.org/" != token.getNamespaceURI(3)) == False) self.assert_( ("http://test5.org/" != token.getNamespaceURI(4)) == False) token.clearNamespaces() self.assert_(token.getNamespacesLength() == 0) _dummyList = [ns] _dummyList[:] = [] del _dummyList _dummyList = [token] _dummyList[:] = [] del _dummyList _dummyList = [triple] _dummyList[:] = [] del _dummyList _dummyList = [attr] _dummyList[:] = [] del _dummyList pass
def rFromFlux(flux): fluxSBML = libsbml.XMLNode() triple = libsbml.XMLTriple("flux", "", "") att = libsbml.XMLAttributes() att.add( "forward", str(flux.forward) ) # Forcing string conversion to invoke __str__ for rangedNumber att.add("backward", str(flux.backward)) att.add("net", str(flux.net)) att.add("exchange", str(flux.exchange)) ns = libsbml.XMLNamespaces() token = libsbml.XMLToken(triple, att, ns) fluxNode = libsbml.XMLNode(token) fluxSBML.addChild(fluxNode) return [fluxSBML]
def test_XMLAttributes_clear1(self): xa = libsbml.XMLAttributes() xt2 = libsbml.XMLTriple("name2", "http://name2.org/", "p2") i = xa.add("name1", "val1", "http://name1.org/", "p1") i = xa.add(xt2, "val2") i = xa.add("noprefix", "val3") self.assert_(xa.getLength() == 3) self.assert_(xa.isEmpty() == False) i = xa.clear() self.assert_(i == libsbml.LIBSBML_OPERATION_SUCCESS) self.assert_(xa.getLength() == 0) self.assert_(xa.isEmpty() == True) _dummyList = [xa] _dummyList[:] = [] del _dummyList _dummyList = [xt2] _dummyList[:] = [] del _dummyList pass
def test_XMLAttributes_add_get(self): attrs = libsbml.XMLAttributes() self.assert_(attrs.getLength() == 0) self.assertEqual(True, attrs.isEmpty()) attrs.add("xmlns", "http://foo.org/") self.assert_(attrs.getLength() == 1) self.assert_(attrs.isEmpty() == False) attrs.add("foo", "bar") self.assert_(attrs.getLength() == 2) self.assert_(attrs.isEmpty() == False) self.assert_(attrs.getIndex("xmlns") == 0) self.assert_(attrs.getIndex("foo") == 1) self.assert_(attrs.getIndex("bar") == -1) self.assert_(attrs.getValue("xmlns") == "http://foo.org/") self.assert_(attrs.getValue("foo") == "bar") self.assert_(attrs.getValue("bar") == "") self.assert_(attrs.getName(0) == "xmlns") self.assert_(attrs.getName(1) == "foo") self.assert_(attrs.getName(2) == "") pass
def test_XMLToken_newSetters_addAttributes1(self): triple = libsbml.XMLTriple("test", "", "") attr = libsbml.XMLAttributes() token = libsbml.XMLToken(triple, attr) xt2 = libsbml.XMLTriple("name3", "http://name3.org/", "p3") i = token.addAttr("name1", "val1") self.assert_(i == libsbml.LIBSBML_OPERATION_SUCCESS) self.assert_(token.getAttributesLength() == 1) self.assert_(token.isAttributesEmpty() == False) self.assert_(("name1" != token.getAttrName(0)) == False) self.assert_(("val1" != token.getAttrValue(0)) == False) i = token.addAttr("name2", "val2", "http://name1.org/", "p1") self.assert_(i == libsbml.LIBSBML_OPERATION_SUCCESS) self.assert_(token.getAttributesLength() == 2) self.assert_(token.isAttributesEmpty() == False) self.assert_(("name2" != token.getAttrName(1)) == False) self.assert_(("val2" != token.getAttrValue(1)) == False) self.assert_(("http://name1.org/" != token.getAttrURI(1)) == False) self.assert_(("p1" != token.getAttrPrefix(1)) == False) i = token.addAttr(xt2, "val2") self.assert_(i == libsbml.LIBSBML_OPERATION_SUCCESS) self.assert_(token.getAttributesLength() == 3) self.assert_(token.isAttributesEmpty() == False) self.assert_(("name3" != token.getAttrName(2)) == False) self.assert_(("val2" != token.getAttrValue(2)) == False) self.assert_(("http://name3.org/" != token.getAttrURI(2)) == False) self.assert_(("p3" != token.getAttrPrefix(2)) == False) _dummyList = [xt2] _dummyList[:] = [] del _dummyList _dummyList = [triple] _dummyList[:] = [] del _dummyList _dummyList = [attr] _dummyList[:] = [] del _dummyList _dummyList = [token] _dummyList[:] = [] del _dummyList pass
def test_XMLToken_newSetters_setAttributes2(self): triple = libsbml.XMLTriple("test", "", "") token = libsbml.XMLToken(triple) nattr = libsbml.XMLAttributes() xt1 = libsbml.XMLTriple("name1", "http://name1.org/", "p1") nattr.add(xt1, "val1") i = token.setAttributes(nattr) self.assert_(i == libsbml.LIBSBML_INVALID_XML_OPERATION) self.assert_(token.isAttributesEmpty() == True) _dummyList = [nattr] _dummyList[:] = [] del _dummyList _dummyList = [triple] _dummyList[:] = [] del _dummyList _dummyList = [token] _dummyList[:] = [] del _dummyList _dummyList = [xt1] _dummyList[:] = [] del _dummyList pass
def test_XMLToken_newSetters_removeNamespaces1(self): triple = libsbml.XMLTriple("test", "", "") attr = libsbml.XMLAttributes() token = libsbml.XMLToken(triple, attr) token.addNamespace("http://test1.org/", "test1") self.assert_(token.getNamespacesLength() == 1) i = token.removeNamespace("test2") self.assert_(i == libsbml.LIBSBML_INDEX_EXCEEDS_SIZE) self.assert_(token.getNamespacesLength() == 1) i = token.removeNamespace("test1") self.assert_(i == libsbml.LIBSBML_OPERATION_SUCCESS) self.assert_(token.getNamespacesLength() == 0) _dummyList = [token] _dummyList[:] = [] del _dummyList _dummyList = [triple] _dummyList[:] = [] del _dummyList _dummyList = [attr] _dummyList[:] = [] del _dummyList pass
def test_SyntaxChecker_validXHTML(self): NS24 = libsbml.SBMLNamespaces(2,4) NS31 = libsbml.SBMLNamespaces(3,1) toptriple = libsbml.XMLTriple("notes", "", "") triple = libsbml.XMLTriple("p", "", "") att = libsbml.XMLAttributes() ns = libsbml.XMLNamespaces() ns.add( "http://www.w3.org/1999/xhtml", "") tt = libsbml.XMLToken("This is my text") n1 = libsbml.XMLNode(tt) toptoken = libsbml.XMLToken(toptriple,att) topnode = libsbml.XMLNode(toptoken) token = libsbml.XMLToken(triple,att,ns) node = libsbml.XMLNode(token) node.addChild(n1) topnode.addChild(node) self.assert_( libsbml.SyntaxChecker.hasExpectedXHTMLSyntax(topnode,None) == True ) self.assert_( libsbml.SyntaxChecker.hasExpectedXHTMLSyntax(topnode,NS24) == True ) self.assert_( libsbml.SyntaxChecker.hasExpectedXHTMLSyntax(topnode,NS31) == True ) triple = libsbml.XMLTriple("html", "", "") token = libsbml.XMLToken(triple,att,ns) node = libsbml.XMLNode(token) node.addChild(n1) topnode.removeChild(0) topnode.addChild(node) self.assert_( libsbml.SyntaxChecker.hasExpectedXHTMLSyntax(topnode,None) == True ) self.assert_( libsbml.SyntaxChecker.hasExpectedXHTMLSyntax(topnode,NS24) == False ) self.assert_( libsbml.SyntaxChecker.hasExpectedXHTMLSyntax(topnode,NS31) == True ) triple = libsbml.XMLTriple("html", "", "") ns.clear() token = libsbml.XMLToken(triple,att,ns) node = libsbml.XMLNode(token) node.addChild(n1) topnode.removeChild(0) topnode.addChild(node) self.assert_( libsbml.SyntaxChecker.hasExpectedXHTMLSyntax(topnode,None) == False ) self.assert_( libsbml.SyntaxChecker.hasExpectedXHTMLSyntax(topnode,NS24) == False ) self.assert_( libsbml.SyntaxChecker.hasExpectedXHTMLSyntax(topnode,NS31) == False ) pass
def test_XMLNode_getters(self): NS = libsbml.XMLNamespaces() NS.add("http://test1.org/", "test1") token = libsbml.XMLToken("This is a test") node = libsbml.XMLNode(token) self.assert_(node != None) self.assert_(node.getNumChildren() == 0) self.assert_(("This is a test" != node.getCharacters()) == False) self.assert_(node.getChild(1) != None) attr = libsbml.XMLAttributes() self.assert_(attr != None) attr.add("attr2", "value") triple = libsbml.XMLTriple("attr", "uri", "prefix") token = libsbml.XMLToken(triple, attr) self.assert_(token != None) node = libsbml.XMLNode(token) self.assert_(("attr" != node.getName()) == False) self.assert_(("uri" != node.getURI()) == False) self.assert_(("prefix" != node.getPrefix()) == False) returnattr = node.getAttributes() self.assert_(("attr2" != returnattr.getName(0)) == False) self.assert_(("value" != returnattr.getValue(0)) == False) token = libsbml.XMLToken(triple, attr, NS) node = libsbml.XMLNode(token) returnNS = node.getNamespaces() self.assert_(returnNS.getLength() == 1) self.assert_(returnNS.isEmpty() == False) _dummyList = [triple] _dummyList[:] = [] del _dummyList _dummyList = [token] _dummyList[:] = [] del _dummyList _dummyList = [node] _dummyList[:] = [] del _dummyList pass
def test_XMLNode_remove(self): attr = libsbml.XMLAttributes() trp_p = libsbml.XMLTriple("parent", "", "") trp_c1 = libsbml.XMLTriple("child1", "", "") trp_c2 = libsbml.XMLTriple("child2", "", "") trp_c3 = libsbml.XMLTriple("child3", "", "") trp_c4 = libsbml.XMLTriple("child4", "", "") trp_c5 = libsbml.XMLTriple("child5", "", "") p = libsbml.XMLNode(trp_p, attr) c1 = libsbml.XMLNode(trp_c1, attr) c2 = libsbml.XMLNode(trp_c2, attr) c3 = libsbml.XMLNode(trp_c3, attr) c4 = libsbml.XMLNode(trp_c4, attr) c5 = libsbml.XMLNode(trp_c5, attr) p.addChild(c1) p.addChild(c2) p.addChild(c3) p.addChild(c4) p.addChild(c5) r = p.removeChild(5) self.assert_(r == None) r = p.removeChild(1) self.assert_(p.getNumChildren() == 4) self.assert_(("child2" != r.getName()) == False) _dummyList = [r] _dummyList[:] = [] del _dummyList r = p.removeChild(3) self.assert_(p.getNumChildren() == 3) self.assert_(("child5" != r.getName()) == False) _dummyList = [r] _dummyList[:] = [] del _dummyList r = p.removeChild(0) self.assert_(p.getNumChildren() == 2) self.assert_(("child1" != r.getName()) == False) _dummyList = [r] _dummyList[:] = [] del _dummyList r = p.removeChild(1) self.assert_(p.getNumChildren() == 1) self.assert_(("child4" != r.getName()) == False) _dummyList = [r] _dummyList[:] = [] del _dummyList r = p.removeChild(0) self.assert_(p.getNumChildren() == 0) self.assert_(("child3" != r.getName()) == False) _dummyList = [r] _dummyList[:] = [] del _dummyList p.addChild(c1) p.addChild(c2) p.addChild(c3) p.addChild(c4) p.addChild(c5) r = p.removeChild(4) self.assert_(p.getNumChildren() == 4) self.assert_(("child5" != r.getName()) == False) _dummyList = [r] _dummyList[:] = [] del _dummyList r = p.removeChild(3) self.assert_(p.getNumChildren() == 3) self.assert_(("child4" != r.getName()) == False) _dummyList = [r] _dummyList[:] = [] del _dummyList r = p.removeChild(2) self.assert_(p.getNumChildren() == 2) self.assert_(("child3" != r.getName()) == False) _dummyList = [r] _dummyList[:] = [] del _dummyList r = p.removeChild(1) self.assert_(p.getNumChildren() == 1) self.assert_(("child2" != r.getName()) == False) _dummyList = [r] _dummyList[:] = [] del _dummyList r = p.removeChild(0) self.assert_(p.getNumChildren() == 0) self.assert_(("child1" != r.getName()) == False) _dummyList = [r] _dummyList[:] = [] del _dummyList p.addChild(c1) p.addChild(c2) p.addChild(c3) p.addChild(c4) p.addChild(c5) r = p.removeChild(0) self.assert_(p.getNumChildren() == 4) self.assert_(("child1" != r.getName()) == False) _dummyList = [r] _dummyList[:] = [] del _dummyList r = p.removeChild(0) self.assert_(p.getNumChildren() == 3) self.assert_(("child2" != r.getName()) == False) _dummyList = [r] _dummyList[:] = [] del _dummyList r = p.removeChild(0) self.assert_(p.getNumChildren() == 2) self.assert_(("child3" != r.getName()) == False) _dummyList = [r] _dummyList[:] = [] del _dummyList r = p.removeChild(0) self.assert_(p.getNumChildren() == 1) self.assert_(("child4" != r.getName()) == False) _dummyList = [r] _dummyList[:] = [] del _dummyList r = p.removeChild(0) self.assert_(p.getNumChildren() == 0) self.assert_(("child5" != r.getName()) == False) _dummyList = [r] _dummyList[:] = [] del _dummyList p.addChild(c1) p.addChild(c2) p.addChild(c3) p.addChild(c4) p.addChild(c5) r = p.removeChild(0) self.assert_(("child1" != r.getName()) == False) p.insertChild(0, r) self.assert_(p.getNumChildren() == 5) self.assert_(("child1" != p.getChild(0).getName()) == False) _dummyList = [r] _dummyList[:] = [] del _dummyList r = p.removeChild(1) self.assert_(("child2" != r.getName()) == False) p.insertChild(1, r) self.assert_(p.getNumChildren() == 5) self.assert_(("child2" != p.getChild(1).getName()) == False) _dummyList = [r] _dummyList[:] = [] del _dummyList r = p.removeChild(2) self.assert_(("child3" != r.getName()) == False) p.insertChild(2, r) self.assert_(p.getNumChildren() == 5) self.assert_(("child3" != p.getChild(2).getName()) == False) _dummyList = [r] _dummyList[:] = [] del _dummyList r = p.removeChild(3) self.assert_(("child4" != r.getName()) == False) p.insertChild(3, r) self.assert_(p.getNumChildren() == 5) self.assert_(("child4" != p.getChild(3).getName()) == False) _dummyList = [r] _dummyList[:] = [] del _dummyList r = p.removeChild(4) self.assert_(("child5" != r.getName()) == False) p.insertChild(4, r) self.assert_(p.getNumChildren() == 5) self.assert_(("child5" != p.getChild(4).getName()) == False) _dummyList = [r] _dummyList[:] = [] del _dummyList _dummyList = [p] _dummyList[:] = [] del _dummyList _dummyList = [c1] _dummyList[:] = [] del _dummyList _dummyList = [c2] _dummyList[:] = [] del _dummyList _dummyList = [c3] _dummyList[:] = [] del _dummyList _dummyList = [c4] _dummyList[:] = [] del _dummyList _dummyList = [c5] _dummyList[:] = [] del _dummyList _dummyList = [attr] _dummyList[:] = [] del _dummyList _dummyList = [trp_p] _dummyList[:] = [] del _dummyList _dummyList = [trp_c1] _dummyList[:] = [] del _dummyList _dummyList = [trp_c2] _dummyList[:] = [] del _dummyList _dummyList = [trp_c3] _dummyList[:] = [] del _dummyList _dummyList = [trp_c4] _dummyList[:] = [] del _dummyList _dummyList = [trp_c5] _dummyList[:] = [] del _dummyList pass
def test_XMLNode_createElement(self): name = "test" uri = "http://test.org/" prefix = "p" text = "text node" triple = libsbml.XMLTriple(name, uri, prefix) ns = libsbml.XMLNamespaces() attr = libsbml.XMLAttributes() ns.add(uri, prefix) attr.add("id", "value", uri, prefix) snode = libsbml.XMLNode(triple, attr, ns) self.assert_(snode != None) self.assert_(snode.getNumChildren() == 0) self.assert_((name != snode.getName()) == False) self.assert_((prefix != snode.getPrefix()) == False) self.assert_((uri != snode.getURI()) == False) self.assert_(snode.isElement() == True) self.assert_(snode.isStart() == True) self.assert_(snode.isEnd() == False) self.assert_(snode.isText() == False) snode.setEnd() self.assert_(snode.isEnd() == True) snode.unsetEnd() self.assert_(snode.isEnd() == False) cattr = snode.getAttributes() self.assert_(cattr != None) self.assert_(("id" != cattr.getName(0)) == False) self.assert_(("value" != cattr.getValue(0)) == False) self.assert_((prefix != cattr.getPrefix(0)) == False) self.assert_((uri != cattr.getURI(0)) == False) _dummyList = [triple] _dummyList[:] = [] del _dummyList _dummyList = [attr] _dummyList[:] = [] del _dummyList _dummyList = [ns] _dummyList[:] = [] del _dummyList _dummyList = [snode] _dummyList[:] = [] del _dummyList attr = libsbml.XMLAttributes() attr.add("id", "value") triple = libsbml.XMLTriple(name, "", "") snode = libsbml.XMLNode(triple, attr) self.assert_(snode != None) self.assert_(snode.getNumChildren() == 0) self.assert_(("test" != snode.getName()) == False) self.assert_(snode.getPrefix() == "") self.assert_(snode.getURI() == "") self.assert_(snode.isElement() == True) self.assert_(snode.isStart() == True) self.assert_(snode.isEnd() == False) self.assert_(snode.isText() == False) cattr = snode.getAttributes() self.assert_(cattr != None) self.assert_(("id" != cattr.getName(0)) == False) self.assert_(("value" != cattr.getValue(0)) == False) self.assert_(cattr.getPrefix(0) == "") self.assert_(cattr.getURI(0) == "") enode = libsbml.XMLNode(triple) self.assert_(enode != None) self.assert_(enode.getNumChildren() == 0) self.assert_(("test" != enode.getName()) == False) self.assert_(enode.getPrefix() == "") self.assert_(enode.getURI() == "") self.assert_(enode.isElement() == True) self.assert_(enode.isStart() == False) self.assert_(enode.isEnd() == True) self.assert_(enode.isText() == False) tnode = libsbml.XMLNode(text) self.assert_(tnode != None) self.assert_((text != tnode.getCharacters()) == False) self.assert_(tnode.getNumChildren() == 0) self.assert_(tnode.getName() == "") self.assert_(tnode.getPrefix() == "") self.assert_(tnode.getURI() == "") self.assert_(tnode.isElement() == False) self.assert_(tnode.isStart() == False) self.assert_(tnode.isEnd() == False) self.assert_(tnode.isText() == True) _dummyList = [triple] _dummyList[:] = [] del _dummyList _dummyList = [attr] _dummyList[:] = [] del _dummyList _dummyList = [snode] _dummyList[:] = [] del _dummyList _dummyList = [enode] _dummyList[:] = [] del _dummyList _dummyList = [tnode] _dummyList[:] = [] del _dummyList pass
def test_XMLNode_attribute_add_remove(self): triple = libsbml.XMLTriple("test", "", "") attr = libsbml.XMLAttributes() node = libsbml.XMLNode(triple, attr) xt1 = libsbml.XMLTriple("name1", "http://name1.org/", "p1") xt2 = libsbml.XMLTriple("name2", "http://name2.org/", "p2") xt3 = libsbml.XMLTriple("name3", "http://name3.org/", "p3") xt1a = libsbml.XMLTriple("name1", "http://name1a.org/", "p1a") xt2a = libsbml.XMLTriple("name2", "http://name2a.org/", "p2a") node.addAttr("name1", "val1", "http://name1.org/", "p1") node.addAttr(xt2, "val2") self.assert_(node.getAttributesLength() == 2) self.assert_(node.isAttributesEmpty() == False) self.assert_(("name1" != node.getAttrName(0)) == False) self.assert_(("val1" != node.getAttrValue(0)) == False) self.assert_(("http://name1.org/" != node.getAttrURI(0)) == False) self.assert_(("p1" != node.getAttrPrefix(0)) == False) self.assert_(("name2" != node.getAttrName(1)) == False) self.assert_(("val2" != node.getAttrValue(1)) == False) self.assert_(("http://name2.org/" != node.getAttrURI(1)) == False) self.assert_(("p2" != node.getAttrPrefix(1)) == False) self.assert_(node.getAttrValue("name1") == "") self.assert_(node.getAttrValue("name2") == "") self.assert_(("val1" != node.getAttrValue("name1", "http://name1.org/") ) == False) self.assert_(("val2" != node.getAttrValue("name2", "http://name2.org/") ) == False) self.assert_(("val1" != node.getAttrValue(xt1)) == False) self.assert_(("val2" != node.getAttrValue(xt2)) == False) self.assert_(node.hasAttr(-1) == False) self.assert_(node.hasAttr(2) == False) self.assert_(node.hasAttr(0) == True) self.assert_(node.hasAttr("name1", "http://name1.org/") == True) self.assert_(node.hasAttr("name2", "http://name2.org/") == True) self.assert_(node.hasAttr("name3", "http://name3.org/") == False) self.assert_(node.hasAttr(xt1) == True) self.assert_(node.hasAttr(xt2) == True) self.assert_(node.hasAttr(xt3) == False) node.addAttr("noprefix", "val3") self.assert_(node.getAttributesLength() == 3) self.assert_(node.isAttributesEmpty() == False) self.assert_(("noprefix" != node.getAttrName(2)) == False) self.assert_(("val3" != node.getAttrValue(2)) == False) self.assert_(node.getAttrURI(2) == "") self.assert_(node.getAttrPrefix(2) == "") self.assert_(("val3" != node.getAttrValue("noprefix")) == False) self.assert_(("val3" != node.getAttrValue("noprefix", "")) == False) self.assert_(node.hasAttr("noprefix") == True) self.assert_(node.hasAttr("noprefix", "") == True) node.addAttr(xt1, "mval1") node.addAttr("name2", "mval2", "http://name2.org/", "p2") self.assert_(node.getAttributesLength() == 3) self.assert_(node.isAttributesEmpty() == False) self.assert_(("name1" != node.getAttrName(0)) == False) self.assert_(("mval1" != node.getAttrValue(0)) == False) self.assert_(("http://name1.org/" != node.getAttrURI(0)) == False) self.assert_(("p1" != node.getAttrPrefix(0)) == False) self.assert_(("name2" != node.getAttrName(1)) == False) self.assert_(("mval2" != node.getAttrValue(1)) == False) self.assert_(("http://name2.org/" != node.getAttrURI(1)) == False) self.assert_(("p2" != node.getAttrPrefix(1)) == False) self.assert_(node.hasAttr(xt1) == True) self.assert_(node.hasAttr("name1", "http://name1.org/") == True) node.addAttr("noprefix", "mval3") self.assert_(node.getAttributesLength() == 3) self.assert_(node.isAttributesEmpty() == False) self.assert_(("noprefix" != node.getAttrName(2)) == False) self.assert_(("mval3" != node.getAttrValue(2)) == False) self.assert_(node.getAttrURI(2) == "") self.assert_(node.getAttrPrefix(2) == "") self.assert_(node.hasAttr("noprefix") == True) self.assert_(node.hasAttr("noprefix", "") == True) node.addAttr(xt1a, "val1a") node.addAttr(xt2a, "val2a") self.assert_(node.getAttributesLength() == 5) self.assert_(("name1" != node.getAttrName(3)) == False) self.assert_(("val1a" != node.getAttrValue(3)) == False) self.assert_(("http://name1a.org/" != node.getAttrURI(3)) == False) self.assert_(("p1a" != node.getAttrPrefix(3)) == False) self.assert_(("name2" != node.getAttrName(4)) == False) self.assert_(("val2a" != node.getAttrValue(4)) == False) self.assert_(("http://name2a.org/" != node.getAttrURI(4)) == False) self.assert_(("p2a" != node.getAttrPrefix(4)) == False) self.assert_( ("val1a" != node.getAttrValue("name1", "http://name1a.org/") ) == False) self.assert_( ("val2a" != node.getAttrValue("name2", "http://name2a.org/") ) == False) self.assert_(("val1a" != node.getAttrValue(xt1a)) == False) self.assert_(("val2a" != node.getAttrValue(xt2a)) == False) node.removeAttr(xt1a) node.removeAttr(xt2a) self.assert_(node.getAttributesLength() == 3) node.removeAttr("name1", "http://name1.org/") self.assert_(node.getAttributesLength() == 2) self.assert_(node.isAttributesEmpty() == False) self.assert_(("name2" != node.getAttrName(0)) == False) self.assert_(("mval2" != node.getAttrValue(0)) == False) self.assert_(("http://name2.org/" != node.getAttrURI(0)) == False) self.assert_(("p2" != node.getAttrPrefix(0)) == False) self.assert_(("noprefix" != node.getAttrName(1)) == False) self.assert_(("mval3" != node.getAttrValue(1)) == False) self.assert_(node.getAttrURI(1) == "") self.assert_(node.getAttrPrefix(1) == "") self.assert_(node.hasAttr("name1", "http://name1.org/") == False) node.removeAttr(xt2) self.assert_(node.getAttributesLength() == 1) self.assert_(node.isAttributesEmpty() == False) self.assert_(("noprefix" != node.getAttrName(0)) == False) self.assert_(("mval3" != node.getAttrValue(0)) == False) self.assert_(node.getAttrURI(0) == "") self.assert_(node.getAttrPrefix(0) == "") self.assert_(node.hasAttr(xt2) == False) self.assert_(node.hasAttr("name2", "http://name2.org/") == False) node.removeAttr("noprefix") self.assert_(node.getAttributesLength() == 0) self.assert_(node.isAttributesEmpty() == True) self.assert_(node.hasAttr("noprefix") == False) self.assert_(node.hasAttr("noprefix", "") == False) _dummyList = [node] _dummyList[:] = [] del _dummyList _dummyList = [xt1] _dummyList[:] = [] del _dummyList _dummyList = [xt2] _dummyList[:] = [] del _dummyList _dummyList = [xt3] _dummyList[:] = [] del _dummyList _dummyList = [xt1a] _dummyList[:] = [] del _dummyList _dummyList = [xt2a] _dummyList[:] = [] del _dummyList _dummyList = [triple] _dummyList[:] = [] del _dummyList _dummyList = [attr] _dummyList[:] = [] del _dummyList pass
def test_XMLNode_attribute_set_clear(self): triple = libsbml.XMLTriple("test", "", "") attr = libsbml.XMLAttributes() node = libsbml.XMLNode(triple, attr) nattr = libsbml.XMLAttributes() xt1 = libsbml.XMLTriple("name1", "http://name1.org/", "p1") xt2 = libsbml.XMLTriple("name2", "http://name2.org/", "p2") xt3 = libsbml.XMLTriple("name3", "http://name3.org/", "p3") xt4 = libsbml.XMLTriple("name4", "http://name4.org/", "p4") xt5 = libsbml.XMLTriple("name5", "http://name5.org/", "p5") nattr.add(xt1, "val1") nattr.add(xt2, "val2") nattr.add(xt3, "val3") nattr.add(xt4, "val4") nattr.add(xt5, "val5") node.setAttributes(nattr) self.assert_(node.getAttributesLength() == 5) self.assert_(node.isAttributesEmpty() == False) self.assert_(("name1" != node.getAttrName(0)) == False) self.assert_(("val1" != node.getAttrValue(0)) == False) self.assert_(("http://name1.org/" != node.getAttrURI(0)) == False) self.assert_(("p1" != node.getAttrPrefix(0)) == False) self.assert_(("name2" != node.getAttrName(1)) == False) self.assert_(("val2" != node.getAttrValue(1)) == False) self.assert_(("http://name2.org/" != node.getAttrURI(1)) == False) self.assert_(("p2" != node.getAttrPrefix(1)) == False) self.assert_(("name3" != node.getAttrName(2)) == False) self.assert_(("val3" != node.getAttrValue(2)) == False) self.assert_(("http://name3.org/" != node.getAttrURI(2)) == False) self.assert_(("p3" != node.getAttrPrefix(2)) == False) self.assert_(("name4" != node.getAttrName(3)) == False) self.assert_(("val4" != node.getAttrValue(3)) == False) self.assert_(("http://name4.org/" != node.getAttrURI(3)) == False) self.assert_(("p4" != node.getAttrPrefix(3)) == False) self.assert_(("name5" != node.getAttrName(4)) == False) self.assert_(("val5" != node.getAttrValue(4)) == False) self.assert_(("http://name5.org/" != node.getAttrURI(4)) == False) self.assert_(("p5" != node.getAttrPrefix(4)) == False) ntriple = libsbml.XMLTriple("test2", "http://test2.org/", "p2") node.setTriple(ntriple) self.assert_(("test2" != node.getName()) == False) self.assert_(("http://test2.org/" != node.getURI()) == False) self.assert_(("p2" != node.getPrefix()) == False) node.clearAttributes() self.assert_(node.getAttributesLength() == 0) self.assert_(node.isAttributesEmpty() != False) _dummyList = [triple] _dummyList[:] = [] del _dummyList _dummyList = [ntriple] _dummyList[:] = [] del _dummyList _dummyList = [node] _dummyList[:] = [] del _dummyList _dummyList = [attr] _dummyList[:] = [] del _dummyList _dummyList = [nattr] _dummyList[:] = [] del _dummyList _dummyList = [xt1] _dummyList[:] = [] del _dummyList _dummyList = [xt2] _dummyList[:] = [] del _dummyList _dummyList = [xt3] _dummyList[:] = [] del _dummyList _dummyList = [xt4] _dummyList[:] = [] del _dummyList _dummyList = [xt5] _dummyList[:] = [] del _dummyList pass
def test_XMLAttributes_add_remove_qname_C(self): xa = libsbml.XMLAttributes() xt1 = libsbml.XMLTriple("name1", "http://name1.org/", "p1") xt2 = libsbml.XMLTriple("name2", "http://name2.org/", "p2") xt3 = libsbml.XMLTriple("name3", "http://name3.org/", "p3") xt1a = libsbml.XMLTriple("name1", "http://name1a.org/", "p1a") xt2a = libsbml.XMLTriple("name2", "http://name2a.org/", "p2a") xa.add("name1", "val1", "http://name1.org/", "p1") xa.add(xt2, "val2") self.assert_(xa.getLength() == 2) self.assert_(xa.isEmpty() == False) self.assert_(("name1" != xa.getName(0)) == False) self.assert_(("val1" != xa.getValue(0)) == False) self.assert_(("http://name1.org/" != xa.getURI(0)) == False) self.assert_(("p1" != xa.getPrefix(0)) == False) self.assert_(("name2" != xa.getName(1)) == False) self.assert_(("val2" != xa.getValue(1)) == False) self.assert_(("http://name2.org/" != xa.getURI(1)) == False) self.assert_(("p2" != xa.getPrefix(1)) == False) self.assert_(("val1" != xa.getValue("name1")) == False) self.assert_(("val2" != xa.getValue("name2")) == False) self.assert_( ("val1" != xa.getValue("name1", "http://name1.org/")) == False) self.assert_( ("val2" != xa.getValue("name2", "http://name2.org/")) == False) self.assert_(("val1" != xa.getValue(xt1)) == False) self.assert_(("val2" != xa.getValue(xt2)) == False) self.assert_(xa.hasAttribute(-1) == False) self.assert_(xa.hasAttribute(2) == False) self.assert_(xa.hasAttribute(0) == True) self.assert_(xa.hasAttribute("name1", "http://name1.org/") == True) self.assert_(xa.hasAttribute("name2", "http://name2.org/") == True) self.assert_(xa.hasAttribute("name3", "http://name3.org/") == False) self.assert_(xa.hasAttribute(xt1) == True) self.assert_(xa.hasAttribute(xt2) == True) self.assert_(xa.hasAttribute(xt3) == False) xa.add("noprefix", "val3") self.assert_(xa.getLength() == 3) self.assert_(xa.isEmpty() == False) self.assert_(("noprefix" != xa.getName(2)) == False) self.assert_(("val3" != xa.getValue(2)) == False) self.assert_(xa.getURI(2) == "") self.assert_(xa.getPrefix(2) == "") self.assert_(("val3" != xa.getValue("noprefix", "")) == False) self.assert_(xa.hasAttribute("noprefix") == True) self.assert_(xa.hasAttribute("noprefix", "") == True) xa.add(xt1, "mval1") xa.add("name2", "mval2", "http://name2.org/", "p2") xa.add("noprefix", "mval3") self.assert_(xa.getLength() == 3) self.assert_(xa.isEmpty() == False) self.assert_(("name1" != xa.getName(0)) == False) self.assert_(("mval1" != xa.getValue(0)) == False) self.assert_(("http://name1.org/" != xa.getURI(0)) == False) self.assert_(("p1" != xa.getPrefix(0)) == False) self.assert_(("name2" != xa.getName(1)) == False) self.assert_(("mval2" != xa.getValue(1)) == False) self.assert_(("http://name2.org/" != xa.getURI(1)) == False) self.assert_(("p2" != xa.getPrefix(1)) == False) self.assert_(("noprefix" != xa.getName(2)) == False) self.assert_(("mval3" != xa.getValue(2)) == False) self.assert_(xa.getURI(2) == "") self.assert_(xa.getPrefix(2) == "") self.assert_(xa.hasAttribute(xt1) == True) self.assert_(xa.hasAttribute("name1", "http://name1.org/") == True) self.assert_(xa.hasAttribute("noprefix") == True) xa.add(xt1a, "val1a") xa.add(xt2a, "val2a") self.assert_(xa.getLength() == 5) self.assert_(("name1" != xa.getName(3)) == False) self.assert_(("val1a" != xa.getValue(3)) == False) self.assert_(("http://name1a.org/" != xa.getURI(3)) == False) self.assert_(("p1a" != xa.getPrefix(3)) == False) self.assert_(("name2" != xa.getName(4)) == False) self.assert_(("val2a" != xa.getValue(4)) == False) self.assert_(("http://name2a.org/" != xa.getURI(4)) == False) self.assert_(("p2a" != xa.getPrefix(4)) == False) self.assert_(("mval1" != xa.getValue("name1")) == False) self.assert_(("mval2" != xa.getValue("name2")) == False) self.assert_( ("val1a" != xa.getValue("name1", "http://name1a.org/")) == False) self.assert_( ("val2a" != xa.getValue("name2", "http://name2a.org/")) == False) self.assert_(("val1a" != xa.getValue(xt1a)) == False) self.assert_(("val2a" != xa.getValue(xt2a)) == False) xa.remove(xt1a) xa.remove(xt2a) self.assert_(xa.getLength() == 3) xa.remove("name1", "http://name1.org/") self.assert_(xa.getLength() == 2) self.assert_(xa.isEmpty() == False) self.assert_(("name2" != xa.getName(0)) == False) self.assert_(("mval2" != xa.getValue(0)) == False) self.assert_(("http://name2.org/" != xa.getURI(0)) == False) self.assert_(("p2" != xa.getPrefix(0)) == False) self.assert_(("noprefix" != xa.getName(1)) == False) self.assert_(("mval3" != xa.getValue(1)) == False) self.assert_(xa.getURI(1) == "") self.assert_(xa.getPrefix(1) == "") self.assert_(xa.hasAttribute("name1", "http://name1.org/") == False) xa.remove(xt2) self.assert_(xa.getLength() == 1) self.assert_(xa.isEmpty() == False) self.assert_(("noprefix" != xa.getName(0)) == False) self.assert_(("mval3" != xa.getValue(0)) == False) self.assert_(xa.getURI(0) == "") self.assert_(xa.getPrefix(0) == "") self.assert_(xa.hasAttribute(xt2) == False) self.assert_(xa.hasAttribute("name2", "http://name2.org/") == False) xa.remove("noprefix", "") self.assert_(xa.getLength() == 0) self.assert_(xa.isEmpty() == True) self.assert_(xa.hasAttribute("noprefix") == False) self.assert_(xa.hasAttribute("noprefix", "") == False) _dummyList = [xa] _dummyList[:] = [] del _dummyList _dummyList = [xt1] _dummyList[:] = [] del _dummyList _dummyList = [xt2] _dummyList[:] = [] del _dummyList _dummyList = [xt3] _dummyList[:] = [] del _dummyList _dummyList = [xt1a] _dummyList[:] = [] del _dummyList _dummyList = [xt2a] _dummyList[:] = [] del _dummyList pass