Rename AmbigousOptionError as ConflictOptionError
This commit is contained in:
parent
3170237c8e
commit
80438b1495
|
@ -2,10 +2,12 @@
|
|||
import autopath
|
||||
from py.test import raises
|
||||
|
||||
from tiramisu.config import *
|
||||
from tiramisu.option import *
|
||||
from tiramisu.error import *
|
||||
from tiramisu.setting import owners
|
||||
from tiramisu.config import Config
|
||||
from tiramisu.option import ChoiceOption, BoolOption, IntOption, FloatOption, \
|
||||
StrOption, OptionDescription, SymLinkOption
|
||||
from tiramisu.error import ConflictOptionError, PropertiesOptionError
|
||||
|
||||
|
||||
def make_description():
|
||||
gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
|
||||
|
@ -26,6 +28,8 @@ def make_description():
|
|||
wantframework_option,
|
||||
intoption, boolop])
|
||||
return descr
|
||||
|
||||
|
||||
#____________________________________________________________
|
||||
# change with __setattr__
|
||||
def test_attribute_access():
|
||||
|
@ -37,12 +41,14 @@ def test_attribute_access():
|
|||
config.string = "foo"
|
||||
assert config.string == "foo"
|
||||
|
||||
|
||||
def test_setitem():
|
||||
s = StrOption("string", "", default=["string", "sdfsdf"], default_multi="prout", multi=True)
|
||||
descr = OptionDescription("options", "", [s])
|
||||
config = Config(descr)
|
||||
config.string[1] = "titi"
|
||||
|
||||
|
||||
def test_reset():
|
||||
"if value is None, resets to default owner"
|
||||
s = StrOption("string", "", default="string")
|
||||
|
@ -55,6 +61,7 @@ def test_reset():
|
|||
assert config.string == 'string'
|
||||
assert config.cfgimpl_get_values().getowner(s) == owners.default
|
||||
|
||||
|
||||
def test_reset_with_multi():
|
||||
s = StrOption("string", "", default=["string"], default_multi="string", multi=True)
|
||||
descr = OptionDescription("options", "", [s])
|
||||
|
@ -71,6 +78,7 @@ def test_reset_with_multi():
|
|||
assert config.cfgimpl_get_values().getowner(s) == 'default'
|
||||
raises(ValueError, "config.string = None")
|
||||
|
||||
|
||||
def test_default_with_multi():
|
||||
"default with multi is a list"
|
||||
s = StrOption("string", "", default=[], default_multi="string", multi=True)
|
||||
|
@ -82,10 +90,13 @@ def test_default_with_multi():
|
|||
config = Config(descr)
|
||||
assert config.string == []
|
||||
|
||||
|
||||
def test_idontexist():
|
||||
descr = make_description()
|
||||
cfg = Config(descr)
|
||||
raises(AttributeError, "cfg.idontexist")
|
||||
|
||||
|
||||
# ____________________________________________________________
|
||||
def test_attribute_access_with_multi():
|
||||
s = StrOption("string", "", default=["string"], default_multi="string", multi=True)
|
||||
|
@ -94,6 +105,7 @@ def test_attribute_access_with_multi():
|
|||
config.string = ["foo", "bar"]
|
||||
assert config.string == ["foo", "bar"]
|
||||
|
||||
|
||||
def test_item_access_with_multi():
|
||||
s = StrOption("string", "", default=["string"], multi=True)
|
||||
descr = OptionDescription("options", "", [s])
|
||||
|
@ -106,6 +118,7 @@ def test_item_access_with_multi():
|
|||
# assert config.string[0] == 'changetest'
|
||||
# assert config.string[
|
||||
|
||||
|
||||
def test_access_with_multi_default():
|
||||
s = StrOption("string", "", default=["string"], multi=True)
|
||||
descr = OptionDescription("options", "", [s])
|
||||
|
@ -122,6 +135,7 @@ def test_access_with_multi_default():
|
|||
# config.string = ["foo", "bar"]
|
||||
# assert config.string == ["foo", "bar"]
|
||||
|
||||
|
||||
def test_multi_with_requires():
|
||||
s = StrOption("string", "", default=["string"], default_multi="string", multi=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
|
@ -136,6 +150,7 @@ def test_multi_with_requires():
|
|||
raises(PropertiesOptionError, "config.str = ['a', 'b']")
|
||||
assert config.cfgimpl_get_settings().has_property('hidden', stroption)
|
||||
|
||||
|
||||
def test__requires_with_inverted():
|
||||
s = StrOption("string", "", default=["string"], multi=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
|
@ -147,6 +162,7 @@ def test__requires_with_inverted():
|
|||
config.int = 1
|
||||
assert not config.cfgimpl_get_settings().has_property('hidden', stroption)
|
||||
|
||||
|
||||
def test_multi_with_requires_in_another_group():
|
||||
s = StrOption("string", "", default=["string"], multi=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
|
@ -163,6 +179,7 @@ def test_multi_with_requires_in_another_group():
|
|||
raises(PropertiesOptionError, "config.opt.str = ['a', 'b']")
|
||||
assert config.cfgimpl_get_settings().has_property('hidden', stroption)
|
||||
|
||||
|
||||
def test_apply_requires_from_config():
|
||||
s = StrOption("string", "", default=["string"], multi=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
|
@ -196,6 +213,7 @@ def test_apply_requires_with_disabled():
|
|||
raises(PropertiesOptionError, 'config.opt.str')
|
||||
assert config.cfgimpl_get_settings().has_property('disabled', stroption)
|
||||
|
||||
|
||||
def test_multi_with_requires_with_disabled_in_another_group():
|
||||
s = StrOption("string", "", default=["string"], multi=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
|
@ -212,6 +230,7 @@ def test_multi_with_requires_with_disabled_in_another_group():
|
|||
raises(PropertiesOptionError, "config.opt.str = ['a', 'b']")
|
||||
assert config.cfgimpl_get_settings().has_property('disabled', stroption)
|
||||
|
||||
|
||||
def test_multi_with_requires_that_is_multi():
|
||||
s = StrOption("string", "", default=["string"], multi=True)
|
||||
intoption = IntOption('int', 'Test int option', default=[0], multi=True)
|
||||
|
@ -226,22 +245,25 @@ def test_multi_with_requires_that_is_multi():
|
|||
raises(PropertiesOptionError, "config.str = ['a', 'b']")
|
||||
assert config.cfgimpl_get_settings().has_property('hidden', stroption)
|
||||
|
||||
|
||||
def test_multi_with_bool():
|
||||
s = BoolOption("bool", "", default=[False], multi=True)
|
||||
descr = OptionDescription("options", "", [s])
|
||||
config = Config(descr)
|
||||
assert descr.bool.is_multi() == True
|
||||
assert descr.bool.is_multi() is True
|
||||
config.bool = [True, False]
|
||||
assert config.cfgimpl_get_values()[s] == [True, False]
|
||||
assert config.bool == [True, False]
|
||||
|
||||
|
||||
def test_multi_with_bool_two():
|
||||
s = BoolOption("bool", "", default=[False], multi=True)
|
||||
descr = OptionDescription("options", "", [s])
|
||||
config = Config(descr)
|
||||
assert descr.bool.is_multi() == True
|
||||
assert descr.bool.is_multi() is True
|
||||
raises(ValueError, "config.bool = True")
|
||||
|
||||
|
||||
def test_choice_access_with_multi():
|
||||
ch = ChoiceOption("t1", "", ("a", "b"), default=["a"], multi=True)
|
||||
descr = OptionDescription("options", "", [ch])
|
||||
|
@ -257,6 +279,8 @@ def test_choice_access_with_multi():
|
|||
# cfg = Config(descr)
|
||||
# booloption.setoption(cfg, False)
|
||||
# assert cfg.bool == False
|
||||
|
||||
|
||||
#____________________________________________________________
|
||||
def test_dwim_set():
|
||||
descr = OptionDescription("opt", "", [
|
||||
|
@ -277,9 +301,10 @@ def test_dwim_set():
|
|||
c.set(b2=False, **{'sub.c1': 'c'})
|
||||
assert not c.b2
|
||||
assert c.sub.c1 == 'c'
|
||||
raises(AmbigousOptionError, "c.set(d1=True)")
|
||||
raises(ConflictOptionError, "c.set(d1=True)")
|
||||
raises(AttributeError, "c.set(unknown='foo')")
|
||||
|
||||
|
||||
def test_more_set():
|
||||
descr = OptionDescription("opt", "", [
|
||||
OptionDescription("s1", "", [
|
||||
|
@ -291,6 +316,7 @@ def test_more_set():
|
|||
assert config.s1.a
|
||||
assert config.int == 23
|
||||
|
||||
|
||||
def test_set_with_hidden_option():
|
||||
boolopt = BoolOption("a", "", default=False, properties=(('hidden'),))
|
||||
descr = OptionDescription("opt", "", [
|
||||
|
@ -302,6 +328,7 @@ def test_set_with_hidden_option():
|
|||
setting.read_write()
|
||||
raises(PropertiesOptionError, "config.set(**d)")
|
||||
|
||||
|
||||
def test_set_with_unknown_option():
|
||||
boolopt = BoolOption("b", "", default=False)
|
||||
descr = OptionDescription("opt", "", [
|
||||
|
@ -320,14 +347,14 @@ def test_set_symlink_option():
|
|||
config = Config(descr)
|
||||
setattr(config, "s1.b", True)
|
||||
setattr(config, "s1.b", False)
|
||||
assert config.s1.b == False
|
||||
assert config.c == False
|
||||
assert config.s1.b is False
|
||||
assert config.c is False
|
||||
config.c = True
|
||||
assert config.s1.b == True
|
||||
assert config.c == True
|
||||
assert config.s1.b is True
|
||||
assert config.c is True
|
||||
config.c = False
|
||||
assert config.s1.b == False
|
||||
assert config.c == False
|
||||
assert config.s1.b is False
|
||||
assert config.c is False
|
||||
|
||||
##____________________________________________________________
|
||||
#def test_config_impl_values():
|
||||
|
@ -360,6 +387,7 @@ def test_set_symlink_option():
|
|||
# s.setoption(config, 'bol')
|
||||
# assert config.string == 'bol'
|
||||
|
||||
|
||||
def test_allow_multiple_changes_from_config():
|
||||
"""
|
||||
a `setoption` from the config object is much like the attribute access,
|
||||
|
@ -375,27 +403,27 @@ def test_allow_multiple_changes_from_config():
|
|||
assert config.string == "oh"
|
||||
config.set(string2='blah')
|
||||
assert config.bip.string2 == 'blah'
|
||||
|
||||
|
||||
# ____________________________________________________________
|
||||
# accessing a value by the get method
|
||||
def test_access_by_get():
|
||||
descr = make_description()
|
||||
cfg = Config(descr)
|
||||
raises(AttributeError, "cfg.find(byname='idontexist')")
|
||||
assert cfg.find_first(byname='wantref', type_='value') == False
|
||||
assert cfg.gc.dummy == False
|
||||
assert cfg.find_first(byname='dummy', type_='value') == False
|
||||
assert cfg.find_first(byname='wantref', type_='value') is False
|
||||
assert cfg.gc.dummy is False
|
||||
assert cfg.find_first(byname='dummy', type_='value') is False
|
||||
|
||||
|
||||
def test_access_by_get_whith_hide():
|
||||
b1 = BoolOption("b1", "", properties=(('hidden'),))
|
||||
descr = OptionDescription("opt", "", [
|
||||
OptionDescription("sub", "", [
|
||||
b1,
|
||||
ChoiceOption("c1", "", ('a', 'b', 'c'), 'a'),
|
||||
BoolOption("d1", ""),
|
||||
]),
|
||||
descr = OptionDescription("opt", "",
|
||||
[OptionDescription("sub", "",
|
||||
[b1, ChoiceOption("c1", "", ('a', 'b', 'c'), 'a'),
|
||||
BoolOption("d1", "")]),
|
||||
BoolOption("b2", ""),
|
||||
BoolOption("d1", ""),
|
||||
])
|
||||
BoolOption("d1", "")])
|
||||
c = Config(descr)
|
||||
setting = c.cfgimpl_get_settings()
|
||||
setting.read_write()
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
# the whole pypy projet is under MIT licence
|
||||
# ____________________________________________________________
|
||||
#from inspect import getmembers, ismethod
|
||||
from tiramisu.error import PropertiesOptionError, AmbigousOptionError
|
||||
from tiramisu.error import PropertiesOptionError, ConflictOptionError
|
||||
from tiramisu.option import OptionDescription, Option, SymLinkOption
|
||||
from tiramisu.setting import groups, Setting, apply_requires
|
||||
from tiramisu.value import Values
|
||||
|
@ -401,7 +401,7 @@ class Config(SubConfig):
|
|||
child = getattr(homeconfig._cfgimpl_descr, name)
|
||||
homeconfig.setoption(name, child, value)
|
||||
elif len(candidates) > 1:
|
||||
raise AmbigousOptionError(
|
||||
raise ConflictOptionError(
|
||||
_('more than one option that ends with {}').format(key))
|
||||
else:
|
||||
raise AttributeError(
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
#AttributeError if no option or optiondescription in optiondescription (also when specified a path)
|
||||
|
||||
|
||||
class AmbigousOptionError(StandardError):
|
||||
class ConflictOptionError(StandardError):
|
||||
"more than one option"
|
||||
pass
|
||||
|
||||
|
|
Loading…
Reference in New Issue