def test_clear(): cache = Cache('test', data_dir='./cache', url=db_url, type='ext:database') o = object() cache.set_value("test", o) assert cache.has_key("test") cache.clear() assert not cache.has_key("test")
def test_clear(): cache = Cache('test', url=db_url, type=db_type, database=db_name) o = object() cache.set_value("test", o) assert cache.has_key("test") cache.clear() assert not cache.has_key("test")
def test_has_key_multicache(): cache = Cache('test', data_dir='./cache', type='dbm') o = object() cache.set_value("test", o) assert "test" in cache cache = Cache('test', data_dir='./cache', type='dbm') assert "test" in cache
def test_has_key_multicache(): cache = Cache('test', data_dir='./cache', url=mc_url, type='ext:memcached') o = object() cache.set_value("test", o) assert "test" in cache cache = Cache('test', data_dir='./cache', url=mc_url, type='ext:memcached') assert "test" in cache
def test_spaces_in_unicode_keys(): cache = Cache('test', data_dir='./cache', url=mc_url, type='ext:memcached') o = object() cache.set_value(u_('hi ŏ'), o) assert u_('hi ŏ') in cache assert u_('hŏa') not in cache cache.remove_value(u_('hi ŏ')) assert u_('hi ŏ') not in cache
def test_expiretime(): cache = Cache('test', data_dir='./cache', url=uri, type='mongodb_gridfs') cache.set_value('test', 20, expiretime=-10) cache.set_value('foo', 20) assert not cache.has_key('test') assert 'test' not in cache assert cache.has_key('foo') assert 'foo' in cache
def test_spaces_in_keys(): cache = Cache("test", data_dir="./cache", url=mc_url, type="ext:memcached") cache.set_value("has space", 24) assert cache.has_key("has space") assert 24 == cache.get_value("has space") cache.set_value("hasspace", 42) assert cache.has_key("hasspace") assert 42 == cache.get_value("hasspace")
def test_spaces_in_unicode_keys(): cache = Cache("test", data_dir="./cache", url=mc_url, type="ext:memcached") o = object() cache.set_value(u"hi ŏ", o) assert u"hi ŏ" in cache assert u"hŏa" not in cache cache.remove_value(u"hi ŏ") assert u"hi ŏ" not in cache
def test_spaces_in_keys(): cache = Cache('test', data_dir='./cache', url=uri, type='mongodb', sparse_collection=True, skip_pickle=True) cache.set_value("has space", 24) assert cache.has_key("has space") assert 24 == cache.get_value("has space") cache.set_value("hasspace", 42) assert cache.has_key("hasspace") assert 42 == cache.get_value("hasspace")
def test_has_key_multicache(): cache = Cache('test', data_dir='./cache', url=uri, type='mongodb', sparse_collection=True, skip_pickle=True) o = object() cache.set_value("test", o) assert cache.has_key("test") assert "test" in cache cache = Cache('test', data_dir='./cache', url=uri, type='mongodb', sparse_collection=True, skip_pickle=True) assert cache.has_key("test")
def test_has_key_multicache(): cache = Cache('test', data_dir='./cache', url=db_url, type='ext:database') o = object() cache.set_value("test", o) assert "test" in cache cache = Cache('test', data_dir='./cache', url=db_url, type='ext:database') assert "test" in cache cache.remove_value('test')
def test_unicode_keys(): cache = Cache('test', url=db_url, type=db_type, database=db_name) o = object() cache.set_value(u'hiŏ', o) assert u'hiŏ' in cache assert u'hŏa' not in cache cache.remove_value(u'hiŏ') assert u'hiŏ' not in cache
def test_spaces_in_keys(): cache = Cache('test', data_dir='./cache', url=mc_url, type='ext:memcached') cache.set_value("has space", 24) assert cache.has_key("has space") assert 24 == cache.get_value("has space") cache.set_value("hasspace", 42) assert cache.has_key("hasspace") assert 42 == cache.get_value("hasspace")
def test_spaces_in_keys(): cache = Cache('test', data_dir='./cache', url=uri, type='mongodb') cache.set_value("has space", 24) assert cache.has_key("has space") assert 24 == cache.get_value("has space") cache.set_value("hasspace", 42) assert cache.has_key("hasspace") assert 42 == cache.get_value("hasspace")
def test_has_key_multicache(): cache = Cache('test', data_dir='./cache', url=uri, type='mongodb') o = object() cache.set_value("test", o) assert cache.has_key("test") assert "test" in cache cache = Cache('test', data_dir='./cache', url=uri, type='mongodb') assert cache.has_key("test")
def test_spaces_in_unicode_keys(): cache = Cache('test', data_dir='./cache', url=uri, type='mongodb') o = object() cache.set_value(u'hi ŏ', o) assert u'hi ŏ' in cache assert u'hŏa' not in cache cache.remove_value(u'hi ŏ') assert u'hi ŏ' not in cache
def test_unicode_keys(): cache = Cache("test", data_dir="./cache", url=db_url, type="ext:database") o = object() cache.set_value(u"hiŏ", o) assert u"hiŏ" in cache assert u"hŏa" not in cache cache.remove_value(u"hiŏ") assert u"hiŏ" not in cache
def test_has_key_multicache(): cache = Cache("test", data_dir="./cache", url=db_url, type="ext:database") o = object() cache.set_value("test", o) assert cache.has_key("test") assert "test" in cache cache = Cache("test", data_dir="./cache", url=db_url, type="ext:database") assert cache.has_key("test")
def test_spaces_in_unicode_keys(self): cache = Cache('test', **self.CACHE_ARGS) o = object() cache.set_value(u_('hi ŏ'), o) assert u_('hi ŏ') in cache assert u_('hŏa') not in cache cache.remove_value(u_('hi ŏ')) assert u_('hi ŏ') not in cache
def test_unicode_keys(): cache = Cache('test', data_dir='./cache', url=uri, type='mongodb', sparse_collection=True) o = object() cache.set_value(u'hiŏ', o) assert u'hiŏ' in cache assert u'hŏa' not in cache cache.remove_value(u'hiŏ') assert u'hiŏ' not in cache
def test_long_unicode_keys(): cache = Cache('test', data_dir='./cache', url=mc_url, type='ext:memcached') o = object() long_str = u_('Очень длинная строка, которая не влезает в сто двадцать восемь байт и поэтому не проходит ограничение в check_key, что очень прискорбно, не правда ли, друзья? Давайте же скорее исправим это досадное недоразумение!') cache.set_value(long_str, o) assert long_str in cache cache.remove_value(long_str) assert long_str not in cache
def test_spaces_in_keys(self): cache = Cache('test', **self.CACHE_ARGS) cache.set_value("has space", 24) assert cache.has_key("has space") assert 24 == cache.get_value("has space") cache.set_value("hasspace", 42) assert cache.has_key("hasspace") assert 42 == cache.get_value("hasspace")
def test_has_key_multicache(): cache = Cache("test", data_dir="./cache", type="dbm") o = object() cache.set_value("test", o) assert cache.has_key("test") assert "test" in cache cache = Cache("test", data_dir="./cache", type="dbm") assert cache.has_key("test")
def test_has_key_multicache(self): cache = Cache('test', **self.CACHE_ARGS) o = object() cache.set_value("test", o) assert cache.has_key("test") assert "test" in cache cache = Cache('test', **self.CACHE_ARGS) assert cache.has_key("test")
def test_has_key(): cache = Cache('test', data_dir='./cache', url=mc_url, type='ext:memcached') o = object() cache.set_value("test", o) assert "test" in cache assert "foo" not in cache cache.remove_value("test") assert "test" not in cache
def test_unicode_keys(): cache = Cache('test', data_dir='./cache', type='dbm') o = object() cache.set_value(u'hiŏ', o) assert u'hiŏ' in cache assert u'hŏa' not in cache cache.remove_value(u'hiŏ') assert u'hiŏ' not in cache
def test_unicode_keys(): cache = Cache('test', data_dir='./cache', url=db_url, type='ext:database') o = object() cache.set_value(u_('hiŏ'), o) assert u_('hiŏ') in cache assert u_('hŏa') not in cache cache.remove_value(u_('hiŏ')) assert u_('hiŏ') not in cache
def test_expiretime_automatic(self): if not self.SUPPORTS_EXPIRATION: self.skipTest('NamespaceManager does not support automatic expiration') cache = Cache('test', **self.CACHE_ARGS) cache.set_value("has space", 24, expiretime=1) assert cache.namespace.has_key("has space") time.sleep(1.1) assert not cache.namespace.has_key("has space")
def test_client(self): cache = Cache('test', data_dir='./cache', url=mc_url, type="ext:memcached", protocol='binary') o = object() cache.set_value("test", o) assert "test" in cache assert "foo" not in cache cache.remove_value("test") assert "test" not in cache
def test_clear(self): cache = Cache('test', **self.CACHE_ARGS) cache.set_value('test', 20) cache.set_value('fred', 10) assert cache.has_key('test') assert 'test' in cache assert cache.has_key('fred') cache.clear() assert not cache.has_key("test")
def test_dropping_keys(): cache = Cache("test", data_dir="./cache", url=mc_url, type="ext:memcached") cache.set_value("test", 20) cache.set_value("fred", 10) assert cache.has_key("test") assert "test" in cache assert cache.has_key("fred") # Directly nuke the actual key, to simulate it being removed by memcached cache.namespace.mc.delete("test_test") assert not cache.has_key("test") assert cache.has_key("fred") # Nuke the keys dict, it might die, who knows cache.namespace.mc.delete("test:keys") assert cache.has_key("fred") # And we still need clear to work, even if it won't work well cache.clear()
def test_dropping_keys(): cache = Cache('test', data_dir='./cache', url=mc_url, type='ext:memcached') cache.set_value('test', 20) cache.set_value('fred', 10) assert cache.has_key('test') assert 'test' in cache assert cache.has_key('fred') # Directly nuke the actual key, to simulate it being removed by memcached cache.namespace.mc.delete('test_test') assert not cache.has_key('test') assert cache.has_key('fred') # Nuke the keys dict, it might die, who knows cache.namespace.mc.delete('test:keys') assert cache.has_key('fred') # And we still need clear to work, even if it won't work well cache.clear()
def test_legacy_cache(): cache = Cache('newtests', data_dir='./cache', type='dbm') cache.set_value('x', '1') assert cache.get_value('x') == '1' cache.set_value('x', '2', type='file', data_dir='./cache') assert cache.get_value('x') == '1' assert cache.get_value('x', type='file', data_dir='./cache') == '2' cache.remove_value('x') cache.remove_value('x', type='file', data_dir='./cache') assert cache.get_value('x', expiretime=1, createfunc=lambda: '5') == '5' assert cache.get_value('x', expiretime=1, createfunc=lambda: '6', type='file', data_dir='./cache') == '6' assert cache.get_value('x', expiretime=1, createfunc=lambda: '7') == '5' assert cache.get_value('x', expiretime=1, createfunc=lambda: '8', type='file', data_dir='./cache') == '6' time.sleep(1) assert cache.get_value('x', expiretime=1, createfunc=lambda: '9') == '9' assert cache.get_value('x', expiretime=1, createfunc=lambda: '10', type='file', data_dir='./cache') == '10' assert cache.get_value('x', expiretime=1, createfunc=lambda: '11') == '9' assert cache.get_value('x', expiretime=1, createfunc=lambda: '12', type='file', data_dir='./cache') == '10'
def test_legacy_cache(): cache = Cache("newtests", data_dir="./cache", type="dbm") cache.set_value("x", "1") assert cache.get_value("x") == "1" cache.set_value("x", "2", type="file", data_dir="./cache") assert cache.get_value("x") == "1" assert cache.get_value("x", type="file", data_dir="./cache") == "2" cache.remove_value("x") cache.remove_value("x", type="file", data_dir="./cache") assert cache.get_value("x", expiretime=1, createfunc=lambda: "5") == "5" assert (cache.get_value("x", expiretime=1, createfunc=lambda: "6", type="file", data_dir="./cache") == "6") assert cache.get_value("x", expiretime=1, createfunc=lambda: "7") == "5" assert (cache.get_value("x", expiretime=1, createfunc=lambda: "8", type="file", data_dir="./cache") == "6") time.sleep(1) assert cache.get_value("x", expiretime=1, createfunc=lambda: "9") == "9" assert (cache.get_value("x", expiretime=1, createfunc=lambda: "10", type="file", data_dir="./cache") == "10") assert cache.get_value("x", expiretime=1, createfunc=lambda: "11") == "9" assert (cache.get_value("x", expiretime=1, createfunc=lambda: "12", type="file", data_dir="./cache") == "10")
def test_dropping_keys(): cache = Cache('test', data_dir='./cache', url=uri, type='mongodb', sparse_collection=True, skip_pickle=True) cache.set_value('test', 20) cache.set_value('fred', 10) assert cache.has_key('test') assert 'test' in cache assert cache.has_key('fred') # Directly nuke the actual key, to simulate it being removed by mongodb cache.namespace.mongo.update({'_id': { 'namespace': 'test', 'key': 'test' }}, {'$unset': { 'data': True }}, safe=True) assert not cache.has_key('test') assert cache.has_key('fred') # Nuke the keys dict, it might die, who knows cache.namespace.mongo.remove( { '_id': 'test', 'data.test': { '$exists': True } }, safe=True) assert cache.has_key('fred') # And we still need clear to work, even if it won't work well cache.clear()
def test_expire_changes(): cache = Cache("test_bar", data_dir="./cache", type="dbm") cache.set_value("test", 10) assert cache.has_key("test") assert cache["test"] == 10 # ensure that we can change a never-expiring value cache.set_value("test", 20, expiretime=1) assert cache.has_key("test") assert cache["test"] == 20 time.sleep(1) assert not cache.has_key("test") # test that we can change it before its expired cache.set_value("test", 30, expiretime=50) assert cache.has_key("test") assert cache["test"] == 30 cache.set_value("test", 40, expiretime=3) assert cache.has_key("test") assert cache["test"] == 40 time.sleep(3) assert not cache.has_key("test")
def test_expire_changes(): cache = Cache('test_bar', data_dir='./cache', type='dbm') cache.set_value('test', 10) assert cache.has_key('test') assert cache['test'] == 10 # ensure that we can change a never-expiring value cache.set_value('test', 20, expiretime=1) assert cache.has_key('test') assert cache['test'] == 20 time.sleep(1) assert not cache.has_key('test') # test that we can change it before its expired cache.set_value('test', 30, expiretime=50) assert cache.has_key('test') assert cache['test'] == 30 cache.set_value('test', 40, expiretime=3) assert cache.has_key('test') assert cache['test'] == 40 time.sleep(3) assert not cache.has_key('test')
def test_expiretime(self): cache = Cache('test', **self.CACHE_ARGS) cache.set_value("has space", 24, expiretime=1) assert cache.has_key("has space") time.sleep(1.1) assert not cache.has_key("has space")
def test_unicode_values(): cache = Cache('test', data_dir='./cache', url=uri, type='mongodb_gridfs') cache.set_value('test', u'hiŏ') assert 'test' in cache