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
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)
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)
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))
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))
def test_raises_error_if_appending_blob_without_id_being_set(self): bag = obnamlib.Bag() self.assertRaises(obnamlib.BagIdNotSetError, bag.append, 'blob')
def test_has_no_bytes_initially(self): bag = obnamlib.Bag() self.assertEqual(bag.get_bytes(), 0)
def test_is_empty_initially(self): bag = obnamlib.Bag() self.assertEqual(len(bag), 0)
def test_sets_bag_id_to_string(self): bag = obnamlib.Bag() bag.set_id('well-known') self.assertEqual(bag.get_id(), 'well-known')
def test_sets_bag_id_to_integer(self): bag = obnamlib.Bag() bag.set_id(123) self.assertEqual(bag.get_id(), 123)
def test_has_no_bag_id_initially(self): bag = obnamlib.Bag() self.assertEqual(bag.get_id(), None)
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)
def _new_bag(self): bag = obnamlib.Bag() bag.set_id(self._bag_store.reserve_bag_id()) return bag