示例#1
0
class TestClass(object):
    simple = basic.BasicProperty("simple", "documentation")
    withBound = basic.BasicProperty("withBound",
                                    "documentation",
                                    boundaries=(boundary.Type(str), ))
    withDefaultValue = basic.BasicProperty(
        "withDefaultValue",
        "documentation",
        defaultValue='this',
    )
    withDefaultFunction = basic.BasicProperty(
        "withDefaultFunction",
        "documentation",
        defaultFunction=lambda x, y: [],
    )
    withDefaultValueNoSet = basic.BasicProperty(
        "withDefaultValueNoSet",
        "documentation",
        defaultValue='this',
        setDefaultOnGet=0,
    )
    withDefaultFunctionNoSet = basic.BasicProperty(
        "withDefaultFunctionNoSet",
        "documentation",
        defaultFunction=lambda x, y: [],
        setDefaultOnGet=0,
    )
 def testStr(self):
     """Test string-conversion code with real objects"""
     property = basic.BasicProperty("this")
     bound = boundary.Type(str)
     client = self
     value = "some value"
     object = boundary.BoundaryError(property, bound, client, value,
                                     "somemessage")
     str(object)
 def testRepr(self):
     """Test representation code with real objects"""
     property = basic.BasicProperty("this")
     bound = boundary.Type(str)
     client = self
     value = "some value"
     object = boundary.BoundaryError(property, bound, client, value,
                                     "somemessage")
     repr(object)
示例#4
0
 def testBadInit(self):
     """Test improper initialisation of the property objects"""
     self.failUnlessRaises(
         TypeError,
         basic.BasicProperty,
         "name",
         "documentation",
         boundary.Type(str),
     )
     self.failUnlessRaises(TypeError, basic.BasicProperty)
class WeakValueDictionaryProperty(DictionaryProperty):
    """Weak-Value dictionary property object"""
    dataType = "dict.weakvalue"
    boundaries = [boundary.Type(weakref.WeakValueDictionary)]
    baseType = weakref.WeakValueDictionary

    def coerce(self, client, value):
        """Ensure that value is a weak-value dictionary

		If the value is not already a dictionary or
		WeakKeyDictionary, will go through DictionaryProperty's
		coercion mechanism first.
		"""
        if not isinstance(value, (dict, weakref.WeakValueDictionary)):
            value = super(WeakValueDictionaryProperty,
                          self).coerce(client, value)
        if isinstance(value, dict):
            value = weakref.WeakValueDictionary(value)
        return value
 def testError(self):
     """Test that the reported error is properly configured"""
     bound = boundary.Type("basictypes.boundary.Boundary")
     self._testError(bound, 'object')
 def testImported(self):
     """Test a unicode value"""
     bound = boundary.Type("basictypes.boundary.Boundary")
     self.failUnlessRaises(boundary.BoundaryTypeError, bound, None, None,
                           None)
     bound(boundary.Boundary(), None, None)
 def testBad1(self):
     """Test a non-string value"""
     bound = boundary.Type(str)
     self.failUnlessRaises(boundary.BoundaryTypeError, bound, None, None, 1)
 def testGood2(self):
     """Test a unicode value"""
     bound = boundary.Type(str)
     self.failUnlessRaises(boundary.BoundaryTypeError, bound, None, None,
                           u"some value")
示例#10
0
 def testGood(self):
     """Test a string value"""
     boundary.Type(str)("some value")