@@ -1659,6 +1659,77 @@ def test_sripts_hexdiff_version(self):
16591659 def test_sripts_hexmerge_version (self ):
16601660 self .versionChecker ('%s scripts/hexmerge.py --version' )
16611661
1662+
1663+ class TestWriteHexFileByteCount (unittest .TestCase ):
1664+
1665+ def setUp (self ):
1666+ self .f = StringIO (hex8 )
1667+
1668+ def tearDown (self ):
1669+ self .f .close ()
1670+ del self .f
1671+
1672+ def test_write_hex_file_bad_byte_count (self ):
1673+ ih = intelhex .IntelHex (self .f )
1674+ sio = StringIO ()
1675+ with self .assertRaises (ValueError ):
1676+ ih .write_hex_file (sio , byte_count = 0 )
1677+ with self .assertRaises (ValueError ):
1678+ ih .write_hex_file (sio , byte_count = - 1 )
1679+ with self .assertRaises (ValueError ):
1680+ ih .write_hex_file (sio , byte_count = 256 )
1681+
1682+ def test_write_hex_file_byte_count_1 (self ):
1683+ ih = intelhex .IntelHex (self .f )
1684+ sio = StringIO ()
1685+ ih .write_hex_file (sio , byte_count = 1 )
1686+ s = sio .getvalue ()
1687+ # control written hex first line to check that byte count is 1
1688+ sio .seek (0 )
1689+ self .assertEqual (sio .readline (), ':0100000002FD\n ' ,
1690+ "Written hex is not in byte count 1" )
1691+ sio .close ()
1692+
1693+ fin = StringIO (s )
1694+ ih2 = intelhex .IntelHex (fin )
1695+
1696+ self .assertEqual (ih .tobinstr (), ih2 .tobinstr (),
1697+ "Written hex file does not equal with original" )
1698+
1699+ def test_write_hex_file_byte_count_13 (self ):
1700+ ih = intelhex .IntelHex (self .f )
1701+ sio = StringIO ()
1702+ ih .write_hex_file (sio , byte_count = 13 )
1703+ s = sio .getvalue ()
1704+ # control written hex first line to check that byte count is 13
1705+ sio .seek (0 )
1706+ self .assertEqual (sio .readline (), ':0D0000000205A2E576246AF8E6057622786E\n ' ,
1707+ "Written hex is not in byte count 1" )
1708+ sio .close ()
1709+
1710+ fin = StringIO (s )
1711+ ih2 = intelhex .IntelHex (fin )
1712+
1713+ self .assertEqual (ih .tobinstr (), ih2 .tobinstr (),
1714+ "Written hex file does not equal with original" )
1715+
1716+ def test_write_hex_file_byte_count_255 (self ):
1717+ ih = intelhex .IntelHex (self .f )
1718+ sio = StringIO ()
1719+ ih .write_hex_file (sio , byte_count = 255 )
1720+ s = sio .getvalue ()
1721+ # control written hex first line to check that byte count is 255
1722+ sio .seek (0 )
1723+ self .assertEqual (sio .readline (), ':FF0000000205A2E576246AF8E60576227867300702786AE475F0011204AD0204552000EB7F2ED2008018EF540F2490D43440D4FF30040BEF24BFB41A0050032461FFE57760021577057AE57A7002057930070D7867E475F0011204ADEF02049B02057B7403D2078003E4C207F5768B678A688969E4F577F579F57AE57760077F2012003E80F57578FFC201C200C202C203C205C206C20812000CFF700D3007057F0012004FAF7AAE7922B4255FC2D5C20412000CFF24D0B40A00501A75F00A787730D50508B6FF0106C6A426F620D5047002D20380D924CFB41A00EF5004C2E5D20402024FD20180C6D20080C0D20280BCD2D580BAD20580B47F2012003E20020774010E\n ' ,
1724+ "Written hex is not in byte count 1" )
1725+ sio .close ()
1726+
1727+ fin = StringIO (s )
1728+ ih2 = intelhex .IntelHex (fin )
1729+
1730+ self .assertEqual (ih .tobinstr (), ih2 .tobinstr (),
1731+ "Written hex file does not equal with original" )
1732+
16621733##
16631734# MAIN
16641735if __name__ == '__main__' :
0 commit comments