Permalink
Browse files

Added TemporalStorage.clear() test cases.

  • Loading branch information...
1 parent 5e7c1f2 commit 37feb9b7776ed07fe30f0b8eb8e83bf74d27cbfb @BasicWolf committed Jan 1, 2013
Showing with 43 additions and 4 deletions.
  1. +43 −4 kaylee/testsuite/storage_tests.py
@@ -74,6 +74,7 @@ def test_remove_and_del(self):
self.assertRaises(KeyError, ts.__getitem__, 't1')
self.assertEqual(len(ts), 0)
+ # add one, remove two
ts.add('t1', node_id, 'r1')
self.assertRaises(KeyError, ts.remove, 't1', NodeID())
self.assertRaises(KeyError, ts.remove, 't2')
@@ -100,27 +101,62 @@ def test_remove_and_del(self):
self.assertRaises(KeyError, ts.__getitem__, tid)
self.assertEqual(len(ts), 0)
+ def test_clear(self):
+ # fill and clear
+ ts = self.cls()
+ self._fill_storage(ts, SOME)
+ self.assertEqual(len(ts), SOME)
+ ts.clear()
+ self.assertEqual(len(ts), 0)
+
+ # double fill and clear
+ ts = self.cls()
+ self._fill_storage(ts, SOME)
+ self._fill_storage(ts, SOME)
+ self.assertEqual(len(ts), SOME)
+ ts.clear()
+ self.assertEqual(len(ts), 0)
+
+ # same ts, fill and clear
+ self._fill_storage(ts, SOME, node_id=NodeID())
+ self.assertEqual(len(ts), SOME)
+ ts.clear()
+ self.assertEqual(len(ts), 0)
+
+ # remove all and clear
+ ts = self.cls()
+ self._fill_storage(ts, SOME, node_id=NodeID())
+ for i in range(0, SOME):
+ ts.remove(_tgen(i))
+ self.assertEqual(len(ts), 0)
+ ts.clear()
+ self.assertEqual(len(ts), 0)
+
def test_count_and_total_count(self):
- # remove many
+ # initial counts
ts = self.cls()
self.assertEqual(len(ts), 0)
self.assertEqual(ts.count, 0)
self.assertEqual(ts.total_count, 0)
+ # fill
self._fill_storage(ts, SOME)
self.assertEqual(len(ts), SOME)
self.assertEqual(ts.count, SOME)
self.assertEqual(ts.total_count, SOME)
+ # double fill
self._fill_storage(ts, SOME)
self._fill_storage(ts, SOME)
self.assertEqual(ts.total_count, 3 * SOME)
+ # remove
ts.remove('t0')
self.assertEqual(len(ts), SOME - 1)
self.assertEqual(ts.count, SOME - 1)
self.assertEqual(ts.total_count, 3 * SOME - 3)
+ # remove with specific node id
nid = NodeID()
ts.add('t1', nid, 'r12')
self.assertEqual(len(ts), SOME - 1)
@@ -132,23 +168,26 @@ def test_count_and_total_count(self):
self.assertEqual(ts.count, SOME - 1)
self.assertEqual(ts.total_count, 3 * SOME - 3)
+ # add one, remove
ts.add('t0', NodeID(), 'r0')
for i in range(0, SOME):
ts.remove(_tgen(i))
self.assertEqual(len(ts), 0)
self.assertEqual(ts.count, 0)
self.assertEqual(ts.total_count, 0)
+ # more double fill
self._fill_storage(ts, MANY)
self._fill_storage(ts, MANY)
self.assertEqual(len(ts), MANY)
self.assertEqual(ts.count, MANY)
self.assertEqual(ts.total_count, 2 * MANY)
- nodes = set(n for n, r in ts.values())
- self.assertEqual(len(nodes), MANY)
-
+ def test_keys():
+ pass
+ def test_values():
+ pass
@staticmethod
def _fill_storage(ts, count, tgen_func=_tgen, rgen_func=_rgen, node_id=None):

0 comments on commit 37feb9b

Please sign in to comment.