Ejemplo n.º 1
0
 def test_UnitDefinition_copyConstructor(self):
   o1 = libsbml.UnitDefinition(2,4)
   o1.setId("c")
   self.assert_( o1.getId() ==  "c" )
   o2 = libsbml.UnitDefinition(o1)
   self.assert_( o2.getId() ==  "c" )
   self.assert_( o2.getParentSBMLObject() == o1.getParentSBMLObject() )
   o2 = None
   o1 = None
   pass  
Ejemplo n.º 2
0
 def test_UnitDefinition_assignmentOperator(self):
   o1 = libsbml.UnitDefinition(2,4)
   o1.setId("c")
   self.assert_( o1.getId() ==  "c" )
   o2 = libsbml.UnitDefinition(2,4)
   o2 = o1
   self.assert_( o2.getId() ==  "c" )
   self.assert_( o2.getParentSBMLObject() == o1.getParentSBMLObject() )
   o2 = None
   o1 = None
   pass  
Ejemplo n.º 3
0
 def test_Model_getUnitDefinitionById(self):
     ud1 = libsbml.UnitDefinition(2, 4)
     ud2 = libsbml.UnitDefinition(2, 4)
     ud1.setId("mmls")
     ud2.setId("volume")
     ud1.createUnit()
     ud2.createUnit()
     self.M.addUnitDefinition(ud1)
     self.M.addUnitDefinition(ud2)
     self.assert_(self.M.getNumUnitDefinitions() == 2)
     self.assert_(self.M.getUnitDefinition("mmls") != ud1)
     self.assert_(self.M.getUnitDefinition("volume") != ud2)
     self.assert_(self.M.getUnitDefinition("rototillers") == None)
     pass
Ejemplo n.º 4
0
 def test_Model_add_get_UnitDefinitions(self):
     ud1 = libsbml.UnitDefinition(2, 4)
     ud2 = libsbml.UnitDefinition(2, 4)
     ud1.setId("ud1")
     ud2.setId("ud2")
     ud1.createUnit()
     ud2.createUnit()
     self.M.addUnitDefinition(ud1)
     self.M.addUnitDefinition(ud2)
     self.assert_(self.M.getNumUnitDefinitions() == 2)
     self.assert_(self.M.getUnitDefinition(0) != ud1)
     self.assert_(self.M.getUnitDefinition(1) != ud2)
     self.assert_(self.M.getUnitDefinition(2) == None)
     pass
Ejemplo n.º 5
0
 def test_Model_getUnitDefinition(self):
     ud1 = libsbml.UnitDefinition(2, 4)
     ud2 = libsbml.UnitDefinition(2, 4)
     ud1.setId("mmls")
     ud2.setId("volume")
     ud1.createUnit()
     ud2.createUnit()
     self.M.addUnitDefinition(ud1)
     self.M.addUnitDefinition(ud2)
     self.assert_(self.M.getNumUnitDefinitions() == 2)
     ud1 = self.M.getUnitDefinition(0)
     ud2 = self.M.getUnitDefinition(1)
     self.assert_(("mmls" == ud1.getId()))
     self.assert_(("volume" == ud2.getId()))
     pass
Ejemplo n.º 6
0
 def test_UnitDefinition_isVariantOfSubstancePerTime_4(self):
   ud = libsbml.UnitDefinition(2,2)
   dim = ud.createUnit()
   dim.setKind(libsbml.UnitKind_forName("dimensionless"))
   perTime = ud.createUnit()
   perTime.setKind(libsbml.UnitKind_forName("second"))
   perTime.setExponent(-1)
   u = ud.createUnit()
   self.assertEqual( False, ud.isVariantOfSubstancePerTime() )
   u.setKind(libsbml.UNIT_KIND_KILOGRAM)
   u.setExponent(1)
   self.assertEqual( True, ud.isVariantOfSubstancePerTime() )
   u.setScale(-1)
   perTime.setScale(-1)
   self.assertEqual( True, ud.isVariantOfSubstancePerTime() )
   u.setMultiplier(2)
   self.assertEqual( True, ud.isVariantOfSubstancePerTime() )
   u.setOffset(3)
   self.assertEqual( True, ud.isVariantOfSubstancePerTime() )
   u.setExponent(-3)
   self.assertEqual( False, ud.isVariantOfSubstancePerTime() )
   u.setExponent(1)
   perTime.setExponent(-3)
   self.assertEqual( False, ud.isVariantOfSubstancePerTime() )
   perTime.setExponent(-1)
   ud.addUnit(dim)
   self.assertEqual( True, ud.isVariantOfSubstancePerTime() )
   _dummyList = [ ud ]; _dummyList[:] = []; del _dummyList
   pass  
