Example #1
0
 def test_autobind_non_existent_event(self, mocked_exception):
     event = "test-event"
     handler = lambda: None
     task = MyTask()
     with task.autobind(event, handler):
         self.assertEqual(len(task._events_listeners), 0)
         mocked_exception.assert_called_once_with(mock.ANY, handler, event, task)
Example #2
0
 def test_autobind_non_existent_event(self, mocked_exception):
     event = 'test-event'
     handler = lambda: None
     task = MyTask()
     with task.autobind(event, handler):
         self.assertEqual(len(task._events_listeners), 0)
         mocked_exception.assert_called_once_with(mock.ANY, handler, event,
                                                  task)
Example #3
0
    def test_update_progress_handler_failure(self, mocked_exception):
        def progress_callback(*args, **kwargs):
            raise Exception("Woot!")

        task = ProgressTask()
        with task.autobind("update_progress", progress_callback):
            task.execute([0.5])
        mocked_exception.assert_called_once_with(
            mock.ANY, reflection.get_callable_name(progress_callback), "update_progress"
        )
Example #4
0
    def test_update_progress_handler_failure(self, mocked_exception):
        def progress_callback(*args, **kwargs):
            raise Exception('Woot!')

        task = ProgressTask()
        with task.autobind('update_progress', progress_callback):
            task.execute([0.5])
        mocked_exception.assert_called_once_with(
            mock.ANY, reflection.get_callable_name(progress_callback),
            'update_progress')
Example #5
0
    def test_update_progress_upper_bound(self, mocked_warn):
        result = []

        def progress_callback(task, event_data, progress):
            result.append(progress)

        task = ProgressTask()
        with task.autobind("update_progress", progress_callback):
            task.execute([1.0, 1.5, 2.0])
        self.assertEqual(result, [1.0, 1.0, 1.0])
        self.assertEqual(mocked_warn.call_count, 2)
Example #6
0
    def test_update_progress_within_bounds(self):
        values = [0.0, 0.5, 1.0]
        result = []

        def progress_callback(task, event_data, progress):
            result.append(progress)

        task = ProgressTask()
        with task.autobind("update_progress", progress_callback):
            task.execute(values)
        self.assertEqual(result, values)
Example #7
0
    def test_update_progress_upper_bound(self, mocked_warn):
        result = []

        def progress_callback(task, event_data, progress):
            result.append(progress)

        task = ProgressTask()
        with task.autobind('update_progress', progress_callback):
            task.execute([1.0, 1.5, 2.0])
        self.assertEqual(result, [1.0, 1.0, 1.0])
        self.assertEqual(mocked_warn.call_count, 2)
Example #8
0
    def test_update_progress_within_bounds(self):
        values = [0.0, 0.5, 1.0]
        result = []

        def progress_callback(task, event_data, progress):
            result.append(progress)

        task = ProgressTask()
        with task.autobind('update_progress', progress_callback):
            task.execute(values)
        self.assertEqual(result, values)
Example #9
0
 def test_autobind_handler_is_none(self):
     task = MyTask()
     with task.autobind("update_progress", None):
         self.assertEqual(len(task._events_listeners), 0)
Example #10
0
 def test_autobind_handler_is_none(self):
     task = MyTask()
     with task.autobind('update_progress', None):
         self.assertEqual(len(task._events_listeners), 0)