def testBooleanAttribute(self):
     from comoonics.ComDataObject import DataObject
     print "Testing boolean"
     path="//device[@id='rootfs']"
     element=comoonics.XmlTools.evaluateXPath(path, self.doc)[0]
     obj=DataObject(element)
     print "%s.options: %s" %(path, obj.getAttribute("options"))
     result=obj.getAttributeBoolean("options")
     print "%s.optionsAsBoolean: '%s'" %(path, result)
     self.assertTrue(result, "AttributeBoolean(%s) should return True but returned %s" %("options", result))
Example #2
0
 def testBooleanAttribute(self):
     from comoonics.ComDataObject import DataObject
     print "Testing boolean"
     path = "//device[@id='rootfs']"
     element = comoonics.XmlTools.evaluateXPath(path, self.doc)[0]
     obj = DataObject(element)
     print "%s.options: %s" % (path, obj.getAttribute("options"))
     result = obj.getAttributeBoolean("options")
     print "%s.optionsAsBoolean: '%s'" % (path, result)
     self.assertTrue(
         result, "AttributeBoolean(%s) should return True but returned %s" %
         ("options", result))
Example #3
0
class test_DataObject(unittest.TestCase):
    def __init__(self, testMethod="runTest"):
        import os.path
        import inspect
        super(test_DataObject, self).__init__(testMethod)

        #parse the document
        self.doc = comoonics.XmlTools.parseXMLFile(
            os.path.join(os.path.dirname(inspect.getfile(self.__class__)),
                         "example_config.xml"))

        from comoonics.ComDataObject import DataObject
        self.obj = DataObject(self.doc.documentElement, self.doc)


#    def testToString(self):
#        _str=""
#        result=self.obj.__str__()
#        self.assertEquals(str, result, "str(obj):%s != %s" %(_str, result))

    def testHasAttributeXYZ(self):
        attribute = "xyz"
        print "Testing hasAttribute(%s)" % attribute
        if self.obj.hasAttribute(attribute):
            self.assert_("Found Attribute \"%s\"!! Should not happen!!!" %
                         attribute)
        else:
            print "No Attribute \"%s\" available. (OK)" % attribute

    def testHasAttributeID(self):
        attribute = "id"
        print "Testing hasAttribute(%s)" % attribute
        if self.obj.hasAttribute(attribute):
            print "Found Attribute \"%s\"!! (OK)" % attribute
        else:
            self.assert_("No Attribute \"%s\"!! Should not happen!!!" %
                         attribute)

    def testGetAttributeXYZWDefault(self):
        attribute = "xyz"
        default = ""
        print "Testing getAttribute(%s, %s)" % (attribute, default)
        result = self.obj.getAttribute(attribute, default)
        self.assertEquals(
            result, default, "Attribute %s is not default %s but %s" %
            (attribute, result, default))

    def testGetAttributeIDDefault(self):
        attribute = "id"
        default = "bootfs"
        print "Testing getAttribute(%s, %s)" % (attribute, default)
        result = self.obj.getAttribute(attribute, default)
        self.assertEquals(
            result, default, "Attribute %s is not default %s but %s" %
            (attribute, result, default))

    def testGetAttributeXYZ(self):
        attribute = "xyz"
        print "Testing getAttribute(%s)" % (attribute)
        try:
            result = self.obj.getAttribute(attribute)
            self.assert_(
                "Found value for Attribute \"%s\": %s !!!Should not happen !!!"
                % (attribute, result))
        except:
            print "Exception %s caught (OK)" % sys.exc_value

    def testBooleanAttribute(self):
        from comoonics.ComDataObject import DataObject
        print "Testing boolean"
        path = "//device[@id='rootfs']"
        element = comoonics.XmlTools.evaluateXPath(path, self.doc)[0]
        obj = DataObject(element)
        print "%s.options: %s" % (path, obj.getAttribute("options"))
        result = obj.getAttributeBoolean("options")
        print "%s.optionsAsBoolean: '%s'" % (path, result)
        self.assertTrue(
            result, "AttributeBoolean(%s) should return True but returned %s" %
            ("options", result))
class test_DataObject(unittest.TestCase):    

    def __init__(self, testMethod="runTest"):
        import os.path
        import inspect
        super(test_DataObject, self).__init__(testMethod)


        #parse the document
        self.doc = comoonics.XmlTools.parseXMLFile(os.path.join(os.path.dirname(inspect.getfile(self.__class__)), "example_config.xml"))

        from comoonics.ComDataObject import DataObject
        self.obj=DataObject(self.doc.documentElement, self.doc)

#    def testToString(self):
#        _str=""
#        result=self.obj.__str__()
#        self.assertEquals(str, result, "str(obj):%s != %s" %(_str, result))

    def testHasAttributeXYZ(self):
        attribute="xyz"
        print "Testing hasAttribute(%s)" %attribute
        if self.obj.hasAttribute(attribute):
            self.assert_("Found Attribute \"%s\"!! Should not happen!!!" %attribute)
        else:
            print "No Attribute \"%s\" available. (OK)" % attribute

    def testHasAttributeID(self):
        attribute="id"
        print "Testing hasAttribute(%s)" %attribute
        if self.obj.hasAttribute(attribute):
            print "Found Attribute \"%s\"!! (OK)" %attribute
        else:
            self.assert_("No Attribute \"%s\"!! Should not happen!!!" %attribute)

    def testGetAttributeXYZWDefault(self):
        attribute="xyz"
        default=""
        print "Testing getAttribute(%s, %s)" %(attribute, default)
        result=self.obj.getAttribute(attribute, default)
        self.assertEquals(result, default, "Attribute %s is not default %s but %s" %(attribute, result, default))

    def testGetAttributeIDDefault(self):
        attribute="id"
        default="bootfs"
        print "Testing getAttribute(%s, %s)" %(attribute, default)
        result=self.obj.getAttribute(attribute, default)
        self.assertEquals(result, default, "Attribute %s is not default %s but %s" %(attribute, result, default))

    def testGetAttributeXYZ(self):
        attribute="xyz"
        print "Testing getAttribute(%s)" %(attribute)
        try:
            result=self.obj.getAttribute(attribute)
            self.assert_("Found value for Attribute \"%s\": %s !!!Should not happen !!!" %(attribute, result))
        except:
            print "Exception %s caught (OK)" %sys.exc_value

    def testBooleanAttribute(self):
        from comoonics.ComDataObject import DataObject
        print "Testing boolean"
        path="//device[@id='rootfs']"
        element=comoonics.XmlTools.evaluateXPath(path, self.doc)[0]
        obj=DataObject(element)
        print "%s.options: %s" %(path, obj.getAttribute("options"))
        result=obj.getAttributeBoolean("options")
        print "%s.optionsAsBoolean: '%s'" %(path, result)
        self.assertTrue(result, "AttributeBoolean(%s) should return True but returned %s" %("options", result))