Example #1
0
 def test_skeleton_day_active(self, setdt):
     setdt(2013, 1, 30, 12)
     tracker = Tracker()
     tracker.deserialize({"life":
         "days\n"
         "    day#bcdef: today\n"
         "        @started: September 23, 2012 11:00 AM\n"
         "        _genactive#cdefg: something\n"
         "            @active\n"
         "    sleep#defgh: today\n"
         "todo bucket#ghijk\n"
         "fitness log#hijkl"
     })
     today = tracker.root.find("days > day: today").one()
     tracker.root.active_node.started = None
     assert match(serialize_to_str(tracker.root), (
         "days#00001\n"
         "    day#bcdef: {0}\n"
         "        @started: September 23, 2012 11:00:00 AM\n"
         "        _genactive#cdefg: something\n"
         "            @active\n"
         "    sleep#defgh: {0}\n"
         "todo bucket#ghijk\n"
         "fitness log#hijkl\n"
     ).format(today.text))
     assert set(tracker.root.ids) == {
             "00001", "bcdef", "cdefg", "defgh", "ghijk", "hijkl", "00000"}
Example #2
0
def test_searchhooks(setdt, monkeypatch):
    monkeypatch.setattr(searching, "parsecreatefilters", [
        _parsehook_dayparse,
        _parsehook_dayabs
    ])
    setdt(2014, 2, 19, 12)
    tracker = Tracker(skeleton=False)

    tracker.deserialize({"life":
        "task: something\n"
        "days\n"
        "    day: today\n"
        "    day: tomorrow\n"
        "    day: September 20, 2014\n"
    })

    something = tracker.root.find("something").one()
    assert something.find("today").one().date == date(2014, 2, 19)
    assert something.find("tomorrow").one().date == date(2014, 2, 20)
    assert something.find("sept 20, 2014").one().date == date(2014, 9, 20)
    assert not something.find("invalid date sept 20, 1995").first()

    # subject to change
    assert not something.find("sept 21, 2014").first()

    assert (searching.parse("day: today")
            == searching.Queries(searching.parse("today").queries[0]))

    setdt(2014, 2, 20, 12)
    assert something.find("today").one().date == date(2014, 2, 20)
Example #3
0
    def test_load_basic(self, tmpdir):
        tracker_obj = Tracker(nodecreator=FakeNodeCreator(),
                skeleton=False)
        f = tmpdir.join('life')
        with f.open("wb") as w:
            w.write((
                "firstchild: \u2028args\n"
                "    secondchild: \u2028other args\n"
                "        @option: \u2028data\n"
                "        thirdchild: \u2028herp derp\n"
                "    fourthchild: \u2028ark dark\n"
            ).encode("utf-8"))
        tracker_obj.load(str(tmpdir))

        root = tracker_obj.root
        root_child0 = root.children.next_neighbor
        assert root_child0.id in root.ids
        assert len(root_child0.id) == 5
        assert root_child0.text == "\u2028args"
        assert root_child0.node_type == "firstchild"

        root_child0_child0 = root_child0.children.next_neighbor
        assert root_child0_child0.id in root.ids
        assert len(root_child0_child0.id) == 5
        assert root_child0_child0.text == "\u2028other args"
        assert root_child0_child0.node_type == "secondchild"
        assert root_child0_child0.metadata["option"] == "\u2028data"

        root_child0_child0_child0 = root_child0_child0.children.next_neighbor
        assert root_child0_child0_child0.text == "\u2028herp derp"
        assert root_child0_child0_child0.node_type == "thirdchild"

        root_child0_child1 = root_child0_child0.next_neighbor
        assert root_child0_child1.text == "\u2028ark dark"
        assert root_child0_child1.node_type == "fourthchild"
Example #4
0
    def test_iter_parents(self):
        tracker = Tracker(skeleton=False)

        input_str = (
            "_genactive: 0\n"
            "    _genactive: 1\n"
            "        _genactive: 2\n"
            "            _genactive: 3\n"
            "                @active"
        )

        tracker.deserialize({"life": input_str})

        expected_pairs = [
            ("_genactive", "3"),
            ("_genactive", "2"),
            ("_genactive", "1"),
            ("_genactive", "0"),
            ("life", None)
        ]

        for expected, node in izip_longest(expected_pairs,
                tracker.root.active_node.iter_parents()):
            node_type, text = expected
            assert node_type == node.node_type
            assert text == node.text
