2013-08-27 21:36:52 +02: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()
|
|
|
|
|
2017-07-21 22:34:41 +02:00
|
|
|
from py.test import raises
|
2013-08-27 09:46:52 +02:00
|
|
|
|
2017-07-21 22:34:41 +02:00
|
|
|
from tiramisu.error import ConfigError
|
2018-08-14 22:15:40 +02:00
|
|
|
from tiramisu import Config
|
2017-10-14 13:33:25 +02:00
|
|
|
from tiramisu.option import BoolOption, OptionDescription, MasterSlaves
|
2017-07-04 19:59:42 +02:00
|
|
|
from tiramisu.setting import groups, owners
|
2013-09-06 23:15:28 +02:00
|
|
|
from tiramisu.storage import list_sessions, delete_session
|
2013-08-27 09:46:52 +02:00
|
|
|
|
|
|
|
|
2018-10-31 08:00:19 +01:00
|
|
|
def teardown_function(function):
|
|
|
|
assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__)
|
|
|
|
|
|
|
|
|
2013-08-27 09:46:52 +02:00
|
|
|
def test_non_persistent():
|
|
|
|
b = BoolOption('b', '')
|
|
|
|
o = OptionDescription('od', '', [b])
|
|
|
|
Config(o, session_id='test_non_persistent')
|
|
|
|
|
|
|
|
|
2018-09-11 20:11:13 +02:00
|
|
|
def test_list():
|
|
|
|
b = BoolOption('b', '')
|
|
|
|
o = OptionDescription('od', '', [b])
|
|
|
|
c = Config(o, session_id='test_non_persistent')
|
|
|
|
c.option('b').value.set(True)
|
2018-10-31 08:00:19 +01:00
|
|
|
assert 'test_non_persistent' in list_sessions()
|
2018-09-11 20:11:13 +02:00
|
|
|
del(c)
|
2018-10-31 08:00:19 +01:00
|
|
|
assert 'test_non_persistent' not in list_sessions()
|
2018-09-11 20:11:13 +02:00
|
|
|
|
|
|
|
|
2018-09-13 22:01:27 +02:00
|
|
|
def test_delete_not_persisten():
|
|
|
|
b = BoolOption('b', '')
|
|
|
|
o = OptionDescription('od', '', [b])
|
|
|
|
try:
|
|
|
|
Config(o, session_id='test_persistent', persistent=True)
|
|
|
|
except:
|
|
|
|
c = Config(o, session_id='not_test_persistent')
|
2018-10-31 08:00:19 +01:00
|
|
|
assert 'not_test_persistent' in list_sessions()
|
2018-09-13 22:01:27 +02:00
|
|
|
del c
|
2018-10-31 08:00:19 +01:00
|
|
|
assert 'not_test_persistent' not in list_sessions()
|
2018-09-13 22:01:27 +02:00
|
|
|
#
|
|
|
|
c = Config(o, session_id='not_test_persistent')
|
|
|
|
raises(ValueError, "delete_session('not_test_persistent')")
|
|
|
|
|
|
|
|
|
2018-09-11 20:11:13 +02:00
|
|
|
def test_create_persistent():
|
|
|
|
b = BoolOption('b', '')
|
|
|
|
o = OptionDescription('od', '', [b])
|
|
|
|
try:
|
|
|
|
Config(o, session_id='test_persistent', persistent=True)
|
|
|
|
delete_session('test_persistent')
|
|
|
|
except ValueError:
|
|
|
|
# storage is not persistent
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
def test_create_delete_not_persistent():
|
|
|
|
b = BoolOption('b', '')
|
|
|
|
o = OptionDescription('od', '', [b])
|
|
|
|
try:
|
|
|
|
Config(o, session_id='test_persistent', persistent=True)
|
|
|
|
delete_session('test_persistent')
|
|
|
|
except ValueError:
|
|
|
|
raises(ValueError, "delete_session('test_persistent')")
|
|
|
|
|
|
|
|
|
|
|
|
def test_list_sessions_persistent():
|
|
|
|
b = BoolOption('b', '')
|
|
|
|
o = OptionDescription('od', '', [b])
|
|
|
|
try:
|
|
|
|
c = Config(o, session_id='test_persistent', persistent=True)
|
|
|
|
c.option('b').value.set(True)
|
|
|
|
except ValueError:
|
|
|
|
# storage is not persistent
|
|
|
|
pass
|
|
|
|
else:
|
2018-10-31 08:00:19 +01:00
|
|
|
assert 'test_persistent' in list_sessions()
|
2018-09-11 20:11:13 +02:00
|
|
|
delete_session('test_persistent')
|
|
|
|
|
|
|
|
|
|
|
|
def test_delete_session_persistent():
|
|
|
|
b = BoolOption('b', '')
|
|
|
|
o = OptionDescription('od', '', [b])
|
|
|
|
try:
|
|
|
|
Config(o, session_id='test_persistent', persistent=True)
|
|
|
|
except ValueError:
|
|
|
|
# storage is not persistent
|
|
|
|
pass
|
|
|
|
else:
|
2018-10-31 08:00:19 +01:00
|
|
|
assert 'test_persistent' in list_sessions()
|
2018-09-11 20:11:13 +02:00
|
|
|
delete_session('test_persistent')
|
2018-10-31 08:00:19 +01:00
|
|
|
assert 'test_persistent' not in list_sessions()
|
2018-09-11 20:11:13 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_create_persistent_retrieve():
|
|
|
|
b = BoolOption('b', '')
|
|
|
|
o = OptionDescription('od', '', [b])
|
|
|
|
try:
|
|
|
|
c = Config(o, session_id='test_persistent', persistent=True)
|
|
|
|
except ValueError:
|
|
|
|
# storage is not persistent
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
assert c.option('b').value.get() is None
|
|
|
|
c.option('b').value.set(True)
|
|
|
|
assert c.option('b').value.get() is True
|
|
|
|
del c
|
|
|
|
c = Config(o, session_id='test_persistent', persistent=True)
|
|
|
|
assert c.option('b').value.get() is True
|
2018-10-31 08:00:19 +01:00
|
|
|
assert 'test_persistent' in list_sessions()
|
2018-09-11 20:11:13 +02:00
|
|
|
delete_session(c.config.name())
|
|
|
|
del c
|
|
|
|
c = Config(o, session_id='test_persistent', persistent=True)
|
|
|
|
assert c.option('b').value.get() is None
|
|
|
|
delete_session(c.config.name())
|
|
|
|
del c
|
|
|
|
|
|
|
|
|
|
|
|
def test_two_persistent():
|
|
|
|
b = BoolOption('b', '')
|
|
|
|
o = OptionDescription('od', '', [b])
|
|
|
|
try:
|
|
|
|
c = Config(o, session_id='test_persistent', persistent=True)
|
|
|
|
except ValueError:
|
|
|
|
# storage is not persistent
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
c2 = Config(o, session_id='test_persistent', persistent=True)
|
|
|
|
c2.property.pop('cache')
|
|
|
|
assert c.option('b').value.get() is None
|
|
|
|
assert c2.option('b').value.get() is None
|
|
|
|
#
|
|
|
|
c.option('b').value.set(False)
|
|
|
|
assert c.option('b').value.get() is False
|
|
|
|
assert c2.option('b').value.get() is False
|
|
|
|
#
|
|
|
|
c.option('b').value.set(True)
|
|
|
|
assert c.option('b').value.get() is True
|
|
|
|
assert c2.option('b').value.get() is True
|
|
|
|
delete_session('test_persistent')
|
|
|
|
|
|
|
|
|
|
|
|
def test_create_persistent_retrieve_owner():
|
|
|
|
b = BoolOption('b', '')
|
|
|
|
o = OptionDescription('od', '', [b])
|
|
|
|
try:
|
|
|
|
c = Config(o, session_id='test_persistent', persistent=True)
|
|
|
|
except ValueError:
|
|
|
|
# storage is not persistent
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
assert c.option('b').owner.isdefault()
|
|
|
|
c.option('b').value.set(True)
|
|
|
|
assert c.option('b').value.get()
|
|
|
|
assert c.option('b').owner.get() == 'user'
|
|
|
|
##owners.addowner('persistentowner')
|
|
|
|
c.option('b').owner.set('persistentowner')
|
|
|
|
assert c.option('b').owner.get() == 'persistentowner'
|
|
|
|
del c
|
|
|
|
#
|
|
|
|
c = Config(o, session_id='test_persistent', persistent=True)
|
|
|
|
c.option('b').owner.set('persistentowner')
|
|
|
|
delete_session(c.config.name())
|
|
|
|
del c
|
|
|
|
#
|
|
|
|
c = Config(o, session_id='test_persistent', persistent=True)
|
|
|
|
assert c.option('b').value.get() is None
|
|
|
|
assert c.option('b').owner.isdefault()
|
|
|
|
delete_session(c.config.name())
|
|
|
|
del c
|
|
|
|
|
|
|
|
|
|
|
|
def test_create_persistent_retrieve_owner_masterslaves():
|
|
|
|
a = BoolOption('a', '', multi=True)
|
|
|
|
b = BoolOption('b', '', multi=True)
|
|
|
|
o = MasterSlaves('a', '', [a, b])
|
|
|
|
#o.impl_set_group_type(groups.master)
|
|
|
|
o1 = OptionDescription('a', '', [o])
|
|
|
|
try:
|
|
|
|
c = Config(o1, session_id='test_persistent', persistent=True)
|
|
|
|
except ValueError:
|
|
|
|
# storage is not persistent
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
assert c.option('a.a').owner.isdefault()
|
|
|
|
c.option('a.a').value.set([True, False])
|
|
|
|
c.option('a.b', 1).value.set(True)
|
|
|
|
assert c.option('a.a').owner.get() == 'user'
|
|
|
|
assert c.option('a.b', 0).owner.isdefault()
|
|
|
|
assert c.option('a.b', 1).owner.get() == 'user'
|
|
|
|
#owners.addowner('persistentowner2')
|
|
|
|
c.option('a.b', 1).owner.set('persistentowner2')
|
|
|
|
c.option('a.b', 0).value.set(True)
|
|
|
|
assert c.option('a.b', 0).owner.get() == 'user'
|
|
|
|
assert c.option('a.b', 1).owner.get() == 'persistentowner2'
|
|
|
|
assert c.option('a.a').value.get() == [True, False]
|
|
|
|
del c
|
|
|
|
#
|
|
|
|
c = Config(o1, session_id='test_persistent', persistent=True)
|
|
|
|
assert c.option('a.a').value.get() == [True, False]
|
|
|
|
assert c.option('a.b', 0).owner.get() == 'user'
|
|
|
|
assert c.option('a.b', 1).owner.get() == 'persistentowner2'
|
|
|
|
delete_session(c.config.name())
|
|
|
|
del c
|
|
|
|
#
|
|
|
|
c = Config(o1, session_id='test_persistent', persistent=True)
|
|
|
|
assert c.option('a.a').value.get() == []
|
|
|
|
delete_session(c.config.name())
|
|
|
|
del c
|
|
|
|
|
|
|
|
|
|
|
|
def test_two_persistent_owner():
|
|
|
|
b = BoolOption('b', '')
|
|
|
|
o = OptionDescription('od', '', [b])
|
|
|
|
try:
|
|
|
|
c = Config(o, session_id='test_persistent', persistent=True)
|
|
|
|
c.property.pop('cache')
|
|
|
|
except ValueError:
|
|
|
|
# storage is not persistent
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
c2 = Config(o, session_id='test_persistent', persistent=True)
|
|
|
|
c2.property.pop('cache')
|
|
|
|
assert c.option('b').owner.isdefault()
|
|
|
|
assert c2.option('b').owner.isdefault()
|
|
|
|
c.option('b').value.set(False)
|
|
|
|
assert c.option('b').owner.get() == 'user'
|
|
|
|
assert c2.option('b').owner.get() == 'user'
|
|
|
|
c.option('b').owner.set('persistent')
|
|
|
|
assert c.option('b').owner.get() == 'persistent'
|
|
|
|
assert c2.option('b').owner.get() == 'persistent'
|
|
|
|
delete_session('test_persistent')
|
|
|
|
|
|
|
|
|
|
|
|
def test_create_persistent_retrieve_information():
|
|
|
|
b = BoolOption('b', '')
|
|
|
|
o = OptionDescription('od', '', [b])
|
|
|
|
try:
|
|
|
|
c = Config(o, session_id='test_persistent', persistent=True)
|
|
|
|
except ValueError:
|
|
|
|
# storage is not persistent
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
c.information.set('info', 'string')
|
|
|
|
assert c.information.get('info') == 'string'
|
|
|
|
del c
|
|
|
|
#
|
|
|
|
c = Config(o, session_id='test_persistent', persistent=True)
|
|
|
|
assert c.information.get('info') == 'string'
|
|
|
|
delete_session(c.config.name())
|
|
|
|
del c
|
|
|
|
#
|
|
|
|
c = Config(o, session_id='test_persistent', persistent=True)
|
|
|
|
assert c.information.get('info', None) is None
|
|
|
|
delete_session(c.config.name())
|
|
|
|
del c
|
|
|
|
|
|
|
|
|
|
|
|
def test_two_persistent_information():
|
|
|
|
b = BoolOption('b', '')
|
|
|
|
o = OptionDescription('od', '', [b])
|
|
|
|
try:
|
|
|
|
c = Config(o, session_id='test_persistent', persistent=True)
|
|
|
|
c.property.pop('cache')
|
|
|
|
except ValueError:
|
|
|
|
# storage is not persistent
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
c.information.set('info', 'string')
|
|
|
|
assert c.information.get('info') == 'string'
|
|
|
|
c2 = Config(o, session_id='test_persistent', persistent=True)
|
|
|
|
c2.property.pop('cache')
|
|
|
|
assert c2.information.get('info') == 'string'
|
|
|
|
delete_session('test_persistent')
|
|
|
|
|
|
|
|
|
|
|
|
def test_two_different_persistents():
|
|
|
|
b = BoolOption('b', '')
|
|
|
|
o = OptionDescription('od', '', [b])
|
|
|
|
try:
|
|
|
|
c = Config(o, session_id='test_persistent', persistent=True)
|
|
|
|
c.property.pop('cache')
|
|
|
|
d = Config(o, session_id='test_persistent2', persistent=True)
|
|
|
|
d.property.pop('cache')
|
|
|
|
except ValueError:
|
|
|
|
# storage is not persistent
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
c.option('b').property.add('test')
|
|
|
|
assert c.option('b').property.get() == {'test'}
|
|
|
|
assert d.option('b').property.get() == set()
|
|
|
|
assert c.option('b').value.get() is None
|
|
|
|
assert d.option('b').value.get() is None
|
|
|
|
c.option('b').value.set(True)
|
|
|
|
assert c.option('b').value.get() == True
|
|
|
|
assert d.option('b').value.get() is None
|
|
|
|
|
|
|
|
delete_session('test_persistent')
|
|
|
|
delete_session('test_persistent2')
|
|
|
|
|
|
|
|
|
|
|
|
def test_two_different_information():
|
|
|
|
b = BoolOption('b', '')
|
|
|
|
o = OptionDescription('od', '', [b])
|
|
|
|
try:
|
|
|
|
c = Config(o, session_id='test_persistent', persistent=True)
|
|
|
|
c.information.set('a', 'a')
|
|
|
|
d = Config(o, session_id='test_persistent2', persistent=True)
|
|
|
|
d.information.set('a', 'b')
|
|
|
|
except ValueError:
|
|
|
|
# storage is not persistent
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
assert c.information.get('a') == 'a'
|
|
|
|
assert d.information.get('a') == 'b'
|
|
|
|
|
|
|
|
delete_session('test_persistent')
|
|
|
|
delete_session('test_persistent2')
|
2018-09-12 21:05:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_exportation_importation():
|
|
|
|
b = BoolOption('b', '')
|
|
|
|
o = OptionDescription('od', '', [b])
|
|
|
|
try:
|
|
|
|
c = Config(o, session_id='test_persistent', persistent=True)
|
|
|
|
d = Config(o, session_id='test_persistent2', persistent=True)
|
2018-09-15 22:44:49 +02:00
|
|
|
e = Config(o, session_id='test_persistent3', persistent=True)
|
2018-09-12 21:05:56 +02:00
|
|
|
except ValueError:
|
|
|
|
# storage is not persistent
|
|
|
|
pass
|
|
|
|
else:
|
2018-09-15 22:44:49 +02:00
|
|
|
c.owner.set('export')
|
2018-09-12 21:05:56 +02:00
|
|
|
assert c.option('b').value.get() is None
|
|
|
|
c.option('b').value.set(True)
|
|
|
|
assert c.option('b').value.get() is True
|
2018-09-15 22:44:49 +02:00
|
|
|
assert c.owner.get() == 'export'
|
2018-09-12 21:05:56 +02:00
|
|
|
del c
|
|
|
|
#
|
|
|
|
c = Config(o, session_id='test_persistent', persistent=True)
|
2018-09-15 22:44:49 +02:00
|
|
|
assert c.owner.get() == 'export'
|
|
|
|
assert c.value.exportation() == [['b'], [None], [True], ['export']]
|
2018-09-12 21:05:56 +02:00
|
|
|
d.value.importation(c.value.exportation())
|
2018-09-15 22:44:49 +02:00
|
|
|
assert c.value.exportation() == [['b'], [None], [True], ['export']]
|
|
|
|
assert c.owner.get() == 'export'
|
|
|
|
assert d.value.exportation() == [['b'], [None], [True], ['export']]
|
|
|
|
assert d.owner.get() == 'user'
|
2018-09-12 21:05:56 +02:00
|
|
|
del d
|
|
|
|
#
|
|
|
|
d = Config(o, session_id='test_persistent2', persistent=True)
|
2018-09-15 22:44:49 +02:00
|
|
|
assert d.value.exportation() == [['b'], [None], [True], ['export']]
|
|
|
|
assert d.owner.get() == 'user'
|
|
|
|
#
|
|
|
|
e.value.importation(c.value.exportation(with_default_owner=True))
|
|
|
|
assert e.value.exportation() == [['b'], [None], [True], ['export']]
|
|
|
|
assert e.owner.get() == 'export'
|
|
|
|
del e
|
|
|
|
#
|
|
|
|
e = Config(o, session_id='test_persistent3', persistent=True)
|
|
|
|
assert e.value.exportation() == [['b'], [None], [True], ['export']]
|
|
|
|
assert e.owner.get() == 'export'
|
|
|
|
#
|
2018-09-12 21:05:56 +02:00
|
|
|
delete_session('test_persistent')
|
|
|
|
delete_session('test_persistent2')
|
2018-09-15 22:44:49 +02:00
|
|
|
delete_session('test_persistent3')
|