add tests for find()
This commit is contained in:
parent
9deb67f887
commit
f48f3e7544
1 changed files with 16 additions and 5 deletions
|
@ -13,17 +13,20 @@ def make_description():
|
||||||
objspaceoption = ChoiceOption('objspace', 'Object space',
|
objspaceoption = ChoiceOption('objspace', 'Object space',
|
||||||
('std', 'thunk'), 'std')
|
('std', 'thunk'), 'std')
|
||||||
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||||
|
booloption2 = BoolOption('bool', 'Test boolean option', default=True)
|
||||||
intoption = IntOption('int', 'Test int option', default=0)
|
intoption = IntOption('int', 'Test int option', default=0)
|
||||||
|
floatoption2 = FloatOption('float', 'Test float option', default=2.3)
|
||||||
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
||||||
stroption = StrOption('str', 'Test string option', default="abc")
|
stroption = StrOption('str', 'Test string option', default="abc")
|
||||||
boolop = BoolOption('boolop', 'Test boolean option op', default=True)
|
boolop = BoolOption('boolop', 'Test boolean option op', default=True)
|
||||||
wantref_option = BoolOption('wantref', 'Tests', default=False)
|
wantref_option = BoolOption('wantref', 'Tests', default=False)
|
||||||
wantframework_option = BoolOption('wantframework', 'Test', default=False)
|
wantframework_option = BoolOption('wantframework', 'Test', default=False)
|
||||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
gcgroup2 = OptionDescription('gc2', '', [booloption2])
|
||||||
|
gcgroup = OptionDescription('gc', '', [gcgroup2, gcoption, gcdummy, floatoption])
|
||||||
descr = OptionDescription('tiramisu', '', [gcgroup, booloption, objspaceoption,
|
descr = OptionDescription('tiramisu', '', [gcgroup, booloption, objspaceoption,
|
||||||
wantref_option, stroption,
|
wantref_option, stroption,
|
||||||
wantframework_option,
|
wantframework_option,
|
||||||
intoption, boolop])
|
intoption, boolop, floatoption2])
|
||||||
return descr
|
return descr
|
||||||
|
|
||||||
|
|
||||||
|
@ -101,7 +104,10 @@ def test_find_in_config():
|
||||||
descr = make_description()
|
descr = make_description()
|
||||||
conf = Config(descr)
|
conf = Config(descr)
|
||||||
assert conf.find(byname='dummy') == [conf.unwrap_from_path('gc.dummy')]
|
assert conf.find(byname='dummy') == [conf.unwrap_from_path('gc.dummy')]
|
||||||
|
assert conf.find(byname='float') == [conf.unwrap_from_path('gc.float'), conf.unwrap_from_path('float')]
|
||||||
|
assert conf.find_first(byname='bool') == conf.unwrap_from_path('gc.gc2.bool')
|
||||||
assert conf.find_first(byname='dummy') == conf.unwrap_from_path('gc.dummy')
|
assert conf.find_first(byname='dummy') == conf.unwrap_from_path('gc.dummy')
|
||||||
|
assert conf.find_first(byname='float') == conf.unwrap_from_path('gc.float')
|
||||||
assert conf.find(bytype=ChoiceOption) == [conf.unwrap_from_path('gc.name'), conf.unwrap_from_path('objspace')]
|
assert conf.find(bytype=ChoiceOption) == [conf.unwrap_from_path('gc.name'), conf.unwrap_from_path('objspace')]
|
||||||
assert conf.find_first(bytype=ChoiceOption) == conf.unwrap_from_path('gc.name')
|
assert conf.find_first(bytype=ChoiceOption) == conf.unwrap_from_path('gc.name')
|
||||||
assert conf.find(byvalue='ref') == [conf.unwrap_from_path('gc.name')]
|
assert conf.find(byvalue='ref') == [conf.unwrap_from_path('gc.name')]
|
||||||
|
@ -111,9 +117,14 @@ def test_find_in_config():
|
||||||
assert conf.find_first(bytype=BoolOption, byname='dummy') == conf.unwrap_from_path('gc.dummy')
|
assert conf.find_first(bytype=BoolOption, byname='dummy') == conf.unwrap_from_path('gc.dummy')
|
||||||
assert conf.find(byvalue=False, byname='dummy') == [conf.unwrap_from_path('gc.dummy')]
|
assert conf.find(byvalue=False, byname='dummy') == [conf.unwrap_from_path('gc.dummy')]
|
||||||
assert conf.find_first(byvalue=False, byname='dummy') == conf.unwrap_from_path('gc.dummy')
|
assert conf.find_first(byvalue=False, byname='dummy') == conf.unwrap_from_path('gc.dummy')
|
||||||
## byattrs
|
#subconfig
|
||||||
#assert conf.find_first(byattrs= dict(default=2.3)) == conf.unwrap_from_path('gc.float')
|
assert conf.gc.find(byname='dummy') == [conf.unwrap_from_path('gc.dummy')]
|
||||||
#assert conf.find_first(byvalue=False, byname='dummy', byattrs=dict(default=False)) == conf.unwrap_from_path('gc.dummy')
|
assert conf.gc.find(byname='float') == [conf.unwrap_from_path('gc.float')]
|
||||||
|
assert conf.gc.find(byname='bool') == [conf.unwrap_from_path('gc.gc2.bool')]
|
||||||
|
raises(AttributeError, "conf.gc.find(byname='wantref').first()")
|
||||||
|
# not OptionDescription
|
||||||
|
raises(AttributeError, "conf.find_first(byname='gc')")
|
||||||
|
raises(AttributeError, "conf.gc.find_first(byname='gc2')")
|
||||||
|
|
||||||
|
|
||||||
def test_find_multi():
|
def test_find_multi():
|
||||||
|
|
Loading…
Reference in a new issue