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
|
||||
properties.default_factor_size = self.global_factor
|
||||
|
||||
# Load cache factors from the config, but override them with the
|
||||
# environment if they exist
|
||||
# Load cache factors from the config
|
||||
individual_factors = cache_config.get("per_cache_factors", {}) or {}
|
||||
if not isinstance(individual_factors, dict):
|
||||
raise ConfigError("caches.per_cache_factors must be a dictionary")
|
||||
|
||||
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
|
||||
|
||||
# Override with environment
|
||||
# Override factors from environment if necessary
|
||||
individual_factors.update(
|
||||
{
|
||||
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
|
||||
self.resize_all_caches()
|
||||
|
||||
|
|
|
@ -49,8 +49,8 @@ class CacheConfigTests(TestCase):
|
|||
|
||||
def test_config_overrides_environ(self):
|
||||
"""
|
||||
Individual cache factors defined in config will take precedence over
|
||||
ones in the environment.
|
||||
Individual cache factors defined in the environment will take precedence
|
||||
over those in the config.
|
||||
"""
|
||||
config = {"caches": {"per_cache_factors": {"foo": 2, "bar": 3}}}
|
||||
t = TestConfig()
|
||||
|
@ -62,7 +62,7 @@ class CacheConfigTests(TestCase):
|
|||
|
||||
self.assertEqual(
|
||||
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):
|
||||
|
|
Loading…
Reference in New Issue