diff --git a/test/test_mandatory.py b/test/test_mandatory.py index 6172c2a..1010256 100644 --- a/test/test_mandatory.py +++ b/test/test_mandatory.py @@ -2,7 +2,7 @@ import autopath #from py.test import raises from tiramisu.config import Config, mandatory_warnings -from tiramisu.option import StrOption, OptionDescription +from tiramisu.option import StrOption, OptionDescription, UnicodeOption from tiramisu.error import PropertiesOptionError @@ -11,7 +11,7 @@ def make_description(): properties=('mandatory', )) stroption1 = StrOption('str1', 'Test string option', properties=('mandatory', )) - stroption2 = StrOption('str2', 'Test string option', + stroption2 = UnicodeOption('unicode2', 'Test string option', properties=('mandatory', )) stroption3 = StrOption('str3', 'Test string option', multi=True, properties=('mandatory', )) @@ -42,9 +42,9 @@ def test_mandatory_rw(): setting = config.cfgimpl_get_settings() setting.read_write() #not mandatory in rw - config.str2 - config.str2 = 'yes' - assert config.str2 == 'yes' + config.str1 + config.str1 = 'yes' + assert config.str1 == 'yes' def test_mandatory_default(): @@ -180,6 +180,29 @@ def test_mandatory_disabled(): assert prop == ['disabled', 'mandatory'] +def test_mandatory_unicode(): + descr = make_description() + config = Config(descr) + setting = config.cfgimpl_get_settings() + config.unicode2 + setting.read_only() + prop = [] + try: + config.unicode2 + except PropertiesOptionError, err: + prop = err.proptype + assert prop == ['mandatory'] + setting.read_write() + config.unicode2 = u'' + setting.read_only() + prop = [] + try: + config.unicode2 + except PropertiesOptionError, err: + prop = err.proptype + assert prop == ['mandatory'] + + def test_mandatory_warnings_ro(): descr = make_description() config = Config(descr) @@ -192,11 +215,11 @@ def test_mandatory_warnings_ro(): except PropertiesOptionError, err: proc = err.proptype assert proc == ['mandatory'] - assert list(mandatory_warnings(config)) == ['str', 'str1', 'str2', 'str3'] + assert list(mandatory_warnings(config)) == ['str', 'str1', 'unicode2', 'str3'] setting.read_write() config.str = 'a' setting.read_only() - assert list(mandatory_warnings(config)) == ['str1', 'str2', 'str3'] + assert list(mandatory_warnings(config)) == ['str1', 'unicode2', 'str3'] def test_mandatory_warnings_rw(): @@ -206,9 +229,9 @@ def test_mandatory_warnings_rw(): setting = config.cfgimpl_get_settings() setting.read_write() config.str - assert list(mandatory_warnings(config)) == ['str', 'str1', 'str2', 'str3'] + assert list(mandatory_warnings(config)) == ['str', 'str1', 'unicode2', 'str3'] config.str = 'a' - assert list(mandatory_warnings(config)) == ['str1', 'str2', 'str3'] + assert list(mandatory_warnings(config)) == ['str1', 'unicode2', 'str3'] def test_mandatory_warnings_disabled(): @@ -218,9 +241,9 @@ def test_mandatory_warnings_disabled(): setting = config.cfgimpl_get_settings() setting.read_write() config.str - assert list(mandatory_warnings(config)) == ['str', 'str1', 'str2', 'str3'] + assert list(mandatory_warnings(config)) == ['str', 'str1', 'unicode2', 'str3'] setting.add_property('disabled', descr.str) - assert list(mandatory_warnings(config)) == ['str1', 'str2', 'str3'] + assert list(mandatory_warnings(config)) == ['str1', 'unicode2', 'str3'] def test_mandatory_warnings_frozen(): @@ -230,7 +253,7 @@ def test_mandatory_warnings_frozen(): setting = config.cfgimpl_get_settings() setting.read_write() config.str - assert list(mandatory_warnings(config)) == ['str', 'str1', 'str2', 'str3'] + assert list(mandatory_warnings(config)) == ['str', 'str1', 'unicode2', 'str3'] setting.add_property('frozen', descr.str) setting.read_only() - assert list(mandatory_warnings(config)) == ['str', 'str1', 'str2', 'str3'] + assert list(mandatory_warnings(config)) == ['str', 'str1', 'unicode2', 'str3'] diff --git a/tiramisu/option.py b/tiramisu/option.py index d410fc9..cad39f9 100644 --- a/tiramisu/option.py +++ b/tiramisu/option.py @@ -79,6 +79,7 @@ class Option(BaseInformation): __slots__ = ('_name', '_requires', '_multi', '_validator', '_default_multi', '_default', '_properties', '_callback', '_multitype', '_master_slaves', '_consistencies', '_empty') + _empty = '' def __init__(self, name, doc, default=None, default_multi=None, requires=None, multi=False, callback=None, @@ -110,7 +111,6 @@ class Option(BaseInformation): validate_requires_arg(requires, self._name) self._requires = requires self._multi = multi - self._empty = '' self._consistencies = None if validator is not None: if type(validator) != FunctionType: @@ -345,6 +345,7 @@ class StrOption(Option): class UnicodeOption(Option): __slots__ = ('opt_type') opt_type = 'unicode' + _empty = u'' def _validate(self, value): return isinstance(value, unicode)