def _test_write(self, skool, base_address, exp_data, exp_err=None, asm_mode=0, fix_mode=0, start=None, end=None): if skool is None: skoolfile = '-' binfile = self.write_bin_file(suffix='.bin') else: skoolfile = self.write_text_file(skool, suffix='.skool') binfile = skoolfile[:-6] + '.bin' self.tempfiles.append(binfile) bin_writer = skool2bin.BinWriter(skoolfile, asm_mode, fix_mode) bin_writer.write(binfile, start, end) with open(binfile, 'rb') as f: data = list(f.read()) self.assertEqual(exp_data, data) size = len(data) stderr = self.to_lines(self.err.getvalue(), True) if exp_err: self.assertEqual(exp_err, stderr[:-1]) self.assertEqual( stderr[-1], "Wrote {}: start={}, end={}, size={}".format( binfile, base_address, base_address + size, size))
def test_binary_file_to_stdout(self): skoolfile = self.write_text_file('t30000 DEFM "abc"', suffix='.skool') bin_writer = skool2bin.BinWriter(skoolfile) bin_writer.write('-', None, None) self.assertEqual(self.out.getvalue(), b'abc') self.assertEqual(self.err.getvalue(), "Wrote stdout: start=30000, end=30003, size=3\n")
def _test_write(self, skool, base_address, exp_data, asm_mode=0, fix_mode=0, start=None, end=None): if skool is None: skoolfile = '-' binfile = self.write_bin_file(suffix='.bin') else: skoolfile = self.write_text_file(dedent(skool).strip(), suffix='.skool') binfile = skoolfile[:-6] + '.bin' self.tempfiles.append(binfile) bin_writer = skool2bin.BinWriter(skoolfile, asm_mode, fix_mode) bin_writer.write(binfile, start, end) with open(binfile, 'rb') as f: data = list(f.read()) self.assertEqual(exp_data, data) size = len(data) status = "Wrote {}: start={}, end={}, size={}\n".format( binfile, base_address, base_address + size, size) self.assertEqual(status, self.err.getvalue()) self.err.clear()