2013-11-23 23:34:17 +01:00
|
|
|
## 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()
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
import pytest
|
|
|
|
import warnings
|
2014-02-16 23:37:27 +01:00
|
|
|
|
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
|
2014-02-16 23:37:27 +01:00
|
|
|
from tiramisu.option import ChoiceOption, BoolOption, IntOption, FloatOption,\
|
2019-12-08 09:09:48 +01:00
|
|
|
StrOption, SymLinkOption, StrOption, IPOption, OptionDescription, \
|
2014-02-16 23:37:27 +01:00
|
|
|
PortOption, NetworkOption, NetmaskOption, DomainnameOption, EmailOption, \
|
|
|
|
URLOption, FilenameOption
|
|
|
|
|
|
|
|
|
2014-04-14 23:00:37 +02:00
|
|
|
def test_slots_option():
|
|
|
|
c = ChoiceOption('a', '', ('a',))
|
2020-01-22 20:46:18 +01:00
|
|
|
with pytest.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', '')
|
2020-01-22 20:46:18 +01:00
|
|
|
with pytest.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', '')
|
2020-01-22 20:46:18 +01:00
|
|
|
with pytest.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', '')
|
2020-01-22 20:46:18 +01:00
|
|
|
with pytest.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', '')
|
2020-01-22 20:46:18 +01:00
|
|
|
with pytest.raises(AttributeError):
|
|
|
|
c.x = 1
|
2014-04-14 23:00:37 +02:00
|
|
|
c = SymLinkOption('b', c)
|
2020-01-22 20:46:18 +01:00
|
|
|
with pytest.raises(AttributeError):
|
|
|
|
c.x = 1
|
2018-10-31 08:00:19 +01:00
|
|
|
del c
|
2019-12-08 09:09:48 +01:00
|
|
|
c = StrOption('a', '')
|
2020-01-22 20:46:18 +01:00
|
|
|
with pytest.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', '')
|
2020-01-22 20:46:18 +01:00
|
|
|
with pytest.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', '', [])
|
2020-01-22 20:46:18 +01:00
|
|
|
with pytest.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', '')
|
2020-01-22 20:46:18 +01:00
|
|
|
with pytest.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', '')
|
2020-01-22 20:46:18 +01:00
|
|
|
with pytest.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', '')
|
2020-01-22 20:46:18 +01:00
|
|
|
with pytest.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', '')
|
2020-01-22 20:46:18 +01:00
|
|
|
with pytest.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', '')
|
2020-01-22 20:46:18 +01:00
|
|
|
with pytest.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', '')
|
2020-01-22 20:46:18 +01:00
|
|
|
with pytest.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', '')
|
2020-01-22 20:46:18 +01:00
|
|
|
with pytest.raises(AttributeError):
|
|
|
|
c.x = 1
|
2018-10-31 08:00:19 +01:00
|
|
|
del c
|
2014-04-14 23:00:37 +02:00
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_slots_option_readonly():
|
2014-04-14 23:00:37 +02:00
|
|
|
a = ChoiceOption('a', '', ('a',))
|
|
|
|
b = BoolOption('b', '')
|
|
|
|
c = IntOption('c', '')
|
|
|
|
d = FloatOption('d', '')
|
|
|
|
e = StrOption('e', '')
|
2019-12-08 09:09:48 +01:00
|
|
|
g = StrOption('g', '')
|
2014-04-14 23:00:37 +02:00
|
|
|
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'
|
2023-04-15 16:12:35 +02:00
|
|
|
Config(m)
|
2020-01-22 20:46:18 +01:00
|
|
|
with pytest.raises(AttributeError):
|
|
|
|
a._requires = 'a'
|
|
|
|
with pytest.raises(AttributeError):
|
|
|
|
b._requires = 'b'
|
|
|
|
with pytest.raises(AttributeError):
|
|
|
|
c._requires = 'c'
|
|
|
|
with pytest.raises(AttributeError):
|
|
|
|
d._requires = 'd'
|
|
|
|
with pytest.raises(AttributeError):
|
|
|
|
e._requires = 'e'
|
|
|
|
with pytest.raises(AttributeError):
|
|
|
|
g._requires = 'g'
|
|
|
|
with pytest.raises(AttributeError):
|
|
|
|
h._requires = 'h'
|
|
|
|
with pytest.raises(AttributeError):
|
|
|
|
i._requires = 'i'
|
|
|
|
with pytest.raises(AttributeError):
|
|
|
|
j._requires = 'j'
|
|
|
|
with pytest.raises(AttributeError):
|
|
|
|
k._requires = 'k'
|
|
|
|
with pytest.raises(AttributeError):
|
|
|
|
l._requires = 'l'
|
|
|
|
with pytest.raises(AttributeError):
|
|
|
|
m._requires = 'm'
|
|
|
|
with pytest.raises(AttributeError):
|
|
|
|
o._requires = 'o'
|
|
|
|
with pytest.raises(AttributeError):
|
|
|
|
p._requires = 'p'
|
|
|
|
with pytest.raises(AttributeError):
|
|
|
|
q._requires = 'q'
|
2023-04-15 16:12:35 +02:00
|
|
|
# assert not list_sessions()
|
2014-04-14 23:00:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
#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__)
|
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_slots_setting():
|
2014-04-14 23:00:37 +02:00
|
|
|
od1 = OptionDescription('a', '', [])
|
|
|
|
od2 = OptionDescription('a', '', [od1])
|
2023-04-15 16:12:35 +02:00
|
|
|
cfg = Config(od2)
|
|
|
|
s = cfg._config_bag.context.get_settings()
|
|
|
|
s
|
|
|
|
with pytest.raises(AttributeError):
|
|
|
|
s.x = 1
|
|
|
|
# assert not list_sessions()
|
2014-04-14 23:00:37 +02:00
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_slots_value():
|
2014-04-14 23:00:37 +02:00
|
|
|
od1 = OptionDescription('a', '', [])
|
|
|
|
od2 = OptionDescription('a', '', [od1])
|
2023-04-15 16:12:35 +02:00
|
|
|
cfg = Config(od2)
|
|
|
|
v = cfg._config_bag.context.get_values()
|
|
|
|
v
|
|
|
|
with pytest.raises(AttributeError):
|
|
|
|
v.x = 1
|
|
|
|
# assert not list_sessions()
|