179 lines
6.4 KiB
Python
179 lines
6.4 KiB
Python
# coding: utf-8
|
|
import autopath
|
|
from tiramisu import setting
|
|
setting.expires_time = 1
|
|
from tiramisu.option import IntOption, OptionDescription
|
|
from tiramisu.config import Config
|
|
from time import sleep
|
|
|
|
|
|
def make_description():
|
|
u1 = IntOption('u1', '', multi=True)
|
|
u2 = IntOption('u2', '')
|
|
u3 = IntOption('u3', '', multi=True)
|
|
return OptionDescription('od1', '', [u1, u2, u3])
|
|
|
|
|
|
def test_cache():
|
|
od1 = make_description()
|
|
c = Config(od1)
|
|
values = c.cfgimpl_get_values()
|
|
settings = c.cfgimpl_get_settings()
|
|
c.u1
|
|
assert od1.u1 in values._p_get_cached('value')
|
|
assert od1.u1 in settings._p_get_cached('property')
|
|
c.u2
|
|
assert od1.u1 in values._p_get_cached('value')
|
|
assert od1.u1 in settings._p_get_cached('property')
|
|
assert od1.u2 in values._p_get_cached('value')
|
|
assert od1.u2 in settings._p_get_cached('property')
|
|
|
|
|
|
def test_cache_reset():
|
|
od1 = make_description()
|
|
c = Config(od1)
|
|
values = c.cfgimpl_get_values()
|
|
settings = c.cfgimpl_get_settings()
|
|
#when change a value
|
|
c.u1
|
|
assert od1.u1 in values._p_get_cached('value')
|
|
assert od1.u1 in settings._p_get_cached('property')
|
|
c.u2 = 1
|
|
assert od1.u1 not in values._p_get_cached('value')
|
|
assert od1.u1 not in settings._p_get_cached('property')
|
|
#when remove a value
|
|
c.u1
|
|
assert od1.u1 in values._p_get_cached('value')
|
|
assert od1.u1 in settings._p_get_cached('property')
|
|
del(c.u2)
|
|
assert od1.u1 not in values._p_get_cached('value')
|
|
assert od1.u1 not in settings._p_get_cached('property')
|
|
#when add/del property
|
|
c.u1
|
|
assert od1.u1 in values._p_get_cached('value')
|
|
assert od1.u1 in settings._p_get_cached('property')
|
|
c.cfgimpl_get_settings()[od1.u2].append('test')
|
|
assert od1.u1 not in values._p_get_cached('value')
|
|
assert od1.u1 not in settings._p_get_cached('property')
|
|
c.u1
|
|
assert od1.u1 in values._p_get_cached('value')
|
|
assert od1.u1 in settings._p_get_cached('property')
|
|
c.cfgimpl_get_settings()[od1.u2].remove('test')
|
|
assert od1.u1 not in values._p_get_cached('value')
|
|
assert od1.u1 not in settings._p_get_cached('property')
|
|
#when enable/disabled property
|
|
c.u1
|
|
assert od1.u1 in values._p_get_cached('value')
|
|
assert od1.u1 in settings._p_get_cached('property')
|
|
c.cfgimpl_get_settings().append('test')
|
|
assert od1.u1 not in values._p_get_cached('value')
|
|
assert od1.u1 not in settings._p_get_cached('property')
|
|
c.u1
|
|
assert od1.u1 in values._p_get_cached('value')
|
|
assert od1.u1 in settings._p_get_cached('property')
|
|
c.cfgimpl_get_settings().remove('test')
|
|
assert od1.u1 not in values._p_get_cached('value')
|
|
assert od1.u1 not in settings._p_get_cached('property')
|
|
|
|
|
|
def test_cache_reset_multi():
|
|
od1 = make_description()
|
|
c = Config(od1)
|
|
values = c.cfgimpl_get_values()
|
|
settings = c.cfgimpl_get_settings()
|
|
#when change a value
|
|
c.u1
|
|
assert od1.u1 in values._p_get_cached('value')
|
|
assert od1.u1 in settings._p_get_cached('property')
|
|
c.u3 = [1]
|
|
assert od1.u1 not in values._p_get_cached('value')
|
|
assert od1.u1 not in settings._p_get_cached('property')
|
|
#when append value
|
|
c.u1
|
|
assert od1.u1 in values._p_get_cached('value')
|
|
assert od1.u1 in settings._p_get_cached('property')
|
|
c.u3.append(1)
|
|
assert od1.u1 not in values._p_get_cached('value')
|
|
assert od1.u1 not in settings._p_get_cached('property')
|
|
#when pop value
|
|
c.u1
|
|
assert od1.u1 in values._p_get_cached('value')
|
|
assert od1.u1 in settings._p_get_cached('property')
|
|
c.u3.pop(1)
|
|
assert od1.u1 not in values._p_get_cached('value')
|
|
assert od1.u1 not in settings._p_get_cached('property')
|
|
#when remove a value
|
|
c.u1
|
|
assert od1.u1 in values._p_get_cached('value')
|
|
assert od1.u1 in settings._p_get_cached('property')
|
|
del(c.u3)
|
|
assert od1.u1 not in values._p_get_cached('value')
|
|
assert od1.u1 not in settings._p_get_cached('property')
|
|
|
|
|
|
def test_reset_cache():
|
|
od1 = make_description()
|
|
c = Config(od1)
|
|
values = c.cfgimpl_get_values()
|
|
settings = c.cfgimpl_get_settings()
|
|
c.u1
|
|
assert od1.u1 in values._p_get_cached('value')
|
|
assert od1.u1 in settings._p_get_cached('property')
|
|
c.cfgimpl_reset_cache()
|
|
assert od1.u1 not in values._p_get_cached('value')
|
|
assert od1.u1 not in settings._p_get_cached('property')
|
|
c.u1
|
|
sleep(1)
|
|
c.u2
|
|
assert od1.u1 in values._p_get_cached('value')
|
|
assert od1.u1 in settings._p_get_cached('property')
|
|
assert od1.u2 in values._p_get_cached('value')
|
|
assert od1.u2 in settings._p_get_cached('property')
|
|
c.cfgimpl_reset_cache()
|
|
assert od1.u1 not in values._p_get_cached('value')
|
|
assert od1.u1 not in settings._p_get_cached('property')
|
|
assert od1.u2 not in values._p_get_cached('value')
|
|
assert od1.u2 not in settings._p_get_cached('property')
|
|
|
|
|
|
def test_reset_cache_only_expired():
|
|
od1 = make_description()
|
|
c = Config(od1)
|
|
values = c.cfgimpl_get_values()
|
|
settings = c.cfgimpl_get_settings()
|
|
c.u1
|
|
assert od1.u1 in values._p_get_cached('value')
|
|
assert od1.u1 in settings._p_get_cached('property')
|
|
c.cfgimpl_reset_cache(True)
|
|
assert od1.u1 in values._p_get_cached('value')
|
|
assert od1.u1 in settings._p_get_cached('property')
|
|
sleep(1)
|
|
c.u2
|
|
assert od1.u1 in values._p_get_cached('value')
|
|
assert od1.u1 in settings._p_get_cached('property')
|
|
assert od1.u2 in values._p_get_cached('value')
|
|
assert od1.u2 in settings._p_get_cached('property')
|
|
c.cfgimpl_reset_cache(True)
|
|
assert od1.u1 not in values._p_get_cached('value')
|
|
assert od1.u1 not in settings._p_get_cached('property')
|
|
assert od1.u2 in values._p_get_cached('value')
|
|
assert od1.u2 in settings._p_get_cached('property')
|
|
|
|
|
|
def test_reset_cache_only():
|
|
od1 = make_description()
|
|
c = Config(od1)
|
|
values = c.cfgimpl_get_values()
|
|
settings = c.cfgimpl_get_settings()
|
|
c.u1
|
|
assert od1.u1 in values._p_get_cached('value')
|
|
assert od1.u1 in settings._p_get_cached('property')
|
|
c.cfgimpl_reset_cache(only=('values',))
|
|
assert od1.u1 not in values._p_get_cached('value')
|
|
assert od1.u1 in settings._p_get_cached('property')
|
|
c.u1
|
|
assert od1.u1 in values._p_get_cached('value')
|
|
assert od1.u1 in settings._p_get_cached('property')
|
|
c.cfgimpl_reset_cache(only=('settings',))
|
|
assert od1.u1 in values._p_get_cached('value')
|
|
assert od1.u1 not in settings._p_get_cached('property')
|