Exemplo n.º 1
0
def test_from_tree_is_robust_to_unnecessary_namespace():
    t = symbol('t', 'var * {name: string, amount: int32}')
    expr = t.amount + 1

    tree = to_tree(expr)  # don't use namespace

    assert from_tree(tree, {'t': t}).isidentical(expr)
Exemplo n.º 2
0
def test_from_tree_is_robust_to_unnecessary_namespace():
    t = symbol('t', 'var * {name: string, amount: int32}')
    expr = t.amount + 1

    tree = to_tree(expr)  # don't use namespace

    assert from_tree(tree, {'t': t}).isidentical(expr)
Exemplo n.º 3
0
def test_to_from_tree_namespace():
    t = symbol('t', 'var * {name: string, amount: int32}')
    expr = t.name

    tree = to_tree(expr, names={t: 't'})
    assert tree == {'op': 'Field', 'args': ['t', 'name']}

    new = from_tree(tree, namespace={'t': t})
    assert new.isidentical(expr)
Exemplo n.º 4
0
def test_to_from_tree_namespace():
    t = symbol('t', 'var * {name: string, amount: int32}')
    expr = t.name

    tree = to_tree(expr, names={t: 't'})
    assert tree == {'op': 'Field', 'args': ['t', 'name']}

    new = from_tree(tree, namespace={'t': t})
    assert new.isidentical(expr)
Exemplo n.º 5
0
def test_to_and_from_tree_with_literal():
    data = frozenset([1, 2])
    expr = literal(data)
    as_tree = {
        'args': [
            frozenset({1, 2}),
            datashape.dshape("2 * int64"),
            None,
        ],
        'op': 'Literal',
    }
    assert to_tree(expr) == as_tree

    assert from_tree(as_tree).isidentical(expr)
Exemplo n.º 6
0
def test_to_and_from_tree_with_literal():
    data = frozenset([1, 2])
    expr = literal(data)
    as_tree = {
        'args': [
            frozenset({1, 2}),
            datashape.dshape("2 * int64"),
            None,
        ],
        'op': 'Literal',
    }
    assert to_tree(expr) == as_tree

    assert from_tree(as_tree).isidentical(expr)
Exemplo n.º 7
0
def _compserver(payload):
    dataset = settings.datamanager.all_datasets()
    ns = payload.get('namespace', dict())

    ns[':leaf'] = symbol('leaf', discover(dataset))

    expr = from_tree(payload['expr'], namespace=ns)
    assert len(expr._leaves()) == 1
    leaf = expr._leaves()[0]

    try:
        result = compute(expr, {leaf: dataset})
    except Exception as e:
        logger.exception(e)
        msg = traceback.format_exc()
        raise ServerException(msg, status_code=500)
    return expr, result
Exemplo n.º 8
0
def test_to_from_json():
    t = symbol('t', 'var * {name: string, amount: int}')
    assert from_tree(to_tree(t)).isidentical(t)
    assert from_tree(to_tree(t.amount + 1)).isidentical(t.amount + 1)
Exemplo n.º 9
0
def test_to_from_json():
    t = symbol('t', 'var * {name: string, amount: int}')
    assert from_tree(to_tree(t)).isidentical(t)
    assert from_tree(to_tree(t.amount + 1)).isidentical(t.amount + 1)
Exemplo n.º 10
0
def test_to_from_json():
    t = TableSymbol('t', '{name: string, amount: int}')
    expr = t.amount.sum()

    assert from_tree(to_tree(t)).isidentical(t)