view 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
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()