Changeset 14005


Ignore:
Timestamp:
2 Jul 2016, 16:48:00 (8 years ago)
Author:
uli
Message:

flake8.

Start with a cleanup.

File:
1 edited

Legend:

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

    r13159 r14005  
    4040from waeup.kofa.university import Faculty
    4141from waeup.kofa.utils.converters import (
    42     IObjectConverter, IFieldConverter, DefaultFieldConverter,
    43     ListFieldConverter, PhoneNumberFieldConverter, ResultEntryConverter,
    44     DefaultObjectConverter)
     42    IObjectConverter, DefaultFieldConverter, ListFieldConverter,
     43    PhoneNumberFieldConverter, ResultEntryConverter, DefaultObjectConverter)
    4544from waeup.kofa.utils.helpers import attrs_to_fields
    4645
     
    5655    ('Three', 3),
    5756    )
     57
     58
    5859class IContact(Interface):
    5960    """Sample interface for sample content type used here in tests.
    6061    """
    6162    name = schema.TextLine(
    62         title = u'Name',
    63         default = u'Manfred',
    64         readonly = True,
     63        title=u'Name',
     64        default=u'Manfred',
     65        readonly=True,
    6566        )
    6667    age = schema.Int(
    67         title = u'Age',
    68         default = 23,
    69         required = True,
     68        title=u'Age',
     69        default=23,
     70        required=True,
    7071        )
    7172    city = schema.TextLine(
    72         title = u'City',
    73         required = True,
     73        title=u'City',
     74        required=True,
    7475        )
    7576    vip = schema.Bool(
    76         title = u'Celebrity',
    77         default = False,
    78         required = True,
     77        title=u'Celebrity',
     78        default=False,
     79        required=True,
    7980        )
    8081    birthday = schema.Date(
    81         title = u'Birthday',
    82         default = None,
     82        title=u'Birthday',
     83        default=None,
    8384        )
    8485    fav_color = schema.Choice(
    85         title = u'Favourite color',
    86         default = u'red',
    87         vocabulary = colors,
     86        title=u'Favourite color',
     87        default=u'red',
     88        vocabulary=colors,
    8889        )
    8990    num_cars = schema.Choice(
    90         title = u'Number of cars owned',
    91         default = None,
    92         vocabulary = car_nums,
     91        title=u'Number of cars owned',
     92        default=None,
     93        vocabulary=car_nums,
    9394        )
    9495    grades = schema.List(
    95         title = u'School Grades',
    96         value_type = ResultEntryField(),
    97         required = True,
    98         default = [],
     96        title=u'School Grades',
     97        value_type=ResultEntryField(),
     98        required=True,
     99        #defaultFactory=list,
     100        default=[],
    99101        )
    100102    fav_colors = schema.List(
    101         title = u'Favourite colors',
    102         value_type = schema.Choice(
    103             vocabulary = colors
     103        title=u'Favourite colors',
     104        value_type=schema.Choice(
     105            vocabulary=colors
    104106            ),
    105         required = True,
    106         default = [],
     107        required=True,
     108        #defaultFactory=list
     109        default=[],
    107110        )
    108111    friends = schema.List(
    109         title = u'Friends',
    110         value_type = schema.TextLine(
    111             title = u'Name',
     112        title=u'Friends',
     113        value_type=schema.TextLine(
     114            title=u'Name',
    112115            )
    113116        )
     
    117120        if contact.age > 16 and contact.name == 'Kevin':
    118121            raise Invalid('Kevins are age 16 or below.')
     122
    119123
    120124class Contact(object):
     
    127131form_fields_omit = form.Fields(IContact).omit('name', 'vip')
    128132
     133
    129134class ContactFactory(object):
    130135    """A factory for faculty containers.
     
    137142    def getInterfaces(self):
    138143        return implementedBy(Faculty)
     144
    139145
    140146class FieldConverterTests(unittest.TestCase):
     
    156162        return
    157163
     164
    158165class ConverterTests(FunctionalTestCase):
    159166
     
    197204        contact.age = 33
    198205        input_data = dict(name='Rudi', age='99')
    199         converter = IObjectConverter(IContact) # a converter to IContact
     206        converter = IObjectConverter(IContact)  # a converter to IContact
    200207        err, inv_err, data = converter.fromStringDict(
    201208            input_data, contact)
     
    209216        input_data1 = dict(vip='on')
    210217        input_data2 = dict(vip='')
    211         converter = IObjectConverter(IContact) # a converter to IContact
     218        converter = IObjectConverter(IContact)  # a converter to IContact
    212219        err1, inv_err1, data1 = converter.fromStringDict(
    213220            input_data1, contact1)
     
    218225
    219226    def test_bool_nonstandard_values1(self):
    220         # We accept 'true', 'True', 'tRuE', 'faLSE' and similar.
     227         # We accept 'true', 'True', 'tRuE', 'faLSE' and similar.
    221228        contact1 = Contact()
    222229        contact2 = Contact()
    223230        input_data1 = dict(vip='True')
    224231        input_data2 = dict(vip='false')
    225         converter = IObjectConverter(IContact) # a converter to IContact
     232        converter = IObjectConverter(IContact)  # a converter to IContact
    226233        err1, inv_err1, data1 = converter.fromStringDict(
    227234            input_data1, contact1)
     
    237244        input_data1 = dict(vip='1')
    238245        input_data2 = dict(vip='0')
    239         converter = IObjectConverter(IContact) # a converter to IContact
     246        converter = IObjectConverter(IContact)  # a converter to IContact
    240247        err1, inv_err1, data1 = converter.fromStringDict(
    241248            input_data1, contact1)
     
    251258        input_data1 = dict(vip='Yes')
    252259        input_data2 = dict(vip='no')
    253         converter = IObjectConverter(IContact) # a converter to IContact
     260        converter = IObjectConverter(IContact)  # a converter to IContact
    254261        err1, inv_err1, data1 = converter.fromStringDict(
    255262            input_data1, contact1)
     
    262269        contact = Contact()
    263270        input_data = dict(age='99')
    264         converter = IObjectConverter(IContact) # a converter to IContact
     271        converter = IObjectConverter(IContact)  # a converter to IContact
    265272        err, inv_err, data = converter.fromStringDict(
    266273            input_data, contact)
     
    271278        contact = Contact()
    272279        input_data = dict(age='sweet sixteen')
    273         converter = IObjectConverter(IContact) # a converter to IContact
     280        converter = IObjectConverter(IContact)  # a converter to IContact
    274281        err, inv_err, new_contact = converter.fromStringDict(
    275282            input_data, contact)
     
    280287        contact = Contact()
    281288        input_data = dict(name='Rudi')
    282         converter = IObjectConverter(IContact) # a converter to IContact
     289        converter = IObjectConverter(IContact)  # a converter to IContact
    283290        err, inv_err, data = converter.fromStringDict(
    284291            input_data, contact)
     
    290297        contact = Contact()
    291298        input_data = dict(name='Kevin', age='22')
    292         converter = IObjectConverter(IContact) # a converter to IContact
     299        converter = IObjectConverter(IContact)  # a converter to IContact
    293300        err, inv_err, new_contact = converter.fromStringDict(
    294301            input_data, contact)
     
    298305    def test_date(self):
    299306        contact = Contact()
    300         converter = IObjectConverter(IContact) # a converter to IContact
     307        converter = IObjectConverter(IContact)  # a converter to IContact
    301308
    302309        # The input format for dates: YYYY-MM-DD
     
    309316            dict(birthday='1945-23-12'), contact)
    310317        #assert data['birthday'] == datetime.date(1945, 12, 23)
    311         assert err[0][1] =='Invalid datetime data'
     318        assert err[0][1] == 'Invalid datetime data'
    312319
    313320        # '08' is not interpreted as octal number
     
    319326    def test_date_invalid(self):
    320327        contact = Contact()
    321         converter = IObjectConverter(IContact) # a converter to IContact
     328        converter = IObjectConverter(IContact)  # a converter to IContact
    322329        err, inv_err, data = converter.fromStringDict(
    323330            dict(birthday='not-a-date'), contact)
     
    327334        # We can use our own formfields and select only a subset of fields
    328335        contact = Contact()
    329         converter = IObjectConverter(IContact) # a converter to IContact
     336        converter = IObjectConverter(IContact)  # a converter to IContact
    330337        input_data = dict(name='Bruno', age='99', vip='on')
    331338        err, inv_err, data = converter.fromStringDict(
     
    339346        # We can use our own formfields and omit some fields
    340347        contact = Contact()
    341         converter = IObjectConverter(IContact) # a converter to IContact
     348        converter = IObjectConverter(IContact)  # a converter to IContact
    342349        input_data = dict(name='Bruno', age='99', vip='on')
    343350        err, inv_err, data = converter.fromStringDict(
     
    350357    def test_factory(self):
    351358        # We can use factories to convert values
    352         converter = IObjectConverter(IContact) # a converter to IContact
     359        converter = IObjectConverter(IContact)  # a converter to IContact
    353360        # pass string ``contact`` instead of a real object
    354361        err, inv_err, data = converter.fromStringDict(
     
    360367    def test_choice_vocab(self):
    361368        # We can handle vocabularies
    362         converter = IObjectConverter(IContact) # a converter to IContact
     369        converter = IObjectConverter(IContact)  # a converter to IContact
    363370        err, inv_err, data = converter.fromStringDict(
    364371            dict(fav_color='blue'), 'contact')
     
    369376    def test_choice_vocab_invalid_value(self):
    370377        # We can handle vocabularies
    371         converter = IObjectConverter(IContact) # a converter to IContact
     378        converter = IObjectConverter(IContact)  # a converter to IContact
    372379        err, inv_err, data = converter.fromStringDict(
    373380            dict(fav_color='magenta'), 'contact')
     
    378385    def test_non_string_choice(self):
    379386        # We can handle vocabs with non-string values
    380         converter = IObjectConverter(IContact) # a converter to IContact
     387        converter = IObjectConverter(IContact)  # a converter to IContact
    381388        err, inv_err, data = converter.fromStringDict(
    382389            dict(num_cars='1'), 'contact')
     
    401408        g_val1, g_val2 = list(g_src.factory.getValues())[0:2]
    402409        req_string = u"[('%s', '%s'), ('%s', '%s')]" % (
    403                 s_val1, g_val1, s_val2, g_val2)
     410            s_val1, g_val1, s_val2, g_val2)
    404411        err, inv_err, data = converter.fromStringDict(
    405412            {"grades": req_string,
Note: See TracChangeset for help on using the changeset viewer.