tiramisu/tests/test_slots.py

166 lines
4.8 KiB
Python
Raw Normal View History

## coding: utf-8
2017-07-09 09:49:03 +02:00
from .autopath import do_autopath
2015-07-24 17:54:10 +02:00
do_autopath()
from py.test import raises
2018-03-19 08:33:53 +01:00
try:
2018-08-01 08:37:58 +02:00
from tiramisu.setting import OptionBag, ConfigBag
2018-03-19 08:33:53 +01:00
tiramisu_version = 3
except:
tiramisu_version = 2
2018-08-14 22:15:40 +02:00
from tiramisu import Config
from tiramisu.config import SubConfig
from tiramisu.option import ChoiceOption, BoolOption, IntOption, FloatOption,\
StrOption, SymLinkOption, UnicodeOption, IPOption, OptionDescription, \
PortOption, NetworkOption, NetmaskOption, DomainnameOption, EmailOption, \
URLOption, FilenameOption
2018-10-31 08:00:19 +01:00
from tiramisu.storage import list_sessions, delete_session
def teardown_function(function):
assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__)
2014-04-14 23:00:37 +02:00
def test_slots_option():
c = ChoiceOption('a', '', ('a',))
raises(AttributeError, "c.x = 1")
2018-10-31 08:00:19 +01:00
del c
2014-04-14 23:00:37 +02:00
c = BoolOption('a', '')
raises(AttributeError, "c.x = 1")
2018-10-31 08:00:19 +01:00
del c
2014-04-14 23:00:37 +02:00
c = IntOption('a', '')
raises(AttributeError, "c.x = 1")
2018-10-31 08:00:19 +01:00
del c
2014-04-14 23:00:37 +02:00
c = FloatOption('a', '')
raises(AttributeError, "c.x = 1")
2018-10-31 08:00:19 +01:00
del c
2014-04-14 23:00:37 +02:00
c = StrOption('a', '')
raises(AttributeError, "c.x = 1")
c = SymLinkOption('b', c)
raises(AttributeError, "c.x = 1")
2018-10-31 08:00:19 +01:00
del c
2014-04-14 23:00:37 +02:00
c = UnicodeOption('a', '')
raises(AttributeError, "c.x = 1")
2018-10-31 08:00:19 +01:00
del c
2014-04-14 23:00:37 +02:00
c = IPOption('a', '')
raises(AttributeError, "c.x = 1")
2018-10-31 08:00:19 +01:00
del c
2014-04-14 23:00:37 +02:00
c = OptionDescription('a', '', [])
raises(AttributeError, "c.x = 1")
2018-10-31 08:00:19 +01:00
del c
2014-04-14 23:00:37 +02:00
c = PortOption('a', '')
raises(AttributeError, "c.x = 1")
2018-10-31 08:00:19 +01:00
del c
2014-04-14 23:00:37 +02:00
c = NetworkOption('a', '')
raises(AttributeError, "c.x = 1")
2018-10-31 08:00:19 +01:00
del c
2014-04-14 23:00:37 +02:00
c = NetmaskOption('a', '')
raises(AttributeError, "c.x = 1")
2018-10-31 08:00:19 +01:00
del c
2014-04-14 23:00:37 +02:00
c = DomainnameOption('a', '')
raises(AttributeError, "c.x = 1")
2018-10-31 08:00:19 +01:00
del c
2014-04-14 23:00:37 +02:00
c = EmailOption('a', '')
raises(AttributeError, "c.x = 1")
2018-10-31 08:00:19 +01:00
del c
2014-04-14 23:00:37 +02:00
c = URLOption('a', '')
raises(AttributeError, "c.x = 1")
2018-10-31 08:00:19 +01:00
del c
2014-04-14 23:00:37 +02:00
c = FilenameOption('a', '')
raises(AttributeError, "c.x = 1")
2018-10-31 08:00:19 +01:00
del c
2014-04-14 23:00:37 +02:00
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', '')
o = EmailOption('o', '')
p = URLOption('p', '')
q = FilenameOption('q', '')
m = OptionDescription('m', '', [a, b, c, d, e, g, h, i, j, k, l, o, p, q])
2019-10-27 11:09:15 +01:00
a._name = 'a'
b._name = 'b'
c._name = 'c'
d._name = 'd'
e._name = 'e'
g._name = 'g'
h._name = 'h'
i._name = 'i'
j._name = 'j'
k._name = 'k'
l._name = 'l'
m._name = 'm'
o._name = 'o'
p._name = 'p'
q._name = 'q'
2014-04-14 23:00:37 +02:00
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'")
raises(AttributeError, "o._requires = 'o'")
raises(AttributeError, "p._requires = 'p'")
raises(AttributeError, "q._requires = 'q'")
#def test_slots_description():
# # __slots__ for OptionDescription should be complete for __getattr__
# 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])
c = Config(od2)
raises(AttributeError, "c._config_bag.context.x = 1")
raises(AttributeError, "c._config_bag.context.cfgimpl_x = 1")
2018-08-01 08:37:58 +02:00
option_bag = OptionBag()
option_bag.set_option(od2,
'a',
None,
ConfigBag(c._config_bag.context))
sc = c._config_bag.context.get_subconfig(option_bag)
2014-04-14 23:00:37 +02:00
assert isinstance(sc, SubConfig)
raises(AttributeError, "sc.x = 1")
raises(AttributeError, "sc.cfgimpl_x = 1")
def test_slots_setting():
od1 = OptionDescription('a', '', [])
od2 = OptionDescription('a', '', [od1])
c = Config(od2)
s = c._config_bag.context.cfgimpl_get_settings()
2015-07-24 17:54:10 +02:00
s
2014-04-14 23:00:37 +02:00
raises(AttributeError, "s.x = 1")
def test_slots_value():
od1 = OptionDescription('a', '', [])
od2 = OptionDescription('a', '', [od1])
c = Config(od2)
v = c._config_bag.context.cfgimpl_get_values()
2015-07-24 17:54:10 +02:00
v
2014-04-14 23:00:37 +02:00
raises(AttributeError, "v.x = 1")