Ejemplo n.º 1
0
def testSimpleReadWrite(nodesLeaves, tempdir):
    nodes, leaves = nodesLeaves
    fhs = FileHashStore(tempdir)

    for leaf in leaves:
        fhs.writeLeaf(leaf)
    for i, leaf in enumerate(leaves):
        assert leaf == fhs.readLeaf(i + 1)

    for node in nodes:
        fhs.writeNode(node)
    for i, node in enumerate(nodes):
        assert node[2] == fhs.readNode(i + 1)

    lvs = fhs.readLeafs(1, len(leaves))
    for i, l in enumerate(lvs):
        assert leaves[i] == l

    nds = fhs.readNodes(1, len(nodes))
    for i, n in enumerate(nds):
        assert nodes[i][2] == n

    # Check that hash store can be closed and re-opened and the contents remain same
    leaf_count = fhs.leafCount
    node_count = fhs.nodeCount
    fhs.close()
    reopened_hash_store = FileHashStore(tempdir)
    assert reopened_hash_store.leafCount == leaf_count
    assert reopened_hash_store.nodeCount == node_count
Ejemplo n.º 2
0
def writtenFhs(tempdir, nodes, leaves):
    fhs = FileHashStore(tempdir)
    for leaf in leaves:
        fhs.writeLeaf(leaf)
    for node in nodes:
        fhs.writeNode(node)
    return fhs
Ejemplo n.º 3
0
def testIncorrectWrites(tempdir):
    fhs = FileHashStore(tempdir, leafSize=50, nodeSize=50)

    with pytest.raises(ValueError):
        fhs.writeLeaf(b"less than 50")
    with pytest.raises(ValueError):
        fhs.writeNode((8, 1, b"also less than 50"))

    with pytest.raises(ValueError):
        fhs.writeLeaf(b"more than 50" + b'1' * 50)
    with pytest.raises(ValueError):
        fhs.writeNode((4, 1, b"also more than 50" + b'1' * 50))
Ejemplo n.º 4
0
def testIncorrectWrites(tempdir):
    fhs = FileHashStore(tempdir, leafSize=50, nodeSize=50)

    with pytest.raises(ValueError):
        fhs.writeLeaf(b"less than 50")
    with pytest.raises(ValueError):
        fhs.writeNode((8, 1, b"also less than 50"))

    with pytest.raises(ValueError):
        fhs.writeLeaf(b"more than 50" + b'1'*50)
    with pytest.raises(ValueError):
        fhs.writeNode((4, 1, b"also more than 50" + b'1'*50))
Ejemplo n.º 5
0
def testSimpleReadWrite(nodesLeaves, tempdir):
    nodes, leaves = nodesLeaves
    fhs = FileHashStore(tempdir)

    for leaf in leaves:
        fhs.writeLeaf(leaf)
    for i, leaf in enumerate(leaves):
        assert leaf == fhs.readLeaf(i + 1)

    for node in nodes:
        fhs.writeNode(node)
    for i, node in enumerate(nodes):
        assert node[2] == fhs.readNode(i + 1)

    lvs = fhs.readLeafs(1, len(leaves))
    for i, l in enumerate(lvs):
        assert leaves[i] == l

    nds = fhs.readNodes(1, len(nodes))
    for i, n in enumerate(nds):
        assert nodes[i][2] == n