Example #1
0
    def test_org_date(self):
        reference = m.OrgDate(datetime.date(2016, 8, 5), datetime.time(12, 0))
        same = m.OrgDate(datetime.date(2016, 8, 5), datetime.time(12, 0))
        earlier = m.OrgDate(datetime.date(2016, 8, 4), datetime.time(12, 0))
        later = m.OrgDate(datetime.date(2016, 8, 5), datetime.time(12, 45))

        self.assertEqual(reference, same)
        self.assertEqual(earlier < reference, True)
        self.assertEqual(reference < later, True)
        self.assertEqual(min(later, earlier, reference), earlier)
Example #2
0
    def test_merge_schedule_time(self):
        conf = m.InteractiveMergeConf(tests.TestAdapter())
        tasks = [
            m.TasksTree('!!!Choose earlier!!!').update(
                schedule_time=m.OrgDate(datetime.date(2015, 12, 15))),
            m.TasksTree('Press Ctrl-D').update(
                schedule_time=m.OrgDate(datetime.date(2015, 12, 10)))
        ]

        self.assertEqual(
            conf.merge_schedule_time(m.MergeEntry(tasks[0], tasks[1])),
            tasks[1].schedule_time)
Example #3
0
    def test_parsing_special_comments(self):
        m.default_locale = locale.locale_alias['ru']

        org_text = textwrap.dedent("""\
            * TODO Headline A
              CLOSED: [2015-12-09 Wed 12:34] SCHEDULED: <2015-12-09 Wed>
            * TODO Headline B
              SCHEDULED: <2015-12-09 Wed 20:00-21:00>
              https://anticode.ninja
              [[https://anticode.ninja][#anticode.ninja# blog]]
              [[https://github.com/anticodeninja/michel2][michel2 #repo #github]]
              Normal note
            """)

        org_tree = m.TasksTree.parse_text(org_text)

        self.assertEqual(len(org_tree), 2)

        self.assertEqual(org_tree[0].title, "Headline A")
        self.assertEqual(len(org_tree[0].links), 0)
        self.assertEqual(org_tree[0].schedule_time,
                         m.OrgDate(datetime.date(2015, 12, 9)))
        self.assertEqual(
            org_tree[0].closed_time,
            m.OrgDate(datetime.date(2015, 12, 9), datetime.time(12, 34)))
        self.assertEqual(org_tree[0].notes, [])

        self.assertEqual(org_tree[1].title, "Headline B")
        self.assertEqual(len(org_tree[1].links), 3)
        self.assertEqual(org_tree[1].links[0],
                         m.TaskLink('https://anticode.ninja'))
        self.assertEqual(
            org_tree[1].links[1],
            m.TaskLink('https://anticode.ninja', '#anticode.ninja# blog'))
        self.assertEqual(
            org_tree[1].links[2],
            m.TaskLink('https://github.com/anticodeninja/michel2', 'michel2',
                       ['repo', 'github']))
        self.assertEqual(
            org_tree[1].schedule_time,
            m.OrgDate(datetime.date(2015, 12, 9), datetime.time(20, 0),
                      datetime.timedelta(hours=1)))
        self.assertEqual(org_tree[1].notes, ["Normal note"])

        self.assertEqual(str(org_tree), org_text)
Example #4
0
    def test_repeated_scheduled_one_day_issue(self):

        # Arrange
        base_tree = m.TasksTree.parse_text("""\
            * TODO RepeatedTask
              SCHEDULED: <2018-09-17 Mon>
            * TODO RepeatedTask
              SCHEDULED: <2018-10-08 Mon>
        """)

        org_tree = m.TasksTree.parse_text("""\
            * TODO RepeatedTask
              SCHEDULED: <2018-10-08 Mon>
            * TODO RepeatedTask
              SCHEDULED: <2018-10-08 Mon>
        """)

        remote_tree, indexes = tests.createTestTree([
            "RepeatedTask",
            dict(todo=True,
                 schedule_time=m.OrgDate(datetime.date(2018, 9, 17))),
            "RepeatedTask",
            dict(todo=True,
                 schedule_time=m.OrgDate(datetime.date(2018, 10, 8))),
        ])

        # Act
        remote_sync_plan = m.treemerge(org_tree, remote_tree, base_tree,
                                       tests.TestMergeConf())

        # Assert
        result_text = textwrap.dedent("""\
            * TODO RepeatedTask
              SCHEDULED: <2018-10-08 Mon>
            * TODO RepeatedTask
              SCHEDULED: <2018-10-08 Mon>
            """)
        self.assertEqual(str(org_tree), result_text)
        self.assertEqual(len(remote_sync_plan), 1)

        assertObj = next(x for x in remote_sync_plan
                         if x['item'] == indexes[0])
        self.assertEqual(assertObj['action'], 'update')
