233
|
1 import unittest
|
|
2 import io
|
|
3 import hexfile
|
|
4
|
|
5
|
|
6 class testHexFile(unittest.TestCase):
|
|
7 def setUp(self):
|
|
8 pass
|
|
9
|
|
10 def testSave(self):
|
|
11 hf = hexfile.HexFile()
|
|
12 f = io.StringIO()
|
|
13 region = hexfile.HexFileRegion(0x8000, bytes.fromhex('aabbcc'))
|
|
14 hf.regions.append(region)
|
|
15 hf.save(f)
|
|
16
|
|
17 def testLoad(self):
|
|
18 hf = hexfile.HexFile()
|
|
19 dummyhex = """
|
|
20 :01400000aa15
|
|
21 """
|
|
22 f = io.StringIO(dummyhex)
|
|
23 hf.load(f)
|
|
24
|
|
25 def testIncorrectCrc(self):
|
|
26 hf = hexfile.HexFile()
|
|
27 txt = ":01400000aabb"
|
|
28 f = io.StringIO(txt)
|
|
29 with self.assertRaises(hexfile.HexFileException):
|
|
30 hf.load(f)
|
|
31
|
|
32 def testIncorrectLength(self):
|
|
33 hf = hexfile.HexFile()
|
|
34 txt = ":0140002200aabb"
|
|
35 f = io.StringIO(txt)
|
|
36 with self.assertRaises(hexfile.HexFileException):
|
|
37 hf.load(f)
|
|
38
|
|
39 if __name__ == '__main__':
|
|
40 unittest.main()
|
|
41
|