Esempio n. 1
0
 def test_merge_tasks_no_matches(self):
     """
     Merging tasks when no tasks match returns an empty set of tasks.
     """
     tree = Tree()
     matches = tree.merge_tasks(
         [action_task, message_task], [lambda task: False])
     self.expectThat(list(matches), Equals([]))
Esempio n. 2
0
 def test_merge_tasks_no_matches(self):
     """
     Merging tasks when no tasks match returns an empty set of tasks.
     """
     tree = Tree()
     matches = tree.merge_tasks(
         [action_task, message_task], [lambda task: False])
     self.expectThat(list(matches), Equals([]))
Esempio n. 3
0
 def test_merge_startless_tasks(self):
     """
     Merging a task that will never have a start parent raises
     ``RuntimeError``.
     """
     tree = Tree()
     self.assertThat(
         lambda: tree.merge_tasks([action_task_end]),
         raises(RuntimeError))
Esempio n. 4
0
 def test_merge_nested_tasks(self):
     """
     Merge nested tasks into the tree and retrieve an list of key-node
     pairs ordered by task timestamp.
     """
     tree = Tree()
     matches = tree.merge_tasks([action_task_end, action_task])
     self.expectThat(matches, Is(None))
     keys, nodes = zip(*tree.nodes())
     self.expectThat(
         list(keys),
         Equals(['f3a32bb3-ea6b-457c-aa99-08a3d0491ab4']))
     self.assertThat(
         list(_flattened_tasks(nodes)),
         MatchesListwise([Equals(action_task),
                          Equals(action_task_end)]))
Esempio n. 5
0
 def test_merge_nested_tasks(self):
     """
     Merge nested tasks into the tree and retrieve an list of key-node
     pairs ordered by task timestamp.
     """
     tree = Tree()
     matches = tree.merge_tasks([action_task_end, action_task])
     self.expectThat(matches, Is(None))
     keys, nodes = zip(*tree.nodes())
     self.expectThat(
         list(keys),
         Equals(['f3a32bb3-ea6b-457c-aa99-08a3d0491ab4']))
     self.assertThat(
         list(_flattened_tasks(nodes)),
         MatchesListwise([Equals(action_task),
                          Equals(action_task_end)]))
Esempio n. 6
0
 def test_merge_startless_tasks(self):
     """
     Merging a task that will never have a start parent creates a fake start
     task.
     """
     tree = Tree()
     missing_task = missing_start_task(action_task_end)
     matches = tree.merge_tasks([action_task_end])
     self.expectThat(matches, Is(None))
     keys, nodes = zip(*tree.nodes())
     self.expectThat(
         list(keys),
         Equals(['f3a32bb3-ea6b-457c-aa99-08a3d0491ab4']))
     self.assertThat(
         list(_flattened_tasks(nodes)),
         MatchesListwise([Equals(missing_task),
                          Equals(action_task_end)]))
Esempio n. 7
0
 def test_merge_tasks(self):
     """
     Merge tasks into the tree and retrieve an list of key-node
     pairs ordered by task timestamp.
     """
     tree = Tree()
     matches = tree.merge_tasks([message_task, action_task])
     self.expectThat(matches, Is(None))
     keys, nodes = zip(*tree.nodes())
     self.expectThat(
         list(keys),
         Equals(['cdeb220d-7605-4d5f-8341-1a170222e308',
                 'f3a32bb3-ea6b-457c-aa99-08a3d0491ab4']))
     self.assertThat(
         list(_flattened_tasks(nodes)),
         MatchesListwise([Equals(message_task),
                          Equals(action_task)]))
Esempio n. 8
0
 def test_merge_tasks(self):
     """
     Merge tasks into the tree and retrieve an list of key-node
     pairs ordered by task timestamp.
     """
     tree = Tree()
     matches = tree.merge_tasks([message_task, action_task])
     self.expectThat(matches, Is(None))
     keys, nodes = zip(*tree.nodes())
     self.expectThat(
         list(keys),
         Equals(['cdeb220d-7605-4d5f-8341-1a170222e308',
                 'f3a32bb3-ea6b-457c-aa99-08a3d0491ab4']))
     self.assertThat(
         list(_flattened_tasks(nodes)),
         MatchesListwise([Equals(message_task),
                          Equals(action_task)]))
Esempio n. 9
0
 def test_merge_startless_tasks(self):
     """
     Merging a task that will never have a start parent creates a fake start
     task.
     """
     tree = Tree()
     missing_task = missing_start_task(action_task_end)
     matches = tree.merge_tasks([action_task_end])
     self.expectThat(matches, Is(None))
     keys, nodes = zip(*tree.nodes())
     self.expectThat(
         list(keys),
         Equals(['f3a32bb3-ea6b-457c-aa99-08a3d0491ab4']))
     self.assertThat(
         list(_flattened_tasks(nodes)),
         MatchesListwise([Equals(missing_task),
                          Equals(action_task_end)]))
Esempio n. 10
0
 def test_merge_tasks_filtered(self):
     """
     Merge tasks into the tree with a filter function, generating a set of
     matches that can be used to prune the tree.
     """
     tree = Tree()
     filters = [lambda task: task.get(u'action_type') == u'app:action']
     matches = tree.merge_tasks([action_task, message_task], filters)
     keys, nodes = zip(*tree.nodes(matches))
     self.expectThat(
         list(keys),
         Equals(['f3a32bb3-ea6b-457c-aa99-08a3d0491ab4']))
     self.expectThat(
         list(keys),
         Equals(list(matches)))
     self.assertThat(
         [c.task for n in nodes for c in n.children()],
         MatchesListwise([Equals(action_task)]))
Esempio n. 11
0
    def test_merge_tasks_filtered(self):
        """
        Merge tasks into the tree with a filter function, generating a set of
        matches that can be used to prune the tree.
        """
        tree = Tree()
        filters = [lambda task: task.get(u'action_type') == u'app:action']
        matches = tree.merge_tasks([action_task, message_task], filters)
        keys, nodes = zip(*tree.nodes(matches))
        self.expectThat(
            list(keys),
            Equals(['f3a32bb3-ea6b-457c-aa99-08a3d0491ab4']))
        self.expectThat(
            list(keys),
            Equals(list(matches)))

        self.assertThat(
            list(_flattened_tasks(nodes)),
            MatchesListwise([Equals(action_task)]))
Esempio n. 12
0
 def test_initial(self):
     """
     The initial state of a tree is always empty.
     """
     tree = Tree()
     self.assertThat(tree.nodes(), Equals([]))
Esempio n. 13
0
 def test_initial(self):
     """
     The initial state of a tree is always empty.
     """
     tree = Tree()
     self.assertThat(tree.nodes(), Equals([]))