test_noop.py (2035B)
1 # standard imports 2 import unittest 3 import os 4 import logging 5 import sys 6 import importlib 7 import tempfile 8 9 # local imports 10 from shep.persist import PersistedState 11 from shep.store.noop import NoopStoreFactory 12 from shep.error import ( 13 StateExists, 14 StateInvalid, 15 StateItemExists, 16 StateItemNotFound, 17 ) 18 19 logging.basicConfig(level=logging.DEBUG) 20 logg = logging.getLogger() 21 22 23 class TestNoopStore(unittest.TestCase): 24 25 def setUp(self): 26 self.factory = NoopStoreFactory() 27 self.states = PersistedState(self.factory.add, 3) 28 self.states.add('foo') 29 self.states.add('bar') 30 self.states.add('baz') 31 32 33 def test_add(self): 34 self.states.put('abcd', state=self.states.FOO, contents='baz') 35 v = self.states.get('abcd') 36 self.assertEqual(v, 'baz') 37 v = self.states.state('abcd') 38 self.assertEqual(v, self.states.FOO) 39 40 41 def test_next(self): 42 self.states.put('abcd') 43 44 self.states.next('abcd') 45 self.assertEqual(self.states.state('abcd'), self.states.FOO) 46 47 self.states.next('abcd') 48 self.assertEqual(self.states.state('abcd'), self.states.BAR) 49 50 self.states.next('abcd') 51 self.assertEqual(self.states.state('abcd'), self.states.BAZ) 52 53 with self.assertRaises(StateInvalid): 54 self.states.next('abcd') 55 56 v = self.states.state('abcd') 57 self.assertEqual(v, self.states.BAZ) 58 59 60 def test_replace(self): 61 with self.assertRaises(StateItemNotFound): 62 self.states.replace('abcd', contents='foo') 63 64 self.states.put('abcd', state=self.states.FOO, contents='baz') 65 self.states.replace('abcd', contents='bar') 66 v = self.states.get('abcd') 67 self.assertEqual(v, 'bar') 68 69 70 def test_factory_ls(self): 71 self.states.put('abcd') 72 self.states.put('xxxx', state=self.states.BAZ) 73 r = self.factory.ls() 74 self.assertEqual(len(r), 0) 75 76 77 if __name__ == '__main__': 78 unittest.main()