Example #1
0
 def test_write_read(self):
     thing = Thing()
     p = Pipe()
     p.put(thing)
     read = p.reader.get()
     p.close()
     self.assertEqual(read, thing)
Example #2
0
 def test_multiple_write_read(self):
     things = [
         Thing(),
         Thing(),
         Thing()
     ]
     p = Pipe()
     for t in things:
         p.put(t)
     read = []
     for _ in things:
         read.append(p.reader.get())
     p.close()
     self.assertEqual(read, things)
Example #3
0
    def test_call_pipe_broken(self):
        def method():
            pass

        pipe = Pipe()
        call = Call(method)
        call(pipe)
Example #4
0
 def test_init(self, _open):
     _open.return_value = Reader(0), Writer(1)
     p = Pipe()
     self.assertTrue(isinstance(p.reader, Reader))
     self.assertTrue(isinstance(p.writer, Writer))
     self.assertEqual(p.reader.fd, 0)
     self.assertEqual(p.writer.fd, 1)
Example #5
0
    def test_call_exception(self):
        method = Mock(side_effect=ValueError)
        pipe = Pipe()
        pipe.reader.close = Mock()
        call = Call(method)

        # test
        call(pipe)
        reply = protocol.Reply.read(pipe.reader)

        # validation
        self.assertEqual(reply.code, protocol.Raised.CODE)
Example #6
0
 def test_write_read(self):
     thing = Thing()
     p = Pipe()
     p.put(thing)
     read = p.reader.get()
     p.close()
     self.assertEqual(read, thing)
Example #7
0
 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()
Example #8
0
 def test_multiple_write_read(self):
     things = [Thing(), Thing(), Thing()]
     p = Pipe()
     for t in things:
         p.put(t)
     read = []
     for _ in things:
         read.append(p.reader.get())
     p.close()
     self.assertEqual(read, things)
Example #9
0
    def test_report(self):
        pipe = Pipe()
        p = Progress(pipe.writer)
        p.total = 1
        p.completed = 2
        p.details = 'hello'

        # test
        p.report()

        # validation
        reply = protocol.Reply.read(pipe.reader)
        self.assertEqual(reply.code, protocol.Progress.CODE)
        self.assertEqual(reply.payload.total, p.total)
        self.assertEqual(reply.payload.completed, p.completed)
        self.assertEqual(reply.payload.details, p.details)
Example #10
0
    def test_call(self, context, monitor):
        method = Mock(return_value=18)
        pipe = Pipe()
        pipe.reader.close = Mock()
        call = Call(method, 1, 2, a=1, b=2)

        # test
        call(pipe)

        # validation
        pipe.reader.close.assert_called_once_with()
        monitor.assert_called_once_with(pipe.writer)
        monitor.return_value.start.assert_called_once_with()
        reply = protocol.Reply.read(pipe.reader)
        self.assertTrue(isinstance(context.return_value.progress, Progress))
        self.assertEqual(reply.code, protocol.Result.CODE)
        self.assertEqual(reply.payload, method.return_value)
Example #11
0
 def test_eof(self):
     p = Pipe()
     p.writer.close()
     self.assertRaises(EOFError, p.reader.get)
     p.close()
Example #12
0
 def test_poll(self, _open):
     _open.return_value = Mock(), Mock()
     p = Pipe()
     p.poll()
     _open.return_value[0].poll.assert_called_once_with()
Example #13
0
 def test_close(self, _open):
     _open.return_value = Mock(), Mock()
     p = Pipe()
     p.close()
     _open.return_value[0].close.assert_called_once_with()
     _open.return_value[1].close.assert_called_once_with()
Example #14
0
 def test_enter(self, _open):
     _open.return_value = Mock(), Mock()
     p = Pipe()
     self.assertEqual(p.__enter__(), p)
Example #15
0
 def test_exit(self, _open, close):
     _open.return_value = Mock(), Mock()
     p = Pipe()
     p.__exit__()
     close.assert_called_once_with()
Example #16
0
 def test_get(self, _open):
     _open.return_value = Mock(), Mock()
     p = Pipe()
     thing = p.get()
     _open.return_value[0].get.assert_called_once_with()
     self.assertEqual(thing, _open.return_value[0].get.return_value)
Example #17
0
 def test_put(self, _open):
     _open.return_value = Mock(), Mock()
     thing = Thing()
     p = Pipe()
     p.put(thing)
     _open.return_value[1].put.assert_called_once_with(thing)
Example #18
0
 def test_close(self, _open):
     _open.return_value = Mock(), Mock()
     p = Pipe()
     p.close()
     _open.return_value[0].close.assert_called_once_with()
     _open.return_value[1].close.assert_called_once_with()
Example #19
0
 def test_poll(self, _open):
     _open.return_value = Mock(), Mock()
     p = Pipe()
     p.poll()
     _open.return_value[0].poll.assert_called_once_with()
Example #20
0
 def test_get(self, _open):
     _open.return_value = Mock(), Mock()
     p = Pipe()
     thing = p.get()
     _open.return_value[0].get.assert_called_once_with()
     self.assertEqual(thing, _open.return_value[0].get.return_value)
Example #21
0
 def test_open(self, pipe):
     pipe.return_value = 0, 1
     reader, writer = Pipe._open()
     self.assertEqual(reader.fd, 0)
     self.assertEqual(writer.fd, 1)
Example #22
0
 def test_put(self, _open):
     _open.return_value = Mock(), Mock()
     thing = Thing()
     p = Pipe()
     p.put(thing)
     _open.return_value[1].put.assert_called_once_with(thing)
Example #23
0
 def test_open(self, pipe):
     pipe.return_value = 0, 1
     reader, writer = Pipe._open()
     self.assertEqual(reader.fd, 0)
     self.assertEqual(writer.fd, 1)
Example #24
0
 def test_enter(self, _open):
     _open.return_value = Mock(), Mock()
     p = Pipe()
     self.assertEqual(p.__enter__(), p)
Example #25
0
 def test_eof(self):
     p = Pipe()
     p.writer.close()
     self.assertRaises(EOFError, p.reader.get)
     p.close()
Example #26
0
 def test_exit(self, _open, close):
     _open.return_value = Mock(), Mock()
     p = Pipe()
     p.__exit__()
     close.assert_called_once_with()