def test_dict_round_trip(self): leaf = obnamlib.CowLeaf() leaf.insert('foo', 'bar') some_dict = leaf.as_dict() leaf2 = obnamlib.CowLeaf() leaf2.from_dict(some_dict) some_dict2 = leaf2.as_dict() self.assertNotEqual(id(some_dict), id(some_dict2)) self.assertEqual(some_dict, some_dict2)
def test_inserting_adds_key(self): leaf = obnamlib.CowLeaf() leaf.insert('foo', 'bar') self.assertEqual(leaf.keys(), ['foo'])
def test_lookup_returns_inserted_value(self): key = 'fookey' value = 'barvalue' leaf = obnamlib.CowLeaf() leaf.insert(key, value) self.assertEqual(leaf.lookup(key), value)
def test_inserting_increases_length(self): leaf = obnamlib.CowLeaf() leaf.insert('foo', 'bar') self.assertEqual(len(leaf), 1)
def test_has_no_keys_initially(self): leaf = obnamlib.CowLeaf() self.assertEqual(leaf.keys(), [])
def test_lookup_returns_None_if_key_is_missing(self): leaf = obnamlib.CowLeaf() self.assertEqual(leaf.lookup(42), None)
def test_has_zero_length_initially(self): leaf = obnamlib.CowLeaf() self.assertEqual(len(leaf), 0)
def get_leaf(self, leaf_id): leaf = obnamlib.CowLeaf() leaf.from_dict(self._blob_store.get_blob(leaf_id)) return leaf
def commit(self): fake_leaf = obnamlib.CowLeaf() fake_leaf.insert('leaf_list', self._leaf_list.as_dict()) list_id = self._store.put_leaf(fake_leaf) self._store.flush() return list_id
def _make_split_leaf(self, leaf, sorted_keys): new = obnamlib.CowLeaf() for key in sorted_keys: new.insert(key, leaf.lookup(key)) new_id = self._store.put_leaf(new) self._leaf_list.insert_leaf(sorted_keys[0], sorted_keys[-1], new_id)
def _add_new_leaf(self, key, value): leaf = obnamlib.CowLeaf() leaf.insert(key, value) leaf_id = self._store.put_leaf(leaf) self._leaf_list.insert_leaf(key, key, leaf_id)