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})
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')
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)
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')
def test_dispatch(self): x = message.BytesRead(90) x.dispatch(self.listener, 54) self.assertEquals(self.listener.calls, [('bytes-read', (90, 54), {})])