1 #!/usr/bin/env python 2 # Copyright 2013 The Chromium Authors. All rights reserved. 3 # Use of this source code is governed by a BSD-style license that can be 4 # found in the LICENSE file. 5 6 from test_object_store import TestObjectStore 7 import unittest 8 9 class TestObjectStoreTest(unittest.TestCase): 10 def testEmpty(self): 11 store = TestObjectStore('namespace') 12 self.assertEqual(None, store.Get('hi').Get()) 13 self.assertEqual({}, store.GetMulti(['hi', 'lo']).Get()) 14 15 def testNonEmpty(self): 16 store = TestObjectStore('namespace') 17 store.Set('hi', 'bye') 18 self.assertEqual('bye', store.Get('hi').Get()) 19 self.assertEqual({'hi': 'bye'}, store.GetMulti(['hi', 'lo']).Get()) 20 store.Set('hi', 'blah') 21 self.assertEqual('blah', store.Get('hi').Get()) 22 self.assertEqual({'hi': 'blah'}, store.GetMulti(['hi', 'lo']).Get()) 23 store.Del('hi') 24 self.assertEqual(None, store.Get('hi').Get()) 25 self.assertEqual({}, store.GetMulti(['hi', 'lo']).Get()) 26 27 def testCheckAndReset(self): 28 store = TestObjectStore('namespace') 29 store.Set('x', 'y') 30 self.assertTrue(*store.CheckAndReset(set_count=1)) 31 store.Set('x', 'y') 32 store.Set('x', 'y') 33 self.assertTrue(*store.CheckAndReset(set_count=2)) 34 store.Set('x', 'y') 35 store.Set('x', 'y') 36 store.Get('x').Get() 37 store.Get('x').Get() 38 store.Get('x').Get() 39 store.Del('x') 40 self.assertTrue(*store.CheckAndReset(get_count=3, set_count=2, del_count=1)) 41 42 if __name__ == '__main__': 43 unittest.main() 44