Ejemplo n.º 7
0
 def test_UnitDefinition(self):
     ud = libsbml.UnitDefinition(2, 4)
     self.assertEqual(False, (ud.hasRequiredAttributes()))
     ud.setId("ud")
     self.assertEqual(True, ud.hasRequiredAttributes())
     ud = None
     pass
Ejemplo n.º 8
0
 def test_UnitDefinition(self):
   ud = libsbml.UnitDefinition(2,4)
   self.assertEqual( False, (ud.hasRequiredElements()) )
   ud.createUnit()
   self.assertEqual( True, ud.hasRequiredElements() )
   ud = None
   pass  
Ejemplo n.º 9
0
 def test_UnitDefinition_createUnit(self):
   m = libsbml.UnitDefinition(2,2)
   p = m.createUnit()
   self.assert_( m.getNumUnits() == 1 )
   self.assert_( (p).getLevel() == 2 )
   self.assert_( (p).getVersion() == 2 )
   _dummyList = [ m ]; _dummyList[:] = []; del _dummyList
   pass  
Ejemplo n.º 10
0
 def test_UnitDefinition_addUnit4(self):
   m = libsbml.UnitDefinition(2,2)
   p = None
   i = m.addUnit(p)
   self.assert_( i == libsbml.LIBSBML_OPERATION_FAILED )
   self.assert_( m.getNumUnits() == 0 )
   _dummyList = [ m ]; _dummyList[:] = []; del _dummyList
   pass  
Ejemplo n.º 11
0
 def test_UnitDefinition_addUnit3(self):
   m = libsbml.UnitDefinition(2,2)
   p = libsbml.Unit(1,2)
   p.setKind(libsbml.UNIT_KIND_MOLE)
   i = m.addUnit(p)
   self.assert_( i == libsbml.LIBSBML_LEVEL_MISMATCH )
   self.assert_( m.getNumUnits() == 0 )
   _dummyList = [ p ]; _dummyList[:] = []; del _dummyList
   _dummyList = [ m ]; _dummyList[:] = []; del _dummyList
   pass  
Ejemplo n.º 12
0
 def test_Unit_parent_create(self):
     ud = libsbml.UnitDefinition(2, 4)
     u = ud.createUnit()
     self.assert_(ud.getNumUnits() == 1)
     lo = ud.getListOfUnits()
     self.assert_(lo == ud.getUnit(0).getParentSBMLObject())
     self.assert_(lo == u.getParentSBMLObject())
     self.assert_(ud == lo.getParentSBMLObject())
     ud = None
     pass
Ejemplo n.º 13
0
 def test_UnitDefinition_clone(self):
   o1 = libsbml.UnitDefinition(2,4)
   o1.setId("c")
   self.assert_( o1.getId() ==  "c" )
   o2 = o1.clone()
   self.assert_( o2.getId() ==  "c" )
   self.assert_( o2.getParentSBMLObject() == o1.getParentSBMLObject() )
   o2 = None
   o1 = None
   pass  
Ejemplo n.º 14
0
 def test_UnitDefinition_parent_add(self):
     ia = libsbml.UnitDefinition(2, 4)
     m = libsbml.Model(2, 4)
     ia.setId("u")
     ia.createUnit()
     m.addUnitDefinition(ia)
     ia = None
     lo = m.getListOfUnitDefinitions()
     self.assert_(lo == m.getUnitDefinition(0).getParentSBMLObject())
     self.assert_(m == lo.getParentSBMLObject())
     pass
