Example #1
0
def test_has_key_in_conjunction_finds_node(sample_traced_object):
    obj = treehorn.GoDown(condition=treehorn.HasKey("c1") & treehorn.HasKey("e"), label='sample')
    result = list(obj(sample_traced_object))
    assert result[0] == treehorn.splitter(
            {'sample': {"c1": "d1", "some_list": [10, 20, 40], "e": "whatever"}}
    )
    assert len(result) == 1
Example #2
0
def full_relation():
    has_email = treehorn.GoDown(condition=treehorn.HasKey('email'))
    has_city = treehorn.GoDown(condition=treehorn.HasKey('city'))
    has_email + 'email'
    has_city + 'city'
    sample_relation = treehorn.Relation('sample')
    sample_relation == (has_email + 'email')['email'] > (has_city + 'city')['city']
    return sample_relation
Example #3
0
def test_has_key_in_disjunction_negation_finds_node(sample_traced_object):
    obj = treehorn.GoDown(
        condition=treehorn.HasKey("c1") & (~treehorn.HasKey("nonexistent")), label='sample'
    )
    result = list(obj(sample_traced_object))
    # result = list(obj._generator)
    assert result[0] == treehorn.splitter(
            {'sample': {"c1": "d1", "some_list": [10, 20, 40], "e": "whatever"}}
    )
    assert len(result) == 1
Example #4
0
def p_condition(p):
    """condition : LPAREN condition AND condition RPAREN
                 | LPAREN condition OR condition RPAREN
                 | NOT condition
                 | TOP
                 | HAS KEY LABEL
    """
    if len(p) == 2 and p[1] == "TOP":
        p[0] = treehorn.IsRoot()
    elif len(p) == 6 and p[3] == "AND":
        p[0] = p[2] & p[4]
    elif len(p) == 6 and p[3] == "OR":
        p[0] = p[2] | p[4]
    elif len(p) == 3 and p[1] == "NOT":
        p[0] = ~p[2]
    elif len(p) == 4 and p[1] == "HAS" and p[2] == "KEY":
        p[0] = treehorn.HasKey(key=p[3])
    else:
        raise Exception("This should not happen.")
Example #5
0
def city_condition():
    has_city_key = treehorn.GoDown(condition=treehorn.HasKey('city'))
    has_city_key + 'city'
    return has_city_key
Example #6
0
def email_condition():
    has_email_key = treehorn.GoDown(condition=treehorn.HasKey('email'))
    return has_email_key
Example #7
0
def test_has_key_correctly_finds_nothing(sample_traced_object):
    obj = treehorn.GoDown(condition=treehorn.HasKey("nonexistent"))
    result = list(obj(sample_traced_object))
    assert len(result) == 0
Example #8
0
def test_traversal_creates_generator(sample_traced_object):
    obj = treehorn.GoDown(condition=treehorn.HasKey("a1"), label='sample')
    assert obj(sample_traced_object) is not None
Example #9
0
def test_instantiate_condition():
    obj = treehorn.HasKey("key")
    assert isinstance(obj, (treehorn.HasKey,))
Example #10
0
def test_and(sample_traced_object):
    obj = treehorn.GoDown(condition=treehorn.HasKey("c1") & treehorn.HasKey("e"), label='sample')
    result = list(obj(sample_traced_object))
    assert len(result) == 1