view python/testhexfile.py @ 233:d3dccf12ca88

Added hexfile tests
author Windel Bouwman
date Sun, 14 Jul 2013 12:28:23 +0200
parents
children 58155c7c4a8e
line wrap: on
line source

import unittest
import io
import hexfile


class testHexFile(unittest.TestCase):
    def setUp(self):
        pass

    def testSave(self):
        hf = hexfile.HexFile()
        f = io.StringIO()
        region = hexfile.HexFileRegion(0x8000, bytes.fromhex('aabbcc'))
        hf.regions.append(region)
        hf.save(f)

    def testLoad(self):
        hf = hexfile.HexFile()
        dummyhex = """
        :01400000aa15
        """
        f = io.StringIO(dummyhex)
        hf.load(f)

    def testIncorrectCrc(self):
        hf = hexfile.HexFile()
        txt = ":01400000aabb"
        f = io.StringIO(txt)
        with self.assertRaises(hexfile.HexFileException):
            hf.load(f)

    def testIncorrectLength(self):
        hf = hexfile.HexFile()
        txt = ":0140002200aabb"
        f = io.StringIO(txt)
        with self.assertRaises(hexfile.HexFileException):
            hf.load(f)

if __name__ == '__main__':
    unittest.main()