Skip to content

Commit

Permalink
tests: Add a couple of extra tests for the batch flashing.
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosperate committed Dec 23, 2023
1 parent 0f98551 commit a8f78ed
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/test_cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,9 @@ def test_compare_uicr_customer(
assert mock_open_temp_html.call_count == 1


###############################################################################
# Flash commands
###############################################################################
@mock.patch("ubittool.cmds.os.fsync", autospec=True)
@mock.patch("ubittool.cmds.uflash.find_microbit", autospec=True)
def test_flash_drag_n_drop(mock_find_microbit, mock_fsync):
Expand All @@ -462,3 +465,13 @@ def test_flash_drag_n_drop_no_mb(mock_find_microbit):
cmds.flash_drag_n_drop("not_a_real.hex")

assert "Could not find a MICROBIT drive" in str(exc_info.value)


@mock.patch.object(cmds.programmer.MicrobitMcu, "flash_hex", autospec=True)
def test_flash_pyocd(mock_microbit_mcu_flash_hex):
"""Check the flash with PyOCD function."""
cmds.flash_pyocd("path/to/hex_file.hex")

assert (
mock_microbit_mcu_flash_hex.call_args[0][1] == "path/to/hex_file.hex"
)
38 changes: 38 additions & 0 deletions tests/test_programmer.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,3 +344,41 @@ def test_read_uicr_customer(mock_read_memory):
assert result_data1 == data_bytes
assert start_addres2 == 0x1000_1080
assert result_data2 == data_bytes


###############################################################################
# find_microbit_ids()
###############################################################################
@mock.patch(
"ubittool.programmer.ConnectHelper.get_all_connected_probes", autospec=True
)
def test_find_microbit_ids(mock_get_all_connected_probes):
"""Test find_microbit_ids()."""

class MockProbe:
def __init__(self, _id):
self.unique_id = _id

mock_get_all_connected_probes.return_value = [
MockProbe("9900"),
MockProbe("9901"),
MockProbe("9903"),
MockProbe("9904"),
MockProbe("9905"),
]

ids = programmer.find_microbit_ids()

assert ids == ("9900", "9901", "9903", "9904", "9905")


@mock.patch(
"ubittool.programmer.ConnectHelper.get_all_connected_probes", autospec=True
)
def test_find_microbit_ids_empty(mock_get_all_connected_probes):
"""Test find_microbit_ids()."""
mock_get_all_connected_probes.return_value = []

ids = programmer.find_microbit_ids()

assert ids == tuple()

0 comments on commit a8f78ed

Please sign in to comment.