Ignore:
Timestamp:
20 Nov 2012, 00:09:00 (12 years ago)
Author:
uli
Message:

attrs_to_fields now supports an additional 'omit' parameter.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/utils/tests/test_helpers.py

    r9372 r9689  
    2828from cStringIO import StringIO
    2929from zope import schema
    30 from zope.interface import Interface, Attribute, implements
     30from zope.interface import Interface, Attribute, implements, implementer
    3131from zope.security.testing import Principal, Participation
    3232from zope.security.management import newInteraction, endInteraction
     
    5252        self.assertEqual(result4, 30)
    5353        return
     54
     55    def test_attrs_to_fields_properties(self):
     56        # we can omit single fields in order to retrieve properties
     57        class IMyInterface(Interface):
     58            attr1 = schema.Int(
     59                title = u'Attribute 1', readonly = True, default = 110,
     60                )
     61
     62        @helpers.attrs_to_fields
     63        @implementer(IMyInterface)
     64        class MyClass1(object):
     65            @property
     66            def attr1(self):
     67                return 42
     68
     69        @implementer(IMyInterface)
     70        class MyClass2(object):
     71            @property
     72            def attr1(self):
     73                return 42
     74        MyClass2 = helpers.attrs_to_fields(MyClass2, omit=['attr1'])
     75
     76        obj1 = MyClass1()
     77        obj2 = MyClass2()
     78
     79        self.assertEqual(obj1.attr1, 110)
     80        self.assertEqual(obj2.attr1, 42)
     81        return
     82
    5483
    5584class RemoveFileOrDirectoryTestCase(unittest.TestCase):
     
    461490            contents, '\r\n')
    462491        return
     492
    463493
    464494
Note: See TracChangeset for help on using the changeset viewer.