Example #5
0
    def test_parse_scheduled_and_closed_time(self):
        m.OrgDate.default_locale = getLocaleAlias('us')

        org_text = textwrap.dedent("""\
            * Headline 1
              Normal notes
            * Headline 2
              SCHEDULED: <2015-11-18 Wed>
            * Headline 3
              SCHEDULED: <2015-12-09 Wed 19:00-20:00>
            * DONE Headline 4
              CLOSED: [2015-12-10 Thu 03:25]
            * DONE Headline 5
              CLOSED: [2015-12-10 Thu 03:25] SCHEDULED: <2015-12-09 Wed 03:00>
            """)
        tasktree = m.TasksTree.parse_text(org_text)

        self.assertEqual(tasktree[0].closed_time, None)
        self.assertEqual(tasktree[0].schedule_time, None)

        self.assertEqual(tasktree[1].closed_time, None)
        self.assertEqual(tasktree[1].schedule_time,
                         m.OrgDate(datetime.date(2015, 11, 18)))

        self.assertEqual(tasktree[2].closed_time, None)
        self.assertEqual(
            tasktree[2].schedule_time,
            m.OrgDate(datetime.date(2015, 12, 9), datetime.time(19, 0),
                      datetime.timedelta(hours=1)))

        self.assertEqual(
            tasktree[3].closed_time,
            m.OrgDate(datetime.date(2015, 12, 10), datetime.time(3, 25)))
        self.assertEqual(tasktree[3].schedule_time, None)

        self.assertEqual(
            tasktree[4].closed_time,
            m.OrgDate(datetime.date(2015, 12, 10), datetime.time(3, 25)))
        self.assertEqual(
            tasktree[4].schedule_time,
            m.OrgDate(datetime.date(2015, 12, 9), datetime.time(3, 0)))

        self.assertEqual(str(tasktree), org_text)
Example #6
0
    def test_sync_time(self):

        # Arrange
        org_tree = m.TasksTree.parse_text("""\
            * TODO Headline A
            * TODO Headline B
            * TODO Headline C
              SCHEDULED: <2015-12-09 Wed 20:00-21:00>
        """)

        remote_tree, indexes = tests.createTestTree([
            "Headline A",
            dict(todo=True,
                 schedule_time=m.OrgDate(datetime.date(2015, 12, 9))),
            "Headline B",
            dict(todo=True),
            "Headline C",
            dict(completed=True,
                 closed_time=self.now,
                 schedule_time=m.OrgDate(datetime.date(2015, 12, 9),
                                         datetime.time(20, 0),
                                         datetime.timedelta(hours=1))),
            "Headline D",
            dict(todo=True,
                 schedule_time=m.OrgDate(datetime.date(2015, 12, 9))),
        ])

        # Act
        m.treemerge(org_tree, remote_tree, None, tests.TestMergeConf())

        # Assert
        result_text = textwrap.dedent("""\
            * TODO Headline A
              SCHEDULED: <2015-12-09 Wed>
            * TODO Headline B
            * DONE Headline C
              CLOSED: [{0}] SCHEDULED: <2015-12-09 Wed 20:00-21:00>
            * TODO Headline D
              SCHEDULED: <2015-12-09 Wed>
            """.format(self.now.to_org_format()))
        self.assertEqual(str(org_tree), result_text)
Example #7
0
 def __gen_remote(self, *days):
     temp = []
     if 1 in days:
         temp += [
             "RepeatedTask",
             dict(todo=True,
                  schedule_time=m.OrgDate(datetime.date(2015, 12, 1)))
         ]
     if 3 in days:
         temp += [
             "RepeatedTask",
             dict(todo=True,
                  schedule_time=m.OrgDate(datetime.date(2015, 12, 3)))
         ]
     if 5 in days:
         temp += [
             "RepeatedTask",
             dict(todo=True,
                  schedule_time=m.OrgDate(datetime.date(2015, 12, 5)))
         ]
     return temp
