def testLiteralAttributes(self):
        view = self.view
        """Test basic features of literal attributes"""
        kind = view.findPath('//Schema/Core/Kind')
        itemKind = view.findPath('//Schema/Core/Item')
        self.assert_(itemKind is not None)
        attrKind = view.findPath('//Schema/Core/Attribute')
        self.assert_(attrKind is not None)
        stringType = view.findPath('//Schema/Core/String')
        self.assert_(stringType is not None)

        attr = attrKind.newItem('testAttr', itemKind, type=stringType)
        itemKind.attributes.add(attr, 'testAttr')
        self.assert_(itemKind.getAttribute('testAttr', True) is not None)

        kind1 = Kind('kind1', view, kind)
        self.assert_(kind1 is not None)

        item1 = Item('item1', view, itemKind)
        self.assert_(item1 is not None)

        #Test hasAttributeAspect and getAttributeAspect
        self.assert_(
            kind1.hasAttributeAspect('attributes', 'cardinality') and
            kind1.getAttributeAspect('attributes', 'cardinality') == 'list')

        self.assert_(
            kind1.hasAttributeAspect('superKinds', 'cardinality') and
            kind1.getAttributeAspect('superKinds', 'cardinality') == 'list')

        self.assert_(
            kind1.hasAttributeAspect('classes', 'cardinality')
            and kind1.getAttributeAspect('classes', 'cardinality') == 'dict')

        # up to here testAttr is an unset Chandler attribute
        self.failUnlessRaises(AttributeError, lambda: item1.testAttr)
        # now set the attribute
        item1.setAttributeValue('testAttr', u'myName')
        self.assertEquals(item1.testAttr, u'myName')
        #test __getattr__ and getAttributeValue() access
        self.assertEquals(item1.testAttr, item1.getAttributeValue('testAttr'))
        # now remove attribute value
        item1.removeAttributeValue('testAttr')
        self.failUnlessRaises(AttributeError, lambda: item1.testAttr)
        #TODO need a test for list valued literal attribute

        # test dict valued literal attribute
        self.assert_(kind.classes['python'] is not None)
Ejemplo n.º 2
0
    def testLiteralAttributes(self):
        view = self.view
        """Test basic features of literal attributes"""
        kind = view.findPath('//Schema/Core/Kind')
        itemKind = view.findPath('//Schema/Core/Item')
        self.assert_(itemKind is not None)
        attrKind = view.findPath('//Schema/Core/Attribute')
        self.assert_(attrKind is not None)
        stringType = view.findPath('//Schema/Core/String')
        self.assert_(stringType is not None)

        attr = attrKind.newItem('testAttr', itemKind, type=stringType)
        itemKind.attributes.add(attr, 'testAttr')
        self.assert_(itemKind.getAttribute('testAttr', True) is not None)

        kind1 = Kind('kind1', view, kind)
        self.assert_(kind1 is not None)

        item1 = Item('item1', view, itemKind)
        self.assert_(item1 is not None)

        #Test hasAttributeAspect and getAttributeAspect
        self.assert_(kind1.hasAttributeAspect('attributes','cardinality') and
                     kind1.getAttributeAspect('attributes','cardinality') == 'list')

        self.assert_(kind1.hasAttributeAspect('superKinds','cardinality') and
                     kind1.getAttributeAspect('superKinds','cardinality') == 'list')

        self.assert_(kind1.hasAttributeAspect('classes','cardinality') and
                     kind1.getAttributeAspect('classes','cardinality') == 'dict')

        # up to here testAttr is an unset Chandler attribute
        self.failUnlessRaises(AttributeError, lambda: item1.testAttr)
        # now set the attribute
        item1.setAttributeValue('testAttr', u'myName')
        self.assertEquals(item1.testAttr, u'myName')
        #test __getattr__ and getAttributeValue() access
        self.assertEquals(item1.testAttr, item1.getAttributeValue('testAttr'))
        # now remove attribute value
        item1.removeAttributeValue('testAttr')
        self.failUnlessRaises(AttributeError, lambda: item1.testAttr)
        #TODO need a test for list valued literal attribute

        # test dict valued literal attribute
        self.assert_(kind.classes['python'] is not None)