예제 #1
0
    def test(self):

        field = Text(title=u"Foo thing")

        class I(Interface):

            getFoo, setFoo = accessors(field)

        class Bad(object):
            implements(I)

        class Good(object):
            implements(I)

            def __init__(self):
                self.set = 0

            def getFoo(self):
                return u"foo"

            def setFoo(self, v):
                self.set += 1

        names = I.names()
        names.sort()
        self.assertEqual(names, ['getFoo', 'setFoo'])
        self.assertEqual(I['getFoo'].field, field)
        self.assertEqual(I['getFoo'].__name__, 'getFoo')
        self.assertEqual(I['getFoo'].__doc__, u'get Foo thing')
        self.assertEqual(I['getFoo'].__class__, FieldReadAccessor)
        self.assertEqual(I['getFoo'].writer, I['setFoo'])

        # test some field attrs
        for attr in ('title', 'description', 'readonly'):
            self.assertEqual(getattr(I['getFoo'], attr), getattr(field, attr))

        self.assert_(IText.providedBy(I['getFoo']))

        self.assert_(IMethod.providedBy(I['getFoo']))
        self.assert_(IMethod.providedBy(I['setFoo']))

        self.assertEqual(I['setFoo'].field, field)
        self.assertEqual(I['setFoo'].__name__, 'setFoo')
        self.assertEqual(I['setFoo'].__doc__, u'set Foo thing')
        self.assertEqual(I['setFoo'].__class__, FieldWriteAccessor)

        self.assertRaises(Exception, verifyClass, I, Bad)
        self.assertRaises(Exception, verifyObject, I, Bad())

        self.assertEquals(I['getFoo'].query(Bad(), 42), 42)
        self.assertRaises(AttributeError, I['getFoo'].get, Bad())

        verifyClass(I, Good)
        verifyObject(I, Good())

        self.assertEquals(I['getFoo'].query(Good(), 42), u'foo')
        self.assertEquals(I['getFoo'].get(Good()), u'foo')
        instance = Good()
        I['getFoo'].set(instance, u'whatever')
        self.assertEquals(instance.set, 1)
예제 #2
0
    def test_doc(self):

        field = Text(title=u"Foo thing")

        class I(Interface):

            getFoo, setFoo = accessors(field)

            def bar():
                pass

            x = Text()

        d = document.asStructuredText(I)
        self.assertEqual(
            d, "I\n"
            "\n"
            " Attributes:\n"
            "\n"
            "  x -- no documentation\n"
            "\n"
            " Methods:\n"
            "\n"
            "  bar() -- no documentation\n"
            "\n"
            "  getFoo() -- get Foo thing\n"
            "\n"
            "  setFoo(newvalue) -- set Foo thing\n"
            "\n")
예제 #3
0
        class I(Interface):

            getFoo, setFoo = accessors(field)

            def bar():
                pass

            x = Text()
예제 #4
0
 def test__doc__(self):
     field = Text(title=u"test fiield",
                  description=(u"To make sure that\n"
                               u"doc strings are working correctly\n"))
     self.assertEqual(
         field.__doc__, u"test fiield\n\n"
         u"To make sure that\n"
         u"doc strings are working correctly\n")
예제 #5
0
class ILocaleVersion(Interface):
    """Represents the version of a locale.

    The locale version is part of the ILocaleIdentity object.
    """

    number = TextLine(title=u"Version Number",
                      description=u"The version number of the locale.",
                      constraint=re.compile(r'^([0-9].)*[0-9]$').match,
                      required=True,
                      readonly=True)

    generationDate = Date(
        title=u"Generation Date",
        description=u"Specifies the creation date of the locale.",
        constraint=lambda date: date < datetime.now(),
        readonly=True)

    notes = Text(
        title=u"Notes",
        description=u"Some release notes for the version of this locale.",
        readonly=True)
예제 #6
0
class I(Interface):

    title = Text(description=u"Short summary", default=u'say something')
    weight = Float(min=0.0)
    code = Bytes(min_length=6, max_length=6, default='xxxxxx')
예제 #7
0
 class S2(Interface):
     b = Text()
     a = Text()
예제 #8
0
 class S1(Interface):
     a = Text()
     b = Text()