scripts: Fix twisterlib for ruff - B006
This fixes ruff linting error B006, where mutables were used as default parameters. Signed-off-by: Lukasz Mrugala <lukaszx.mrugala@intel.com>
This commit is contained in:
parent
12a374cc8b
commit
96beec0add
8 changed files with 45 additions and 22 deletions
|
@ -776,7 +776,6 @@
|
|||
"UP032", # https://docs.astral.sh/ruff/rules/f-string
|
||||
]
|
||||
"./scripts/pylib/twister/twisterlib/environment.py" = [
|
||||
"B006", # https://docs.astral.sh/ruff/rules/mutable-argument-default
|
||||
"E501", # https://docs.astral.sh/ruff/rules/line-too-long
|
||||
"UP031", # https://docs.astral.sh/ruff/rules/printf-string-formatting
|
||||
]
|
||||
|
@ -792,7 +791,6 @@
|
|||
"UP032", # https://docs.astral.sh/ruff/rules/f-string
|
||||
]
|
||||
"./scripts/pylib/twister/twisterlib/hardwaremap.py" = [
|
||||
"B006", # https://docs.astral.sh/ruff/rules/mutable-argument-default
|
||||
"E501", # https://docs.astral.sh/ruff/rules/line-too-long
|
||||
"UP015", # https://docs.astral.sh/ruff/rules/redundant-open-modes
|
||||
"UP031", # https://docs.astral.sh/ruff/rules/printf-string-formatting
|
||||
|
@ -813,7 +811,6 @@
|
|||
"UP031", # https://docs.astral.sh/ruff/rules/printf-string-formatting
|
||||
]
|
||||
"./scripts/pylib/twister/twisterlib/quarantine.py" = [
|
||||
"B006", # https://docs.astral.sh/ruff/rules/mutable-argument-default
|
||||
"E501", # https://docs.astral.sh/ruff/rules/line-too-long
|
||||
"UP015", # https://docs.astral.sh/ruff/rules/redundant-open-modes
|
||||
"UP031", # https://docs.astral.sh/ruff/rules/printf-string-formatting
|
||||
|
@ -826,7 +823,6 @@
|
|||
"UP032", # https://docs.astral.sh/ruff/rules/f-string
|
||||
]
|
||||
"./scripts/pylib/twister/twisterlib/runner.py" = [
|
||||
"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
|
||||
"SIM115", # https://docs.astral.sh/ruff/rules/open-file-with-context-handler
|
||||
|
@ -840,13 +836,11 @@
|
|||
"UP031", # https://docs.astral.sh/ruff/rules/printf-string-formatting
|
||||
]
|
||||
"./scripts/pylib/twister/twisterlib/testinstance.py" = [
|
||||
"B006", # https://docs.astral.sh/ruff/rules/mutable-argument-default
|
||||
"E501", # https://docs.astral.sh/ruff/rules/line-too-long
|
||||
"UP015", # https://docs.astral.sh/ruff/rules/redundant-open-modes
|
||||
"UP031", # https://docs.astral.sh/ruff/rules/printf-string-formatting
|
||||
]
|
||||
"./scripts/pylib/twister/twisterlib/testplan.py" = [
|
||||
"B006", # https://docs.astral.sh/ruff/rules/mutable-argument-default
|
||||
"E402", # https://docs.astral.sh/ruff/rules/module-import-not-at-top-of-file
|
||||
"E501", # https://docs.astral.sh/ruff/rules/line-too-long
|
||||
"F401", # https://docs.astral.sh/ruff/rules/unused-import
|
||||
|
@ -856,7 +850,6 @@
|
|||
"UP032", # https://docs.astral.sh/ruff/rules/f-string
|
||||
]
|
||||
"./scripts/pylib/twister/twisterlib/testsuite.py" = [
|
||||
"B006", # https://docs.astral.sh/ruff/rules/mutable-argument-default
|
||||
"E501", # https://docs.astral.sh/ruff/rules/line-too-long
|
||||
"UP031", # https://docs.astral.sh/ruff/rules/printf-string-formatting
|
||||
"UP032", # https://docs.astral.sh/ruff/rules/f-string
|
||||
|
|
|
@ -1060,7 +1060,9 @@ class TwisterEnv:
|
|||
logger.exception("Failure while reading head commit date.")
|
||||
|
||||
@staticmethod
|
||||
def run_cmake_script(args=[]):
|
||||
def run_cmake_script(args=None):
|
||||
if args is None:
|
||||
args = []
|
||||
script = os.fspath(args[0])
|
||||
|
||||
logger.debug("Running cmake script %s", script)
|
||||
|
|
|
@ -430,7 +430,11 @@ class HardwareMap:
|
|||
logger.info("Detected devices:")
|
||||
self.dump(detected=True)
|
||||
|
||||
def dump(self, filtered=[], header=[], connected_only=False, detected=False):
|
||||
def dump(self, filtered=None, header=None, connected_only=False, detected=False):
|
||||
if filtered is None:
|
||||
filtered = []
|
||||
if header is None:
|
||||
header = []
|
||||
print("")
|
||||
table = []
|
||||
if detected:
|
||||
|
|
|
@ -28,7 +28,9 @@ class QuarantineException(Exception):
|
|||
class Quarantine:
|
||||
"""Handle tests under quarantine."""
|
||||
|
||||
def __init__(self, quarantine_list=[]) -> None:
|
||||
def __init__(self, quarantine_list=None) -> None:
|
||||
if quarantine_list is None:
|
||||
quarantine_list = []
|
||||
self.quarantine = QuarantineData()
|
||||
for quarantine_file in quarantine_list:
|
||||
self.quarantine.extend(QuarantineData.load_data_from_yaml(quarantine_file))
|
||||
|
|
|
@ -513,11 +513,13 @@ class CMake:
|
|||
self.default_encoding = sys.getdefaultencoding()
|
||||
self.jobserver = jobserver
|
||||
|
||||
def parse_generated(self, filter_stages=[]):
|
||||
def parse_generated(self, filter_stages=None):
|
||||
self.defconfig = {}
|
||||
return {}
|
||||
|
||||
def run_build(self, args=[]):
|
||||
def run_build(self, args=None):
|
||||
if args is None:
|
||||
args = []
|
||||
|
||||
logger.debug("Building %s for %s" % (self.source_dir, self.platform.name))
|
||||
|
||||
|
@ -594,7 +596,9 @@ class CMake:
|
|||
|
||||
return ret
|
||||
|
||||
def run_cmake(self, args="", filter_stages=[]):
|
||||
def run_cmake(self, args="", filter_stages=None):
|
||||
if filter_stages is None:
|
||||
filter_stages = []
|
||||
|
||||
if not self.options.disable_warnings_as_errors:
|
||||
warnings_as_errors = 'y'
|
||||
|
@ -711,7 +715,9 @@ class FilterBuilder(CMake):
|
|||
|
||||
self.log = "config-twister.log"
|
||||
|
||||
def parse_generated(self, filter_stages=[]):
|
||||
def parse_generated(self, filter_stages=None):
|
||||
if filter_stages is None:
|
||||
filter_stages = []
|
||||
|
||||
if self.platform.name == "unit_testing":
|
||||
return {}
|
||||
|
@ -877,7 +883,9 @@ class ProjectBuilder(FilterBuilder):
|
|||
self.log_info("{}".format(b_log), inline_logs)
|
||||
|
||||
|
||||
def _add_to_pipeline(self, pipeline, op: str, additionals: dict={}):
|
||||
def _add_to_pipeline(self, pipeline, op: str, additionals: dict=None):
|
||||
if additionals is None:
|
||||
additionals = {}
|
||||
try:
|
||||
if op:
|
||||
task = dict({'op': op, 'test': self.instance}, **additionals)
|
||||
|
@ -1161,7 +1169,9 @@ class ProjectBuilder(FilterBuilder):
|
|||
testcase.reason = tc_info.get('reason')
|
||||
|
||||
|
||||
def cleanup_artifacts(self, additional_keep: list[str] = []):
|
||||
def cleanup_artifacts(self, additional_keep: list[str] = None):
|
||||
if additional_keep is None:
|
||||
additional_keep = []
|
||||
logger.debug("Cleaning up {}".format(self.instance.build_dir))
|
||||
allow = [
|
||||
os.path.join('zephyr', '.config'),
|
||||
|
@ -1529,7 +1539,9 @@ class ProjectBuilder(FilterBuilder):
|
|||
|
||||
return args_expanded
|
||||
|
||||
def cmake(self, filter_stages=[]):
|
||||
def cmake(self, filter_stages=None):
|
||||
if filter_stages is None:
|
||||
filter_stages = []
|
||||
args = []
|
||||
for va in self.testsuite.extra_args.copy():
|
||||
cond_args = va.split(":")
|
||||
|
|
|
@ -300,7 +300,9 @@ class TestInstance:
|
|||
|
||||
return testsuite_runnable and target_ready
|
||||
|
||||
def create_overlay(self, platform, enable_asan=False, enable_ubsan=False, enable_coverage=False, coverage_platform=[]):
|
||||
def create_overlay(self, platform, enable_asan=False, enable_ubsan=False, enable_coverage=False, coverage_platform=None):
|
||||
if coverage_platform is None:
|
||||
coverage_platform = []
|
||||
# Create this in a "twister/" subdirectory otherwise this
|
||||
# will pass this overlay to kconfig.py *twice* and kconfig.cmake
|
||||
# will silently give that second time precedence over any
|
||||
|
|
|
@ -544,7 +544,9 @@ class TestPlan:
|
|||
testcases.remove(case.name)
|
||||
return testcases
|
||||
|
||||
def add_testsuites(self, testsuite_filter=[]):
|
||||
def add_testsuites(self, testsuite_filter=None):
|
||||
if testsuite_filter is None:
|
||||
testsuite_filter = []
|
||||
for root in self.env.test_roots:
|
||||
root = os.path.abspath(root)
|
||||
|
||||
|
@ -656,7 +658,9 @@ class TestPlan:
|
|||
if not matched_quarantine and self.options.quarantine_verify:
|
||||
instance.add_filter("Not under quarantine", Filters.QUARANTINE)
|
||||
|
||||
def load_from_file(self, file, filter_platform=[]):
|
||||
def load_from_file(self, file, filter_platform=None):
|
||||
if filter_platform is None:
|
||||
filter_platform = []
|
||||
try:
|
||||
with open(file, "r") as json_test_plan:
|
||||
jtp = json.load(json_test_plan)
|
||||
|
|
|
@ -43,7 +43,9 @@ class ScanPathResult:
|
|||
has_registered_test_suites: bool = False,
|
||||
has_run_registered_test_suites: bool = False,
|
||||
has_test_main: bool = False,
|
||||
ztest_suite_names: list[str] = []):
|
||||
ztest_suite_names: list[str] = None):
|
||||
if ztest_suite_names is None:
|
||||
ztest_suite_names = []
|
||||
self.matches = matches
|
||||
self.warnings = warnings
|
||||
self.has_registered_test_suites = has_registered_test_suites
|
||||
|
@ -260,10 +262,12 @@ def _find_ztest_testcases(search_area, testcase_regex):
|
|||
|
||||
return testcase_names, warnings
|
||||
|
||||
def find_c_files_in(path: str, extensions: list = ['c', 'cpp', 'cxx', 'cc']) -> list:
|
||||
def find_c_files_in(path: str, extensions: list = None) -> list:
|
||||
"""
|
||||
Find C or C++ sources in the directory specified by "path"
|
||||
"""
|
||||
if extensions is None:
|
||||
extensions = ['c', 'cpp', 'cxx', 'cc']
|
||||
if not os.path.isdir(path):
|
||||
return []
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue