tiramisu/test/test_multi.py

67 lines
1.8 KiB
Python
Raw Normal View History

2014-02-02 18:21:09 +01:00
# coding: utf-8
2015-07-24 17:54:10 +02:00
from autopath import do_autopath
do_autopath()
2014-02-02 18:21:09 +01:00
from tiramisu.value import Multi
from tiramisu.option import IntOption, StrOption, OptionDescription
2014-02-02 18:21:09 +01:00
from tiramisu.config import Config
from tiramisu.error import ConfigError, PropertiesOptionError
2015-11-19 22:25:00 +01:00
from tiramisu.setting import groups
2014-02-02 18:21:09 +01:00
import weakref
from py.test import raises
def test_multi():
i = IntOption('int', '', multi=True)
o = OptionDescription('od', '', [i])
c = Config(o)
2015-07-24 17:54:10 +02:00
multi = Multi([1, 2, 3], weakref.ref(c), i, 'int')
2014-02-02 18:21:09 +01:00
raises(ValueError, "Multi([1,2,3], c, i, 'int')")
raises(ValueError, "Multi(multi, weakref.ref(c), i, 'int')")
assert c is multi._getcontext()
del(c)
raises(ConfigError, "multi._getcontext()")
2016-11-19 19:16:31 +01:00
def test_multi_unique():
i = IntOption('int', '', multi=True, unique=True)
o = OptionDescription('od', '', [i])
c = Config(o)
assert c.int == []
c.int = [0]
assert c.int == [0]
raises(ValueError, "c.int = [0, 0]")
raises(ValueError, "c.int = [1, 0, 2, 3, 4, 5, 6, 0, 7]")
raises(ValueError, "c.int.append(0)")
raises(ValueError, "c.int.extend([1, 2, 1, 3])")
raises(ValueError, "c.int.extend([1, 2, 0, 3])")
c.int.extend([4, 5, 6])
2016-11-20 18:02:10 +01:00
def test_non_valid_multi():
raises(ValueError, "IntOption('int', '', multi='string')")
raises(ValueError, "IntOption('int', '', multi=True, unique='string')")
2016-11-19 19:16:31 +01:00
def test_non_multi_unique():
raises(ValueError, "IntOption('int', '', unique=True)")
def test_multi_none():
s = StrOption('str', '', multi=True)
o = OptionDescription('od', '', [s])
c = Config(o)
c.read_only()
assert c.str == []
c.read_write()
c.str.append(None)
assert c.str == [None]
c.read_only()
raises(PropertiesOptionError, "c.str")
c.read_write()
c.str = ['']
assert c.str == ['']
c.read_only()
raises(PropertiesOptionError, "c.str")