def test_content(self):
        #Content with ContentID
        c = Content(ID((0, 1, 2)), load=Blob("Hello"))
        s = c.serialize()
        c2 = ContentDeserializer(ID).deserialize(s)
        self.assertEqual(c, c2)

        #Content with BlockCellName
        c = Content(BlockCellName("user/block/path/to/file.h"), load=Blob("Bye"))
        s = c.serialize()
        c2 = ContentDeserializer(BlockCellName).deserialize(s)
        self.assertEqual(c, c2)
 def _process_leaves(self, virtual_cell, realizations, biiout):
     '''for a virtual cell, creates the leaves if they don't exist
     @param virtual_cell: the cell that serves as base
     @param realizations: a set to add the leaves BlockCellNames
     @param biiout: biiout
     '''
     block_cell_name = virtual_cell.name
     for leave in virtual_cell.resource_leaves:
         realizations.add(leave)
         try:
             cell = self.block_holder[leave.cell_name].cell
         except KeyError:
             #The leave it is pointing does not exist
             biiout.info('%s virtual realization not existing, creating it' % leave)
             cell = SimpleCell(leave)
             cell.type = virtual_cell.type
             content = Content(leave, Blob(""), created=True)
             content.parser = parser_factory(cell.type, cell.name.cell_name)
             self.block_holder.add_resource(Resource(cell, content))
         cell.container = block_cell_name
Example #3
0
def checkin_block_files(hive_holder, block_name, files, biiout):
    '''
    Params:
        hive_holder: HiveHolder
        block_name: BlockName
        files: {cell_name: content}
        processor_changes: ProcessorChanges
        biiout: biiout
    '''
    block_name = BlockName(block_name)
    types_blobs = obtain_types_blobs(files)  # {cell_name: (TYPE, Content/CellType/None)}
    # FIXME: What happens if merge result is larger than individual files, reject???
    changevalidator.remove_large_cells(types_blobs, biiout)
    try:
        block_holder = hive_holder[block_name]
    except KeyError:
        block_holder = BlockHolder(block_name, [])
        hive_holder.add_holder(block_holder)

    for cell_name, (biitype, blob) in types_blobs.iteritems():
        block_cell_name = block_name + cell_name
        cell = SimpleCell(block_cell_name, biitype)
        try:
            resource = block_holder[cell_name]
        except KeyError:
            content = Content(block_cell_name, load=blob)
        else:
            content = resource.content
            if content is None or blob != content.load:
                content = Content(block_cell_name, load=blob)
            else:
                content.set_blob(blob)

        resource = Resource(cell, content)
        block_holder.add_resource(resource)

    for cell_name, resource in block_holder.resources.items():
        if cell_name not in types_blobs:
            block_holder.delete_resource(cell_name)
 def test_content_similarity(self):
     content = Content(ID((0, 0, 0)), load=None)
     self.assertEquals(content.similarity(content), 1)