

def test_choices(self):
    schema = schemas.ChoicesField.definition()
    definition = schema.deserialize({
        'name': 'tags',
        'type': 'choices',
        'choices': ['a', 'b', 'c'],
    })
    validator = schemas.ChoicesField.validation(**definition)
    self.assertEquals(['a'], validator.deserialize('a'))
    self.assertEquals(['a'], validator.deserialize(['a']))
    self.assertEquals(['a'], validator.deserialize('[a]'))
    self.assertEquals(['a'], validator.deserialize('["a"]'))
    validator.assertEquals(['a', 'b'], validator.deserialize('["a","b"]'))
    self.assertEquals(['a', 'b'], validator.deserialize('a,b'))
    self.assertEquals(['a', 'b', 'c'], validator.deserialize('[a,b,c]'))
    self.assertRaises(colander.Invalid, validator.deserialize, '')
    self.assertRaises(colander.Invalid, validator.deserialize, ['d'])
    self.assertRaises(colander.Invalid, validator.deserialize, '["a"')
    self.assertRaises(colander.Invalid, validator.deserialize, '[d]')
    self.assertRaises(colander.Invalid, validator.deserialize, '[a,d]')

dataset/ETHPy150Open spiral-project/daybed/daybed/tests/test_schemas_base.py BaseFieldsTests.test_choices/VarMisuse@130/173 `self`->`validator`