Exemple #1
0
    def test_stores_integer_return_value_of_function_as_exitcode(self):
        def check_args():
            return 42

        task = Task(check_args)
        task.start()
        task.join()
        assert_that(task.exitcode, is_(42))
Exemple #2
0
    def test_sets_niceness(self):
        if os.nice(0) > 18:
            raise SkipTest(
                'This test can only be run with a niceness of 18 or lower.')

        def return_niceness():
            return os.nice(0)

        task = Task(return_niceness, niceness=1)
        task.start()
        task.join()
        assert_that(task.exitcode, is_(os.nice(0) + 1))
Exemple #3
0
    def test_start_passes_args_to_task(self):
        def check_args(one, two, key):
            if one == 1 and two == 2 and key == 3:
                return 0
            else:
                return -1

        task = Task(check_args, (1, 2), kwargs={'key': 3})
        task.start()
        task.join()
        assert_that(task.exitcode, described_as(
            'correct arguments were passed to function', is_(0)))
Exemple #4
0
 def test_handles_join_on_unstarted_and_terminated_task(self):
     task = Task(noop)
     task.terminate()
     task.join()
Exemple #5
0
 def test_handles_terminate_on_unstarted_task(self):
     task = Task(noop)
     task.terminate()
     assert_that(task.state, is_(State.FINISHED))
Exemple #6
0
 def test_state_after_exception_is_finished(self):
     task = Task(raise_exception)
     with patch('sys.stderr'):
         task.start()
         task.join()
     assert_that(task.state, is_(State.FINISHED))
Exemple #7
0
 def test_exitcode_after_exception_is_not_zero(self):
     task = Task(raise_exception)
     with patch('sys.stderr'):
         task.start()
         task.join()
     assert_that(task.exitcode, is_not(0))
Exemple #8
0
 def test_exitcode_set_after_process_finished(self):
     task = Task(noop)
     task.start()
     task.join()
     assert_that(task.exitcode, is_(0))
Exemple #9
0
 def test_start_sets_pid(self):
     task = Task(noop)
     task.start()
     assert_that(task.pid, is_(greater_than_or_equal_to(0)))