def testString2(self): b = Buffer(1024) self.assertEqual(0, b.position) self.assertEqual(1024, b.limit) self.assertEqual('\0' * 10, b.read_bytes(10)) b.clear() b.flip() #try read string past limit try: b.read_bytes(10) self.fail("expected buffer underflow") except BufferUnderflowError: pass #expected
def testBytes(self): #test that we can write all bytes into buffer #and get them back without any encoding/decoding stuff going on #a string with all possible bytes B = ''.join([chr(i) for i in range(256)]) b = Buffer(1024) b.write_bytes(B) b.flip() self.assertEqual(256, b.limit) x = b.read_bytes(256) self.assertEquals(B, x)