Exemplo n.º 1
0
def test_removing_item_from_list_serializes_sensibly():
    # Test with only whitespace in between items
    tree: ContainerNode = lkml.parse("name: [a, b, c]")
    node: ListNode = tree.container.items[0]
    assert str(node) == "name: [a, b, c]"

    new_items = tuple(item for item in node.items if item.value != "b")
    node = replace(node, items=new_items)
    assert str(node) == "name: [a, c]"

    node = replace(node, items=tuple())
    assert str(node) == "name: []"

    # Test with leading and trailing spaces
    tree: ContainerNode = lkml.parse("name: [ a, b, c ]")
    node: ListNode = tree.container.items[0]
    assert str(node) == "name: [ a, b, c ]"

    new_items = tuple(item for item in node.items if item.value != "b")
    node = replace(node, items=new_items)
    assert str(node) == "name: [ a, c ]"

    node = replace(node, items=tuple())
    assert str(node) == "name: []"

    # Test with items on new lines with trailing newline
    tree: DocumentNode = lkml.parse("name: [\n  a,\n  b,\n  c\n]")
    node: ListNode = tree.container.items[0]
    assert str(node) == "name: [\n  a,\n  b,\n  c\n]"

    new_items = tuple(item for item in node.items if item.value != "b")
    node = replace(node, items=new_items)
    assert str(node) == "name: [\n  a,\n  c\n]"

    node = replace(node, items=tuple())
    assert str(node) == "name: []"
Exemplo n.º 2
0
def test_round_trip_should_work(lookml):
    # Load the LookML from file, parsing into a tree
    tree = lkml.parse(lookml)

    # Verify it hasn't changed once converted back to string
    assert str(tree) == lookml

    # Convert that parsed tree into a lossy dictionary
    visitor = DictVisitor()
    tree_as_dict = visitor.visit(tree)

    # Parse the dictionary into a new tree
    parser = DictParser()
    new_tree = parser.parse(tree_as_dict)

    # Verify that the string form of the tree parsed from a dictionary can be re-parsed
    lkml.load(str(new_tree))
Exemplo n.º 3
0
def load(filename):
    """Helper method to load a LookML file from tests/resources and parse it."""
    path = Path(__file__).parent / "resources" / filename
    with path.open() as file:
        text = file.read()
    return lkml.parse(text)