fix tests
parent
c7f3bf66c2
commit
485f17737b
|
@ -103,20 +103,12 @@ class CacheConfig(Config):
|
||||||
# Set the global one so that it's reflected in new caches
|
# Set the global one so that it's reflected in new caches
|
||||||
properties.default_factor_size = self.global_factor
|
properties.default_factor_size = self.global_factor
|
||||||
|
|
||||||
# Load cache factors from the config, but override them with the
|
# Load cache factors from the config
|
||||||
# environment if they exist
|
|
||||||
individual_factors = cache_config.get("per_cache_factors", {}) or {}
|
individual_factors = cache_config.get("per_cache_factors", {}) or {}
|
||||||
if not isinstance(individual_factors, dict):
|
if not isinstance(individual_factors, dict):
|
||||||
raise ConfigError("caches.per_cache_factors must be a dictionary")
|
raise ConfigError("caches.per_cache_factors must be a dictionary")
|
||||||
|
|
||||||
for cache, factor in individual_factors.items():
|
# Override factors from environment if necessary
|
||||||
if not isinstance(factor, (int, float)):
|
|
||||||
raise ConfigError(
|
|
||||||
"caches.per_cache_factors.%s must be a number" % (cache.lower(),)
|
|
||||||
)
|
|
||||||
self.cache_factors[cache.lower()] = factor
|
|
||||||
|
|
||||||
# Override with environment
|
|
||||||
individual_factors.update(
|
individual_factors.update(
|
||||||
{
|
{
|
||||||
key[len(_CACHE_PREFIX) + 1 :].lower(): float(val)
|
key[len(_CACHE_PREFIX) + 1 :].lower(): float(val)
|
||||||
|
@ -125,6 +117,13 @@ class CacheConfig(Config):
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
for cache, factor in individual_factors.items():
|
||||||
|
if not isinstance(factor, (int, float)):
|
||||||
|
raise ConfigError(
|
||||||
|
"caches.per_cache_factors.%s must be a number" % (cache.lower(),)
|
||||||
|
)
|
||||||
|
self.cache_factors[cache.lower()] = factor
|
||||||
|
|
||||||
# Resize all caches (if necessary) with the new factors we've loaded
|
# Resize all caches (if necessary) with the new factors we've loaded
|
||||||
self.resize_all_caches()
|
self.resize_all_caches()
|
||||||
|
|
||||||
|
|
|
@ -49,8 +49,8 @@ class CacheConfigTests(TestCase):
|
||||||
|
|
||||||
def test_config_overrides_environ(self):
|
def test_config_overrides_environ(self):
|
||||||
"""
|
"""
|
||||||
Individual cache factors defined in config will take precedence over
|
Individual cache factors defined in the environment will take precedence
|
||||||
ones in the environment.
|
over those in the config.
|
||||||
"""
|
"""
|
||||||
config = {"caches": {"per_cache_factors": {"foo": 2, "bar": 3}}}
|
config = {"caches": {"per_cache_factors": {"foo": 2, "bar": 3}}}
|
||||||
t = TestConfig()
|
t = TestConfig()
|
||||||
|
@ -62,7 +62,7 @@ class CacheConfigTests(TestCase):
|
||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
dict(t.caches.cache_factors),
|
dict(t.caches.cache_factors),
|
||||||
{"foo": 2.0, "bar": 3.0, "something_or_other": 2.0},
|
{"foo": 1.0, "bar": 3.0, "something_or_other": 2.0},
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_individual_instantiated_before_config_load(self):
|
def test_individual_instantiated_before_config_load(self):
|
||||||
|
|
Loading…
Reference in New Issue