예제 #1
0
    def test_send_error(self):
        sock = FakeSocket()
        sock.close()  # Make it raise an error
        conn = simplerpc.Connection(sock)

        self.assertRaises(socket.error, conn.send, 'FOO', 'Nobody', 'inspects',
                          'the', 'spammish', 'repetition')
        self.assertEqual(conn._sock, None)
예제 #2
0
    def test_recv_closed(self):
        self.stub_recvbuf_pop()

        sock = FakeSocket('foo')
        conn = simplerpc.Connection(sock)

        self.assertRaises(simplerpc.ConnectionClosed, conn.recv)
        self.assertEqual(conn._sock, None)
        self.assertEqual(conn._recvbuf, [])
        self.assertEqual(conn._recvbuf_partial, '')
예제 #3
0
    def test_recv_recvbuf_filled(self):
        self.stub_recvbuf_pop()

        conn = simplerpc.Connection(None)
        conn._recvbuf = ['foo', 'bar']

        result = conn.recv()

        self.assertEqual(result, 'foo')
        self.assertEqual(conn._recvbuf, ['bar'])
예제 #4
0
    def test_close_double(self):
        conn = simplerpc.Connection(None)
        conn._recvbuf.append('foo')
        conn._recvbuf_partial = 'bar'

        conn.close()

        self.assertEqual(conn._sock, None)
        self.assertEqual(conn._recvbuf, [])
        self.assertEqual(conn._recvbuf_partial, '')
예제 #5
0
    def test_send_open(self):
        sock = FakeSocket()
        conn = simplerpc.Connection(sock)

        conn.send('FOO', 'Nobody', 'inspects', 'the', 'spammish', 'repetition')

        self.assertEqual(sock._send_data, [
            '{"cmd": "FOO", "payload": ["Nobody", "inspects", "the", '
            '"spammish", "repetition"]}\n'
        ])
예제 #6
0
    def test_recv_error(self):
        self.stub_recvbuf_pop()

        sock = FakeSocket()
        sock.close()  # Make it raise an error
        conn = simplerpc.Connection(sock)

        self.assertRaises(socket.error, conn.recv)
        self.assertEqual(conn._sock, None)
        self.assertEqual(conn._recvbuf, [])
        self.assertEqual(conn._recvbuf_partial, '')
예제 #7
0
    def test_recv_longmsg(self):
        self.stub_recvbuf_pop()

        sock = FakeSocket('foo', 'bar', 'baz\n')
        conn = simplerpc.Connection(sock)

        result = conn.recv()

        self.assertEqual(result, 'foobarbaz')
        self.assertEqual(conn._sock, sock)
        self.assertEqual(conn._recvbuf, [])
        self.assertEqual(conn._recvbuf_partial, '')
예제 #8
0
    def test_recv_onemsg_onepartial(self):
        self.stub_recvbuf_pop()

        sock = FakeSocket('bar\nfoo')
        conn = simplerpc.Connection(sock)

        result = conn.recv()

        self.assertEqual(result, 'bar')
        self.assertEqual(conn._sock, sock)
        self.assertEqual(conn._recvbuf, [])
        self.assertEqual(conn._recvbuf_partial, 'foo')
예제 #9
0
    def test_close(self):
        sock = FakeSocket()
        conn = simplerpc.Connection(sock)
        conn._recvbuf.append('foo')
        conn._recvbuf_partial = 'bar'

        conn.close()

        self.assertTrue(sock._closed)
        self.assertEqual(conn._sock, None)
        self.assertEqual(conn._recvbuf, [])
        self.assertEqual(conn._recvbuf_partial, '')
예제 #10
0
    def test_recvbuf_pop_msg(self):
        conn = simplerpc.Connection(None)
        conn._recvbuf.append(
            dict(cmd='FOO',
                 payload=[
                     'Nobody', 'inspects', 'the', 'spammish', 'repetition'
                 ]))
        result = conn._recvbuf_pop()

        self.assertEqual(
            result,
            ('FOO', ['Nobody', 'inspects', 'the', 'spammish', 'repetition']))
예제 #11
0
    def test_recv_recvbuf_empty_closed(self):
        self.stub_recvbuf_pop()

        conn = simplerpc.Connection(None)

        self.assertRaises(simplerpc.ConnectionClosed, conn.recv)
예제 #12
0
 def test_recvbuf_pop_exc(self):
     conn = simplerpc.Connection(None)
     conn._recvbuf.append(Exception())
     self.assertRaises(Exception, conn._recvbuf_pop)
예제 #13
0
    def test_send_closed(self):
        conn = simplerpc.Connection(None)

        self.assertRaises(simplerpc.ConnectionClosed, conn.send, 'FOO',
                          'Nobody', 'inspects', 'the', 'spammish',
                          'repetition')