Complete redis and rocksdb tests for factory ls
This commit is contained in:
parent
c150f7cc84
commit
10b2e91ab2
@ -1,6 +1,6 @@
|
||||
[metadata]
|
||||
name = shep
|
||||
version = 0.2.1a2
|
||||
version = 0.2.1rc1
|
||||
description = Multi-state key stores using bit masks
|
||||
author = Louis Holbrook
|
||||
author_email = dev@holbrook.no
|
||||
|
@ -153,6 +153,7 @@ class SimpleFileStoreFactory(StoreFactory):
|
||||
|
||||
def ls(self):
|
||||
r = []
|
||||
import sys
|
||||
for v in os.listdir(self.__path):
|
||||
if re.match(re_processedname, v):
|
||||
r.append(v)
|
||||
|
@ -21,7 +21,7 @@ class RedisStore:
|
||||
|
||||
|
||||
def __from_path(self, s):
|
||||
(left, right) = s.split('.', maxsplit=1)
|
||||
(left, right) = s.split(b'.', maxsplit=1)
|
||||
return right
|
||||
|
||||
|
||||
@ -55,7 +55,7 @@ class RedisStore:
|
||||
r = []
|
||||
for s in matches:
|
||||
k = self.__from_path(s)
|
||||
v = self.redis.get(v)
|
||||
v = self.redis.get(k)
|
||||
r.append((k, v,))
|
||||
|
||||
return r
|
||||
@ -91,7 +91,7 @@ class RedisStore:
|
||||
|
||||
class RedisStoreFactory(StoreFactory):
|
||||
|
||||
def __init__(self, host='localhost', port=6379, db=0, binary=False):
|
||||
def __init__(self, host='localhost', port=6379, db=2, binary=False):
|
||||
self.redis = redis.Redis(host=host, port=port, db=db)
|
||||
self.__binary = binary
|
||||
|
||||
@ -103,3 +103,15 @@ class RedisStoreFactory(StoreFactory):
|
||||
|
||||
def close(self):
|
||||
self.redis.close()
|
||||
|
||||
|
||||
def ls(self):
|
||||
r = []
|
||||
(c, ks) = self.redis.scan(match='*')
|
||||
for k in ks:
|
||||
v = k.rsplit(b'.', maxsplit=1)
|
||||
if v != k:
|
||||
v = v[0].decode('utf-8')
|
||||
if v not in r:
|
||||
r.append(v)
|
||||
return r
|
||||
|
@ -136,12 +136,12 @@ class RocksDbStoreFactory(StoreFactory):
|
||||
|
||||
def ls(self):
|
||||
it = self.db.iterkeys()
|
||||
it.seek_to_first()
|
||||
r = []
|
||||
for k in it:
|
||||
kstr = k.decode('utf-8')
|
||||
v = None
|
||||
try:
|
||||
k.index('/')
|
||||
except ValueError:
|
||||
r.append(kstr)
|
||||
v = k.rsplit(b'.', maxsplit=1)
|
||||
if v != k:
|
||||
v = v[0].decode('utf-8')
|
||||
if v not in r:
|
||||
r.append(v)
|
||||
return r
|
||||
|
@ -242,6 +242,20 @@ class TestFileStore(unittest.TestCase):
|
||||
self.assertEqual(r, 'foo')
|
||||
|
||||
|
||||
def test_factory_ls(self):
|
||||
self.states.put('abcd')
|
||||
self.states.put('xxxx', state=self.states.BAZ)
|
||||
r = self.factory.ls()
|
||||
self.assertEqual(len(r), 2)
|
||||
|
||||
self.states.put('yyyy', state=self.states.BAZ)
|
||||
r = self.factory.ls()
|
||||
self.assertEqual(len(r), 2)
|
||||
|
||||
self.states.put('zzzz', state=self.states.BAR)
|
||||
r = self.factory.ls()
|
||||
self.assertEqual(len(r), 3)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
@ -23,6 +23,7 @@ class TestRedisStore(unittest.TestCase):
|
||||
def setUp(self):
|
||||
from shep.store.redis import RedisStoreFactory
|
||||
self.factory = RedisStoreFactory()
|
||||
self.factory.redis.flushall()
|
||||
self.states = PersistedState(self.factory.add, 3)
|
||||
self.states.add('foo')
|
||||
self.states.add('bar')
|
||||
@ -66,6 +67,24 @@ class TestRedisStore(unittest.TestCase):
|
||||
self.assertEqual(v, 'bar')
|
||||
|
||||
|
||||
def test_factory_ls(self):
|
||||
r = self.factory.ls()
|
||||
self.assertEqual(len(r), 0)
|
||||
|
||||
self.states.put('abcd')
|
||||
self.states.put('xxxx', state=self.states.BAZ)
|
||||
r = self.factory.ls()
|
||||
self.assertEqual(len(r), 2)
|
||||
|
||||
self.states.put('yyyy', state=self.states.BAZ)
|
||||
r = self.factory.ls()
|
||||
self.assertEqual(len(r), 2)
|
||||
|
||||
self.states.put('zzzz', state=self.states.BAR)
|
||||
r = self.factory.ls()
|
||||
self.assertEqual(len(r), 3)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
noredis = False
|
||||
redis = None
|
||||
|
@ -73,6 +73,21 @@ class TestRedisStore(unittest.TestCase):
|
||||
self.assertEqual(v, 'bar')
|
||||
|
||||
|
||||
def test_factory_ls(self):
|
||||
self.states.put('abcd')
|
||||
self.states.put('xxxx', state=self.states.BAZ)
|
||||
r = self.factory.ls()
|
||||
self.assertEqual(len(r), 2)
|
||||
|
||||
self.states.put('yyyy', state=self.states.BAZ)
|
||||
r = self.factory.ls()
|
||||
self.assertEqual(len(r), 2)
|
||||
|
||||
self.states.put('zzzz', state=self.states.BAR)
|
||||
r = self.factory.ls()
|
||||
self.assertEqual(len(r), 3)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
norocksdb = False
|
||||
rocksdb = None
|
||||
|
@ -84,6 +84,5 @@ class TestStateItems(unittest.TestCase):
|
||||
self.assertIsNone(self.mockstore.v.get(item))
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
Loading…
Reference in New Issue
Block a user