Пример #1
0
    def test_stop_sets_stopped_to_true(self):
        """Tests that stop() sets the _stopped attribute to True."""
        process = Process('cmd')
        process._process = mock.Mock()

        process.stop()

        self.assertTrue(process._stopped)
Пример #2
0
    def test_stop_calls_wait(self):
        """Tests that stop() also has the functionality of wait()."""
        process = Process('cmd')
        process._process = mock.Mock()
        process.wait = mock.Mock()

        process.stop()

        self.assertEqual(process.wait.called, True)
Пример #3
0
    def test_stop_sets_stopped_to_true_before_process_kill(self):
        """Tests that stop() sets the _stopped attribute to True.

        This order is required to prevent the _exec_loop from calling
        _on_terminate_callback when the user has killed the process.
        """
        verifier = mock.Mock()
        verifier.passed = False

        def test_call_order():
            self.assertTrue(process._stopped)
            verifier.passed = True

        process = Process('cmd')
        process._process = mock.Mock()
        process._process.poll.return_value = None
        process._kill_process = test_call_order
        process._process.wait.side_effect = subprocess.TimeoutExpired('', '')

        process.stop()

        self.assertEqual(verifier.passed, True)