annotate python/testhexfile.py @ 237:81752b0f85a5

Added burn led test program
author Windel Bouwman
date Wed, 17 Jul 2013 22:31:54 +0200
parents d3dccf12ca88
children 58155c7c4a8e
rev   line source
233
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
1 import unittest
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
2 import io
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
3 import hexfile
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
4
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
5
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
6 class testHexFile(unittest.TestCase):
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
7 def setUp(self):
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
8 pass
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
9
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
10 def testSave(self):
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
11 hf = hexfile.HexFile()
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
12 f = io.StringIO()
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
13 region = hexfile.HexFileRegion(0x8000, bytes.fromhex('aabbcc'))
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
14 hf.regions.append(region)
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
15 hf.save(f)
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
16
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
17 def testLoad(self):
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
18 hf = hexfile.HexFile()
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
19 dummyhex = """
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
20 :01400000aa15
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
21 """
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
22 f = io.StringIO(dummyhex)
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
23 hf.load(f)
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
24
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
25 def testIncorrectCrc(self):
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
26 hf = hexfile.HexFile()
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
27 txt = ":01400000aabb"
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
28 f = io.StringIO(txt)
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
29 with self.assertRaises(hexfile.HexFileException):
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
30 hf.load(f)
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
31
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
32 def testIncorrectLength(self):
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
33 hf = hexfile.HexFile()
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
34 txt = ":0140002200aabb"
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
35 f = io.StringIO(txt)
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
36 with self.assertRaises(hexfile.HexFileException):
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
37 hf.load(f)
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
38
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
39 if __name__ == '__main__':
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
40 unittest.main()
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
41