Example #1
0
def test_updater_handle_inv_tables_outdated(
    filter_func: SDFilterFunc,
    expected_retentions: Dict,
) -> None:
    _previous_tree, inv_tree = _make_trees({}, {})

    fst_inv_node = inv_tree.get_node(("path-to", "node"))
    assert isinstance(fst_inv_node, StructuredDataNode)

    updater = TableUpdater(
        RetentionInfo(
            filter_func,
            RetentionIntervals(1, 2, 3),
        ),
        fst_inv_node,
        StructuredDataNode(),
    )
    result = updater.filter_and_merge(1000)
    if expected_retentions:
        assert result.save_tree
        assert result.reason
    else:
        assert not result.save_tree
        assert not result.reason

    inv_node = inv_tree.get_node(("path-to", "node"))
    assert inv_node is not None
    assert inv_node.table.retentions == expected_retentions
Example #2
0
def test_updater_merge_tables_outdated(
    filter_func: SDFilterFunc,
    expected_retentions: Dict,
) -> None:
    previous_tree, inv_tree = _make_trees(
        {},
        {
            ("Ident 1",): {"old": (1, 2, 3), "keys": (1, 2, 3)},
            ("Ident 2",): {"old": (1, 2, 3), "keys": (1, 2, 3)},
        },
    )

    previous_node = previous_tree.get_node(("path-to", "node"))
    assert previous_node is not None

    inv_node = inv_tree.get_node(("path-to", "node"))
    assert inv_node is not None

    updater = TableUpdater(
        RetentionInfo(
            filter_func,
            RetentionIntervals(4, 5, 6),
        ),
        inv_node,
        previous_node,
    )
    result = updater.filter_and_merge(1000)
    if expected_retentions:
        assert result.save_tree
        assert result.reason
    else:
        assert not result.save_tree
        assert not result.reason

    assert inv_node.table.retentions == expected_retentions
Example #3
0
def test_updater_merge_previous_tables_outdated(filter_func: SDFilterFunc) -> None:
    previous_tree, _inv_tree = _make_trees(
        {},
        {
            ("Ident 1",): {"old": (1, 2, 3)},
            ("Ident 2",): {"old": (1, 2, 3)},
        },
    )
    inv_tree = StructuredDataNode()

    previous_node = previous_tree.get_node(("path-to", "node"))
    assert isinstance(previous_node, StructuredDataNode)

    updater = TableUpdater(
        RetentionInfo(
            filter_func,
            RetentionIntervals(-1, -2, -3),
        ),
        inv_tree.setdefault_node(("path-to", "node")),
        previous_node,
    )
    result = updater.filter_and_merge(1000)
    assert not result.save_tree
    assert not result.reason

    inv_node = inv_tree.get_node(("path-to", "node"))
    assert inv_node is not None
    assert inv_node.table.retentions == {}
def test_updater_handle_inv_tables_outdated(
    filter_func,
    path,
    expected_retentions,
):
    _previous_tree, inv_tree = _make_trees({}, {})

    updater = TableUpdater(
        RetentionInfo(
            filter_func,
            RetentionIntervals(1, 2, 3),
        ),
        inv_tree.get_node(path),
        StructuredDataNode(),
    )
    result = updater.filter_and_merge(1000)
    if expected_retentions:
        assert result.save_tree
        assert result.reason
    else:
        assert not result.save_tree
        assert not result.reason

    inv_node = inv_tree.get_node(["path-to", "node"])
    assert inv_node is not None
    assert inv_node.table.retentions == expected_retentions
Example #5
0
def test_updater_merge_previous_attributes(
    filter_func: SDFilterFunc,
    expected_retentions: Dict,
):
    previous_tree, _inv_tree = _make_trees({"old": (1, 2, 3)}, {})
    inv_tree = StructuredDataNode()

    previous_node = previous_tree.get_node(("path-to", "node"))
    assert isinstance(previous_node, StructuredDataNode)

    updater = AttributesUpdater(
        RetentionInfo(
            filter_func,
            RetentionIntervals(-1, -2, -3),
        ),
        inv_tree.setdefault_node(("path-to", "node")),
        previous_node,
    )
    result = updater.filter_and_merge(-1)
    if expected_retentions:
        assert result.save_tree
        assert result.reason
    else:
        assert not result.save_tree
        assert not result.reason

    inv_node = inv_tree.get_node(("path-to", "node"))
    assert inv_node is not None
    assert inv_node.attributes.retentions == expected_retentions

    if expected_retentions:
        assert "old" in inv_node.attributes.pairs
def test_updater_merge_attributes_outdated(
    filter_func,
    expected_retentions,
):
    previous_tree, inv_tree = _make_trees(
        {
            "old": (1, 2, 3),
            "keys": (1, 2, 3),
        },
        {},
    )

    previous_node = previous_tree.get_node(["path-to", "node"])
    assert previous_node is not None

    inv_node = inv_tree.get_node(["path-to", "node"])
    assert inv_node is not None

    updater = AttributesUpdater(
        RetentionInfo(
            filter_func,
            RetentionIntervals(4, 5, 6),
        ),
        inv_node,
        previous_node,
    )
    result = updater.filter_and_merge(1000)
    if expected_retentions:
        assert result.save_tree
        assert result.reason
    else:
        assert not result.save_tree
        assert not result.reason

    assert inv_node.attributes.retentions == expected_retentions
