Ejemplo n.º 1
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")
        ))
    )
Ejemplo n.º 2
0
 def test_other_tag(self):
     creator = searching.parse_create_single(
             "<- task: target :{started}")
     assert not creator.segment.create_is_before
     assert creator.segment.tags == set(["started"])
     assert creator.segment.create_plurality == "first"
     assert repr(creator)
Ejemplo n.º 3
0
    def test_after_match(self):
        creator = searching.parse_create_single("-> task: mid")
        assert creator.segment.create_is_before
        assert creator.segment.create_activate_hack
        assert creator.segment.tags == set()
        assert creator.segment.create_plurality == "first"

        tracker = Tracker(False)

        nodes = []

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

        nodes.append(tracker.root.createchild("task", "finished"))
        nodes[-1].start()
        nodes[-1].finish()
        nodes.append(tracker.root.createchild("task", "finished 2"))
        nodes[-1].start()
        nodes[-1].finish()
        nodes.append(tracker.root.createchild("task", "started 1"))
        nodes[-1].start()
        nodes.append(tracker.root.createchild("task", "untouched"))

        creator(origin)

        results = list(tracker.root.children)

        assert results[-3].node_type == "task"
        assert results[-3].text == "mid"
        assert results[:-3] + results[-2:] == nodes
        assert repr(creator)
Ejemplo n.º 4
0
    def test_last_reversed(self):
        creator = searching.parse_create_single("<- -task: first")
        assert not creator.segment.create_is_before
        assert creator.segment.tags == set()
        assert creator.segment.create_plurality == "first"

        tracker = Tracker(False)

        nodes = []

        nodes.append(tracker.root.createchild("task", "finished"))
        nodes[-1].start()
        nodes[-1].finish()
        nodes.append(tracker.root.createchild("task", "finished 2"))
        nodes[-1].start()
        nodes[-1].finish()
        nodes.append(tracker.root.createchild("task", "started"))
        nodes[-1].start()
        nodes.append(tracker.root.createchild("task", "untouched"))
        nodes.append(tracker.root.createchild("task", "untouched 2"))

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

        creator(origin)

        results = list(tracker.root.children)

        assert results[-2].node_type == "task"
        assert results[-2].text == "first"
        assert results[:-2] + [origin] == nodes
        assert repr(creator)
Ejemplo n.º 5
0
    def test_create_invalid_day(self):
        creator = searching.parse_create_single("day: September 5, 2020")
        tracker = Tracker(False)

        with pytest.raises(LoadError):
            creator(tracker.root)

        assert tracker.root.find("day").first() is None
Ejemplo n.º 6
0
def test_create_errors(monkeypatch):
    with pytest.raises(searching.CantCreateError) as e:
        searching.parse_create("asdfsdgsdg")
    a = str(e).split("\n")
    assert len(a) == 1
    assert "full node" in a[0]

    with pytest.raises(searching.CantCreateError):
        searching.parse_create_single("sgdfgdf")

    with pytest.raises(searching.CantCreateError):
        searching.parse_create_single("< task: derp")

    with pytest.raises(searching.CantCreateError):
        searching.parse_create_single("*")

    def _hook3(queries):
        return queries * 2
    monkeypatch.setattr(searching, "parsecreatefilters", [
        _hook3
    ])

    with pytest.raises(searching.CantCreateError) as e:
        searching.parse_create("asdfsdgsdg")
    a = str(e.value).split("\n")
    assert len(a) >= 2
    assert "full node" in a[-1]
    assert "full node" in a[-2]
Ejemplo n.º 7
0
 def test_cant_create_with_plurality(self):
     with pytest.raises(searching.CantCreateError):
         searching.parse_create_single("task: test :{first}")
     with pytest.raises(searching.CantCreateError):
         searching.parse_create_single("task: test :{last}")
     with pytest.raises(searching.CantCreateError):
         searching.parse_create_single("task: test :{many}")