示例#1
0
def test_flat_text():
    tracker = Tracker(False, FakeNodeCreator(GenericActivate))

    origin = tracker.root.createchild("task", "origin")

    targets = []
    target1 = origin.createchild("task", "target1")
    targets.append(target1)
    origin.createchild("comment", "ignoreme")
    targets.append(origin.createchild("task", "don't ignore me"))
    origin.createchild("comment", "legitimately ignore me")
    target2 = origin.createchild("task", "target2")
    targets.append(target2)

    query1 = searching.parse_single("task")
    assert query1(origin).list() == targets
    assert repr(query1)

    query2 = searching.parse_single("target1")
    assert query2(origin).list() == [target1]
    assert repr(query2)

    query3 = searching.parse_single("target2")
    assert query3(origin).list() == [target2]
    assert repr(query3)
示例#2
0
def test_parse_filters(monkeypatch):
    def _hook1(queries):
        queries.append(searching.parse_single("comment: derp derp"))
        return queries

    def _hook2(queries):
        queries.append(searching.parse_single("task: some random query"))
        return queries

    monkeypatch.setattr(searching, "parsecreatefilters", [
        _hook1,
        _hook2
    ])

    assert searching.parse("around the world") == searching.Queries(
            searching.parse_single("around the world"),
            searching.parse_single("comment: derp derp"),
            searching.parse_single("task: some random query"),
    )

    assert (searching.parse_create("comment: hoop doop") ==
        searching._Creators(creators=(
            searching.parse_create_single("comment: hoop doop"),
            searching.parse_create_single("comment: derp derp"),
            searching.parse_create_single("task: some random query")
        ))
    )
示例#3
0
def test_id_lookup(makequery):
    tracker = Tracker(False, FakeNodeCreator(GenericActivate))

    origin = tracker.root.createchild("task", "origin", nodeid="orign")
    target1 = origin.createchild("task", "target1", nodeid="abcde")
    target3 = origin.createchild("task", "#abcde")
    ignoreme = origin.createchild("task", "ignoreme")
    ignoreme.createchild("task", "ignore me too")
    peer = tracker.root.createchild("task", "peer")
    target2 = peer.createchild("task", "target2", nodeid="trgt2")
    targetlist = [
        target2.createchild("task") for x in range(10)]

    query1 = makequery("#abcde")
    assert query1(origin).list() == [target1]
    assert query1(target2).list() == [target1]
    assert repr(query1)

    query2 = searching.parse_single("#orign -> task: peer > task: target2")
    assert query2(ignoreme).list() == [target2]
    assert query2(tracker.root).list() == [target2]
    assert repr(query2)

    query3 = makequery("#trgt2>")
    assert query3(ignoreme).list() == targetlist
    assert query3(tracker.root).list() == targetlist
    assert repr(query3)

    query4 = makequery("*: #abcde")
    assert query4(origin).list() == [target3]
    assert repr(query4)

    query5 = makequery("#nonex")
    assert query5(origin).first() is None
    assert repr(query4)
示例#4
0
def test_actions():
    tracker = Tracker(False, FakeNodeCreator(GenericActivate))
    d = tracker.root.createchild("node", "a")\
                    .createchild("node", "b")\
                    .createchild("node", "c")\
                    .createchild("node", "d")

    c = tracker.root.createchild("node", "a")\
                    .createchild("node", "b")\
                    .createchild("node", "c")

    b = tracker.root.createchild("node", "a")\
                    .createchild("node", "b")

    a = tracker.root.createchild("node", "a")

    query = searching.parse_single("node: a > node: b > node: c > node: d")
    assert query.mincreate == 0
    bound = query(tracker.root)
    z = list(bound.actions())
    assert z == [
        searching._NodeResult(d),
        searching._CreateResult(query.segments, 3, c),
        searching._CreateResult(query.segments, 2, b),
        searching._CreateResult(query.segments, 1, a),
    ]
示例#5
0
 def find(self, query, rigid=False):
     from treeoflife import searching
     if rigid:
         query = searching.parse_single(query)
     else:
         query = searching.parse(query)
     return query(self)
