forked from dayorbyte/MongoAlchemy
/
test_sequence_fields.py
83 lines (62 loc) · 2.2 KB
/
test_sequence_fields.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
from nose.tools import *
from mongoalchemy.fields import *
from test.util import known_failure
# List Field
@raises(BadValueException)
def list_wrong_type_test():
ListField(IntField()).wrap(4)
@raises(BadValueException)
def list_bad_type_test_unwrap():
ListField(IntField()).unwrap(4)
@raises(BadValueException)
def list_wrong_child_type_test():
ListField(StringField()).wrap([4])
@raises(Exception)
def list_bad_child_type_test_wrap():
ListField(int).wrap([4])
@raises(Exception)
def list_bad_child_test_unwrap():
ListField(IntField()).unwrap(['4'])
@raises(BadValueException)
def list_too_long_test():
ListField(StringField(), max_capacity=4).unwrap([x for x in '12345'])
@raises(BadValueException)
def list_too_short_test():
ListField(StringField(), min_capacity=4).wrap([x for x in '123'])
def list_just_right_test():
ListField(StringField(), min_capacity=3, max_capacity=3).wrap([x for x in '123'])
def list_value_test():
s = ListField(StringField())
foo = [x for x in '12345']
assert s.unwrap(s.wrap(foo)) == foo
def list_default_test():
s = ListField(StringField(), default_empty=True)
assert s.default == []
# Set Field
@raises(BadValueException)
def set_wrong_type_test_wrap():
SetField(IntField()).wrap([4])
@raises(BadValueException)
def set_wrong_type_test_unwrap():
SetField(IntField()).unwrap((4,))
@raises(BadValueException)
def set_wrong_child_type_test():
SetField(StringField()).wrap(set([4]))
@raises(Exception)
def set_bad_child_type_test():
SetField(int).wrap(set([4]))
@raises(BadValueException)
def set_too_long_test():
SetField(StringField(), max_capacity=4).wrap(set([x for x in '12345']))
@raises(BadValueException)
def set_too_short_test():
SetField(StringField(), min_capacity=4).wrap(set([x for x in '123']))
def set_just_right_test():
SetField(StringField(), min_capacity=3, max_capacity=3).wrap(set([x for x in '123']))
def set_value_test():
s = SetField(StringField())
foo = set([x for x in '12345'])
assert s.unwrap(s.wrap(foo)) == foo
def set_default_test():
assert SetField(StringField(), default_empty=True).default == set()
assert SetField(StringField(), default=set([3])).default == set([3])