示例#1
0
    def test_start_child(self, run, fork):
        fork.return_value = 0
        p = Process(Mock())

        # test
        p.start()

        # validation
        fork.assert_called_once_with()
        run.assert_called_once_with()
示例#2
0
文件: test_mp.py 项目: jortel/gofer
    def test_start_child(self, run, fork):
        fork.return_value = 0
        p = Process(Mock())

        # test
        p.start()

        # validation
        fork.assert_called_once_with()
        run.assert_called_once_with()
示例#3
0
文件: test_mp.py 项目: jortel/gofer
    def test_run(self):
        main = Mock()
        args = (1, 2)
        kwargs = {'a': 3, 'b': 4}

        # test
        p = Process(main, *args, **kwargs)
        p.run()

        # validation
        p.main.assert_called_once_with(*args, **kwargs)
示例#4
0
文件: test_mp.py 项目: jortel/gofer
    def test_start_parent(self, run, fork):
        fork.return_value = 1234
        p = Process(Mock())

        # test
        p.start()

        # validation
        fork.assert_called_once_with()
        self.assertFalse(run.called)
        self.assertEqual(p.pid, fork.return_value)
示例#5
0
    def test_run(self):
        main = Mock()
        args = (1, 2)
        kwargs = {'a': 3, 'b': 4}

        # test
        p = Process(main, *args, **kwargs)
        p.run()

        # validation
        p.main.assert_called_once_with(*args, **kwargs)
示例#6
0
    def test_start_parent(self, run, fork):
        fork.return_value = 1234
        p = Process(Mock())

        # test
        p.start()

        # validation
        fork.assert_called_once_with()
        self.assertFalse(run.called)
        self.assertEqual(p.pid, fork.return_value)
示例#7
0
    def test_init(self):
        main = Mock()
        args = (1, 2)
        kwargs = {'a': 3, 'b': 4}

        # test
        p = Process(main, *args, **kwargs)

        # validation
        self.assertEqual(p.main, main)
        self.assertEqual(p.args, (1, 2))
        self.assertEqual(p.kwargs, {'a': 3, 'b': 4})
示例#8
0
文件: parent.py 项目: swipswaps/gofer
 def __call__(self):
     """
     Invoke the RMI as follows:
       - Fork
       - Start the monitor.
       - Read and dispatch reply messages.
     :return: Whatever method returned.
     """
     pipe = Pipe()
     target = Target(self.method, *self.args, **self.kwargs)
     child = Process(target, pipe)
     monitor = Monitor(Context.current(), child)
     try:
         child.start()
         monitor.start()
         pipe.writer.close()
         retval = self.read(pipe.reader)
         return retval
     finally:
         pipe.close()
         monitor.stop()
         child.wait()
示例#9
0
文件: test_mp.py 项目: jortel/gofer
 def test_terminate(self, kill):
     p = Process(Mock())
     p.pid = 1234
     p.terminate()
     kill.assert_called_once_with(p.pid, 9)
示例#10
0
文件: test_mp.py 项目: jortel/gofer
 def test_wait_error(self, wait):
     wait.side_effect = OSError()
     p = Process(Mock())
     p.wait()
     wait.assert_called_once_with(p.pid, 0)
示例#11
0
文件: test_mp.py 项目: jortel/gofer
 def test_wait(self, wait):
     p = Process(Mock())
     p.wait()
     wait.assert_called_once_with(p.pid, 0)
示例#12
0
文件: test_mp.py 项目: jortel/gofer
 def test_terminate_not_forked(self, kill):
     p = Process(Mock())
     p.terminate()
     self.assertFalse(kill.called)
示例#13
0
 def test_wait(self, wait):
     p = Process(Mock())
     p.wait()
     wait.assert_called_once_with(p.pid, 0)
示例#14
0
 def test_terminate_not_forked(self, kill):
     p = Process(Mock())
     p.terminate()
     self.assertFalse(kill.called)
示例#15
0
 def test_terminate(self, kill):
     p = Process(Mock())
     p.pid = 1234
     p.terminate()
     kill.assert_called_once_with(p.pid, 9)
示例#16
0
 def test_wait_error(self, wait):
     wait.side_effect = OSError()
     p = Process(Mock())
     p.wait()
     wait.assert_called_once_with(p.pid, 0)