Ejemplo n.º 1
0
class Tasks(Visitor):
    def __init__(self, root_folder, root_context):
        Visitor.__init__(self)
        self.root_folder = root_folder
        self.root_context = root_context
        self.project = Project(name="Tasks")
        self.context = Context(name="Tasks")

    def end_project(self, item):
        for child in item.children:
            self.project.add_child(child)
        item.children = []

    def end_folder(self, item):
        if item == self.root_folder:
            self.root_folder.children = []
            self.root_folder.add_child(self.project)

    def end_context(self, item):
        if item != self.root_context:
            for child in item.children:
                if child.type == TASK:
                    self.context.add_child(child)
            item.children = []
        else:
            self.root_context.children = []
            self.root_context.add_child(self.context)

    def __str__(self):
        return "Tasks"
Ejemplo n.º 2
0
class Tasks (Visitor):
    def __init__(self, root_folder, root_context):
        Visitor.__init__(self)
        self.root_folder = root_folder
        self.root_context = root_context
        self.project = Project (name='Tasks')
        self.context = Context (name='Tasks')
    def end_project (self, item):
        for child in item.children:
            self.project.add_child(child)
        item.children = []
    def end_folder (self, item):
        if item == self.root_folder:
            self.root_folder.children = []
            self.root_folder.add_child(self.project)
    def end_context (self, item):
        if item != self.root_context:
            for child in item.children:
                if child.type == TASK:
                    self.context.add_child(child)
            item.children = []
        else:
            self.root_context.children = []
            self.root_context.add_child(self.context)
    def __str__ (self):
        return 'Tasks'
Ejemplo n.º 3
0
 def test_ProjectNameFilterVisitor_include_ignores_children (self):
     n1 = Project (name=u'n1 xxx')
     n2 = Task (name=u'n2')
     n1.add_child(n2)
     
     visitor = ProjectNameFilterVisitor ('xxx')
     traverse (visitor, n1)
     self.assertTrue(n1.marked)
     self.assertTrue(n2.marked)
Ejemplo n.º 4
0
    def test_ProjectNameFilterVisitor_include_ignores_children(self):
        n1 = Project(name=u'n1 xxx')
        n2 = Task(name=u'n2')
        n1.add_child(n2)

        visitor = ProjectNameFilterVisitor('xxx')
        traverse(visitor, n1)
        self.assertTrue(n1.marked)
        self.assertTrue(n2.marked)
Ejemplo n.º 5
0
    def test_Sort_in_order(self):
        n1 = Task(name=u'a n1')
        n2 = Task(name=u'b n2')
        root = Project(name=u'r')
        root.add_child(n1)
        root.add_child(n2)

        visitor = Sort([PROJECT], lambda x: x.name, 'pretty')
        traverse(visitor, root)
        self.assertIs(root.children[0], n1)
        self.assertIs(root.children[1], n2)
Ejemplo n.º 6
0
    def test_Sort_same_use_underlying_order_out_of_order(self):
        n1 = Task(name=u'aaa', order=2)
        n2 = Task(name=u'aaa', order=1)
        root = Project(name=u'r')
        root.add_child(n1)
        root.add_child(n2)

        visitor = Sort([PROJECT], lambda x: x.name, 'pretty')
        traverse(visitor, root)
        self.assertIs(root.children[0], n2)
        self.assertIs(root.children[1], n1)
Ejemplo n.º 7
0
 def test_Sort_out_of__order (self):
     n1 = Task (name=u'b n1')
     n2 = Task (name=u'a n2')
     root = Project (name=u'r')
     root.add_child(n1)
     root.add_child(n2)
     
     visitor = Sort ([PROJECT], lambda x: x.name, 'pretty')
     traverse (visitor, root)
     self.assertIs(root.children[0], n2)
     self.assertIs(root.children[1], n1)
Ejemplo n.º 8
0
 def test_Sort_same_use_underlying_order_out_of_order (self):
     n1 = Task (name=u'aaa', order=2)
     n2 = Task (name=u'aaa', order=1)
     root = Project (name=u'r')
     root.add_child(n1)
     root.add_child(n2)
     
     visitor = Sort ([PROJECT], lambda x: x.name, 'pretty')
     traverse (visitor, root)
     self.assertIs(root.children[0], n2)
     self.assertIs(root.children[1], n1)
Ejemplo n.º 9
0
 def test_project_add_child (self):
     project = Project ()
     child = Task ()
     project.add_child (child)
     self.assertEquals(project, child.parent)
     self.assertEquals(project, child.project)
     
     project = Project ()
     child = Task ()
     grandchild = Task ()
     child.add_child (grandchild)
     project.add_child (child)
     self.assertEquals(project, child.parent)
     self.assertEquals(project, child.project)
     self.assertEquals(project, grandchild.project)
Ejemplo n.º 10
0
    def test_project_add_child(self):
        project = Project()
        child = Task()
        project.add_child(child)
        self.assertEquals(project, child.parent)
        self.assertEquals(project, child.project)

        project = Project()
        child = Task()
        grandchild = Task()
        child.add_child(grandchild)
        project.add_child(child)
        self.assertEquals(project, child.parent)
        self.assertEquals(project, child.project)
        self.assertEquals(project, grandchild.project)
Ejemplo n.º 11
0
 def test_task_add_child (self):
     project = Project ()
     task = Task ()
     child = Task ()
     project.add_child (task)
     task.add_child (child)
     self.assertEquals(task, child.parent)
     self.assertEquals(project, child.project)
     
     project = Project ()
     task = Task ()
     child = Task ()
     grandchild = Task ()
     project.add_child (task)
     task.add_child (child)
     child.add_child (grandchild)
     task.add_child (child)
     self.assertEquals(task, child.parent)
     self.assertEquals(project, child.project)
     self.assertEquals(child, grandchild.parent)
     self.assertEquals(project, grandchild.project)
Ejemplo n.º 12
0
    def test_task_add_child(self):
        project = Project()
        task = Task()
        child = Task()
        project.add_child(task)
        task.add_child(child)
        self.assertEquals(task, child.parent)
        self.assertEquals(project, child.project)

        project = Project()
        task = Task()
        child = Task()
        grandchild = Task()
        project.add_child(task)
        task.add_child(child)
        child.add_child(grandchild)
        task.add_child(child)
        self.assertEquals(task, child.parent)
        self.assertEquals(project, child.project)
        self.assertEquals(child, grandchild.parent)
        self.assertEquals(project, grandchild.project)