1 from tiramisu.option import BoolOption, UnicodeOption, SymLinkOption, \
3 from pickle import dumps, loads
8 for subclass in opt.__class__.__mro__:
9 if subclass is not object:
10 slots.update(subclass.__slots__)
15 for attr in _get_slots(opt):
22 raise Exception('opt should have already attribute {0}'.format(attr))
25 def _diff_opt(opt1, opt2):
26 attr1 = set(_get_slots(opt1))
27 attr2 = set(_get_slots(opt2))
31 raise Exception('more attribute in opt1 {0}'.format(list(diff1)))
33 raise Exception('more attribute in opt2 {0}'.format(list(diff2)))
35 if attr in ['_cache_paths']:
42 val1 = getattr(opt1, attr)
47 val2 = getattr(opt2, attr)
53 elif attr == '_children':
54 assert val1[0] == val2[0]
55 for index, _opt in enumerate(val1[1]):
56 assert _opt._name == val2[1][index]._name
57 elif attr == '_requires':
58 assert val1[0][0][0]._name == val2[0][0][0]._name
59 assert val1[0][0][1:] == val2[0][0][1:]
61 assert val1._name == val2._name
62 elif attr == '_consistencies':
63 # dict is only a cache
64 if isinstance(val1, list):
65 for index, consistency in enumerate(val1):
66 assert consistency[0] == val2[index][0]
67 assert consistency[1]._name == val2[index][1]._name
73 b = BoolOption('b', '')
74 u = UnicodeOption('u', '', requires=[{'option': b, 'expected': True, 'action': 'disabled', 'inverse': True}])
75 #u.impl_add_consistency('not_equal', b)
76 s = SymLinkOption('s', u)
77 o = OptionDescription('o', '', [b, u, s])
78 o1 = OptionDescription('o1', '', [o])
84 _diff_opt(o1.o.b, q.o.b)
85 _diff_opt(o1.o.u, q.o.u)
86 _diff_opt(o1.o.s, q.o.s)
89 def test_diff_opt_cache():
90 b = BoolOption('b', '')
91 u = UnicodeOption('u', '', requires=[{'option': b, 'expected': True, 'action': 'disabled', 'inverse': True}])
92 u.impl_add_consistency('not_equal', b)
93 s = SymLinkOption('s', u)
94 o = OptionDescription('o', '', [b, u, s])
95 o1 = OptionDescription('o1', '', [o])
102 _diff_opt(o1.o.b, q.o.b)
103 _diff_opt(o1.o.u, q.o.u)
104 _diff_opt(o1.o.s, q.o.s)
107 def test_no_state_attr():
108 # all _state_xxx attributes should be deleted
109 b = BoolOption('b', '')
110 u = UnicodeOption('u', '', requires=[{'option': b, 'expected': True, 'action': 'disabled', 'inverse': True}])
111 s = SymLinkOption('s', u)
112 o = OptionDescription('o', '', [b, u, s])
113 o1 = OptionDescription('o1', '', [o])