tiramisu/test/test_mandatory.py

237 lines
6.5 KiB
Python
Raw Normal View History

import autopath
#from py.test import raises
from tiramisu.config import Config, mandatory_warnings
from tiramisu.option import StrOption, OptionDescription
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', ))
stroption2 = StrOption('str2', 'Test string option',
properties=('mandatory', ))
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)
setting = config.cfgimpl_get_settings()
setting.read_only()
prop = []
try:
config.str1
except PropertiesOptionError, err:
prop = err.proptype
assert 'mandatory' in prop
setting.read_write()
config.str1 = 'yes'
setting.read_only()
assert config.str1 == 'yes'
def test_mandatory_rw():
descr = make_description()
config = Config(descr)
setting = config.cfgimpl_get_settings()
setting.read_write()
#not mandatory in rw
config.str2
config.str2 = 'yes'
assert config.str2 == 'yes'
def test_mandatory_default():
descr = make_description()
config = Config(descr)
setting = config.cfgimpl_get_settings()
setting.read_only()
#not mandatory in rw
config.str
setting.read_write()
config.str = 'yes'
setting.read_only()
config.str
setting.read_write()
config.str = None
setting.read_only()
prop = []
try:
config.str
except PropertiesOptionError, err:
prop = err.proptype
assert 'mandatory' in prop
#valeur vide : None, '', u'', ...
def test_mandatory_none():
descr = make_description()
config = Config(descr)
config.str1 = None
setting = config.cfgimpl_get_settings()
assert config.cfgimpl_get_values().getowner(descr.str1) == 'user'
setting.read_only()
prop = []
try:
config.str1
except PropertiesOptionError, err:
prop = err.proptype
assert 'mandatory' in prop
def test_mandatory_empty():
descr = make_description()
config = Config(descr)
config.str1 = ''
setting = config.cfgimpl_get_settings()
assert config.cfgimpl_get_values().getowner(descr.str1) == 'user'
setting.read_only()
prop = []
try:
config.str1
except PropertiesOptionError, err:
prop = err.proptype
assert 'mandatory' in prop
def test_mandatory_multi_none():
descr = make_description()
config = Config(descr)
setting = config.cfgimpl_get_settings()
config.str3 = [None]
setting.read_only()
assert config.cfgimpl_get_values().getowner(descr.str3) == 'user'
prop = []
try:
config.str3
except PropertiesOptionError, err:
prop = err.proptype
assert 'mandatory' in prop
setting.read_write()
config.str3 = ['yes', None]
setting.read_only()
assert config.cfgimpl_get_values().getowner(descr.str3) == 'user'
prop = []
try:
config.str3
except PropertiesOptionError, err:
prop = err.proptype
assert 'mandatory' in prop
def test_mandatory_multi_empty():
descr = make_description()
config = Config(descr)
setting = config.cfgimpl_get_settings()
config.str3 = ['']
setting.read_only()
assert config.cfgimpl_get_values().getowner(descr.str3) == 'user'
prop = []
try:
config.str3
except PropertiesOptionError, err:
prop = err.proptype
assert 'mandatory' in prop
setting.read_write()
config.str3 = ['yes', '']
setting.read_only()
assert config.cfgimpl_get_values().getowner(descr.str3) == 'user'
prop = []
try:
config.str3
except PropertiesOptionError, err:
prop = err.proptype
assert 'mandatory' in prop
def test_mandatory_multi_append():
descr = make_description()
config = Config(descr)
setting = config.cfgimpl_get_settings()
config.str3 = ['yes']
setting.read_write()
config.str3.append(None)
def test_mandatory_disabled():
descr = make_description()
config = Config(descr)
setting = config.cfgimpl_get_settings()
config.str1
setting.read_only()
prop = []
try:
config.str1
except PropertiesOptionError, err:
prop = err.proptype
assert prop == ['mandatory']
setting.add_property('disabled', descr.str1)
prop = []
try:
config.str1
except PropertiesOptionError, err:
prop = err.proptype
assert prop == ['disabled', 'mandatory']
def test_mandatory_warnings_ro():
descr = make_description()
config = Config(descr)
config.str = ''
setting = config.cfgimpl_get_settings()
setting.read_only()
proc = []
try:
config.str
except PropertiesOptionError, err:
proc = err.proptype
assert proc == ['mandatory']
assert list(mandatory_warnings(config)) == ['str', 'str1', 'str2', 'str3']
setting.read_write()
config.str = 'a'
setting.read_only()
assert list(mandatory_warnings(config)) == ['str1', 'str2', 'str3']
def test_mandatory_warnings_rw():
descr = make_description()
config = Config(descr)
config.str = ''
setting = config.cfgimpl_get_settings()
setting.read_write()
config.str
assert list(mandatory_warnings(config)) == ['str', 'str1', 'str2', 'str3']
config.str = 'a'
assert list(mandatory_warnings(config)) == ['str1', 'str2', 'str3']
def test_mandatory_warnings_disabled():
descr = make_description()
config = Config(descr)
config.str = ''
setting = config.cfgimpl_get_settings()
setting.read_write()
config.str
assert list(mandatory_warnings(config)) == ['str', 'str1', 'str2', 'str3']
setting.add_property('disabled', descr.str)
assert list(mandatory_warnings(config)) == ['str1', 'str2', 'str3']
def test_mandatory_warnings_frozen():
descr = make_description()
config = Config(descr)
config.str = ''
setting = config.cfgimpl_get_settings()
setting.read_write()
config.str
assert list(mandatory_warnings(config)) == ['str', 'str1', 'str2', 'str3']
setting.add_property('frozen', descr.str)
setting.read_only()
assert list(mandatory_warnings(config)) == ['str', 'str1', 'str2', 'str3']