2013-04-20 17:30:05 +02:00
|
|
|
# coding: utf-8
|
|
|
|
import autopath
|
2013-08-23 09:29:42 +02:00
|
|
|
from py.test import raises
|
|
|
|
|
2013-04-20 17:30:05 +02:00
|
|
|
from tiramisu.option import IntOption, OptionDescription
|
|
|
|
from tiramisu.config import Config
|
|
|
|
from tiramisu.error import PropertiesOptionError
|
|
|
|
|
|
|
|
|
|
|
|
def make_description():
|
|
|
|
u1 = IntOption('u1', '', properties=('frozen', 'mandatory', 'disabled', ))
|
2013-12-09 15:29:37 +01:00
|
|
|
u2 = IntOption('u2', '', properties=('frozen', 'mandatory', 'disabled', ))
|
|
|
|
return OptionDescription('od1', '', [u1, u2])
|
2013-04-20 17:30:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_permissive():
|
|
|
|
descr = make_description()
|
|
|
|
config = Config(descr)
|
|
|
|
setting = config.cfgimpl_get_settings()
|
2013-04-22 09:19:05 +02:00
|
|
|
config.read_write()
|
2013-04-20 17:30:05 +02:00
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
config.u1
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-04-20 17:30:05 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
2013-08-21 22:21:50 +02:00
|
|
|
setting.setpermissive(('disabled',))
|
2013-04-20 17:30:05 +02:00
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
config.u1
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-04-20 17:30:05 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
setting.append('permissive')
|
|
|
|
config.u1
|
|
|
|
setting.remove('permissive')
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
config.u1
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-04-20 17:30:05 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
|
|
|
|
|
|
|
|
def test_permissive_mandatory():
|
|
|
|
descr = make_description()
|
|
|
|
config = Config(descr)
|
|
|
|
setting = config.cfgimpl_get_settings()
|
2013-04-22 09:19:05 +02:00
|
|
|
config.read_only()
|
2013-04-20 17:30:05 +02:00
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
config.u1
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-04-20 17:30:05 +02:00
|
|
|
props = err.proptype
|
2013-08-28 11:33:43 +02:00
|
|
|
assert set(props) == set(['disabled', 'mandatory'])
|
2013-08-21 22:21:50 +02:00
|
|
|
setting.setpermissive(('mandatory', 'disabled',))
|
2013-04-20 17:30:05 +02:00
|
|
|
setting.append('permissive')
|
|
|
|
config.u1
|
|
|
|
setting.remove('permissive')
|
|
|
|
try:
|
|
|
|
config.u1
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-04-20 17:30:05 +02:00
|
|
|
props = err.proptype
|
2013-08-28 11:33:43 +02:00
|
|
|
assert set(props) == set(['disabled', 'mandatory'])
|
2013-04-20 17:30:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_permissive_frozen():
|
|
|
|
descr = make_description()
|
|
|
|
config = Config(descr)
|
|
|
|
setting = config.cfgimpl_get_settings()
|
2013-04-22 09:19:05 +02:00
|
|
|
config.read_write()
|
2013-08-21 22:21:50 +02:00
|
|
|
setting.setpermissive(('frozen', 'disabled',))
|
2013-04-20 17:30:05 +02:00
|
|
|
try:
|
|
|
|
config.u1 = 1
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-04-20 17:30:05 +02:00
|
|
|
props = err.proptype
|
2013-08-28 21:23:42 +02:00
|
|
|
assert set(props) == set(['frozen', 'disabled'])
|
2013-04-20 17:30:05 +02:00
|
|
|
setting.append('permissive')
|
|
|
|
config.u1 = 1
|
|
|
|
assert config.u1 == 1
|
|
|
|
setting.remove('permissive')
|
|
|
|
try:
|
|
|
|
config.u1 = 1
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-04-20 17:30:05 +02:00
|
|
|
props = err.proptype
|
2013-08-28 21:23:42 +02:00
|
|
|
assert set(props) == set(['frozen', 'disabled'])
|
2013-08-23 09:29:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_invalid_permissive():
|
|
|
|
descr = make_description()
|
|
|
|
config = Config(descr)
|
|
|
|
setting = config.cfgimpl_get_settings()
|
|
|
|
config.read_write()
|
|
|
|
raises(TypeError, "setting.setpermissive(['frozen', 'disabled',])")
|
2013-12-09 15:29:37 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_permissive_option():
|
|
|
|
descr = make_description()
|
|
|
|
u1 = descr.u1
|
|
|
|
config = Config(descr)
|
|
|
|
setting = config.cfgimpl_get_settings()
|
|
|
|
config.read_write()
|
|
|
|
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
config.u1
|
|
|
|
except PropertiesOptionError as err:
|
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
config.u2
|
|
|
|
except PropertiesOptionError as err:
|
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
|
|
|
|
setting.setpermissive(('disabled',), u1)
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
config.u1
|
|
|
|
except PropertiesOptionError as err:
|
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
config.u2
|
|
|
|
except PropertiesOptionError as err:
|
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
|
|
|
|
setting.append('permissive')
|
|
|
|
config.u1
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
config.u2
|
|
|
|
except PropertiesOptionError as err:
|
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
|
|
|
|
setting.remove('permissive')
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
config.u1
|
|
|
|
except PropertiesOptionError as err:
|
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
config.u2
|
|
|
|
except PropertiesOptionError as err:
|
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
|
|
|
|
|
|
|
|
def test_permissive_option_mandatory():
|
|
|
|
descr = make_description()
|
|
|
|
u1 = descr.u1
|
|
|
|
config = Config(descr)
|
|
|
|
setting = config.cfgimpl_get_settings()
|
|
|
|
config.read_only()
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
config.u1
|
|
|
|
except PropertiesOptionError as err:
|
|
|
|
props = err.proptype
|
|
|
|
assert set(props) == set(['disabled', 'mandatory'])
|
|
|
|
setting.setpermissive(('mandatory', 'disabled',), u1)
|
|
|
|
setting.append('permissive')
|
|
|
|
config.u1
|
|
|
|
setting.remove('permissive')
|
|
|
|
try:
|
|
|
|
config.u1
|
|
|
|
except PropertiesOptionError as err:
|
|
|
|
props = err.proptype
|
|
|
|
assert set(props) == set(['disabled', 'mandatory'])
|
|
|
|
|
|
|
|
|
|
|
|
def test_permissive_option_frozen():
|
|
|
|
descr = make_description()
|
|
|
|
config = Config(descr)
|
|
|
|
u1 = descr.u1
|
|
|
|
setting = config.cfgimpl_get_settings()
|
|
|
|
config.read_write()
|
|
|
|
setting.setpermissive(('frozen', 'disabled'), u1)
|
|
|
|
try:
|
|
|
|
config.u1 = 1
|
|
|
|
except PropertiesOptionError as err:
|
|
|
|
props = err.proptype
|
|
|
|
assert set(props) == set(['frozen', 'disabled'])
|
|
|
|
setting.append('permissive')
|
|
|
|
config.u1 = 1
|
|
|
|
assert config.u1 == 1
|
|
|
|
setting.remove('permissive')
|
|
|
|
try:
|
|
|
|
config.u1 = 1
|
|
|
|
except PropertiesOptionError as err:
|
|
|
|
props = err.proptype
|
|
|
|
assert set(props) == set(['frozen', 'disabled'])
|
|
|
|
|
|
|
|
|
|
|
|
def test_invalid_option_permissive():
|
|
|
|
descr = make_description()
|
|
|
|
u1 = descr.u1
|
|
|
|
config = Config(descr)
|
|
|
|
setting = config.cfgimpl_get_settings()
|
|
|
|
config.read_write()
|
|
|
|
raises(TypeError, "setting.setpermissive(['frozen', 'disabled',], u1)")
|