Skip to content

Commit e20f2d3

Browse files
author
Janne Kiiskila
committed
target_test - assert if sectors keyword missing
Assert it properly and thus give out the target name where the issue is, rather than just error out with KeyError and leave the poor sod wondering where exactly the issue is. Before: ``` =================================== FAILURES =================================== _____________________________ test_bl_has_sectors ______________________________ def test_bl_has_sectors(): """Assert a bootloader supporting pack has sector information""" cache = Cache(True, True) named_targets = ( target for target in TARGETS if (hasattr(target, "device_name") and getattr(target, "bootloader_supported", False)) ) for target in named_targets: assert target.device_name in cache.index,\ ("Target %s contains invalid device_name %s" % (target.name, target.device_name)) > assert cache.index[target.device_name]["sectors"],\ ("Device name %s is misssing sector information" % (target.device_name)) E KeyError: 'sectors' ``` After ``` ___________________________________________________ test_bl_has_sectors ___________________________________________________ def test_bl_has_sectors(): """Assert a bootloader supporting pack has sector information""" # ToDo: validity checks for the information IN the sectors! cache = Cache(True, True) named_targets = ( target for target in TARGETS if (hasattr(target, "device_name") and getattr(target, "bootloader_supported", False)) ) for target in named_targets: assert target.device_name in cache.index,\ ("Target %s contains invalid device_name %s" % (target.name, target.device_name)) > assert "sectors" in cache.index[target.device_name],\ ("Target %s does not have sectors" % (target.name)) E AssertionError: Target NUCLEO_L073RZ does not have sectors E assert 'sectors' in {'algorithms': [{'default': True, 'file_name': 'CMSIS/Flash/STM32L0xx_192.FLM', 'ram_size': None, 'ram_start': None, ....on_secure_callable': False, 'peripheral': False, ...}, 'default': True, 'size': 196608, 'start': 134217728, ...}}, ...} ``` This helps you finding the offending target a bit faster. Kudos to Jammu Kekkonen ([email protected]) to figuring out how to actually run this test & the assertion. Ref: Mbed OS issue #12219
1 parent dc63202 commit e20f2d3

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

tools/test/targets/target_test.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
See the License for the specific language governing permissions and
1616
limitations under the License.
1717
"""
18+
# How to run this test?
19+
#
20+
# Note! You must be in the mbed-os -folder!
21+
#
22+
# python -m pytest tools/test/targets/target_test.py
23+
#
1824
import os
1925
import sys
2026
import shutil
@@ -39,6 +45,7 @@ def test_device_name():
3945

4046
def test_bl_has_sectors():
4147
"""Assert a bootloader supporting pack has sector information"""
48+
# ToDo: validity checks for the information IN the sectors!
4249
cache = Cache(True, True)
4350
named_targets = (
4451
target for target in TARGETS if
@@ -48,6 +55,9 @@ def test_bl_has_sectors():
4855
assert target.device_name in cache.index,\
4956
("Target %s contains invalid device_name %s" %
5057
(target.name, target.device_name))
58+
assert "sectors" in cache.index[target.device_name],\
59+
("Target %s does not have sectors" %
60+
(target.name))
5161
assert cache.index[target.device_name]["sectors"],\
5262
("Device name %s is misssing sector information" %
5363
(target.device_name))

0 commit comments

Comments
 (0)