Ejemplo n.º 15
0
 def test_Unit_parent_add(self):
     ud = libsbml.UnitDefinition(2, 4)
     u = libsbml.Unit(2, 4)
     u.setKind(libsbml.UNIT_KIND_MOLE)
     ud.addUnit(u)
     u = None
     self.assert_(ud.getNumUnits() == 1)
     lo = ud.getListOfUnits()
     self.assert_(lo == ud.getUnit(0).getParentSBMLObject())
     self.assert_(ud == lo.getParentSBMLObject())
     ud = None
     pass
Ejemplo n.º 16
0
 def test_UnitDefinition_addUnit1(self):
   m = libsbml.UnitDefinition(2,2)
   p = libsbml.Unit(2,2)
   i = m.addUnit(p)
   self.assert_( i == libsbml.LIBSBML_INVALID_OBJECT )
   p.setKind(libsbml.UNIT_KIND_MOLE)
   i = m.addUnit(p)
   self.assert_( i == libsbml.LIBSBML_OPERATION_SUCCESS )
   self.assert_( m.getNumUnits() == 1 )
   _dummyList = [ p ]; _dummyList[:] = []; del _dummyList
   _dummyList = [ m ]; _dummyList[:] = []; del _dummyList
   pass  
Ejemplo n.º 17
0
 def test_UnitDefinition_printUnits(self):
   ud = libsbml.UnitDefinition(2,4)
   ud.setId( "mmls")
   perTime = ud.createUnit()
   perTime.setKind(libsbml.UnitKind_forName("second"))
   perTime.setExponent(-1)
   ud_str = libsbml.UnitDefinition.printUnits(ud,False)
   self.assert_((                 "second (exponent = -1, multiplier = 1, scale = 0)" == ud_str ))
   ud_str1 = libsbml.UnitDefinition.printUnits(ud,True)
   self.assert_((  "(1 second)^-1" == ud_str1 ))
   ud1 = libsbml.UnitDefinition(2,4)
   ud1.setId( "mmls")
   u = ud1.createUnit()
   u.setKind(libsbml.UNIT_KIND_KILOGRAM)
   u.setExponent(1)
   u.setScale(2)
   u.setMultiplier(3.0)
   ud_str2 = libsbml.UnitDefinition.printUnits(ud1,False)
   self.assert_((                 "kilogram (exponent = 1, multiplier = 3, scale = 2)" == ud_str2 ))
   ud_str3 = libsbml.UnitDefinition.printUnits(ud1,True)
   self.assert_((  "(300 kilogram)^1" == ud_str3 ))
   pass  
Ejemplo n.º 18
0
 def test_UnitDefinition_createWithName(self):
   ud = libsbml.UnitDefinition(2,4)
   ud.setName( "mmol_per_liter_per_sec")
   self.assert_( ud.getTypeCode() == libsbml.SBML_UNIT_DEFINITION )
   self.assert_( ud.getMetaId() == "" )
   self.assert_( ud.getNotes() == None )
   self.assert_( ud.getAnnotation() == None )
   self.assert_( ud.getId() == "" )
   self.assert_((  "mmol_per_liter_per_sec" == ud.getName() ))
   self.assertEqual( True, ud.isSetName() )
   self.assert_( ud.getNumUnits() == 0 )
   _dummyList = [ ud ]; _dummyList[:] = []; del _dummyList
   pass  
 def test_internal_consistency_check_99905_unitdef(self):
   d = libsbml.SBMLDocument(2,4)
   u = libsbml.UnitDefinition(2,4)
   d.setLevelAndVersion(2,2,False)
   m = d.createModel()
   u.setId("ud")
   u.setSBOTerm(9)
   u.createUnit()
   m.addUnitDefinition(u)
   errors = d.checkInternalConsistency()
   self.assert_( errors == 0 )
   d = None
   pass  
