Exemplo n.º 1
0
def test_bytes_to_intel_hex_invalid_data():
    """Test there is an error thrown if the input data is invalid."""
    data = [1, 2, 3, 4, "500"]

    try:
        cmds._bytes_to_intel_hex(data=data)
    except Exception:
        # The exception that bubbles up from IntelHex is implementation detail
        # from that library, so it could be anything
        assert True, "Exception raised"
    else:
        raise AssertionError("Exception NOT raised")
Exemplo n.º 2
0
def test_bytes_to_intel_hex():
    """Test the data to Intel Hex string conversion."""
    data = [1, 2, 3, 4, 5]
    expected_hex_str = "\n".join([":050000000102030405EC", INTEL_HEX_EOF])

    result = cmds._bytes_to_intel_hex(data=data)

    assert expected_hex_str == result
Exemplo n.º 3
0
def test_bytes_to_intel_hex_io_error(mock_string_io, mock_stderr):
    """Test the exception handling when an IOError is encountered."""
    data = [1, 2, 3, 4, 5]
    mock_string_io.return_value.write.side_effect = IOError()

    result = cmds._bytes_to_intel_hex(data=data)

    assert result is None
    assert mock_stderr.call_count == 1
Exemplo n.º 4
0
def test_bytes_to_intel_hex_offset():
    """Test the data to Intel Hex string conversion with an offset."""
    data = [1, 2, 3, 4, 5]
    offset = 0x2000000
    expected_hex_str = "\n".join(
        [":020000040200F8", ":050000000102030405EC", INTEL_HEX_EOF])

    result = cmds._bytes_to_intel_hex(data=data, offset=offset)

    assert expected_hex_str == result