Esempio n. 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)
Esempio n. 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, '')
Esempio n. 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'])
Esempio n. 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, '')
Esempio n. 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'
        ])
Esempio 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, '')
Esempio n. 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, '')
Esempio n. 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')
Esempio n. 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, '')
Esempio n. 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']))
Esempio n. 11
0
    def test_recv_recvbuf_empty_closed(self):
        self.stub_recvbuf_pop()

        conn = simplerpc.Connection(None)

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

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