Skip to content

Commit

Permalink
write_hex_file: 'ext_addr_mode' parameter is now case-insensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
fernandez85 committed Jun 29, 2020
1 parent 6731f34 commit 88a2e42
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
2 changes: 2 additions & 0 deletions intelhex/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,8 @@ def write_hex_file(self, f, write_start_addr=True, eolstyle='native', byte_count
minaddr = addresses[0] if addr_len else 0
maxaddr = addresses[-1] if addr_len else 0

# make parameter case-insensitive
ext_addr_mode = ext_addr_mode.lower()
# resolve extended address type
if ext_addr_mode == 'linear':
# enforces Extended Linear Address record type (default)
Expand Down
36 changes: 34 additions & 2 deletions intelhex/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1798,12 +1798,44 @@ def test_write_hex_file_byte_count_255(self):

class TestWriteHexFileExtAddrMode(unittest.TestCase):

def test_write_hex_file_wrong_ext_addr_mode(self):
def test_write_hex_file_ext_addr_mode_param(self):
ih = intelhex.IntelHex()
sio = StringIO()

# invalid param
self.assertRaises(ValueError, ih.write_hex_file, sio, ext_addr_mode='bad')

# insesitive casing check
isValueError = False
try:
ih.write_hex_file(sio, ext_addr_mode='AUTO')
except ValueError:
isValueError = True
self.assertFalse(isValueError)

isValueError = False
try:
ih.write_hex_file(sio, ext_addr_mode='Linear')
except ValueError:
isValueError = True
self.assertFalse(isValueError)

isValueError = False
try:
ih.write_hex_file(sio, ext_addr_mode='segmenT')
except ValueError:
isValueError = True
self.assertFalse(isValueError)

isValueError = False
try:
ih.write_hex_file(sio, ext_addr_mode='NoNe')
except ValueError:
isValueError = True
self.assertFalse(isValueError)

sio.close()

def test_write_hex_file_no_starting_address_simple(self):
#prepare
ih = intelhex.IntelHex(StringIO(hex_simple))
Expand Down

0 comments on commit 88a2e42

Please sign in to comment.