Ejemplo n.º 20
0
 def test_UnitDefinition_ancestor_add(self):
   ia = libsbml.UnitDefinition(2,4)
   m = libsbml.Model(2,4)
   ia.setId("u")
   ia.createUnit()
   m.addUnitDefinition(ia)
   ia = None
   lo = m.getListOfUnitDefinitions()
   obj = m.getUnitDefinition(0)
   self.assert_( obj.getAncestorOfType(libsbml.SBML_MODEL) == m )
   self.assert_( obj.getAncestorOfType(libsbml.SBML_LIST_OF) == lo )
   self.assert_( obj.getAncestorOfType(libsbml.SBML_DOCUMENT) == None )
   self.assert_( obj.getAncestorOfType(libsbml.SBML_EVENT) == None )
   pass  
Ejemplo n.º 21
0
 def test_Unit_ancestor_add(self):
   ud = libsbml.UnitDefinition(2,4)
   u = libsbml.Unit(2,4)
   u.setKind(libsbml.UNIT_KIND_MOLE)
   ud.addUnit(u)
   u = None
   self.assert_( ud.getNumUnits() == 1 )
   lo = ud.getListOfUnits()
   obj = ud.getUnit(0)
   self.assert_( obj.getAncestorOfType(libsbml.SBML_UNIT_DEFINITION) == ud )
   self.assert_( obj.getAncestorOfType(libsbml.SBML_LIST_OF) == lo )
   self.assert_( obj.getAncestorOfType(libsbml.SBML_DOCUMENT) == None )
   self.assert_( obj.getAncestorOfType(libsbml.SBML_COMPARTMENT) == None )
   ud = None
   pass  
 def test_internal_consistency_check_99904_unitdef(self):
   d = libsbml.SBMLDocument(2,4)
   u = libsbml.UnitDefinition(2,4)
   d.setLevelAndVersion(1,2,False)
   m = d.createModel()
   c = m.createCompartment()
   c.setId("cc")
   u.setId("ud")
   u.setMetaId("mmm")
   u.createUnit()
   m.addUnitDefinition(u)
   errors = d.checkInternalConsistency()
   self.assert_( errors == 0 )
   d = None
   pass  
Ejemplo n.º 23
0
 def test_Model_addUnitDefinition5(self):
     m = libsbml.Model(2, 2)
     ud = libsbml.UnitDefinition(2, 2)
     ud.setId("ud")
     ud.createUnit()
     ud1 = libsbml.UnitDefinition(2, 2)
     ud1.setId("ud")
     ud1.createUnit()
     i = m.addUnitDefinition(ud)
     self.assert_(i == libsbml.LIBSBML_OPERATION_SUCCESS)
     self.assert_(m.getNumUnitDefinitions() == 1)
     i = m.addUnitDefinition(ud1)
     self.assert_(i == libsbml.LIBSBML_DUPLICATE_OBJECT_ID)
     self.assert_(m.getNumUnitDefinitions() == 1)
     _dummyList = [ud]
     _dummyList[:] = []
     del _dummyList
     _dummyList = [ud1]
     _dummyList[:] = []
     del _dummyList
     _dummyList = [m]
     _dummyList[:] = []
     del _dummyList
     pass
Ejemplo n.º 24
0
 def test_Model_addUnitDefinition3(self):
     m = libsbml.Model(2, 2)
     ud = libsbml.UnitDefinition(1, 2)
     ud.createUnit()
     ud.setId("ud")
     i = m.addUnitDefinition(ud)
     self.assert_(i == libsbml.LIBSBML_LEVEL_MISMATCH)
     self.assert_(m.getNumUnitDefinitions() == 0)
     _dummyList = [ud]
     _dummyList[:] = []
     del _dummyList
     _dummyList = [m]
     _dummyList[:] = []
     del _dummyList
     pass
Ejemplo n.º 25
0
 def test_UnitDefinition_createWithNS(self):
   xmlns = libsbml.XMLNamespaces()
   xmlns.add( "http://www.sbml.org", "testsbml")
   sbmlns = libsbml.SBMLNamespaces(2,1)
   sbmlns.addNamespaces(xmlns)
   object = libsbml.UnitDefinition(sbmlns)
   self.assert_( object.getTypeCode() == libsbml.SBML_UNIT_DEFINITION )
   self.assert_( object.getMetaId() == "" )
   self.assert_( object.getNotes() == None )
   self.assert_( object.getAnnotation() == None )
   self.assert_( object.getLevel() == 2 )
   self.assert_( object.getVersion() == 1 )
   self.assert_( object.getNamespaces() != None )
   self.assert_( object.getNamespaces().getLength() == 2 )
   _dummyList = [ object ]; _dummyList[:] = []; del _dummyList
   pass  
