def test_common_verbose(self): PySmartCacheSettings.verbose = True os.environ['PYSMARTCACHE_VERBOSE'] = '1' self.assertTrue(PySmartCacheSettings._get_verbose(True)) self.assertTrue(PySmartCacheSettings._get_verbose(None)) PySmartCacheSettings.reset() self.assertTrue(PySmartCacheSettings._get_verbose(None)) os.environ.pop('PYSMARTCACHE_VERBOSE', None) self.assertFalse(PySmartCacheSettings._get_verbose(None))
def __init__(self, func, keys, function_args, function_kwargs, timeout=None, cache_backend=None, cache_host=None, verbose=None): self.timeout = PySmartCacheSettings._get_timeout(timeout) self.cache_backend = PySmartCacheSettings._get_cache_backend(cache_backend) self.verbose = PySmartCacheSettings._get_verbose(verbose) self.func = func self.keys = keys self.function_args = function_args self.function_kwargs = function_kwargs self.function_arguments = inspect.getcallargs(self.func, *self.function_args, **self.function_kwargs) self.now_reference = datetime.datetime.now() self.cache_client = CacheClient.instantiate(self.cache_backend, cache_host) self._create_func_full_qualified_name() self._create_cache_key() self.stored_info = self.info() self.stored_value = self.stored_info['value'] if self.stored_info else None self.stored_at = self.stored_info['date added'] if self.stored_info else None if self.verbose: print '-' * 50 print 'KEY: {}'.format(self.cache_key)
def __init__(self, func, keys, function_args, function_kwargs, timeout=None, cache_backend=None, cache_host=None, verbose=None): self.timeout = PySmartCacheSettings._get_timeout(timeout) self.cache_backend = PySmartCacheSettings._get_cache_backend( cache_backend) self.verbose = PySmartCacheSettings._get_verbose(verbose) self.func = func self.keys = keys self.function_args = function_args self.function_kwargs = function_kwargs self.function_arguments = inspect.getcallargs(self.func, *self.function_args, **self.function_kwargs) self.now_reference = datetime.datetime.now() self.cache_client = CacheClient.instantiate(self.cache_backend, cache_host) self._create_func_full_qualified_name() self._create_cache_key() self.stored_info = self.info() self.stored_value = self.stored_info[ 'value'] if self.stored_info else None self.stored_at = self.stored_info[ 'date added'] if self.stored_info else None if self.verbose: print '-' * 50 print 'KEY: {}'.format(self.cache_key)
def test_verbose_different_from_0_or_1(self): with self.assertRaises(ImproperlyConfigured) as e: PySmartCacheSettings._get_verbose(2) self.assertEquals(str(e.exception), 'PySmartCache verbose settings must be 0 or 1')
def test_verbose_nan(self): with self.assertRaises(ImproperlyConfigured) as e: PySmartCacheSettings._get_verbose('NaN NaN NaN NaN Batman!') self.assertEquals(str(e.exception), 'PySmartCache verbose settings must be numeric')