Skip to content

Commit 3bddb13

Browse files
erwangokartben
authored andcommitted
scripts: test runners: stm32cubeprogrammer: Update --download-address test
Fix --download-address to expect a signed.bin file when --download-address is provided. To allow testing this case despite the checks put in the runner, add a patch functions which return that zephyr.bin is actually present Signed-off-by: Erwan Gouriou <erwan.gouriou@st.com>
1 parent 1be4025 commit 3bddb13

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

scripts/west_commands/tests/test_stm32cubeprogrammer.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
# SPDX-License-Identifier: Apache-2.0
44

55
import argparse
6+
import os
67
from pathlib import Path
78
from unittest.mock import patch, call
89

910
import pytest
1011

1112
from runners.stm32cubeprogrammer import STM32CubeProgrammerBinaryRunner
12-
from conftest import RC_KERNEL_HEX, RC_KERNEL_ELF
13-
13+
from conftest import RC_KERNEL_HEX, RC_KERNEL_ELF, RC_KERNEL_BIN
1414

1515
CLI_PATH = Path("STM32_Programmer_CLI")
1616
"""Default CLI path used in tests."""
@@ -436,7 +436,7 @@
436436
"--connect",
437437
"port=swd",
438438
"--download",
439-
RC_KERNEL_HEX,
439+
RC_KERNEL_BIN,
440440
"0x80000000",
441441
"0x1",
442442
"--start",
@@ -447,6 +447,12 @@
447447
)
448448
"""Test cases."""
449449

450+
os_path_isfile = os.path.isfile
451+
452+
def os_path_isfile_patch(filename):
453+
if filename == RC_KERNEL_BIN:
454+
return True
455+
return os_path_isfile(filename)
450456

451457
@pytest.mark.parametrize("tc", TEST_CASES)
452458
@patch("runners.stm32cubeprogrammer.platform.system")
@@ -455,7 +461,9 @@
455461
@patch.dict("runners.stm32cubeprogrammer.os.environ", ENVIRON)
456462
@patch("runners.core.ZephyrBinaryRunner.require")
457463
@patch("runners.stm32cubeprogrammer.STM32CubeProgrammerBinaryRunner.check_call")
464+
@patch("os.path.isfile", side_effect=os_path_isfile_patch)
458465
def test_stm32cubeprogrammer_init(
466+
os_path_isfile_patch,
459467
check_call, require, path_exists, path_home, system, tc, runner_config
460468
):
461469
"""Tests that ``STM32CubeProgrammerBinaryRunner`` class can be initialized
@@ -494,7 +502,9 @@ def test_stm32cubeprogrammer_init(
494502
@patch.dict("runners.stm32cubeprogrammer.os.environ", ENVIRON)
495503
@patch("runners.core.ZephyrBinaryRunner.require")
496504
@patch("runners.stm32cubeprogrammer.STM32CubeProgrammerBinaryRunner.check_call")
505+
@patch("os.path.isfile", side_effect=os_path_isfile_patch)
497506
def test_stm32cubeprogrammer_create(
507+
os_path_isfile_patch,
498508
check_call, require, path_exists, path_home, system, tc, runner_config
499509
):
500510
"""Tests that ``STM32CubeProgrammerBinaryRunner`` class can be created using

0 commit comments

Comments
 (0)