scripts: Fix twisterlib for ruff - SIM102
This fixes ruff linting error SIM102, where multiple ifs were used instead of combining them with and or similar operators. Signed-off-by: Lukasz Mrugala <lukaszx.mrugala@intel.com>
This commit is contained in:
parent
c0553343c4
commit
dad7a8e17e
7 changed files with 40 additions and 46 deletions
|
@ -759,7 +759,6 @@
|
|||
]
|
||||
"./scripts/pylib/twister/twisterlib/cmakecache.py" = [
|
||||
"E501", # https://docs.astral.sh/ruff/rules/line-too-long
|
||||
"SIM102", # https://docs.astral.sh/ruff/rules/collapsible-if
|
||||
"UP015", # https://docs.astral.sh/ruff/rules/redundant-open-modes
|
||||
"UP032", # https://docs.astral.sh/ruff/rules/f-string
|
||||
]
|
||||
|
@ -786,7 +785,6 @@
|
|||
"./scripts/pylib/twister/twisterlib/handlers.py" = [
|
||||
"E501", # https://docs.astral.sh/ruff/rules/line-too-long
|
||||
"F541", # https://docs.astral.sh/ruff/rules/f-string-missing-placeholders
|
||||
"SIM102", # https://docs.astral.sh/ruff/rules/collapsible-if
|
||||
"SIM105", # https://docs.astral.sh/ruff/rules/suppressible-exception
|
||||
"SIM115", # https://docs.astral.sh/ruff/rules/open-file-with-context-handler
|
||||
"UP007", # https://docs.astral.sh/ruff/rules/non-pep604-annotation
|
||||
|
@ -807,7 +805,6 @@
|
|||
"E501", # https://docs.astral.sh/ruff/rules/line-too-long
|
||||
"F541", # https://docs.astral.sh/ruff/rules/f-string-missing-placeholders
|
||||
"F811", # https://docs.astral.sh/ruff/rules/redefined-while-unused
|
||||
"SIM102", # https://docs.astral.sh/ruff/rules/collapsible-if
|
||||
"UP015", # https://docs.astral.sh/ruff/rules/redundant-open-modes
|
||||
"UP031", # https://docs.astral.sh/ruff/rules/printf-string-formatting
|
||||
"UP032", # https://docs.astral.sh/ruff/rules/f-string
|
||||
|
@ -836,7 +833,6 @@
|
|||
"B006", # https://docs.astral.sh/ruff/rules/mutable-argument-default
|
||||
"E501", # https://docs.astral.sh/ruff/rules/line-too-long
|
||||
"F541", # https://docs.astral.sh/ruff/rules/f-string-missing-placeholders
|
||||
"SIM102", # https://docs.astral.sh/ruff/rules/collapsible-if
|
||||
"SIM115", # https://docs.astral.sh/ruff/rules/open-file-with-context-handler
|
||||
"UP015", # https://docs.astral.sh/ruff/rules/redundant-open-modes
|
||||
"UP031", # https://docs.astral.sh/ruff/rules/printf-string-formatting
|
||||
|
@ -851,7 +847,6 @@
|
|||
"B006", # https://docs.astral.sh/ruff/rules/mutable-argument-default
|
||||
"B904", # https://docs.astral.sh/ruff/rules/raise-without-from-inside-except
|
||||
"E501", # https://docs.astral.sh/ruff/rules/line-too-long
|
||||
"SIM102", # https://docs.astral.sh/ruff/rules/collapsible-if
|
||||
"UP015", # https://docs.astral.sh/ruff/rules/redundant-open-modes
|
||||
"UP031", # https://docs.astral.sh/ruff/rules/printf-string-formatting
|
||||
]
|
||||
|
@ -863,7 +858,6 @@
|
|||
"E501", # https://docs.astral.sh/ruff/rules/line-too-long
|
||||
"F401", # https://docs.astral.sh/ruff/rules/unused-import
|
||||
"F541", # https://docs.astral.sh/ruff/rules/f-string-missing-placeholders
|
||||
"SIM102", # https://docs.astral.sh/ruff/rules/collapsible-if
|
||||
"UP015", # https://docs.astral.sh/ruff/rules/redundant-open-modes
|
||||
"UP031", # https://docs.astral.sh/ruff/rules/printf-string-formatting
|
||||
"UP032", # https://docs.astral.sh/ruff/rules/f-string
|
||||
|
|
|
@ -83,11 +83,10 @@ class CMakeCacheEntry:
|
|||
except ValueError as exc:
|
||||
args = exc.args + ('on line {}: {}'.format(line_no, line),)
|
||||
raise ValueError(args) from exc
|
||||
elif type_ in ['STRING', 'INTERNAL']:
|
||||
# If the value is a CMake list (i.e. is a string which
|
||||
# contains a ';'), convert to a Python list.
|
||||
if ';' in value:
|
||||
value = value.split(';')
|
||||
# If the value is a CMake list (i.e. is a string which contains a ';'),
|
||||
# convert to a Python list.
|
||||
elif type_ in ['STRING', 'INTERNAL'] and ';' in value:
|
||||
value = value.split(';')
|
||||
|
||||
return CMakeCacheEntry(name, value)
|
||||
|
||||
|
|
|
@ -123,8 +123,10 @@ class Handler:
|
|||
return
|
||||
# compare the expect and detect from end one by one without order
|
||||
_d_suite = detected_suite_names[-len(expected_suite_names):]
|
||||
if set(_d_suite) != set(expected_suite_names):
|
||||
if not set(_d_suite).issubset(set(expected_suite_names)):
|
||||
if (
|
||||
set(_d_suite) != set(expected_suite_names)
|
||||
and not set(_d_suite).issubset(set(expected_suite_names))
|
||||
):
|
||||
self._missing_suite_name(expected_suite_names, handler_time)
|
||||
|
||||
def _missing_suite_name(self, expected_suite_names, handler_time):
|
||||
|
@ -221,13 +223,16 @@ class BinaryHandler(Handler):
|
|||
log_out_fp.write(strip_ansi_sequences(line_decoded))
|
||||
log_out_fp.flush()
|
||||
harness.handle(stripped_line)
|
||||
if harness.status != TwisterStatus.NONE:
|
||||
if not timeout_extended or harness.capture_coverage:
|
||||
timeout_extended = True
|
||||
if harness.capture_coverage:
|
||||
timeout_time = time.time() + 30
|
||||
else:
|
||||
timeout_time = time.time() + 2
|
||||
if (
|
||||
harness.status != TwisterStatus.NONE
|
||||
and not timeout_extended
|
||||
or harness.capture_coverage
|
||||
):
|
||||
timeout_extended = True
|
||||
if harness.capture_coverage:
|
||||
timeout_time = time.time() + 30
|
||||
else:
|
||||
timeout_time = time.time() + 2
|
||||
else:
|
||||
reader_t.join(0)
|
||||
break
|
||||
|
@ -455,10 +460,9 @@ class DeviceHandler(Handler):
|
|||
logger.debug("DEVICE: {0}".format(sl))
|
||||
harness.handle(sl)
|
||||
|
||||
if harness.status != TwisterStatus.NONE:
|
||||
if not harness.capture_coverage:
|
||||
ser.close()
|
||||
break
|
||||
if harness.status != TwisterStatus.NONE and not harness.capture_coverage:
|
||||
ser.close()
|
||||
break
|
||||
|
||||
log_out_fp.close()
|
||||
|
||||
|
|
|
@ -157,9 +157,8 @@ class Harness:
|
|||
self.status = TwisterStatus.FAIL
|
||||
self.reason = "Testsuite failed"
|
||||
|
||||
if self.fail_on_fault:
|
||||
if line == self.FAULT:
|
||||
self.fault = True
|
||||
if self.fail_on_fault and line == self.FAULT:
|
||||
self.fault = True
|
||||
|
||||
if self.GCOV_START in line:
|
||||
self.capture_coverage = True
|
||||
|
@ -306,9 +305,8 @@ class Console(Harness):
|
|||
else:
|
||||
logger.error("Unknown harness_config type")
|
||||
|
||||
if self.fail_on_fault:
|
||||
if self.FAULT in line:
|
||||
self.fault = True
|
||||
if self.fail_on_fault and self.FAULT in line:
|
||||
self.fault = True
|
||||
|
||||
if self.GCOV_START in line:
|
||||
self.capture_coverage = True
|
||||
|
|
|
@ -769,14 +769,16 @@ class FilterBuilder(CMake):
|
|||
filter_data.update(self.defconfig)
|
||||
filter_data.update(self.cmake_cache)
|
||||
|
||||
if self.instance.sysbuild and self.env.options.device_testing:
|
||||
# Verify that twister's arguments support sysbuild.
|
||||
# Twister sysbuild flashing currently only works with west, so
|
||||
# --west-flash must be passed.
|
||||
if self.env.options.west_flash is None:
|
||||
logger.warning("Sysbuild test will be skipped. " +
|
||||
"West must be used for flashing.")
|
||||
return {os.path.join(self.platform.name, self.testsuite.name): True}
|
||||
# Verify that twister's arguments support sysbuild.
|
||||
# Twister sysbuild flashing currently only works with west,
|
||||
# so --west-flash must be passed.
|
||||
if (
|
||||
self.instance.sysbuild
|
||||
and self.env.options.device_testing
|
||||
and self.env.options.west_flash is None
|
||||
):
|
||||
logger.warning("Sysbuild test will be skipped. West must be used for flashing.")
|
||||
return {os.path.join(self.platform.name, self.testsuite.name): True}
|
||||
|
||||
if self.testsuite and self.testsuite.filter:
|
||||
try:
|
||||
|
|
|
@ -333,12 +333,10 @@ class TestInstance:
|
|||
content = content + "\nCONFIG_COVERAGE=y"
|
||||
content = content + "\nCONFIG_COVERAGE_DUMP=y"
|
||||
|
||||
if enable_asan:
|
||||
if platform.type == "native":
|
||||
if platform.type == "native":
|
||||
if enable_asan:
|
||||
content = content + "\nCONFIG_ASAN=y"
|
||||
|
||||
if enable_ubsan:
|
||||
if platform.type == "native":
|
||||
if enable_ubsan:
|
||||
content = content + "\nCONFIG_UBSAN=y"
|
||||
|
||||
if content:
|
||||
|
|
|
@ -854,9 +854,8 @@ class TestPlan:
|
|||
# Discard silently
|
||||
continue
|
||||
|
||||
if ts.modules and self.modules:
|
||||
if not set(ts.modules).issubset(set(self.modules)):
|
||||
instance.add_filter(f"one or more required modules not available: {','.join(ts.modules)}", Filters.MODULE)
|
||||
if ts.modules and self.modules and not set(ts.modules).issubset(set(self.modules)):
|
||||
instance.add_filter(f"one or more required modules not available: {','.join(ts.modules)}", Filters.MODULE)
|
||||
|
||||
if self.options.level:
|
||||
tl = self.get_level(self.options.level)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue