Exemple #1
0
    def test_todo_only(self):

        # Arrange
        org_tree = m.TasksTree.parse_text("""\
            * NotEntry
            * TODO TodoEntry
            * DONE CompletedEntry
              CLOSED: [{0}]
            * NotExtEntry
            ** NotExtNotIntEntry
            ** TODO NotExtTodoIntEntry
            ** DONE NotExtCompletedIntEntry
               CLOSED: [{0}]
            * TODO TodoExtEntry
            ** TodoExtNotIntEntry
            ** TODO TodoExtTodoIntEntry
            ** DONE TodoExtCompletedIntEntry
               CLOSED: [{0}]
        """.format(self.now.to_org_format()))

        remote_tree, indexes = tests.createTestTree([
            "TodoEntry",
            dict(completed=True, closed_time=self.now),
            "NotExtTodoIntEntry",
            dict(completed=True, closed_time=self.now),
            "TodoExtEntry",
            dict(completed=True, closed_time=self.now),
            "TodoExtTodoIntEntry",
            dict(completed=True, closed_time=self.now),
            "NewTodoEntry",
            dict(todo=True),
        ])

        # Act
        m.treemerge(org_tree, remote_tree, None,
                    tests.TestMergeConf([[None, "NewTodoEntry", None]]))

        # Assert
        result_text = textwrap.dedent("""\
            * NotEntry
            * DONE TodoEntry
              CLOSED: [{0}]
            * DONE CompletedEntry
              CLOSED: [{0}]
            * NotExtEntry
            ** NotExtNotIntEntry
            ** DONE NotExtTodoIntEntry
               CLOSED: [{0}]
            ** DONE NotExtCompletedIntEntry
               CLOSED: [{0}]
            * DONE TodoExtEntry
              CLOSED: [{0}]
            ** TodoExtNotIntEntry
            ** DONE TodoExtTodoIntEntry
               CLOSED: [{0}]
            ** DONE TodoExtCompletedIntEntry
               CLOSED: [{0}]
            * TODO NewTodoEntry
        """.format(self.now.to_org_format()))
        self.assertEqual(str(org_tree), result_text)
Exemple #2
0
    def test_merge_sync_todo_only(self):

        # Arrange
        org_tree = m.TasksTree.parse_text("""\
            * Headline A
            * Headline B
            ** TODO Headline B1
            * TODO Headline C
            * TODO Headline D
            * Headline E
            ** DONE Headline E1
            * DONE Headline F
            ** Headline F1
        """)

        remote_tree, indexes = tests.createTestTree([
            "Headline B1",
            dict(completed=True, closed_time=self.now),
            "Headline C",
            dict(completed=True, closed_time=self.now),
            "Headline D",
            dict(todo=True),
            "Headline G",
            dict(todo=True),
        ])

        # Act
        m.treemerge(org_tree, remote_tree, None,
                    tests.TestMergeConf([
                        [None, "Headline G", None],
                    ]))

        # Assert
        result_text = textwrap.dedent("""\
            * Headline A
            * Headline B
            ** DONE Headline B1
               CLOSED: [{0}]
            * DONE Headline C
              CLOSED: [{0}]
            * TODO Headline D
            * Headline E
            ** DONE Headline E1
            * DONE Headline F
            ** Headline F1
            * TODO Headline G
            """.format(self.now.to_org_format()))
        self.assertEqual(str(org_tree), result_text)
Exemple #3
0
    def test_links_merge(self):

        # Arrange
        org_tree = m.TasksTree.parse_text("""\
            * TODO Headline A
            https://anticode.ninja
            * TODO Headline B
            [[https://anticode.ninja][#anticode.ninja# blog]]
            [[https://github.com/anticodeninja/michel2][michel2 #repo #github]]
        """.format(self.now.to_org_format()))

        remote_tree, indexes = tests.createTestTree([
            "Headline A",
            dict(todo=True,
                 links=[
                     m.TaskLink("https://anticode.ninja"),
                     m.TaskLink('https://github.com/anticodeninja/michel2',
                                'michel2', ['repo', 'github'])
                 ]), "Headline B",
            dict(todo=True,
                 links=[
                     m.TaskLink('https://anticode.ninja',
                                '#anticode.ninja# blog')
                 ])
        ])

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

        # Assert
        result_text = textwrap.dedent("""\
            * TODO Headline A
              https://anticode.ninja
              [[https://github.com/anticodeninja/michel2][michel2 #repo #github]]
            * TODO Headline B
              [[https://anticode.ninja][#anticode.ninja# blog]]
              [[https://github.com/anticodeninja/michel2][michel2 #repo #github]]
            """.format(self.now.to_org_format()))
        self.assertEqual(str(org_tree), result_text)

        self.assertEqual(len(remote_sync_plan), 1)

        # Headline A
        assertObj = next(x for x in remote_sync_plan
                         if x['item'] == indexes[1])
        self.assertEqual(assertObj['action'], 'update')
        self.assertEqual(assertObj['changes'], ['links'])
        self.assertEqual(len(assertObj['item'].links), 2)
        self.assertEqual(
            assertObj['item'].links[0],
            m.TaskLink('https://anticode.ninja', '#anticode.ninja# blog'))
        self.assertEqual(
            assertObj['item'].links[1],
            m.TaskLink('https://github.com/anticodeninja/michel2', 'michel2',
                       ['repo', 'github']))
Exemple #4
0
    def test_safemerge(self):

        # Arrange
        org_tree = m.TasksTree.parse_text("""\
            * Headline A1
            * Headline A2
            ** Headline A2.1
            * Headline B1
            ** Headline B1.1
            * Headline B2
        """)

        remote_tree, indexes = tests.createTestTree([
            "Headline A1", " Headline A1.1", "Headline B1", " Headline B1.1",
            dict(notes=["Remote append B1.1 body text."]), "Headline A2",
            dict(todo=True), " Headline A2.1", "Headline B2 modified",
            dict(notes=["New B2 body text."])
        ])

        # Act
        m.treemerge(
            org_tree, remote_tree, None,
            tests.TestMergeConf([
                [None, "Headline A1.1", None],
                [
                    "Headline B2", "Headline B2 modified",
                    "Headline B2 modified"
                ],
            ]))

        # Assert
        result_text = textwrap.dedent("""\
            * Headline A1
            ** Headline A1.1
            * Headline A2
            ** Headline A2.1
            * Headline B1
            ** Headline B1.1
               Remote append B1.1 body text.
            * Headline B2 modified
              New B2 body text.
        """)
        self.assertEqual(str(org_tree), result_text)
Exemple #5
0
    def test_merge_sync_todo_only(self):
        org_text = textwrap.dedent("""\
            * Headline A
            * Headline B
            ** TODO Headline B1
            * TODO Headline C
            * TODO Headline D
            * Headline E
            ** DONE Headline E1
            * DONE Headline F
            ** Headline F1
            """)
        org_tree = m.TasksTree.parse_text(org_text)

        remote_tree = m.TasksTree(None)
        remote_tree.add_subtask('Headline B1').update(
            completed=True,
            closed_time=m.OrgDate.now()),
        remote_tree.add_subtask('Headline C').update(
            completed=True,
            closed_time=m.OrgDate.now()),
        remote_tree.add_subtask('Headline D').update(
            todo=True)
        remote_tree.add_subtask('Headline G').update(
            todo=True)

        m.treemerge(org_tree, remote_tree, None, TestMergeConf())
        
        result_text = textwrap.dedent("""\
            * Headline A
            * Headline B
            ** DONE Headline B1
               CLOSED: [{0}]
            * DONE Headline C
              CLOSED: [{0}]
            * TODO Headline D
            * Headline E
            ** DONE Headline E1
            * DONE Headline F
            ** Headline F1
            * TODO Headline G
            """.format(m.OrgDate.now().to_org_format()))
        self.assertEqual(str(org_tree), result_text)
Exemple #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)
Exemple #7
0
    def test_sync_time(self):
        m.OrgDate.default_locale = getLocaleAlias('us')
        
        org_text = textwrap.dedent("""\
            * TODO Headline A
            * TODO Headline B
            * TODO Headline C
              SCHEDULED: <2015-12-09 Wed 20:00-21:00>
            """)
        org_tree = m.TasksTree.parse_text(org_text)

        remote_tree = m.TasksTree(None)
        remote_tree.add_subtask('Headline A').update(
            todo=True,
            schedule_time=m.OrgDate(datetime.date(2015, 12, 9)))
        remote_tree.add_subtask('Headline B').update(
            todo=True)
        remote_tree.add_subtask('Headline C').update(
            completed=True,
            closed_time=m.OrgDate.now(),
            schedule_time=m.OrgDate(datetime.date(2015, 12, 9),
                                    datetime.time(20, 0),
                                    datetime.timedelta(hours=1))),
        remote_tree.add_subtask('Headline D').update(
            todo=True,
            schedule_time=m.OrgDate(datetime.date(2015, 12, 9)))
        
        m.treemerge(org_tree, remote_tree, None, TestMergeConf())

        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(m.OrgDate.now().to_org_format()))
        self.assertEqual(str(org_tree), result_text)
Exemple #8
0
    def test_repeated_scheduled_task_new_remote_addin_merge(self):

        # Arrange
        base_tree = m.TasksTree.parse_text(self.__gen_org(1, 3))
        org_tree = m.TasksTree.parse_text(self.__gen_org(1, 3))
        remote_tree, indexes = tests.createTestTree(self.__gen_remote(1, 3, 5))

        # Act
        remote_sync_plan = m.treemerge(
            org_tree, remote_tree, base_tree,
            tests.TestMergeConf([[None, "RepeatedTask", None]]))

        # Assert
        self.assertEqual(str(org_tree), self.__gen_org(1, 3, 5))
        self.assertEqual(len(remote_sync_plan), 0)
Exemple #9
0
    def test_safemerge(self):
    
        org_text = textwrap.dedent("""\
            * Headline A1
            * Headline A2
            ** Headline A2.1
            * Headline B1
            ** Headline B1.1
               Remote append B1.1 body text.
            * Headline B2
            """)
        org_tree = m.TasksTree.parse_text(org_text)

        remote_tree = m.TasksTree(None)
        remote_tree.add_subtask('Headline A1').\
            add_subtask('Headline A1.1')
        remote_tree.add_subtask('Headline B1').\
            add_subtask('Headline B1.1').update(notes=["Remote append B1.1 body text."])
        remote_tree.add_subtask('Headline A2').update(todo=True).\
            add_subtask('Headline A2.1')
        remote_tree.add_subtask('Headline B2 modified').update(notes=["New B2 body text."])

        m.treemerge(org_tree, remote_tree, None, TestMergeConf())

        result_text = textwrap.dedent("""\
            * Headline A1
            ** Headline A1.1
            * Headline A2
            ** Headline A2.1
            * Headline B1
            ** Headline B1.1
               Remote append B1.1 body text.
            * Headline B2 modified
              New B2 body text.
            """)
        self.assertEqual(str(org_tree), result_text)
Exemple #10
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')
Exemple #11
0
    def test_repeated_scheduled_task_new_org_merge(self):

        # Arrange
        base_tree = m.TasksTree.parse_text(self.__gen_org(3))
        org_tree = m.TasksTree.parse_text(self.__gen_org(3, 5))
        remote_tree, indexes = tests.createTestTree(self.__gen_remote(3))

        # Act
        remote_sync_plan = m.treemerge(
            org_tree, remote_tree, base_tree,
            tests.TestMergeConf([[None, "RepeatedTask", None]]))

        # Assert
        self.assertEqual(str(org_tree), self.__gen_org(3, 5))
        self.assertEqual(len(remote_sync_plan), 1)

        # Add RepeatedTask <2015-12-5 Fri>
        assertObj = next(x for x in remote_sync_plan
                         if x['item'] not in indexes)
        self.assertEqual(assertObj['action'], 'append')
Exemple #12
0
    def test_repeated_scheduled_task_reschedule_org_merge(self):

        # Arrange
        base_tree = m.TasksTree.parse_text(self.__gen_org(1, 3))
        org_tree = m.TasksTree.parse_text(self.__gen_org(1, 5))
        remote_tree, indexes = tests.createTestTree(self.__gen_remote(1, 3))

        # Act
        remote_sync_plan = m.treemerge(
            org_tree, remote_tree, base_tree,
            tests.TestMergeConf([[None, "RepeatedTask", None]]))

        # Assert
        self.assertEqual(str(org_tree), self.__gen_org(1, 5))
        self.assertEqual(len(remote_sync_plan), 1)

        assertObj = next(x for x in remote_sync_plan
                         if x['item'] == indexes[1])
        self.assertEqual(assertObj['action'], 'update')
        self.assertEqual(assertObj['changes'], ['schedule_time'])
Exemple #13
0
    def test_repeated_scheduled_task_reschedule_new_merge(self):

        # Arrange
        base_tree = m.TasksTree.parse_text(self.__gen_org(1))

        org_tree = m.TasksTree.parse_text("""\
            * DONE RepeatedTask
              CLOSED: [2015-12-01 Tue] SCHEDULED: <2015-12-01 Tue>
            * TODO RepeatedTask
              SCHEDULED: <2015-12-03 Sat>
        """)

        remote_tree, indexes = tests.createTestTree(self.__gen_remote(1))

        # Act
        remote_sync_plan = m.treemerge(
            org_tree, remote_tree, base_tree,
            tests.TestMergeConf([[None, "RepeatedTask", None]]))

        # Assert
        result_text = textwrap.dedent("""\
            * DONE RepeatedTask
              CLOSED: [2015-12-01 Tue] SCHEDULED: <2015-12-01 Tue>
            * TODO RepeatedTask
              SCHEDULED: <2015-12-03 Thu>
            """)
        self.assertEqual(str(org_tree), result_text)
        self.assertEqual(len(remote_sync_plan), 2)

        assertObj = next(x for x in remote_sync_plan
                         if x['item'] == indexes[0])
        self.assertEqual(assertObj['action'], 'remove')

        assertObj = next(x for x in remote_sync_plan
                         if x['item'] not in indexes)
        self.assertEqual(assertObj['action'], 'append')