Example #7
0
def test_updater_null_obj_tables_outdated() -> None:
    inv_tree = StructuredDataNode()
    updater = TableUpdater(
        RetentionInfo(
            lambda key: True,
            RetentionIntervals(1, 2, 3),
        ),
        inv_tree,
        StructuredDataNode(),
    )
    result = updater.filter_and_merge(1000)
    assert not result.save_tree
    assert not result.reason

    assert inv_tree.get_node(("path-to", "node")) is None
def test_updater_null_obj_attributes():
    inv_tree = StructuredDataNode()
    updater = AttributesUpdater(
        RetentionInfo(
            lambda key: True,
            RetentionIntervals(1, 2, 3),
        ),
        inv_tree,
        StructuredDataNode(),
    )
    result = updater.filter_and_merge(-1)
    assert not result.save_tree
    assert not result.reason

    assert inv_tree.get_node(["path-to", "node"]) is None
def test_updater_merge_tables(filter_func, expected_retentions):
    previous_tree, inv_tree = _make_trees(
        {},
        {
            ("Ident 1", ): {
                "old": (1, 2, 3),
                "keys": (1, 2, 3),
            },
            ("Ident 2", ): {
                "old": (1, 2, 3),
                "keys": (1, 2, 3),
            },
        },
    )

    previous_node = previous_tree.get_node(["path-to", "node"])
    assert previous_node is not None

    inv_node = inv_tree.get_node(["path-to", "node"])
    assert inv_node is not None

    updater = TableUpdater(
        RetentionInfo(
            filter_func,
            RetentionIntervals(4, 5, 6),
        ),
        inv_node,
        previous_node,
    )
    result = updater.filter_and_merge(-1)
    if expected_retentions:
        assert result.save_tree
        assert result.reason
    else:
        assert not result.save_tree
        assert not result.reason

    assert inv_node.table.retentions == expected_retentions

    if expected_retentions:
        for row in inv_node.table.rows:
            assert "old" in row
            assert row.get("keys").startswith("New Keys")
def test_updater_merge_previous_attributes_outdated(filter_func):
    previous_tree, _inv_tree = _make_trees({"old": (1, 2, 3)}, {})
    inv_tree = StructuredDataNode()

    updater = AttributesUpdater(
        RetentionInfo(
            filter_func,
            RetentionIntervals(-1, -2, -3),
        ),
        inv_tree.setdefault_node(["path-to", "node"]),
        previous_tree.get_node(["path-to", "node"]),
    )
    result = updater.filter_and_merge(1000)
    assert not result.save_tree
    assert not result.reason

    inv_node = inv_tree.get_node(["path-to", "node"])
    assert inv_node is not None
    assert inv_node.attributes.retentions == {}
def test_updater_merge_previous_tables(
    filter_func,
    expected_retentions,
):
    previous_tree, _inv_tree = _make_trees(
        {},
        {
            ("Ident 1", ): {
                "old": (1, 2, 3)
            },
            ("Ident 2", ): {
                "old": RetentionIntervals(1, 2, 3)
            },
        },
    )
    inv_tree = StructuredDataNode()

    updater = TableUpdater(
        RetentionInfo(
            filter_func,
            RetentionIntervals(-1, -2, -3),
        ),
        inv_tree.setdefault_node(["path-to", "node"]),
        previous_tree.get_node(["path-to", "node"]),
    )
    result = updater.filter_and_merge(-1)
    if expected_retentions:
        assert result.save_tree
        assert result.reason
    else:
        assert not result.save_tree
        assert not result.reason

    inv_node = inv_tree.get_node(["path-to", "node"])
    assert inv_node is not None
    assert inv_node.table.retentions == expected_retentions

    if expected_retentions:
        for row in inv_node.table.rows:
            assert "old" in row
Example #12
0
def test_updater_merge_attributes(
    filter_func: SDFilterFunc,
    expected_retentions: Dict,
) -> None:
    previous_tree, inv_tree = _make_trees(
        {
            "old": (1, 2, 3),
            "keys": (1, 2, 3),
        },
        {},
    )

    previous_node = previous_tree.get_node(("path-to", "node"))
    assert previous_node is not None

    inv_node = inv_tree.get_node(("path-to", "node"))
    assert inv_node is not None

    updater = AttributesUpdater(
        RetentionInfo(
            filter_func,
            RetentionIntervals(4, 5, 6),
        ),
        inv_node,
        previous_node,
    )
    result = updater.filter_and_merge(-1)
    if expected_retentions:
        assert result.save_tree
        assert result.reason
    else:
        assert not result.save_tree
        assert not result.reason

    assert inv_node.attributes.retentions == expected_retentions

    if expected_retentions:
        assert "old" in inv_node.attributes.pairs
        assert inv_node.attributes.pairs.get("keys") == "New Keys"