示例#6
0
def test_node_with_colon():
    tracker = Tracker(False, FakeNodeCreator(GenericActivate))
    origin = tracker.root.createchild("task", 'origin')
    target = tracker.root.createchild("task", 'target: with colon')

    query = searching.parse_single("-> task: target: with colon")
    assert query(origin).list() == [target]
    assert repr(query)
示例#7
0
def test_prev_peer():
    tracker = Tracker(False, FakeNodeCreator(GenericActivate))

    target1 = tracker.root.createchild("task", "target1")
    tracker.root.createchild("comment", "ignoreme")
    tracker.root.createchild("task", "don't ignore me")
    tracker.root.createchild("comment", "legitimately ignore me")
    target2 = tracker.root.createchild("task", "target2")
    origin = tracker.root.createchild("task", "origin")

    query1 = searching.parse_single("<- target1")
    assert query1(origin).list() == [target1]
    assert repr(query1)

    query2 = searching.parse_single("<- target2")
    assert query2(origin).list() == [target2]
    assert repr(query2)
示例#8
0
def test_query_creatability():
    assert searching.parse_single("x: y").mincreate == 0
    assert searching.parse_single("z").mincreate == 1
    assert searching.parse_single("x: y > z").mincreate == 2
    assert searching.parse_single("x: y > x: y").mincreate == 0
    assert searching.parse_single("z > x: y").mincreate == 1
    assert searching.parse_single("z > z > x: y > z > x: y").mincreate == 4
    assert searching.parse_single("z > x:").mincreate == 2
示例#9
0
def test_pluralities():
    tracker = Tracker(False, FakeNodeCreator(GenericActivate))

    origin = tracker.root.createchild("task", "origin")

    targets = []

    for i in range(10):
        targets.append(tracker.root.createchild("task", "target %d" % i))

    query1 = searching.parse_single("-> * :{first}")
    assert query1(origin).list() == [targets[0]]
    assert repr(query1)

    query1 = searching.parse_single("-> * :{last}")
    assert query1(origin).list() == [targets[-1]]
    assert repr(query1)

    query1 = searching.parse_single("-> * :{many}")
    assert query1(origin).list() == targets
    assert repr(query1)
示例#10
0
    def __init__(self, root):
        self.bylog = ByLog(root, root.log)
        self.query1 = searching.parse_single("> * :{can_activate}")
        self.query2 = searching.parse_single("-> :{can_activate}")
        self.query3 = searching.parse_single("< :{can_activate}")

        self.results = []
        if (datetime.datetime.now() - self.find_last_jump(root)
                > datetime.timedelta(minutes=30)):
            self.results.append(
                JumpResult(self.bylog.next(),
                    actions=["activate"])
            )

        results = self.query1(root.active_node).actions(creates=False)

        for result in results:
            assert result.exists
            result.actions[:] = ["activate"]
            self.results.append(result)

        if self.results:
            return

        results = self.query2(root.active_node).actions(creates=False)

        for result in results:
            assert result.exists
            result.actions[:] = ["finishactivate"]
            self.results.append(result)

        if self.results:
            return

        results = self.query3(root.active_node).actions(creates=False)

        for result in results:
            assert result.exists
            result.actions[:] = ["finishactivate"]
            self.results.append(result)
示例#11
0
def test_tags_filtering():
    class CustomGeneric(GenericActivate):
        def search_tags(self):
            return self.text.split()

    tracker = Tracker(False, FakeNodeCreator(CustomGeneric))

    targets = []
    nontargets = []

    origin1 = tracker.root.createchild("task", "origin")
    targets.append(origin1.createchild("task", "target node"))
    nontargets.append(origin1.createchild("task", "nontarget node"))
    targets.append(origin1.createchild("task", "target node"))
    nontargets.append(origin1.createchild("task", "nontarget node"))

    query1 = searching.parse_single("task :{target}")
    assert query1(origin1).list() == targets
    assert repr(query1)

    query1 = searching.parse_single("task :{nontarget}")
    assert query1(origin1).list() == nontargets
    assert repr(query1)
