Exemplo n.º 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)
Exemplo n.º 2
0
 def test_implementation(self):
     self.failUnless(verifyObject(interfaces.IVocabulary, self.list_vocab))
     self.failUnless(
         verifyObject(interfaces.IVocabularyTokenized, self.list_vocab))
     self.failUnless(verifyObject(interfaces.IVocabulary, self.items_vocab))
     self.failUnless(
         verifyObject(interfaces.IVocabularyTokenized, self.items_vocab))
Exemplo n.º 3
0
 def test_simple_term(self):
     t = vocabulary.SimpleTerm(1)
     verifyObject(interfaces.ITokenizedTerm, t)
     self.assertEqual(t.value, 1)
     self.assertEqual(t.token, "1")
     t = vocabulary.SimpleTerm(1, "One")
     verifyObject(interfaces.ITokenizedTerm, t)
     self.assertEqual(t.value, 1)
     self.assertEqual(t.token, "One")
Exemplo n.º 4
0
 def test_interfaces(self):
     verifyObject(ITimeDelta, timedelta(minutes=20))
     verifyObject(IDate, date(2000, 1, 2))
     verifyObject(IDateTime, datetime(2000, 1, 2, 10, 20))
     verifyObject(ITime, time(20, 30, 15, 1234))
     verifyObject(ITZInfo, tzinfo())
     verifyClass(ITimeDeltaClass, timedelta)
     verifyClass(IDateClass, date)
     verifyClass(IDateTimeClass, datetime)
     verifyClass(ITimeClass, time)
Exemplo n.º 5
0
 def test_contains(self):
     vocab = states.StateVocabulary()
     self.assert_(verifyObject(IVocabulary, vocab))
     count = 0
     L = list(vocab)
     for term in L:
         count += 1
         self.assert_(term.value in vocab)
     self.assertEqual(count, len(vocab))
     # make sure we get the same values the second time around:
     L = [term.value for term in L]
     L.sort()
     L2 = [term.value for term in vocab]
     L2.sort()
     self.assertEqual(L, L2)
Exemplo n.º 6
0
 def test_simple_term_title(self):
     t = vocabulary.SimpleTerm(1)
     verifyObject(interfaces.ITokenizedTerm, t)
     self.failUnlessRaises(DoesNotImplement, verifyObject,
                           interfaces.ITitledTokenizedTerm, t)
     self.failUnless(t.title is None)
     t = vocabulary.SimpleTerm(1, title="Title")
     verifyObject(interfaces.ITokenizedTerm, t)
     verifyObject(interfaces.ITitledTokenizedTerm, t)
     self.failUnlessEqual(t.title, "Title")
Exemplo n.º 7
0
 def test_prebound_vocabulary(self):
     field = IBirthInfo.getDescriptionFor("state3")
     bound = field.bind(None)
     self.assert_(bound.vocabularyName is None)
     self.assert_(verifyObject(IVocabulary, bound.vocabulary))
     self.assert_("AL" in bound.vocabulary)
Exemplo n.º 8
0
 def test_default_presentation(self):
     field = IBirthInfo.getDescriptionFor("state1")
     bound = field.bind(object())
     self.assert_(verifyObject(IVocabulary, bound.vocabulary))
     self.assertEqual(bound.vocabulary.getTerm("VA").title, "Virginia")
Exemplo n.º 9
0
 def testInterface(self):
     verifyObject(IMessageCatalog, self._catalog)
Exemplo n.º 10
0
 def testInterface(self):
     from zpt._zope.interface.verify import verifyObject
     from zpt._zope.schema.interfaces import IDate
     verifyObject(IDate, self._Field_Factory())
Exemplo n.º 11
0
 def testInterface(self):
     verifyObject(ITranslationDomain, self._domain)
Exemplo n.º 12
0
 def testInterfaces(self):
     import zpt._zope.component
     self.failUnless(
         verifyObject(IComponentArchitecture, zpt._zope.component))
Exemplo n.º 13
0
    def testModule(self):

        from zpt._zope.interface.tests.ifoo import IFoo
        from zpt._zope.interface.tests import dummy

        verifyObject(IFoo, dummy)