Exemple #14
0
    def test_3way_merge(self):
        m.OrgDate.default_locale = getLocaleAlias('us')
        
        base_text = textwrap.dedent("""\
            * 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(m.OrgDate.now().to_org_format()))
        base_tree = m.TasksTree.parse_text(base_text)
        
        org_text = textwrap.dedent("""\
            * 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(m.OrgDate.now().to_org_format()))
        org_tree = m.TasksTree.parse_text(org_text)

        remote_tree = m.TasksTree(None)
        remote_tasks = [
            remote_tree.add_subtask('TitleMergeTask1').update(
                todo=True),
            remote_tree.add_subtask('TitleMergeTask2').update(
                todo=True),
            remote_tree.add_subtask('TitleMergeTask3 remote-edited').update(
                todo=True),
            remote_tree.add_subtask('ScheduleMergeTask1').update(
                todo=True,
                schedule_time=m.OrgDate(datetime.date(2015, 12, 9))),
            remote_tree.add_subtask('ScheduleMergeTask2').update(
                todo=True,
                schedule_time=m.OrgDate(datetime.date(2015, 12, 9))),
            remote_tree.add_subtask('ScheduleMergeTask3').update(
                todo=True,
                schedule_time=m.OrgDate(datetime.date(2015, 12, 11))),
        ]

        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>
            """)


        remote_sync_plan = m.treemerge(org_tree, remote_tree, base_tree, m.InteractiveMergeConf(TestAdapterFor3Way()))

        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'] == remote_tasks[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'] == remote_tasks[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)))
Exemple #15
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)))
Exemple #16
0
    def test_fast_merge(self):
        org_text = textwrap.dedent("""\
            * Headline A
            * Headline B
            ** TODO Headline B1
            ** DONE Headline B2
               CLOSED: [{0}]
            ** TODO Headline B3 original
            * TODO Headline C
            * Headline D
            ** DONE Headline D1
               CLOSED: [{0}]
            * Headline E
            ** DONE Headline E1
            * TODO Headline F
            """.format(m.OrgDate.now().to_org_format()))
        org_tree = m.TasksTree.parse_text(org_text)

        remote_tree = m.TasksTree(None)
        remote_tasks = [
            remote_tree.add_subtask('Headline B1').update(
                completed=True,
                closed_time=m.OrgDate.now()),
            remote_tree.add_subtask('Headline B2 modified').update(
                todo=True),
            remote_tree.add_subtask('Headline B3').update(
                todo=True),
            remote_tree.add_subtask('Headline C').update(
                completed=True,
                closed_time=m.OrgDate.now()),
            remote_tree.add_subtask('Headline D1').update(
                todo=True),
            remote_tree.add_subtask('Headline G').update(
                todo=True),
            remote_tree.add_subtask('Headline H').update(
                completed=True,
                closed_time=m.OrgDate.now())
        ]

        result_text = textwrap.dedent("""\
            * Headline A
            * Headline B
            ** DONE Headline B1
               CLOSED: [{0}]
            ** DONE Headline B2 modified
               CLOSED: [{0}]
            ** TODO Headline B3 original
            * DONE Headline C
              CLOSED: [{0}]
            * Headline D
            ** DONE Headline D1
               CLOSED: [{0}]
            * Headline E
            ** DONE Headline E1
            * TODO Headline F
            * TODO Headline G
            * DONE Headline H
              CLOSED: [{0}]
            """.format(m.OrgDate.now().to_org_format()))


        remote_sync_plan = m.treemerge(org_tree, remote_tree, None, TestMergeConf())

        self.assertEqual(str(org_tree), result_text)
        self.assertEqual(len(remote_sync_plan), 7)

        # Headline B1
        assertObj = next(x for x in remote_sync_plan if x['item'] == remote_tasks[0])
        self.assertEqual(assertObj['action'], 'remove')

        # Headline B2
        assertObj = next(x for x in remote_sync_plan if x['item'] == remote_tasks[1])
        self.assertEqual(assertObj['action'], 'remove')

        # Headline B3
        assertObj = next(x for x in remote_sync_plan if x['item'] == remote_tasks[2])
        self.assertEqual(assertObj['action'], 'update')
        self.assertEqual(assertObj['changes'], ['title'])
        self.assertEqual(assertObj['item'].title, 'Headline B3 original')

        # Headline C
        assertObj = next(x for x in remote_sync_plan if x['item'] == remote_tasks[3])
        self.assertEqual(assertObj['action'], 'remove')

        # Headline D1
        assertObj = next(x for x in remote_sync_plan if x['item'] == remote_tasks[4])
        self.assertEqual(assertObj['action'], 'remove')

        # Headline F
        assertObj = next(x for x in remote_sync_plan if x['item'].title == "Headline F")
        self.assertEqual(assertObj['action'], 'append')
        self.assertEqual(assertObj['item'].title, 'Headline F')

        # Headline H
        assertObj = next(x for x in remote_sync_plan if x['item'] == remote_tasks[6])
        self.assertEqual(assertObj['action'], 'remove')
Exemple #17
0
    def test_fast_merge(self):

        # Arrange
        org_tree = m.TasksTree.parse_text("""\
            * Headline A
            * Headline B
            ** TODO Headline B1
            ** DONE Headline B2
               CLOSED: [{0}]
            ** TODO Headline B3 original
            * TODO Headline C
            * Headline D
            ** DONE Headline D1
               CLOSED: [{0}]
            * Headline E
            ** DONE Headline E1
            * TODO Headline F
        """.format(self.now.to_org_format()))

        remote_tree, indexes = tests.createTestTree([
            "Headline B1",
            dict(completed=True, closed_time=self.now),
            "Headline B2 modified",
            dict(todo=True),
            "Headline B3",
            dict(todo=True),
            "Headline C",
            dict(completed=True, closed_time=self.now),
            "Headline D1",
            dict(todo=True),
            "Headline G",
            dict(todo=True),
            "Headline H",
            dict(completed=True, closed_time=self.now),
        ])

        # Act
        remote_sync_plan = m.treemerge(
            org_tree, remote_tree, None,
            tests.TestMergeConf([
                [None, "Headline G", None],
                [None, "Headline H", None],
                [
                    "Headline B2", "Headline B2 modified",
                    "Headline B2 modified"
                ],
                [
                    "Headline B3 original", "Headline B3",
                    "Headline B3 original"
                ],
            ]))

        # Assert
        result_text = textwrap.dedent("""\
            * Headline A
            * Headline B
            ** DONE Headline B1
               CLOSED: [{0}]
            ** DONE Headline B2 modified
               CLOSED: [{0}]
            ** TODO Headline B3 original
            * DONE Headline C
              CLOSED: [{0}]
            * Headline D
            ** DONE Headline D1
               CLOSED: [{0}]
            * Headline E
            ** DONE Headline E1
            * TODO Headline F
            * TODO Headline G
            * DONE Headline H
              CLOSED: [{0}]
            """.format(self.now.to_org_format()))
        self.assertEqual(str(org_tree), result_text)

        self.assertEqual(len(remote_sync_plan), 7)

        # Headline B1
        assertObj = next(x for x in remote_sync_plan
                         if x['item'] == indexes[0])
        self.assertEqual(assertObj['action'], 'remove')

        # Headline B2
        assertObj = next(x for x in remote_sync_plan
                         if x['item'] == indexes[1])
        self.assertEqual(assertObj['action'], 'remove')

        # Headline B3
        assertObj = next(x for x in remote_sync_plan
                         if x['item'] == indexes[2])
        self.assertEqual(assertObj['action'], 'update')
        self.assertEqual(assertObj['changes'], ['title'])
        self.assertEqual(assertObj['item'].title, 'Headline B3 original')

        # Headline C
        assertObj = next(x for x in remote_sync_plan
                         if x['item'] == indexes[3])
        self.assertEqual(assertObj['action'], 'remove')

        # Headline D1
        assertObj = next(x for x in remote_sync_plan
                         if x['item'] == indexes[4])
        self.assertEqual(assertObj['action'], 'remove')

        # Headline F
        assertObj = next(x for x in remote_sync_plan
                         if x['item'].title == "Headline F")
        self.assertEqual(assertObj['action'], 'append')
        self.assertEqual(assertObj['item'].title, 'Headline F')

        # Headline H
        assertObj = next(x for x in remote_sync_plan
                         if x['item'] == indexes[6])
        self.assertEqual(assertObj['action'], 'remove')
Exemple #18
0
    def test_repeated_task_merge(self):
        m.OrgDate.default_locale = getLocaleAlias('us')
        
        base_text = textwrap.dedent("""\
            * TODO RepeatedTask
              SCHEDULED: <2015-12-09 Wed>
            * TODO RepeatedTask
              SCHEDULED: <2015-12-10 Thu>
            * TODO RepeatedTask
              SCHEDULED: <2015-12-12 Sat>
            """)
        base_tree = m.TasksTree.parse_text(base_text)
        
        org_text = textwrap.dedent("""\
            * TODO RepeatedTask
              SCHEDULED: <2015-12-09 Wed>
            * TODO RepeatedTask
              SCHEDULED: <2015-12-10 Thu>
            * DONE RepeatedTask
              CLOSED: [2015-12-12 Sat] SCHEDULED: <2015-12-12 Sat>
            """)
        org_tree = m.TasksTree.parse_text(org_text)

        remote_tree = m.TasksTree(None)
        remote_tasks = [
            remote_tree.add_subtask('RepeatedTask').update(
                completed=True,
                closed_time=m.OrgDate(datetime.date(2015, 12, 11)),
                schedule_time=m.OrgDate(datetime.date(2015, 12, 11))),
            remote_tree.add_subtask('RepeatedTask').update(
                todo=True,
                schedule_time=m.OrgDate(datetime.date(2015, 12, 9))),
            remote_tree.add_subtask('RepeatedTask').update(
                todo=True,
                schedule_time=m.OrgDate(datetime.date(2015, 12, 12))),
            remote_tree.add_subtask('RepeatedTask').update(
                todo=True,
                schedule_time=m.OrgDate(datetime.date(2015, 12, 14))),
        ]

        result_text = textwrap.dedent("""\
            * TODO RepeatedTask
              SCHEDULED: <2015-12-09 Wed>
            * DONE RepeatedTask
              CLOSED: [2015-12-11 Fri] SCHEDULED: <2015-12-11 Fri>
            * DONE RepeatedTask
              CLOSED: [2015-12-12 Sat] SCHEDULED: <2015-12-12 Sat>
            * TODO RepeatedTask
              SCHEDULED: <2015-12-14 Mon>
            """)


        remote_sync_plan = m.treemerge(org_tree, remote_tree, base_tree, m.InteractiveMergeConf(TestAdapterFor3Way()))

        self.assertEqual(str(org_tree), result_text)
        self.assertEqual(len(remote_sync_plan), 2)

        # Remove RepeatedTask <2015-12-11 Fri>
        assertObj = next(x for x in remote_sync_plan if x['item'] == remote_tasks[0])
        self.assertEqual(assertObj['action'], 'remove')

        # Remove RepeatedTask <2015-12-12 Sat>
        assertObj = next(x for x in remote_sync_plan if x['item'] == remote_tasks[2])
        self.assertEqual(assertObj['action'], 'remove')