commit 71c7aa5c5c8f519f9d3f356cc3ddf87ecff4caec
parent 41fa4cd89558d325f2f13ca3f9fd8363ff70fab5
Author: lash <dev@holbrook.no>
Date: Tue, 26 Apr 2022 06:34:02 +0000
Add noop store
Diffstat:
4 files changed, 128 insertions(+), 0 deletions(-)
diff --git a/CHANGELOG b/CHANGELOG
@@ -1,3 +1,5 @@
+- 0.2.3
+ * Add memstore
- 0.2.2
* Fix composite state factory load regex
- 0.2.1
diff --git a/shep/store/base.py b/shep/store/base.py
@@ -13,3 +13,7 @@ class StoreFactory:
def close(self):
pass
+
+
+ def ls(self):
+ raise NotImplementedError()
diff --git a/shep/store/noop.py b/shep/store/noop.py
@@ -0,0 +1,44 @@
+# local imports
+from .base import StoreFactory
+
+
+class NoopStore:
+
+ def put(self, k, contents=None):
+ pass
+
+
+ def remove(self, k):
+ pass
+
+ def get(self, k):
+ pass
+
+
+ def list(self):
+ return []
+
+
+ def path(self):
+ return None
+
+
+ def replace(self, k, contents):
+ pass
+
+ def modified(self, k):
+ pass
+
+
+ def register_modify(self, k):
+ pass
+
+
+class NoopStoreFactory(StoreFactory):
+
+ def add(self, k):
+ return NoopStore()
+
+
+ def ls(self):
+ return []
diff --git a/tests/test_noop.py b/tests/test_noop.py
@@ -0,0 +1,78 @@
+# standard imports
+import unittest
+import os
+import logging
+import sys
+import importlib
+import tempfile
+
+# local imports
+from shep.persist import PersistedState
+from shep.store.noop import NoopStoreFactory
+from shep.error import (
+ StateExists,
+ StateInvalid,
+ StateItemExists,
+ StateItemNotFound,
+ )
+
+logging.basicConfig(level=logging.DEBUG)
+logg = logging.getLogger()
+
+
+class TestNoopStore(unittest.TestCase):
+
+ def setUp(self):
+ self.factory = NoopStoreFactory()
+ self.states = PersistedState(self.factory.add, 3)
+ self.states.add('foo')
+ self.states.add('bar')
+ self.states.add('baz')
+
+
+ def test_add(self):
+ self.states.put('abcd', state=self.states.FOO, contents='baz')
+ v = self.states.get('abcd')
+ self.assertEqual(v, 'baz')
+ v = self.states.state('abcd')
+ self.assertEqual(v, self.states.FOO)
+
+
+ def test_next(self):
+ self.states.put('abcd')
+
+ self.states.next('abcd')
+ self.assertEqual(self.states.state('abcd'), self.states.FOO)
+
+ self.states.next('abcd')
+ self.assertEqual(self.states.state('abcd'), self.states.BAR)
+
+ self.states.next('abcd')
+ self.assertEqual(self.states.state('abcd'), self.states.BAZ)
+
+ with self.assertRaises(StateInvalid):
+ self.states.next('abcd')
+
+ v = self.states.state('abcd')
+ self.assertEqual(v, self.states.BAZ)
+
+
+ def test_replace(self):
+ with self.assertRaises(StateItemNotFound):
+ self.states.replace('abcd', contents='foo')
+
+ self.states.put('abcd', state=self.states.FOO, contents='baz')
+ self.states.replace('abcd', contents='bar')
+ v = self.states.get('abcd')
+ 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), 0)
+
+
+if __name__ == '__main__':
+ unittest.main()