Ejemplo n.º 26
0
 def test_Unit_ancestor_create(self):
   ud = libsbml.UnitDefinition(2,4)
   u = ud.createUnit()
   self.assert_( ud.getNumUnits() == 1 )
   lo = ud.getListOfUnits()
   self.assert_( u.getAncestorOfType(libsbml.SBML_UNIT_DEFINITION) == ud )
   self.assert_( u.getAncestorOfType(libsbml.SBML_LIST_OF) == lo )
   self.assert_( u.getAncestorOfType(libsbml.SBML_DOCUMENT) == None )
   self.assert_( u.getAncestorOfType(libsbml.SBML_COMPARTMENT) == None )
   obj = ud.getUnit(0)
   self.assert_( obj.getAncestorOfType(libsbml.SBML_UNIT_DEFINITION) == ud )
   self.assert_( obj.getAncestorOfType(libsbml.SBML_LIST_OF) == lo )
   self.assert_( obj.getAncestorOfType(libsbml.SBML_DOCUMENT) == None )
   self.assert_( obj.getAncestorOfType(libsbml.SBML_COMPARTMENT) == None )
   ud = None
   pass  
Ejemplo n.º 27
0
 def test_Model_addUnitDefinition1(self):
     m = libsbml.Model(2, 2)
     ud = libsbml.UnitDefinition(2, 2)
     i = m.addUnitDefinition(ud)
     self.assert_(i == libsbml.LIBSBML_INVALID_OBJECT)
     ud.createUnit()
     i = m.addUnitDefinition(ud)
     self.assert_(i == libsbml.LIBSBML_INVALID_OBJECT)
     ud.setId("ud")
     i = m.addUnitDefinition(ud)
     self.assert_(i == libsbml.LIBSBML_OPERATION_SUCCESS)
     self.assert_(m.getNumUnitDefinitions() == 1)
     _dummyList = [ud]
     _dummyList[:] = []
     del _dummyList
     _dummyList = [m]
     _dummyList[:] = []
     del _dummyList
     pass
Ejemplo n.º 28
0
    def _create_unit_definition(sid, units):
        """ Creates the defined unit definitions.
        (kind, exponent, scale, multiplier)
        """
        unit_def = libsbml.UnitDefinition(3, 1)
        unit_def.setId(sid)
        for data in units:
            kind = data[0]
            exponent = data[1]
            scale = 0
            multiplier = 1.0
            if len(data) > 2:
                scale = data[2]
            if len(data) > 3:
                multiplier = data[3]

            FormatingTestCase._create_unit(unit_def, kind, exponent, scale,
                                           multiplier)
        return unit_def
Ejemplo n.º 29
0
 def test_SBMLDocument_setLevelAndVersion_Error(self):
     d = libsbml.SBMLDocument()
     d.setLevelAndVersion(2, 1, True)
     m1 = libsbml.Model(2, 1)
     u = libsbml.Unit(2, 1)
     u.setKind(libsbml.UnitKind_forName("mole"))
     u.setOffset(3.2)
     ud = libsbml.UnitDefinition(2, 1)
     ud.setId("ud")
     ud.addUnit(u)
     m1.addUnitDefinition(ud)
     d.setModel(m1)
     self.assert_(d.setLevelAndVersion(2, 2, True) == False)
     self.assert_(d.setLevelAndVersion(2, 3, True) == False)
     self.assert_(d.setLevelAndVersion(1, 2, True) == False)
     self.assert_(d.setLevelAndVersion(1, 1, True) == False)
     _dummyList = [d]
     _dummyList[:] = []
     del _dummyList
     pass
Ejemplo n.º 30
0
 def test_UnitDefinition_L1(self):
   ud = libsbml.UnitDefinition(1,2)
   self.assertEqual( True, ud.hasRequiredElements() )
   ud = None
   pass