def test_data_after_eof(self): txt = """:00000001FF :04000001aabbccdded """ f = io.StringIO(txt) with self.assertRaisesRegex(HexFileException, 'after end of file'): HexFile.load(f)
def test_load(self): dummyhex = """ :01400000aa15 w00t """ f = io.StringIO(dummyhex) hf = HexFile.load(f) self.assertEqual(1, len(hf.regions)) self.assertEqual(0x4000, hf.regions[0].address) self.assertSequenceEqual(bytes.fromhex('aa'), hf.regions[0].data)
def test_incorrect_crc(self): txt = ":01400000aabb" f = io.StringIO(txt) with self.assertRaisesRegex(HexFileException, 'crc'): HexFile.load(f)
def save_load(self, hf): f = io.StringIO() hf.save(f) hf2 = HexFile.load(io.StringIO(f.getvalue())) self.assertEqual(hf, hf2)
def test_non_empty_eof(self): txt = ":04000001aabbccdded" f = io.StringIO(txt) with self.assertRaisesRegex(HexFileException, 'end of file not empty'): HexFile.load(f)
def test_startaddress(self): txt = ":04000005aabbccdde9" f = io.StringIO(txt) hf = HexFile.load(f) self.assertEqual(0xaabbccdd, hf.start_address)