view python/testhexfile.py @ 242:c94965418684

Added tag burnchain for changeset ce6d390043a7
author Windel Bouwman
date Mon, 22 Jul 2013 22:56:51 +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()