Example #5
0
def test_activate_deactivate(monkeypatch, setdt):
    setdt(2012, 10, 24)
    tracker = Tracker(nodecreator=FakeNodeCreator(tasks.Task),
            skeleton=False)

    tracker.deserialize({"life":
        "task: \xfc1\n"
        "    @active\n"
        "task: \xfc2\n"
        "task: \xfc3\n"
    })

    setdt(2012, 10, 24, 0, 5)
    navigation._cmd("done", tracker.root)
    navigation._cmd("done", tracker.root)

    assert match(tracker.serialize()["life"], (
        "task#?????: \xfc1\n"
        "    @finished: 5m after October 24, 2012 12:00:00 AM\n"
        "task#?????: \xfc2\n"
        "    @finished: 0s after October 24, 2012 12:05:00 AM\n"
        "task#?????: \xfc3\n"
        "    @started: October 24, 2012 12:05:00 AM\n"
        "    @active\n"
    ))
Example #6
0
def test_task():
    tracker = Tracker(nodecreator=FakeNodeCreator(tasks.Task),
            skeleton=False)

    tracker.deserialize({"life":
        "task: \xfca task\n"
        "    @started: June 7, 2010 7:00 AM"
    })
Example #7
0
 def test_too_indented(self):
     tracker = Tracker(skeleton=False,
             nodecreator=FakeNodeCreator(GenericActivate))
     with pytest.raises(exceptions.LoadError):
         tracker.deserialize({"life":
             "herp\n"
             "    derp\n"
             "            donk\n"
         })
Example #8
0
 def test_load_continued_text(self):
     tracker = Tracker(skeleton=False)
     lines = (
         "_gennode: derp\n"
         "    - herp\n"
         "    - derp\n"
     )
     tracker.deserialize({"life": lines})
     assert tracker.root.children.next_neighbor.text == "derp\nherp\nderp"
Example #9
0
    def test_activation_no_time(self):
        tracker = Tracker(skeleton=False)

        tracker.deserialize({"life":
            "days\n"
            "    day: today\n"
            "        @active\n"
        })

        tracker.root.activate_next()
Example #10
0
def test_active_option():
    tracker = Tracker(nodecreator=FakeNodeCreator(tasks.Task),
            skeleton=False)

    tracker.deserialize({"life":
        "task: \xfca task\n"
        "    @active"
    })

    assert tracker.root.active_node.text == "\xfca task"
Example #11
0
    def test_load_bad_order(self):
        tracker_obj = Tracker(nodecreator=FakeNodeCreator(),
                skeleton=False)

        lines = (
            "firstchild: args\n"
            "    secondchild: other args\n"
            "    @option: this won't work here\n"
        )
        with pytest.raises(exceptions.LoadError):
            tracker_obj.deserialize({"life": lines})
Example #12
0
def test_duplicate_day(setdt):
    setdt(2014, 3, 19, 19, 40)

    tracker = Tracker(skeleton=False)
    tracker.deserialize({"life":
        "days\n"
        "    day: today\n"
    })

    n = tracker.root.find("days").one()
    with pytest.raises(LoadError):
        n.createchild("day", "today")
Example #13
0
    def test_roottype(self):
        class SubRootNode(TreeRootNode):

            target_variable = "present"

        tracker = Tracker(skeleton=False, roottype=SubRootNode)
        assert tracker.roottype is SubRootNode
        assert type(tracker.root) is SubRootNode

        tracker.deserialize({"life": ""})

        assert type(tracker.root) is SubRootNode
Example #14
0
def test_out_of_order(setdt):
    tracker = Tracker(skeleton=False)
    days_node = Days("days", None, tracker.root)
    tracker.root.addchild(days_node)

    setdt(2013, 12, 29, 12)

    days_node.createchild("day", "December 19, 2012")
    days_node.addchild(GenericActivate("archived", "19 a"))
    days_node.addchild(GenericActivate("archived", "19 b"))

    ignoreme = days_node.createchild("day", "December 21, 2012")
    days_node.addchild(GenericActivate("archived", "21 a"))
    days_node.addchild(GenericActivate("archived", "21 b"))

    days_node.createchild("day", "December 23, 2012", before=ignoreme)
    days_node.addchild(GenericActivate("archived", "23 a"))
    days_node.addchild(GenericActivate("archived", "23 b"))

    days_node.createchild("day", "December 22, 2012")
    days_node.addchild(GenericActivate("archived", "22 out of order a"))
    days_node.addchild(GenericActivate("archived", "22 out of order b"))

    days_node.createchild("day", "December 20, 2012")
    days_node.addchild(GenericActivate("archived", "20 out of order a"))
    days_node.addchild(GenericActivate("archived", "20 out of order b"))

    result = tracker.serialize()["life"]
    assert match(result, (
        "days#?????\n"
        "    day#?????: December 19, 2012 (Wednesday, *)\n"
        "    archived#?????: 19 a\n"
        "    archived#?????: 19 b\n"
        "    day#?????: December 20, 2012 (Thursday, *)\n"
        "    day#?????: December 21, 2012 (Friday, *)\n"
        "    archived#?????: 21 a\n"
        "    archived#?????: 21 b\n"

        # December 22 was moved back to before 23, leaving
        # its archived nodes behind
        "    day#?????: December 22, 2012 (Saturday, *)\n"
        "    day#?????: December 23, 2012 (Sunday, *)\n"
        "    archived#?????: 23 a\n"
        "    archived#?????: 23 b\n"

        "    archived#?????: 22 out of order a\n"
        "    archived#?????: 22 out of order b\n"
        "    archived#?????: 20 out of order a\n"
        "    archived#?????: 20 out of order b\n"
    ))
