コード例 #1
0
ファイル: bag_store.py プロジェクト: nom3ad/obnam
def deserialise_bag(serialised):
    obj = obnamlib.deserialise_object(serialised)
    bag = obnamlib.Bag()
    bag.set_id(obj['bag-id'])
    for blob in obj['blobs']:
        bag.append(blob)
    return bag
コード例 #2
0
 def test_appends_a_blob(self):
     blob = 'foo'
     bag = obnamlib.Bag()
     bag.set_id(1)
     bag.append(blob)
     self.assertEqual(len(bag), 1)
     self.assertEqual(bag.get_bytes(), len(blob))
     self.assertEqual(bag[0], blob)
コード例 #3
0
 def setUp(self):
     self.tempdir = tempfile.mkdtemp()
     self.fs = obnamlib.LocalFS(self.tempdir)
     self.store = obnamlib.BagStore()
     self.store.set_location(self.fs, '.')
     self.bag = obnamlib.Bag()
     bag_id = self.store.reserve_bag_id()
     self.bag.set_id(bag_id)
コード例 #4
0
 def test_appending_returns_object_id_when_bag_id_is_a_string(self):
     bag = obnamlib.Bag()
     bag.set_id('well-known')
     object_id = bag.append('foo')
     self.assertEqual(object_id, obnamlib.make_object_id('well-known', 0))
コード例 #5
0
 def test_appending_returns_object_id(self):
     bag = obnamlib.Bag()
     bag.set_id(1)
     object_id = bag.append('foo')
     self.assertEqual(object_id, obnamlib.make_object_id(1, 0))
コード例 #6
0
 def test_raises_error_if_appending_blob_without_id_being_set(self):
     bag = obnamlib.Bag()
     self.assertRaises(obnamlib.BagIdNotSetError, bag.append, 'blob')
コード例 #7
0
 def test_has_no_bytes_initially(self):
     bag = obnamlib.Bag()
     self.assertEqual(bag.get_bytes(), 0)
コード例 #8
0
 def test_is_empty_initially(self):
     bag = obnamlib.Bag()
     self.assertEqual(len(bag), 0)
コード例 #9
0
 def test_sets_bag_id_to_string(self):
     bag = obnamlib.Bag()
     bag.set_id('well-known')
     self.assertEqual(bag.get_id(), 'well-known')
コード例 #10
0
 def test_sets_bag_id_to_integer(self):
     bag = obnamlib.Bag()
     bag.set_id(123)
     self.assertEqual(bag.get_id(), 123)
コード例 #11
0
 def test_has_no_bag_id_initially(self):
     bag = obnamlib.Bag()
     self.assertEqual(bag.get_id(), None)
コード例 #12
0
 def put_well_known_blob(self, well_known_name, blob):
     bag = obnamlib.Bag()
     bag.set_id(well_known_name)
     bag.append(blob)
     self._bag_store.put_bag(bag)
コード例 #13
0
 def _new_bag(self):
     bag = obnamlib.Bag()
     bag.set_id(self._bag_store.reserve_bag_id())
     return bag