def test_write_int_array(self): writer = tools.BinaryWriter(self.tmp_file.name, endian='=') values = [2, 4, 6, 8, 10] writer.write('i', values, length=len(values)) del writer reader = tools.BinaryReader(self.tmp_file.name, endian='=') self.assertEqual(values, reader.read('i', length=len(values)))
def test_write_single_values(self): writer = tools.BinaryWriter(self.tmp_file.name, endian='=') writer.write('i', 42) writer.write('h', 33) writer.write('c', 'a') del writer reader = tools.BinaryReader(self.tmp_file.name, endian='=') self.assertEqual([42], reader.read('i', 1, 0)) self.assertEqual([33], reader.read('h', 1, 4)) self.assertEqual(['a'], reader.read('c', 1, 6))
def test_printf_continuous(self): fmts = [['i', 1, 0, 'Int32Bits'], ['h', 1, 4, 'Int16Bits'], ['c', 1, 6, 'Character']] values = (42, 33, 'a') writer = tools.BinaryWriter(self.tmp_file.name, endian='=') writer.printf(fmts, values) del writer reader = tools.BinaryReader(self.tmp_file.name, endian='=') r = reader.scan(fmts) self.assertEqual(r['Int32Bits'], 42) self.assertEqual(r['Int16Bits'], 33) self.assertEqual(r['Character'], 'a')