def test_read_le_16(self): data = byteify("A Teststring", "utf-8") buf = BytesIO(data) rw = rwops.rw_from_object(buf) self.assertIsInstance(rw, rwops.SDL_RWops) ch = rwops.read_le_16(rw) self.assertEqual(chr(ch & 0x00FF), "A") self.assertEqual(chr(ch >> 8), " ") pos = rwops.rw_seek(rw, 8, rwops.RW_SEEK_SET) self.assertEqual(pos, 8) ch = rwops.read_le_16(rw) self.assertEqual(chr(ch & 0x00FF), "r") self.assertEqual(chr(ch >> 8), "i")
def test_rw_from_file(self): rw = rwops.rw_from_file(self.testfile, "r") self.assertIsInstance(rw, rwops.SDL_RWops) # Read the first 42 bytes(sic!). It should be: # 'This is a test file for pygame2.sdl.rwops!' length = 42 buf = BytesIO() while length >= 2: # Reading in two bytes - we have plain text(1-byte encoding), so # we read in 2 characters at a time. This means that the first # character is always stored in the lo byte. ch = rwops.read_le_16(rw) buf.write(byteify(chr(ch & 0x00FF), "utf-8")) buf.write(byteify(chr(ch >> 8), "utf-8")) length -= 2 self.assertEqual(stringify(buf.getvalue(), "utf-8"), "This is a test file for pygame2.sdl.rwops!")