Example #8
0
    def test_format_emacs_dates(self):
        test_locale = getLocaleAlias('ru')
        if test_locale:
            m.OrgDate.default_locale = test_locale
            self.assertEqual(
                "2015-12-09 Ср",
                m.OrgDate(datetime.date(2015, 12, 9)).to_org_format())

        test_locale = getLocaleAlias('us')
        if test_locale:
            m.OrgDate.default_locale = test_locale
            self.assertEqual(
                "2015-11-18 Wed",
                m.OrgDate(datetime.date(2015, 11, 18)).to_org_format())

        test_locale = getLocaleAlias('de')
        if test_locale:
            m.OrgDate.default_locale = test_locale
            self.assertEqual(
                "2015-12-10 Do",
                m.OrgDate(datetime.date(2015, 12, 10)).to_org_format())
Example #9
0
    def test_3way_merge(self):

        # Arrange
        base_tree = m.TasksTree.parse_text("""\
            * NotTodoTestTask
            * TitleMergeTest
            ** TODO TitleMergeTask1
            ** TODO TitleMergeTask2
            ** TODO TitleMergeTask3
            * ScheduleMergeTest
            * TODO ScheduleMergeTask1
              SCHEDULED: <2015-12-09 Wed>
            * TODO ScheduleMergeTask2
              SCHEDULED: <2015-12-09 Wed>
            * TODO ScheduleMergeTask3
              SCHEDULED: <2015-12-09 Wed>
        """.format(self.now.to_org_format()))

        org_tree = m.TasksTree.parse_text("""\
            * NotTodoTestTask
            * TitleMergeTest
            ** TODO TitleMergeTask1
            ** TODO TitleMergeTask2 org-edited
            ** TODO TitleMergeTask3
            * ScheduleMergeTest
            * TODO ScheduleMergeTask1
              SCHEDULED: <2015-12-09 Wed>
            * TODO ScheduleMergeTask2
              SCHEDULED: <2015-12-10 Thu>
            * TODO ScheduleMergeTask3
              SCHEDULED: <2015-12-09 Wed>
        """.format(self.now.to_org_format()))

        remote_tree, indexes = tests.createTestTree([
            "TitleMergeTask1",
            dict(todo=True), "TitleMergeTask2",
            dict(todo=True), "TitleMergeTask3 remote-edited",
            dict(todo=True), "ScheduleMergeTask1",
            dict(todo=True,
                 schedule_time=m.OrgDate(datetime.date(2015, 12, 9))),
            "ScheduleMergeTask2",
            dict(todo=True,
                 schedule_time=m.OrgDate(datetime.date(2015, 12, 9))),
            "ScheduleMergeTask3",
            dict(todo=True,
                 schedule_time=m.OrgDate(datetime.date(2015, 12, 11)))
        ])

        # Act
        remote_sync_plan = m.treemerge(
            org_tree, remote_tree, base_tree,
            tests.TestMergeConf([
                ["TitleMergeTask2 org-edited", "TitleMergeTask2", None],
                ["TitleMergeTask3", "TitleMergeTask3 remote-edited", None],
            ]))

        # Assert
        result_text = textwrap.dedent("""\
            * NotTodoTestTask
            * TitleMergeTest
            ** TODO TitleMergeTask1
            ** TODO TitleMergeTask2 org-edited
            ** TODO TitleMergeTask3 remote-edited
            * ScheduleMergeTest
            * TODO ScheduleMergeTask1
              SCHEDULED: <2015-12-09 Wed>
            * TODO ScheduleMergeTask2
              SCHEDULED: <2015-12-10 Thu>
            * TODO ScheduleMergeTask3
              SCHEDULED: <2015-12-11 Fri>
            """)
        self.assertEqual(str(org_tree), result_text)

        self.assertEqual(len(remote_sync_plan), 2)

        # TitleMergeTask2 org-edited
        assertObj = next(x for x in remote_sync_plan
                         if x['item'] == indexes[1])
        self.assertEqual(assertObj['action'], 'update')
        self.assertEqual(assertObj['changes'], ['title'])
        self.assertEqual(assertObj['item'].title, 'TitleMergeTask2 org-edited')

        # ScheduleMergeTask2
        assertObj = next(x for x in remote_sync_plan
                         if x['item'] == indexes[4])
        self.assertEqual(assertObj['action'], 'update')
        self.assertEqual(assertObj['changes'], ['schedule_time'])
        self.assertEqual(assertObj['item'].schedule_time,
                         m.OrgDate(datetime.date(2015, 12, 10)))