示例#12
0
def test_parents():
    tracker = Tracker(False, FakeNodeCreator(GenericActivate))

    parent3 = tracker.root.createchild("task", "parent3")
    parent2 = parent3.createchild("task", "parent2")
    parent1 = parent2.createchild("task", "parent1")
    origin1 = parent1.createchild("task", "origin1")

    expected = [
        parent1, parent2, parent3, tracker.root
    ]

    query = searching.parse_single("<")
    assert query(origin1).list() == expected
    assert repr(query)
示例#13
0
    def test_existing_query(self):
        tracker = Tracker(False, FakeNodeCreator(GenericActivate))

        origin = tracker.root.createchild("task", "origin")

        selector = searching.parse_single("task: target")

        creator = searching.parse_create(query=selector)
        creator(origin)

        assert match("\n".join(serialize(origin)), (
            "task#?????: origin\n"
            "    task#?????: target"
        ))
        assert repr(creator)
示例#14
0
def test_queries_structure():
    tracker = Tracker(False, FakeNodeCreator(GenericActivate))

    query = searching.parse_single("> task: 'rigidly defined node'")
    queries = searching.Queries(query)

    origin = tracker.root.createchild("task", "origin")
    target1 = origin.createchild("task", "rigidly defined node")

    assert queries.queries == (query,)

    assert queries(origin).nodes().list() == [target1]
    assert queries(origin).list() == queries(origin).nodes().list()
    # assert list(queries(origin).results)
    # assert list(queries(origin).actions)
    assert queries(origin).first() is target1
    assert queries(origin).first() is queries(origin).one()

    with pytest.raises(searching.NoMatchesError):
        queries(target1).one()
    assert queries(target1).first() is None
示例#15
0
def test_internal__search():
    tracker = Tracker(False, FakeNodeCreator(GenericActivate))
    d = tracker.root.createchild("node1", "a")\
                    .createchild("node1", "b")\
                    .createchild("node1", "c")\
                    .createchild("node1", "d")

    c = tracker.root.createchild("node2", "a")\
                    .createchild("node2", "b")\
                    .createchild("node2", "c")

    b = tracker.root.createchild("node3", "a")\
                    .createchild("node3", "b")

    a = tracker.root.createchild("node4", "a")

    query = searching.parse_single("a > b > c > d")
    bound = query(tracker.root)
    assert list(bound._search(True, False)) == [
        (True, None, d)
    ]

    assert list(bound._search(False, True)) == [
        (False, 3, c),
        (False, 2, b),
        (False, 1, a)
    ]
    assert list(query(a)._search(False, True)) == [
        (False, 0, a)
    ]
    assert list(bound._search(True, True)) == [
        (True, None, d),
        (False, 3, c),
        (False, 2, b),
        (False, 1, a)
    ]
示例#16
0
 def _hook1(queries):
     queries.append(searching.parse_single("comment: derp derp"))
     return queries
示例#17
0
def test_empty_ignore_overflow():
    query = searching.parse_single("task: derp")
    tracker = Tracker(False, FakeNodeCreator(GenericActivate))
    assert not query(tracker.root).ignore_overflow().list()
示例#18
0
def test_no_last():
    query = searching.parse_single("task: derp :{last}")

    tracker = Tracker(False, FakeNodeCreator(GenericActivate))
    assert not query(tracker.root).list()
示例#19
0
def test_solo_create():
    query = searching.parse_single("task: derp")
    tracker = Tracker(False, FakeNodeCreator(GenericActivate))

    lastsegment = query.segments[-1]
    assert lastsegment.can_create
示例#20
0
 def _hook2(queries):
     return [searching.parse_single("herp > task: derp")] + queries
示例#21
0
 def _hook2(queries):
     queries.append(searching.parse_single("task: some random query"))
     return queries
示例#22
0
def test_quoting(querytext, node_type, text):
    q = searching.parse_single(querytext)
    assert q.segments[0].pattern.type == node_type
    assert q.segments[0].pattern.text == text
    assert len(q.segments) == 1