Example #15
0
    def test_day_creation(self, setdt, hour):
        setdt(2013, 1, 30, hour)
        tracker = Tracker(skeleton=False)

        tracker.deserialize({"life":
            "days\n"
            "    day: today\n"
            "        @active\n"
        })

        days_node = tracker.root.children.next_neighbor
        node = days_node.find('sleep: today').one()
        assert node
        assert node.prev_neighbor.node_type == "day"
Example #16
0
def test_searchhooks_mincreate(setdt, monkeypatch):
    monkeypatch.setattr(searching, "parsecreatefilters", [
        _parsehook_dayparse,
        _parsehook_dayabs
    ])
    setdt(2014, 2, 19, 12)
    tracker = Tracker(skeleton=False)

    tracker.deserialize({"life":
        "task: something\n"
        "days\n"
        "    day: today\n"
    })

    query = searching.parse("today > does not exist, cannot create")
    assert query(tracker.root).actions().list() is not None
Example #17
0
 def test_skeleton_load_integration(self, setdt):
     setdt(2013, 1, 30, 12)
     tracker = Tracker()
     tracker.deserialize({"life":
         "todo bucket\n"
         "fitness log"
     })
     assert tracker.root.active_node is tracker.root
     assert match(serialize_to_str(tracker.root), (
         "todo bucket#?????\n"
         "fitness log#?????\n"
     ))
     assert len(tracker.root.ids) == 3
     assert tracker.root.id == "00000"
     assert "00000" in tracker.root.ids
     assert tracker.root.ids["00000"] is tracker.root
     for depth, node in tracker.root.iter_flat_children():
         assert node.id in tracker.root.ids
         assert tracker.root.ids[node.id] is node
Example #18
0
def test_faroff_activate(setdt):
    setdt(2014, 3, 19, 20, 17)

    tracker = Tracker(skeleton=False)
    tracker.deserialize({"life":
        "days\n"
        "    day: today\n"
        "        @active\n"
        "    day: March 25, 2014\n"
    })

    navigation._cmd("create", tracker.root, "March 25, 2014 > task: something")

    navigation._cmd("activate", tracker.root, "March 25, 2014")

    with pytest.raises(searching.NoMatchesError):
        navigation._cmd("activate", tracker.root,
                "March 25, 2014 > task: something")

    assert tracker.root.active_node is tracker.root.find("today").one()
Example #19
0
    def test_unhandled_load_error(self):
        class ExcOnOptionNode(GenericNode):
            def setoption(self, option, value):
                raise Exception("test exception")

        tracker = Tracker(skeleton=False,
                nodecreator=FakeNodeCreator(ExcOnOptionNode))
        input_str = (
            "node1: node1\n"
            "node2: node2\n"
            "node3: node3\n"
            "    @someoption: boom\n"
        )
        try:
            tracker.deserialize({"life": input_str})
        except exceptions.LoadError as e:
            result = str(e)
            assert "At line 4: UNHANDLED ERROR" in result
            assert "Exception: test exception" in result
        else:  # pragma: no cover
            assert False
Example #20
0
 def test_empty_line(self):
     tracker = Tracker(skeleton=False)
     tracker.deserialize({"life":
             "\n"
             "task#12345: whatever\n"
             "   \n"
             "    task#abcde: whatever again\n"
             "\n"
             "    task#hijkl: some other thing\n"
             "\n"
             "\n"
     })
     assert tracker.serialize()["life"] == (
             "\n"
             "task#12345: whatever\n"
             "    \n"
             "    task#abcde: whatever again\n"
             "        \n"
             "    task#hijkl: some other thing\n"
             "        \n"
             "        \n"
     )
