test/py: Rework test_spi.py to assert we found output

When running a newer version of pylint it will complain that page_size
may be used before being assignment. Looking deeper what is going on is
that we could run in to the case where the regex we run for any of the
flash information fails but since we don't have a result, we don't check
it either. In the case of the rest of the numerical values we then have
some assignment (multiplying by some value) and so pylint doesn't
complain. Rework things to assert that each regex has a result and so
failure will stop the test and we won't have any use before assignment.

Signed-off-by: Tom Rini <trini@konsulko.com>
This commit is contained in:
Tom Rini 2025-02-12 16:24:07 -06:00
parent 7fa38ae6c7
commit 3e335ddca6

View file

@ -119,32 +119,30 @@ def spi_pre_commands(u_boot_console, freq):
pytest.fail('Not recognized the SPI flash part name') pytest.fail('Not recognized the SPI flash part name')
m = re.search('page size (.+?) Bytes', output) m = re.search('page size (.+?) Bytes', output)
if m: assert m
try: try:
page_size = int(m.group(1)) page_size = int(m.group(1))
except ValueError: except ValueError:
pytest.fail('Not recognized the SPI page size') pytest.fail('Not recognized the SPI page size')
m = re.search('erase size (.+?) KiB', output) m = re.search('erase size (.+?) KiB', output)
if m: assert m
try: try:
erase_size = int(m.group(1)) erase_size = int(m.group(1))
erase_size *= 1024
except ValueError: except ValueError:
pytest.fail('Not recognized the SPI erase size') pytest.fail('Not recognized the SPI erase size')
erase_size *= 1024
m = re.search('total (.+?) MiB', output) m = re.search('total (.+?) MiB', output)
if m: assert m
try: try:
total_size = int(m.group(1)) total_size = int(m.group(1))
total_size *= 1024 * 1024
except ValueError: except ValueError:
pytest.fail('Not recognized the SPI total size') pytest.fail('Not recognized the SPI total size')
total_size *= 1024 * 1024
m = re.search('Detected (.+?) with', output) m = re.search('Detected (.+?) with', output)
if m: assert m
try: try:
flash_part = m.group(1) flash_part = m.group(1)
assert flash_part == part_name assert flash_part == part_name