From d7b5d9dc160dcfda9c036ec986835dc515a5cf58 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Fri, 19 Apr 2013 20:23:34 +0200 Subject: [PATCH] add SlaveError for slave's length --- test/test_parsing_group.py | 11 ++++++----- tiramisu/setting.py | 4 ++-- tiramisu/value.py | 4 ++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/test/test_parsing_group.py b/test/test_parsing_group.py index ef162b6..f060a97 100644 --- a/test/test_parsing_group.py +++ b/test/test_parsing_group.py @@ -4,6 +4,7 @@ from tiramisu.setting import groups, owners from tiramisu.config import Config from tiramisu.option import ChoiceOption, BoolOption, IntOption, \ StrOption, OptionDescription +from tiramisu.error import SlaveError from py.test import raises @@ -185,18 +186,18 @@ def test_values_with_master_and_slaves_slave(): maconfig = OptionDescription('toto', '', [interface1]) cfg = Config(maconfig) assert cfg.ip_admin_eth0.netmask_admin_eth0 == [] - raises(ValueError, "cfg.ip_admin_eth0.netmask_admin_eth0 = ['255.255.255.0']") + raises(SlaveError, "cfg.ip_admin_eth0.netmask_admin_eth0 = ['255.255.255.0']") cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145") cfg.ip_admin_eth0.netmask_admin_eth0 = ['255.255.255.0'] cfg.ip_admin_eth0.netmask_admin_eth0[0] = '255.255.255.0' - raises(ValueError, "cfg.ip_admin_eth0.netmask_admin_eth0 = ['255.255.255.0', '255.255.255.0']") - raises(ValueError, "cfg.ip_admin_eth0.netmask_admin_eth0 = []") + raises(SlaveError, "cfg.ip_admin_eth0.netmask_admin_eth0 = ['255.255.255.0', '255.255.255.0']") + raises(SlaveError, "cfg.ip_admin_eth0.netmask_admin_eth0 = []") del(cfg.ip_admin_eth0.netmask_admin_eth0) cfg.ip_admin_eth0.netmask_admin_eth0 = ['255.255.255.0'] cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145") assert cfg.ip_admin_eth0.netmask_admin_eth0 == ['255.255.255.0', None] cfg.ip_admin_eth0.netmask_admin_eth0 = ['255.255.255.0', '255.255.255.0'] - raises(ValueError, 'cfg.ip_admin_eth0.netmask_admin_eth0.pop(1)') + raises(SlaveError, 'cfg.ip_admin_eth0.netmask_admin_eth0.pop(1)') def test_values_with_master_and_slaves_master(): @@ -210,6 +211,6 @@ def test_values_with_master_and_slaves_master(): cfg.ip_admin_eth0.ip_admin_eth0 = ["192.168.230.145"] cfg.ip_admin_eth0.ip_admin_eth0 = ["192.168.230.145", "192.168.230.145"] cfg.ip_admin_eth0.netmask_admin_eth0 = ['255.255.255.0', '255.255.255.0'] - raises(ValueError, 'cfg.ip_admin_eth0.ip_admin_eth0 = ["192.168.230.145"]') + raises(SlaveError, 'cfg.ip_admin_eth0.ip_admin_eth0 = ["192.168.230.145"]') cfg.ip_admin_eth0.ip_admin_eth0.pop(1) assert cfg.ip_admin_eth0.ip_admin_eth0 == ["192.168.230.145"] diff --git a/tiramisu/setting.py b/tiramisu/setting.py index f101a0c..38cd487 100644 --- a/tiramisu/setting.py +++ b/tiramisu/setting.py @@ -250,7 +250,7 @@ class Setting(object): if opt_or_descr in self._cache: t = time() props, raise_text, created = self._cache[opt_or_descr] - if t - created < expires_time: + if t < created: properties = props is_cached = True if not is_cached: @@ -318,7 +318,7 @@ class Setting(object): def _set_cache(self, opt, props, raise_text): if self.has_property('expire'): - self._cache[opt] = (props, raise_text, time()) + self._cache[opt] = (props, raise_text, time() + expires_time) def reset_cache(self): self._cache = {} diff --git a/tiramisu/value.py b/tiramisu/value.py index 5838df6..e35cbcb 100644 --- a/tiramisu/value.py +++ b/tiramisu/value.py @@ -86,7 +86,7 @@ class Values(object): if opt in self._cache: t = time() value, created = self._cache[opt] - if t - created < expires_time: + if t < created: return value val = self._getitem(opt, validate, force_permissive, force_properties) self._set_cache(opt, val) @@ -173,7 +173,7 @@ class Values(object): def _set_cache(self, opt, val): if self.context.cfgimpl_get_settings().has_property('expire'): - self._cache[opt] = (val, time()) + self._cache[opt] = (val, time() + expires_time) def reset_cache(self): self._cache = {}