Example #21
0
    def test_save_basic(self, tmpdir):
        tracker = Tracker(nodecreator=FakeNodeCreator(),
                skeleton=False)

        node1 = GenericNode("node1", "\u2665node1_text", tracker.root)
        tracker.root.addchild(node1)
        node2 = GenericNode("node2", "\u2665node2_text", tracker.root)
        tracker.root.addchild(node2)
        node3 = GenericNode("node3", None, tracker.root)
        tracker.root.addchild(node3)

        node1_1 = GenericNode("node1_1", "\u2665node1_1_text", node1)
        node1_1.setoption("herp", "\u2665derp")
        node1.addchild(node1_1)

        node1_2 = GenericNode("node1_2", "\u2665node1_2_text", node1)
        node1_2.continue_text("\u2665herk derk")
        node1.addchild(node1_2)

        node2_1 = GenericNode("node2_1", "\u2665node2_1_text", node2)
        node2_1.setoption("hark", "\u2665dark")
        node2_1.continue_text('\u2665honk donk')
        node2.addchild(node2_1)

        f = tmpdir.join("life")
        tracker.save(str(tmpdir))
        assert match(f.read("rb"), (
            "node1#?????: \u2665node1_text\n"
            "    node1_1#?????: \u2665node1_1_text\n"
            "        @herp: \u2665derp\n"
            "    node1_2#?????: \u2665node1_2_text\n"
            "        - \u2665herk derk\n"
            "node2#?????: \u2665node2_text\n"
            "    node2_1#?????: \u2665node2_1_text\n"
            "        - \u2665honk donk\n"
            "        @hark: \u2665dark\n"
            "node3#?????\n"
        ).encode("utf-8"))
Example #22
0
def main(filename):
    tracker = Tracker()
    try:
        reader = open(filename, "r")
    except IOError:
        pass
    else:
        tracker.load(reader)

    commandline = CommandLineInterface(tracker)

    while True:
        try:
            line = raw_input(commandline.prompt()).strip()

            commandline.command(None, line)
        except (KeyboardInterrupt, EOFError, ExitMainloop) as e:
            print
            break
        except Exception:
            print xtraceback.XTraceback(*sys.exc_info(), color=False)

    tracker.save(open(filename, "w"))
Example #23
0
def test_archival():
    tracker = Tracker(False)
    tracker.deserialize(
        {
            "life": "archived: task#abcde: \xfctest\n"
            "    task#zxcvb: \xfcderp\n"
            "        task#qwert: \xfcderk\n"
            "    task#hjklo: \xfcherp\n"
        }
    )

    assert tracker.serialize()["life"] == (
        "archived#abcde: task#abcde: \xfctest\n"
        "    @_af\n"
        "    archived#zxcvb: task#zxcvb: \xfcderp\n"
        "        @_af\n"
        "        archived#qwert: task#qwert: \xfcderk\n"
        "            @_af\n"
        "    archived#hjklo: task#hjklo: \xfcherp\n"
        "        @_af\n"
    )

    tracker.deserialize(
        {
            "life": "unarchive: archived#abcde: task#abcde: \xfctest\n"
            "    @_af\n"
            "    archived#zxcvb: task#zxcvb: \xfcderp\n"
            "        @_af\n"
            "        archived#qwert: task#qwert: \xfcderk\n"
            "            @_af\n"
            "    archived#hjklo: task#hjklo: \xfcherp\n"
            "        @_af\n"
        }
    )

    assert tracker.serialize()["life"] == (
        "task#abcde: \xfctest\n"
        "    task#zxcvb: \xfcderp\n"
        "        task#qwert: \xfcderk\n"
        "    task#hjklo: \xfcherp\n"
    )
Example #24
0
from __future__ import unicode_literals, print_function

if __name__ == "__main__":
    import sys
    from treeoflife import searching
    if "create" in sys.argv:
        dothing = searching.parse_create
    else:
        dothing = searching.parse

    todofile = "/Users/lahwran/.treeoflife/life"
    from treeoflife.tracker import Tracker
    import time
    tracker = Tracker()
    with open(todofile, "r") as reader:
        tracker.deserialize({"life": reader.read()})

    while True:
        querytext = raw_input("query: ")
        import subprocess
        subprocess.call(["clear"])
        print("query:", querytext)
        a = time.time()
        queryer = dothing(querytext)
        b = time.time()
        print(queryer, b - a)

        inittime = time.time()
        results = queryer(tracker.root)
        finishtime = time.time()
Example #25
0
 def __init__(self, *args, **kwargs):
     kwargs["roottype"] = MixedAlarmRoot
     self._reactor = kwargs.pop("reactor")
     Tracker.__init__(self, *args, **kwargs)