2013-04-16 22:44:16 +02:00
|
|
|
import autopath
|
|
|
|
|
|
|
|
#from py.test import raises
|
2014-03-09 20:06:44 +01:00
|
|
|
from tiramisu.config import Config
|
2013-08-28 11:33:43 +02:00
|
|
|
from tiramisu.option import StrOption, UnicodeOption, OptionDescription
|
2013-04-16 22:44:16 +02:00
|
|
|
from tiramisu.error import PropertiesOptionError
|
|
|
|
|
|
|
|
|
|
|
|
def make_description():
|
|
|
|
stroption = StrOption('str', 'Test string option', default="abc",
|
|
|
|
properties=('mandatory', ))
|
|
|
|
stroption1 = StrOption('str1', 'Test string option',
|
|
|
|
properties=('mandatory', ))
|
2013-04-17 22:06:10 +02:00
|
|
|
stroption2 = UnicodeOption('unicode2', 'Test string option',
|
2013-04-20 11:25:14 +02:00
|
|
|
properties=('mandatory', ))
|
2013-04-16 22:44:16 +02:00
|
|
|
stroption3 = StrOption('str3', 'Test string option', multi=True,
|
|
|
|
properties=('mandatory', ))
|
|
|
|
descr = OptionDescription('tiram', '', [stroption, stroption1, stroption2, stroption3])
|
|
|
|
return descr
|
|
|
|
|
|
|
|
|
|
|
|
def test_mandatory_ro():
|
|
|
|
descr = make_description()
|
|
|
|
config = Config(descr)
|
2013-04-22 09:19:05 +02:00
|
|
|
config.read_only()
|
2013-04-16 22:44:16 +02:00
|
|
|
prop = []
|
|
|
|
try:
|
|
|
|
config.str1
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-04-16 22:44:16 +02:00
|
|
|
prop = err.proptype
|
|
|
|
assert 'mandatory' in prop
|
2013-04-22 09:19:05 +02:00
|
|
|
config.read_write()
|
2013-04-16 22:44:16 +02:00
|
|
|
config.str1 = 'yes'
|
2013-04-22 09:19:05 +02:00
|
|
|
config.read_only()
|
2013-04-16 22:44:16 +02:00
|
|
|
assert config.str1 == 'yes'
|
|
|
|
|
|
|
|
|
|
|
|
def test_mandatory_rw():
|
|
|
|
descr = make_description()
|
|
|
|
config = Config(descr)
|
2013-04-22 09:19:05 +02:00
|
|
|
config.read_write()
|
2013-04-16 22:44:16 +02:00
|
|
|
#not mandatory in rw
|
2013-04-17 22:06:10 +02:00
|
|
|
config.str1
|
|
|
|
config.str1 = 'yes'
|
|
|
|
assert config.str1 == 'yes'
|
2013-04-16 22:44:16 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_mandatory_default():
|
|
|
|
descr = make_description()
|
|
|
|
config = Config(descr)
|
2013-04-22 09:19:05 +02:00
|
|
|
config.read_only()
|
2013-04-16 22:44:16 +02:00
|
|
|
#not mandatory in rw
|
|
|
|
config.str
|
2013-04-22 09:19:05 +02:00
|
|
|
config.read_write()
|
2013-04-16 22:44:16 +02:00
|
|
|
config.str = 'yes'
|
2013-04-22 09:19:05 +02:00
|
|
|
config.read_only()
|
2013-04-16 22:44:16 +02:00
|
|
|
config.str
|
2013-04-22 09:19:05 +02:00
|
|
|
config.read_write()
|
2013-04-16 22:44:16 +02:00
|
|
|
config.str = None
|
2013-04-22 09:19:05 +02:00
|
|
|
config.read_only()
|
2013-04-16 22:44:16 +02:00
|
|
|
prop = []
|
|
|
|
try:
|
|
|
|
config.str
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-04-16 22:44:16 +02:00
|
|
|
prop = err.proptype
|
|
|
|
assert 'mandatory' in prop
|
|
|
|
|
|
|
|
|
|
|
|
#valeur vide : None, '', u'', ...
|
|
|
|
def test_mandatory_none():
|
|
|
|
descr = make_description()
|
|
|
|
config = Config(descr)
|
|
|
|
config.str1 = None
|
2013-08-24 22:32:54 +02:00
|
|
|
assert config.getowner(config.unwrap_from_path('str1')) == 'user'
|
2013-04-22 09:19:05 +02:00
|
|
|
config.read_only()
|
2013-04-16 22:44:16 +02:00
|
|
|
prop = []
|
|
|
|
try:
|
|
|
|
config.str1
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-04-16 22:44:16 +02:00
|
|
|
prop = err.proptype
|
|
|
|
assert 'mandatory' in prop
|
|
|
|
|
|
|
|
|
|
|
|
def test_mandatory_empty():
|
|
|
|
descr = make_description()
|
|
|
|
config = Config(descr)
|
|
|
|
config.str1 = ''
|
2013-08-24 22:32:54 +02:00
|
|
|
assert config.getowner(config.unwrap_from_path('str1')) == 'user'
|
2013-04-22 09:19:05 +02:00
|
|
|
config.read_only()
|
2013-04-16 22:44:16 +02:00
|
|
|
prop = []
|
|
|
|
try:
|
|
|
|
config.str1
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-04-16 22:44:16 +02:00
|
|
|
prop = err.proptype
|
|
|
|
assert 'mandatory' in prop
|
|
|
|
|
|
|
|
|
|
|
|
def test_mandatory_multi_none():
|
|
|
|
descr = make_description()
|
|
|
|
config = Config(descr)
|
|
|
|
config.str3 = [None]
|
2013-08-24 22:32:54 +02:00
|
|
|
assert config.getowner(config.unwrap_from_path('str3')) == 'user'
|
2014-03-29 20:31:56 +01:00
|
|
|
config.read_only()
|
2013-04-16 22:44:16 +02:00
|
|
|
prop = []
|
|
|
|
try:
|
|
|
|
config.str3
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-04-16 22:44:16 +02:00
|
|
|
prop = err.proptype
|
|
|
|
assert 'mandatory' in prop
|
2013-04-22 09:19:05 +02:00
|
|
|
config.read_write()
|
2013-04-16 22:44:16 +02:00
|
|
|
config.str3 = ['yes', None]
|
2013-08-24 22:32:54 +02:00
|
|
|
assert config.getowner(config.unwrap_from_path('str3')) == 'user'
|
2014-03-29 20:31:56 +01:00
|
|
|
config.read_only()
|
2013-04-16 22:44:16 +02:00
|
|
|
prop = []
|
|
|
|
try:
|
|
|
|
config.str3
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-04-16 22:44:16 +02:00
|
|
|
prop = err.proptype
|
|
|
|
assert 'mandatory' in prop
|
|
|
|
|
|
|
|
|
|
|
|
def test_mandatory_multi_empty():
|
|
|
|
descr = make_description()
|
|
|
|
config = Config(descr)
|
|
|
|
config.str3 = ['']
|
2013-08-24 22:32:54 +02:00
|
|
|
assert config.getowner(config.unwrap_from_path('str3')) == 'user'
|
2014-03-29 20:31:56 +01:00
|
|
|
config.read_only()
|
2013-04-16 22:44:16 +02:00
|
|
|
prop = []
|
|
|
|
try:
|
|
|
|
config.str3
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-04-16 22:44:16 +02:00
|
|
|
prop = err.proptype
|
|
|
|
assert 'mandatory' in prop
|
2013-04-22 09:19:05 +02:00
|
|
|
config.read_write()
|
2013-04-16 22:44:16 +02:00
|
|
|
config.str3 = ['yes', '']
|
2013-08-24 22:32:54 +02:00
|
|
|
assert config.getowner(config.unwrap_from_path('str3')) == 'user'
|
2014-03-29 20:31:56 +01:00
|
|
|
config.read_only()
|
2013-04-16 22:44:16 +02:00
|
|
|
prop = []
|
|
|
|
try:
|
|
|
|
config.str3
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-04-16 22:44:16 +02:00
|
|
|
prop = err.proptype
|
|
|
|
assert 'mandatory' in prop
|
|
|
|
|
|
|
|
|
2013-04-17 21:33:34 +02:00
|
|
|
def test_mandatory_multi_append():
|
|
|
|
descr = make_description()
|
|
|
|
config = Config(descr)
|
|
|
|
config.str3 = ['yes']
|
2013-04-22 09:19:05 +02:00
|
|
|
config.read_write()
|
2013-04-17 21:33:34 +02:00
|
|
|
config.str3.append(None)
|
|
|
|
|
|
|
|
|
2013-04-16 22:44:16 +02:00
|
|
|
def test_mandatory_disabled():
|
|
|
|
descr = make_description()
|
|
|
|
config = Config(descr)
|
|
|
|
setting = config.cfgimpl_get_settings()
|
|
|
|
config.str1
|
2013-04-22 09:19:05 +02:00
|
|
|
config.read_only()
|
2013-04-16 22:44:16 +02:00
|
|
|
prop = []
|
|
|
|
try:
|
|
|
|
config.str1
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-04-16 22:44:16 +02:00
|
|
|
prop = err.proptype
|
|
|
|
assert prop == ['mandatory']
|
2013-04-20 17:30:05 +02:00
|
|
|
setting[descr.str1].append('disabled')
|
2013-04-16 22:44:16 +02:00
|
|
|
prop = []
|
|
|
|
try:
|
|
|
|
config.str1
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-04-16 22:44:16 +02:00
|
|
|
prop = err.proptype
|
2013-08-28 11:33:43 +02:00
|
|
|
assert set(prop) == set(['disabled', 'mandatory'])
|
2013-04-16 22:44:16 +02:00
|
|
|
|
|
|
|
|
2013-04-17 22:06:10 +02:00
|
|
|
def test_mandatory_unicode():
|
|
|
|
descr = make_description()
|
|
|
|
config = Config(descr)
|
|
|
|
config.unicode2
|
2013-04-22 09:19:05 +02:00
|
|
|
config.read_only()
|
2013-04-17 22:06:10 +02:00
|
|
|
prop = []
|
|
|
|
try:
|
|
|
|
config.unicode2
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-04-17 22:06:10 +02:00
|
|
|
prop = err.proptype
|
|
|
|
assert prop == ['mandatory']
|
2013-04-22 09:19:05 +02:00
|
|
|
config.read_write()
|
2013-04-17 22:06:10 +02:00
|
|
|
config.unicode2 = u''
|
2013-04-22 09:19:05 +02:00
|
|
|
config.read_only()
|
2013-04-17 22:06:10 +02:00
|
|
|
prop = []
|
|
|
|
try:
|
|
|
|
config.unicode2
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-04-17 22:06:10 +02:00
|
|
|
prop = err.proptype
|
|
|
|
assert prop == ['mandatory']
|
|
|
|
|
|
|
|
|
2013-04-16 22:44:16 +02:00
|
|
|
def test_mandatory_warnings_ro():
|
|
|
|
descr = make_description()
|
|
|
|
config = Config(descr)
|
|
|
|
config.str = ''
|
2013-04-22 09:19:05 +02:00
|
|
|
config.read_only()
|
2013-04-16 22:44:16 +02:00
|
|
|
proc = []
|
|
|
|
try:
|
|
|
|
config.str
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-04-16 22:44:16 +02:00
|
|
|
proc = err.proptype
|
|
|
|
assert proc == ['mandatory']
|
2014-03-09 20:06:44 +01:00
|
|
|
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str', 'str1', 'unicode2', 'str3']
|
2013-04-22 09:19:05 +02:00
|
|
|
config.read_write()
|
2013-04-16 22:44:16 +02:00
|
|
|
config.str = 'a'
|
2013-04-22 09:19:05 +02:00
|
|
|
config.read_only()
|
2014-03-09 20:06:44 +01:00
|
|
|
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str1', 'unicode2', 'str3']
|
2013-04-16 22:44:16 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_mandatory_warnings_rw():
|
|
|
|
descr = make_description()
|
|
|
|
config = Config(descr)
|
|
|
|
config.str = ''
|
2013-04-22 09:19:05 +02:00
|
|
|
config.read_write()
|
2013-04-16 22:44:16 +02:00
|
|
|
config.str
|
2014-03-09 20:06:44 +01:00
|
|
|
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str', 'str1', 'unicode2', 'str3']
|
2013-04-16 22:44:16 +02:00
|
|
|
config.str = 'a'
|
2014-03-09 20:06:44 +01:00
|
|
|
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str1', 'unicode2', 'str3']
|
2013-04-16 22:44:16 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_mandatory_warnings_disabled():
|
|
|
|
descr = make_description()
|
|
|
|
config = Config(descr)
|
|
|
|
config.str = ''
|
|
|
|
setting = config.cfgimpl_get_settings()
|
2013-04-22 09:19:05 +02:00
|
|
|
config.read_write()
|
2013-04-16 22:44:16 +02:00
|
|
|
config.str
|
2014-03-09 20:06:44 +01:00
|
|
|
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str', 'str1', 'unicode2', 'str3']
|
2013-04-20 17:30:05 +02:00
|
|
|
setting[descr.str].append('disabled')
|
2014-03-09 20:06:44 +01:00
|
|
|
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str1', 'unicode2', 'str3']
|
2013-04-17 21:33:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_mandatory_warnings_frozen():
|
|
|
|
descr = make_description()
|
|
|
|
config = Config(descr)
|
|
|
|
config.str = ''
|
|
|
|
setting = config.cfgimpl_get_settings()
|
2013-04-22 09:19:05 +02:00
|
|
|
config.read_write()
|
2013-04-17 21:33:34 +02:00
|
|
|
config.str
|
2014-03-09 20:06:44 +01:00
|
|
|
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str', 'str1', 'unicode2', 'str3']
|
2013-04-20 17:30:05 +02:00
|
|
|
setting[descr.str].append('frozen')
|
2013-04-22 09:19:05 +02:00
|
|
|
config.read_only()
|
2014-03-09 20:06:44 +01:00
|
|
|
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str', 'str1', 'unicode2', 'str3']
|