コード例 #1
0
ファイル: test_tasks.py プロジェクト: scarsman/alligator
    def test_run_failed(self):
        def start(t):
            t.started = True

        def error(t, err):
            t.err_msg = str(err)

        def success(t, result):
            t.success_result = result

        def fail_task(inital, incr_by=1):
            raise IOError('Math is hard.')

        task = Task(on_start=start, on_success=success, on_error=error)

        # Should fail.
        task.to_call(fail_task, 2)

        try:
            task.run()
        except IOError:
            pass

        self.assertTrue(task.started)
        self.assertEqual(task.err_msg, 'Math is hard.')
コード例 #2
0
    def test_run_failed(self):
        def start(t):
            t.started = True

        def error(t, err):
            t.err_msg = str(err)

        def success(t, result):
            t.success_result = result

        def fail_task(inital, incr_by=1):
            raise IOError('Math is hard.')

        task = Task(
            on_start=start,
            on_success=success,
            on_error=error
        )

        # Should fail.
        task.to_call(fail_task, 2)

        try:
            task.run()
        except IOError:
            pass

        self.assertTrue(task.started)
        self.assertEqual(task.err_msg, 'Math is hard.')
コード例 #3
0
    def test_run_success(self):
        def start(t):
            t.started = True

        def error(t, err):
            t.err_msg = str(err)

        def success(t, result):
            t.success_result = result

        def success_task(initial, incr_by=1):
            return initial + incr_by

        task = Task(
            on_start=start,
            on_success=success,
            on_error=error
        )

        # Should succeed.
        task.to_call(success_task, 12, 3)
        result = task.run()
        self.assertEqual(result, 15)
        self.assertTrue(task.started)
        self.assertEqual(task.success_result, 15)
コード例 #4
0
ファイル: test_tasks.py プロジェクト: scarsman/alligator
    def test_run_success(self):
        def start(t):
            t.started = True

        def error(t, err):
            t.err_msg = str(err)

        def success(t, result):
            t.success_result = result

        def success_task(initial, incr_by=1):
            return initial + incr_by

        task = Task(on_start=start, on_success=success, on_error=error)

        # Should succeed.
        task.to_call(success_task, 12, 3)
        result = task.run()
        self.assertEqual(result, 15)
        self.assertTrue(task.started)
        self.assertEqual(task.success_result, 15)