mandatory_warnings is now in values and add force_cache to values
This commit is contained in:
parent
d3f9d20ab5
commit
6e8b570a37
|
@ -253,3 +253,22 @@ def test_reset_cache_only():
|
||||||
c.cfgimpl_reset_cache(only=('settings',))
|
c.cfgimpl_reset_cache(only=('settings',))
|
||||||
assert 'u1' in values._p_.get_cached(c)
|
assert 'u1' in values._p_.get_cached(c)
|
||||||
assert 'u1' not in settings._p_.get_cached(c)
|
assert 'u1' not in settings._p_.get_cached(c)
|
||||||
|
|
||||||
|
|
||||||
|
def test_force_cache():
|
||||||
|
u1 = IntOption('u1', '', multi=True)
|
||||||
|
u2 = IntOption('u2', '')
|
||||||
|
u3 = IntOption('u3', '', multi=True)
|
||||||
|
u4 = IntOption('u4', '', properties=('disabled',))
|
||||||
|
od = OptionDescription('od1', '', [u1, u2, u3, u4])
|
||||||
|
c = Config(od)
|
||||||
|
c.cfgimpl_get_settings().remove('expire')
|
||||||
|
|
||||||
|
c.cfgimpl_get_values().force_cache()
|
||||||
|
assert c.cfgimpl_get_values()._p_.get_cached(c) == {'u1': ([], None), 'u3': ([], None), 'u2': (None, None), 'u4': (None, None)}
|
||||||
|
assert c.cfgimpl_get_settings()._p_.get_cached(c) == {'u4': (set(['disabled']), None), 'u1': (set([]), None), 'u3': (set([]), None), 'u2': (set([]), None)}
|
||||||
|
c.read_only()
|
||||||
|
|
||||||
|
c.cfgimpl_get_values().force_cache()
|
||||||
|
assert c.cfgimpl_get_values()._p_.get_cached(c) == {'u1': ([], None), 'u3': ([], None), 'u2': (None, None)}
|
||||||
|
assert c.cfgimpl_get_settings()._p_.get_cached(c) == {'u4': (set(['disabled']), None), 'u1': (set([]), None), 'u3': (set([]), None), 'u2': (set([]), None)}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import autopath
|
import autopath
|
||||||
|
|
||||||
#from py.test import raises
|
#from py.test import raises
|
||||||
from tiramisu.config import Config, mandatory_warnings
|
from tiramisu.config import Config
|
||||||
from tiramisu.option import StrOption, UnicodeOption, OptionDescription
|
from tiramisu.option import StrOption, UnicodeOption, OptionDescription
|
||||||
from tiramisu.error import PropertiesOptionError
|
from tiramisu.error import PropertiesOptionError
|
||||||
|
|
||||||
|
@ -205,11 +205,11 @@ def test_mandatory_warnings_ro():
|
||||||
except PropertiesOptionError as err:
|
except PropertiesOptionError as err:
|
||||||
proc = err.proptype
|
proc = err.proptype
|
||||||
assert proc == ['mandatory']
|
assert proc == ['mandatory']
|
||||||
assert list(mandatory_warnings(config)) == ['str', 'str1', 'unicode2', 'str3']
|
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str', 'str1', 'unicode2', 'str3']
|
||||||
config.read_write()
|
config.read_write()
|
||||||
config.str = 'a'
|
config.str = 'a'
|
||||||
config.read_only()
|
config.read_only()
|
||||||
assert list(mandatory_warnings(config)) == ['str1', 'unicode2', 'str3']
|
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str1', 'unicode2', 'str3']
|
||||||
|
|
||||||
|
|
||||||
def test_mandatory_warnings_rw():
|
def test_mandatory_warnings_rw():
|
||||||
|
@ -218,9 +218,9 @@ def test_mandatory_warnings_rw():
|
||||||
config.str = ''
|
config.str = ''
|
||||||
config.read_write()
|
config.read_write()
|
||||||
config.str
|
config.str
|
||||||
assert list(mandatory_warnings(config)) == ['str', 'str1', 'unicode2', 'str3']
|
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str', 'str1', 'unicode2', 'str3']
|
||||||
config.str = 'a'
|
config.str = 'a'
|
||||||
assert list(mandatory_warnings(config)) == ['str1', 'unicode2', 'str3']
|
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str1', 'unicode2', 'str3']
|
||||||
|
|
||||||
|
|
||||||
def test_mandatory_warnings_disabled():
|
def test_mandatory_warnings_disabled():
|
||||||
|
@ -230,9 +230,9 @@ def test_mandatory_warnings_disabled():
|
||||||
setting = config.cfgimpl_get_settings()
|
setting = config.cfgimpl_get_settings()
|
||||||
config.read_write()
|
config.read_write()
|
||||||
config.str
|
config.str
|
||||||
assert list(mandatory_warnings(config)) == ['str', 'str1', 'unicode2', 'str3']
|
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str', 'str1', 'unicode2', 'str3']
|
||||||
setting[descr.str].append('disabled')
|
setting[descr.str].append('disabled')
|
||||||
assert list(mandatory_warnings(config)) == ['str1', 'unicode2', 'str3']
|
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str1', 'unicode2', 'str3']
|
||||||
|
|
||||||
|
|
||||||
def test_mandatory_warnings_frozen():
|
def test_mandatory_warnings_frozen():
|
||||||
|
@ -242,7 +242,7 @@ def test_mandatory_warnings_frozen():
|
||||||
setting = config.cfgimpl_get_settings()
|
setting = config.cfgimpl_get_settings()
|
||||||
config.read_write()
|
config.read_write()
|
||||||
config.str
|
config.str
|
||||||
assert list(mandatory_warnings(config)) == ['str', 'str1', 'unicode2', 'str3']
|
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str', 'str1', 'unicode2', 'str3']
|
||||||
setting[descr.str].append('frozen')
|
setting[descr.str].append('frozen')
|
||||||
config.read_only()
|
config.read_only()
|
||||||
assert list(mandatory_warnings(config)) == ['str', 'str1', 'unicode2', 'str3']
|
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str', 'str1', 'unicode2', 'str3']
|
||||||
|
|
|
@ -716,19 +716,5 @@ class MetaConfig(GroupConfig):
|
||||||
|
|
||||||
|
|
||||||
def mandatory_warnings(config):
|
def mandatory_warnings(config):
|
||||||
"""convenience function to trace Options that are mandatory and
|
#only for retro-compatibility
|
||||||
where no value has been set
|
config.cfgimpl_get_values().mandatory_warnings()
|
||||||
|
|
||||||
:returns: generator of mandatory Option's path
|
|
||||||
|
|
||||||
"""
|
|
||||||
#if value in cache, properties are not calculated
|
|
||||||
config.cfgimpl_reset_cache(only=('values',))
|
|
||||||
for path in config.cfgimpl_get_description().impl_getpaths(
|
|
||||||
include_groups=True):
|
|
||||||
try:
|
|
||||||
config._getattr(path, force_properties=frozenset(('mandatory',)))
|
|
||||||
except PropertiesOptionError as err:
|
|
||||||
if err.proptype == ['mandatory']:
|
|
||||||
yield path
|
|
||||||
config.cfgimpl_reset_cache(only=('values',))
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ from time import time
|
||||||
from copy import copy
|
from copy import copy
|
||||||
import sys
|
import sys
|
||||||
import weakref
|
import weakref
|
||||||
from tiramisu.error import ConfigError, SlaveError
|
from tiramisu.error import ConfigError, SlaveError, PropertiesOptionError
|
||||||
from tiramisu.setting import owners, multitypes, expires_time, undefined
|
from tiramisu.setting import owners, multitypes, expires_time, undefined
|
||||||
from tiramisu.autolib import carry_out_calculation
|
from tiramisu.autolib import carry_out_calculation
|
||||||
from tiramisu.i18n import _
|
from tiramisu.i18n import _
|
||||||
|
@ -395,6 +395,42 @@ class Values(object):
|
||||||
raise ValueError(_("information's item"
|
raise ValueError(_("information's item"
|
||||||
" not found: {0}").format(key))
|
" not found: {0}").format(key))
|
||||||
|
|
||||||
|
def mandatory_warnings(self):
|
||||||
|
"""convenience function to trace Options that are mandatory and
|
||||||
|
where no value has been set
|
||||||
|
|
||||||
|
:returns: generator of mandatory Option's path
|
||||||
|
|
||||||
|
"""
|
||||||
|
#if value in cache, properties are not calculated
|
||||||
|
self.reset_cache(False)
|
||||||
|
context = self.context()
|
||||||
|
for path in context.cfgimpl_get_description().impl_getpaths(
|
||||||
|
include_groups=True):
|
||||||
|
try:
|
||||||
|
context._getattr(path,
|
||||||
|
force_properties=frozenset(('mandatory',)))
|
||||||
|
except PropertiesOptionError as err:
|
||||||
|
if err.proptype == ['mandatory']:
|
||||||
|
yield path
|
||||||
|
self.reset_cache(False)
|
||||||
|
|
||||||
|
def force_cache(self):
|
||||||
|
"""parse all option to force data in cache
|
||||||
|
"""
|
||||||
|
context = self.context()
|
||||||
|
if not 'cache' in context.cfgimpl_get_settings():
|
||||||
|
raise PropertiesOptionError(_('can force cache only if cache '
|
||||||
|
'is actived in config'))
|
||||||
|
#remove all cached properties and value to update "expired" time
|
||||||
|
context.cfgimpl_reset_cache()
|
||||||
|
for path in context.cfgimpl_get_description().impl_getpaths(
|
||||||
|
include_groups=True):
|
||||||
|
try:
|
||||||
|
context._getattr(path)
|
||||||
|
except PropertiesOptionError:
|
||||||
|
pass
|
||||||
|
|
||||||
def __getstate__(self):
|
def __getstate__(self):
|
||||||
return {'_p_': self._p_}
|
return {'_p_': self._p_}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue