コード例 #1
0
    def test_create(self):
        x = message.BytesRead()
        self.assertEquals(x.__dict__, {'bytes': None})

        x = message.BytesRead(10)
        self.assertEquals(x.__dict__, {'bytes': 10})

        x = message.BytesRead(bytes=20)
        self.assertEquals(x.__dict__, {'bytes': 20})
コード例 #2
0
    def test_encode(self):
        # test default encode
        x = message.BytesRead()
        e = self.assertRaises(message.EncodeError, x.encode, self.buffer)
        #self.assertEquals(str(e), 'Bytes read not set')

        # test non-int encode
        x = message.BytesRead(bytes='foo.bar')
        e = self.assertRaises(message.EncodeError, x.encode, self.buffer)
        #self.assertEquals(str(e), 'Bytes read wrong type '
        #    '(expected int, got <type \'str\'>)')

        x = message.BytesRead(bytes=50)
        e = x.encode(self.buffer)

        self.assertEquals(e, None)

        self.assertEquals(self.buffer.getvalue(), '\x00\x00\x00\x32')
コード例 #3
0
    def test_decode(self):
        x = message.BytesRead()

        self.assertEquals(x.bytes, None)
        self.buffer.write('\x00\x00\x00\x32')
        self.buffer.seek(0)

        e = x.decode(self.buffer)

        self.assertEquals(e, None)
        self.assertEquals(x.bytes, 50)
コード例 #4
0
    def test_4GB_threshold(self):
        """
        Test wrapping when encoding byte values > 4GB.

        @see: #54
        """
        x = message.BytesRead(bytes=message.BytesRead.FOUR_GB_THRESHOLD)

        x.encode(self.buffer)

        self.assertEqual(self.buffer.getvalue(), '\x00\x00\x00\x00')
コード例 #5
0
    def test_dispatch(self):
        x = message.BytesRead(90)

        x.dispatch(self.listener, 54)

        self.assertEquals(self.listener.calls, [('bytes-read', (90, 54), {})])