tiramisu/test/test_option.py

100 lines
3.5 KiB
Python
Raw Normal View History

2013-08-22 12:17:10 +02:00
"""these tests are here to create some :class:`tiramisu.option.Option`'s
and to compare them
"""
2015-07-24 17:54:10 +02:00
from autopath import do_autopath
do_autopath()
2013-12-09 17:55:52 +01:00
from py.test import raises
2013-05-05 21:43:19 +02:00
2013-12-09 18:56:29 +01:00
from tiramisu.option import IntOption, OptionDescription
2015-11-30 15:55:34 +01:00
from tiramisu.config import Config
2013-12-09 18:56:29 +01:00
def a_func():
return None
2013-05-05 21:43:19 +02:00
2013-12-09 17:55:52 +01:00
def test_option_valid_name():
IntOption('test', '')
raises(ValueError, 'IntOption(1, "")')
2014-06-19 23:22:39 +02:00
raises(ValueError, 'IntOption("1test", "")')
IntOption("test1", "")
2013-12-09 17:55:52 +01:00
raises(ValueError, 'IntOption("impl_test", "")')
raises(ValueError, 'IntOption("_test", "")')
raises(ValueError, 'IntOption("unwrap_from_path", "")')
2014-06-19 23:22:39 +02:00
raises(ValueError, 'IntOption(" ", "")')
2013-12-09 17:55:52 +01:00
2013-12-09 18:56:29 +01:00
def test_option_with_callback():
#no default value with callback
raises(ValueError, "IntOption('test', '', default=1, callback=a_func)")
2017-02-03 23:39:24 +01:00
def test_option_get_information():
description = "it's ok"
string = 'some informations'
i = IntOption('test', description)
raises(ValueError, "i.impl_get_information('noinfo')")
i.impl_set_information('info', string)
assert i.impl_get_information('info') == string
raises(ValueError, "i.impl_get_information('noinfo')")
assert i.impl_get_information('noinfo', 'default') == 'default'
assert i.impl_get_information('doc') == description
assert i.impl_getdoc() == description
def test_option_get_information_config():
description = "it's ok"
string = 'some informations'
string
i = IntOption('test', description)
od = OptionDescription('od', '', [i])
Config(od)
raises(ValueError, "i.impl_get_information('noinfo')")
raises(AttributeError, "i.impl_set_information('info', string)")
2015-12-17 22:41:57 +01:00
# assert i.impl_get_information('info') == string
2017-02-03 23:39:24 +01:00
raises(ValueError, "i.impl_get_information('noinfo')")
assert i.impl_get_information('noinfo', 'default') == 'default'
assert i.impl_get_information('doc') == description
assert i.impl_getdoc() == description
def test_option_get_information_config2():
description = "it's ok"
string = 'some informations'
i = IntOption('test', description)
i.impl_set_information('info', string)
od = OptionDescription('od', '', [i])
Config(od)
raises(ValueError, "i.impl_get_information('noinfo')")
raises(AttributeError, "i.impl_set_information('info', 'hello')")
assert i.impl_get_information('info') == string
raises(ValueError, "i.impl_get_information('noinfo')")
assert i.impl_get_information('noinfo', 'default') == 'default'
assert i.impl_get_information('doc') == description
assert i.impl_getdoc() == description
def test_optiondescription_get_information():
description = "it's ok"
string = 'some informations'
o = OptionDescription('test', description, [])
o.impl_set_information('info', string)
assert o.impl_get_information('info') == string
raises(ValueError, "o.impl_get_information('noinfo')")
assert o.impl_get_information('noinfo', 'default') == 'default'
assert o.impl_get_information('doc') == description
assert o.impl_getdoc() == description
2013-12-09 18:56:29 +01:00
2013-12-09 17:55:52 +01:00
def test_option_multi():
IntOption('test', '', multi=True)
IntOption('test', '', multi=True, default_multi=1)
IntOption('test', '', default=[1], multi=True, default_multi=1)
2013-12-09 18:56:29 +01:00
#add default_multi to not multi's option
2013-12-09 17:55:52 +01:00
raises(ValueError, "IntOption('test', '', default_multi=1)")
2013-12-09 18:56:29 +01:00
#unvalid default_multi
raises(ValueError, "IntOption('test', '', multi=True, default_multi='yes')")
#not default_multi with callback
raises(ValueError, "IntOption('test', '', multi=True, default_multi=1, callback=a_func)")