示例#1
0
def test_objects_list(patch, tree):
    patch.object(Objects, 'base_expression')
    tree.children = [Tree('value', 'value'), 'token']
    result = Objects().list(tree)
    Objects.base_expression.assert_called_with(Tree('value', 'value'))
    items = [Objects.base_expression()]
    assert result == {'$OBJECT': 'list', 'items': items}
示例#2
0
def test_objects_list(patch, tree):
    patch.object(Objects, "base_expression")
    tree.children = [Tree("value", "value"), "token"]
    result = Objects().list(tree)
    Objects.base_expression.assert_called_with(Tree("value", "value"))
    items = [Objects.base_expression()]
    assert result == {"$OBJECT": "list", "items": items}
示例#3
0
def test_objects_map(patch, tree):
    patch.many(Objects, ['string', 'base_expression'])
    subtree = Tree('key_value', [Tree('string', ['key']), 'value'])
    tree.children = [subtree]
    result = Objects().map(tree)
    Objects.string.assert_called_with(subtree.string)
    Objects.base_expression.assert_called_with('value')
    items = [[Objects.string(), Objects.base_expression()]]
    expected = {'$OBJECT': 'dict', 'items': items}
    assert result == expected
示例#4
0
def test_objects_map(patch, tree):
    patch.many(Objects, ["string", "base_expression"])
    subtree = Tree("key_value", [Tree("string", ["key"]), "value"])
    tree.children = [subtree]
    result = Objects().map(tree)
    Objects.string.assert_called_with(subtree.string)
    Objects.base_expression.assert_called_with("value")
    items = [[Objects.string(), Objects.base_expression()]]
    expected = {"$OBJECT": "dict", "items": items}
    assert result == expected
示例#5
0
def test_objects_objects_key_path(patch, tree):
    """
    Ensures that objects like {x: 0} are compiled
    """
    patch.many(Objects, ['base_expression', 'path'])
    subtree = Tree('key_value', [
        Tree('path', ['string.name']),
        Tree('path', ['value.path']),
    ])
    tree.children = [subtree]
    result = Objects().map(tree)
    assert result['items'] == [[Objects.path(), Objects.base_expression()]]
示例#6
0
def test_objects_objects_key_path(patch, tree):
    """
    Ensures that objects like {x: 0} are compiled
    """
    patch.many(Objects, ["base_expression", "path"])
    subtree = Tree(
        "key_value",
        [
            Tree("path", ["string.name"]),
            Tree("path", ["value.path"]),
        ],
    )
    tree.children = [subtree]
    result = Objects().map(tree)
    assert result["items"] == [[Objects.path(), Objects.base_expression()]]