attributes in Option are now read-only if option set in Config (_name is everytime read-only)
This commit is contained in:
@ -37,6 +37,84 @@ def test_slots_option():
|
||||
raises(AttributeError, "c.x = 1")
|
||||
|
||||
|
||||
def test_slots_option_readonly():
|
||||
a = ChoiceOption('a', '', ('a',))
|
||||
b = BoolOption('b', '')
|
||||
c = IntOption('c', '')
|
||||
d = FloatOption('d', '')
|
||||
e = StrOption('e', '')
|
||||
g = UnicodeOption('g', '')
|
||||
h = IPOption('h', '')
|
||||
i = PortOption('i', '')
|
||||
j = NetworkOption('j', '')
|
||||
k = NetmaskOption('k', '')
|
||||
l = DomainnameOption('l', '')
|
||||
m = OptionDescription('m', '', [a, b, c, d, e, g, h, i, j, k, l])
|
||||
a._requires = 'a'
|
||||
b._requires = 'b'
|
||||
c._requires = 'c'
|
||||
d._requires = 'd'
|
||||
e._requires = 'e'
|
||||
g._requires = 'g'
|
||||
h._requires = 'h'
|
||||
i._requires = 'i'
|
||||
j._requires = 'j'
|
||||
k._requires = 'k'
|
||||
l._requires = 'l'
|
||||
m._requires = 'm'
|
||||
Config(m)
|
||||
raises(AttributeError, "a._requires = 'a'")
|
||||
raises(AttributeError, "b._requires = 'b'")
|
||||
raises(AttributeError, "c._requires = 'c'")
|
||||
raises(AttributeError, "d._requires = 'd'")
|
||||
raises(AttributeError, "e._requires = 'e'")
|
||||
raises(AttributeError, "g._requires = 'g'")
|
||||
raises(AttributeError, "h._requires = 'h'")
|
||||
raises(AttributeError, "i._requires = 'i'")
|
||||
raises(AttributeError, "j._requires = 'j'")
|
||||
raises(AttributeError, "k._requires = 'k'")
|
||||
raises(AttributeError, "l._requires = 'l'")
|
||||
raises(AttributeError, "m._requires = 'm'")
|
||||
|
||||
|
||||
def test_slots_option_readonly_name():
|
||||
a = ChoiceOption('a', '', ('a',))
|
||||
b = BoolOption('b', '')
|
||||
c = IntOption('c', '')
|
||||
d = FloatOption('d', '')
|
||||
e = StrOption('e', '')
|
||||
f = SymLinkOption('f', c)
|
||||
g = UnicodeOption('g', '')
|
||||
h = IPOption('h', '')
|
||||
i = PortOption('i', '')
|
||||
j = NetworkOption('j', '')
|
||||
k = NetmaskOption('k', '')
|
||||
l = DomainnameOption('l', '')
|
||||
m = OptionDescription('m', '', [a, b, c, d, e, f, g, h, i, j, k, l])
|
||||
raises(AttributeError, "a._name = 'a'")
|
||||
raises(AttributeError, "b._name = 'b'")
|
||||
raises(AttributeError, "c._name = 'c'")
|
||||
raises(AttributeError, "d._name = 'd'")
|
||||
raises(AttributeError, "e._name = 'e'")
|
||||
raises(AttributeError, "f._name = 'f'")
|
||||
raises(AttributeError, "g._name = 'g'")
|
||||
raises(AttributeError, "h._name = 'h'")
|
||||
raises(AttributeError, "i._name = 'i'")
|
||||
raises(AttributeError, "j._name = 'j'")
|
||||
raises(AttributeError, "k._name = 'k'")
|
||||
raises(AttributeError, "l._name = 'l'")
|
||||
raises(AttributeError, "m._name = 'm'")
|
||||
|
||||
|
||||
def test_slots_description():
|
||||
# __slots__ for OptionDescription must be complete
|
||||
slots = set()
|
||||
for subclass in OptionDescription.__mro__:
|
||||
if subclass is not object:
|
||||
slots.update(subclass.__slots__)
|
||||
assert slots == set(OptionDescription.__slots__)
|
||||
|
||||
|
||||
def test_slots_config():
|
||||
od1 = OptionDescription('a', '', [])
|
||||
od2 = OptionDescription('a', '', [od1])
|
||||
|
Reference in New Issue
Block a user