twister: fixed various pylint issues

Fix various pylint issues.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
Anas Nashif 2022-06-23 17:40:57 -04:00
commit 087f1e4a63
22 changed files with 49 additions and 78 deletions

View file

@ -4,6 +4,7 @@
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import scl import scl
from twisterlib.error import ConfigurationError
class TwisterConfigParser: class TwisterConfigParser:
"""Class to read testsuite yaml files with semantic checking """Class to read testsuite yaml files with semantic checking

View file

@ -17,7 +17,7 @@ import argparse
logger = logging.getLogger('twister') logger = logging.getLogger('twister')
logger.setLevel(logging.DEBUG) logger.setLevel(logging.DEBUG)
from twister.error import TwisterRuntimeError from twisterlib.error import TwisterRuntimeError
ZEPHYR_BASE = os.getenv("ZEPHYR_BASE") ZEPHYR_BASE = os.getenv("ZEPHYR_BASE")
if not ZEPHYR_BASE: if not ZEPHYR_BASE:
@ -627,7 +627,7 @@ structure in the main Zephyr tree: boards/<arch>/<board_name>/""")
sys.exit(1) sys.exit(1)
if options.size: if options.size:
from twister.size_calc import SizeCalculator from twisterlib.size_calc import SizeCalculator
for fn in options.size: for fn in options.size:
sc = SizeCalculator(fn, []) sc = SizeCalculator(fn, [])
sc.size_report() sc.size_report()

View file

@ -15,7 +15,8 @@ import shlex
import subprocess import subprocess
import threading import threading
import select import select
from twister.enviornment import ZEPHYR_BASE import re
from twisterlib.enviornment import ZEPHYR_BASE
try: try:
import serial import serial

View file

@ -14,7 +14,7 @@ import scl
import logging import logging
from pathlib import Path from pathlib import Path
from twister.enviornment import ZEPHYR_BASE from twisterlib.enviornment import ZEPHYR_BASE
try: try:
# Use the C LibYAML parser if available, rather than the Python parser. # Use the C LibYAML parser if available, rather than the Python parser.
@ -153,7 +153,6 @@ class HardwareMap:
if not self.options.device_testing and self.options.hardware_map: if not self.options.device_testing and self.options.hardware_map:
self.load(self.options.hardware_map) self.load(self.options.hardware_map)
logger.info("Available devices:") logger.info("Available devices:")
table = []
self.dump(connected_only=True) self.dump(connected_only=True)
return 0 return 0

View file

@ -5,4 +5,3 @@
class DisablePyTestCollectionMixin(object): class DisablePyTestCollectionMixin(object):
__test__ = False __test__ = False

View file

@ -6,8 +6,8 @@
import os import os
import scl import scl
from twister.config_parser import TwisterConfigParser from twisterlib.config_parser import TwisterConfigParser
from twister.enviornment import ZEPHYR_BASE from twisterlib.enviornment import ZEPHYR_BASE
class Platform: class Platform:
"""Class representing metadata for a particular platform """Class representing metadata for a particular platform

View file

@ -497,4 +497,3 @@ class Reporting:
else: else:
filename = os.path.join(outdir,"{}.xml".format(platform)) filename = os.path.join(outdir,"{}.xml".format(platform))
self.xunit_report(json_file, filename, platform, full_report=True) self.xunit_report(json_file, filename, platform, full_report=True)

View file

@ -17,11 +17,8 @@ import traceback
from colorama import Fore from colorama import Fore
from multiprocessing import Lock, Process, Value from multiprocessing import Lock, Process, Value
from multiprocessing.managers import BaseManager from multiprocessing.managers import BaseManager
from twisterlib.cmakecache import CMakeCache
from numpy import trace from twisterlib.enviornment import canonical_zephyr_base
from twister.cmakecache import CMakeCache
from twister.enviornment import canonical_zephyr_base
logger = logging.getLogger('twister') logger = logging.getLogger('twister')
logger.setLevel(logging.DEBUG) logger.setLevel(logging.DEBUG)
@ -881,4 +878,3 @@ class TwisterRunner:
logger.info("Execution interrupted") logger.info("Execution interrupted")
for p in processes: for p in processes:
p.terminate() p.terminate()

View file

@ -5,7 +5,8 @@
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import subprocess import subprocess
from twister.error import TwisterRuntimeError import sys
from twisterlib.error import TwisterRuntimeError
class SizeCalculator: class SizeCalculator:
@ -224,4 +225,3 @@ class SizeCalculator:
self.sections.append({"name": name, "load_addr": load_addr, self.sections.append({"name": name, "load_addr": load_addr,
"size": size, "virt_addr": virt_addr, "size": size, "virt_addr": virt_addr,
"type": stype, "recognized": recognized}) "type": stype, "recognized": recognized})

View file

@ -7,12 +7,15 @@ import os
import hashlib import hashlib
import random import random
import logging import logging
from twister.testsuite import TestCase
from twister.error import BuildError
from twister.handlers import BinaryHandler, QEMUHandler, DeviceHandler
import shutil import shutil
import glob import glob
from twisterlib.testsuite import TestCase
from twisterlib.error import BuildError
from twisterlib.size_calc import SizeCalculator
from twisterlib.handlers import BinaryHandler, QEMUHandler, DeviceHandler
logger = logging.getLogger('twister') logger = logging.getLogger('twister')
logger.setLevel(logging.DEBUG) logger.setLevel(logging.DEBUG)

View file

@ -10,13 +10,10 @@ import subprocess
import glob import glob
import json import json
import collections import collections
from typing import List
from collections import OrderedDict from collections import OrderedDict
from itertools import islice from itertools import islice
import logging import logging
logger = logging.getLogger('twister') logger = logging.getLogger('twister')
logger.setLevel(logging.DEBUG) logger.setLevel(logging.DEBUG)
@ -25,23 +22,15 @@ try:
except ImportError: except ImportError:
print("Install the anytree module to use the --test-tree option") print("Install the anytree module to use the --test-tree option")
from twister.testsuite import TestSuite, scan_testsuite_path from twisterlib.testsuite import TestSuite, scan_testsuite_path
from twister.error import TwisterRuntimeError from twisterlib.error import TwisterRuntimeError
from twister.platform import Platform from twisterlib.platform import Platform
from twister.config_parser import TwisterConfigParser from twisterlib.config_parser import TwisterConfigParser
from twister.testinstance import TestInstance from twisterlib.testinstance import TestInstance
from zephyr_module import west_projects, parse_modules from zephyr_module import west_projects, parse_modules
try:
# Use the C LibYAML parser if available, rather than the Python parser.
# It's much faster.
from yaml import CSafeLoader as SafeLoader
from yaml import CDumper as Dumper
except ImportError:
from yaml import SafeLoader, Dumper
ZEPHYR_BASE = os.getenv("ZEPHYR_BASE") ZEPHYR_BASE = os.getenv("ZEPHYR_BASE")
if not ZEPHYR_BASE: if not ZEPHYR_BASE:
sys.exit("$ZEPHYR_BASE environment variable undefined") sys.exit("$ZEPHYR_BASE environment variable undefined")
@ -51,8 +40,6 @@ sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts", "dts",
"python-devicetree", "src")) "python-devicetree", "src"))
from devicetree import edtlib # pylint: disable=unused-import from devicetree import edtlib # pylint: disable=unused-import
from twister.enviornment import TwisterEnv, canonical_zephyr_base
sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts/")) sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts/"))
import scl import scl
@ -208,7 +195,7 @@ class TestPlan:
s = self.options.subset s = self.options.subset
try: try:
subset, sets = (int(x) for x in s.split("/")) subset, sets = (int(x) for x in s.split("/"))
except ValueError as e: except ValueError:
raise TwisterRuntimeError("Bad subset value.") raise TwisterRuntimeError("Bad subset value.")
if subset > sets: if subset > sets:
@ -325,7 +312,7 @@ class TestPlan:
if not area: if not area:
area = Node(sec[1], parent=samples) area = Node(sec[1], parent=samples)
t = Node(test, parent=area) Node(test, parent=area)
else: else:
sec = test.split(".") sec = test.split(".")
area = find(tests, lambda node: node.name == sec[0] and node.parent == tests) area = find(tests, lambda node: node.name == sec[0] and node.parent == tests)
@ -336,7 +323,7 @@ class TestPlan:
subarea = find(area, lambda node: node.name == sec[1] and node.parent == area) subarea = find(area, lambda node: node.name == sec[1] and node.parent == area)
if not subarea: if not subarea:
subarea = Node(sec[1], parent=area) subarea = Node(sec[1], parent=area)
t = Node(test, parent=subarea) Node(test, parent=subarea)
for pre, _, node in RenderTree(testsuite): for pre, _, node in RenderTree(testsuite):
print("%s%s" % (pre, node.name)) print("%s%s" % (pre, node.name))
@ -355,14 +342,13 @@ class TestPlan:
def report_excluded_tests(self): def report_excluded_tests(self):
all_tests = self.get_all_tests() all_tests = self.get_all_tests()
to_be_run = set() to_be_run = set()
for i, p in self.instances.items(): for _, p in self.instances.items():
to_be_run.update(p.testsuite.cases) to_be_run.update(p.testsuite.cases)
if all_tests - to_be_run: if all_tests - to_be_run:
print("Tests that never build or run:") print("Tests that never build or run:")
for not_run in all_tests - to_be_run: for not_run in all_tests - to_be_run:
print("- {}".format(not_run)) print("- {}".format(not_run))
return
def report_platform_tests(self, platforms=[]): def report_platform_tests(self, platforms=[]):
if len(platforms) > 1: if len(platforms) > 1:
@ -378,8 +364,6 @@ class TestPlan:
count += 1 count += 1
print(f"Tests found: {count}") print(f"Tests found: {count}")
return
def get_platform_instances(self, platform): def get_platform_instances(self, platform):
filtered_dict = {k:v for k,v in self.instances.items() if k.startswith(platform + os.sep)} filtered_dict = {k:v for k,v in self.instances.items() if k.startswith(platform + os.sep)}
return filtered_dict return filtered_dict

View file

@ -4,7 +4,6 @@
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import os import os
import sys
from pathlib import Path from pathlib import Path
import re import re
import logging import logging
@ -12,9 +11,9 @@ import contextlib
import mmap import mmap
import glob import glob
from typing import List from typing import List
from twister.mixins import DisablePyTestCollectionMixin from twisterlib.mixins import DisablePyTestCollectionMixin
from twister.enviornment import canonical_zephyr_base from twisterlib.enviornment import canonical_zephyr_base
from twister.error import TwisterException, TwisterRuntimeError from twisterlib.error import TwisterException, TwisterRuntimeError
logger = logging.getLogger('twister') logger = logging.getLogger('twister')
logger.setLevel(logging.DEBUG) logger.setLevel(logging.DEBUG)
@ -422,4 +421,3 @@ Tests should reference the category and subsystem with a dot as a separator.
""" """
) )
return unique return unique

View file

@ -12,9 +12,9 @@ import pytest
ZEPHYR_BASE = os.getenv("ZEPHYR_BASE") ZEPHYR_BASE = os.getenv("ZEPHYR_BASE")
sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts/pylib/twister")) sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts/pylib/twister"))
sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts")) sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts"))
from twister.testplan import TestPlan from twisterlib.testplan import TestPlan
from twister.testinstance import TestInstance from twisterlib.testinstance import TestInstance
from twister.enviornment import TwisterEnv, parse_arguments from twisterlib.enviornment import TwisterEnv, parse_arguments
def new_get_toolchain(*args, **kwargs): def new_get_toolchain(*args, **kwargs):
return 'zephyr' return 'zephyr'

View file

@ -13,9 +13,9 @@ import pytest
ZEPHYR_BASE = os.getenv("ZEPHYR_BASE") ZEPHYR_BASE = os.getenv("ZEPHYR_BASE")
sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts/pylib/twister")) sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts/pylib/twister"))
from twister.testinstance import TestInstance from twisterlib.testinstance import TestInstance
from twister.error import BuildError, TwisterException from twisterlib.error import BuildError, TwisterException
from twister.testsuite import TestSuite from twisterlib.testsuite import TestSuite
TESTDATA_1 = [ TESTDATA_1 = [

View file

@ -13,10 +13,10 @@ import pytest
ZEPHYR_BASE = os.getenv("ZEPHYR_BASE") ZEPHYR_BASE = os.getenv("ZEPHYR_BASE")
sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts/pylib/twister")) sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts/pylib/twister"))
from twister.testplan import TestPlan from twisterlib.testplan import TestPlan
from twister.testinstance import TestInstance from twisterlib.testinstance import TestInstance
from twister.testsuite import TestSuite from twisterlib.testsuite import TestSuite
from twister.platform import Platform from twisterlib.platform import Platform
def test_testplan_add_testsuites(class_testplan): def test_testplan_add_testsuites(class_testplan):
@ -255,4 +255,3 @@ def test_add_instances(test_data, class_env, all_testsuites_dict, platforms_list
[platform.name + '/' + s for s in list(all_testsuites_dict.keys())] [platform.name + '/' + s for s in list(all_testsuites_dict.keys())]
assert all(isinstance(n, TestInstance) for n in list(plan.instances.values())) assert all(isinstance(n, TestInstance) for n in list(plan.instances.values()))
assert list(plan.instances.values()) == instance_list assert list(plan.instances.values()) == instance_list

View file

@ -2,7 +2,6 @@
# Copyright (c) 2020 Intel Corporation # Copyright (c) 2020 Intel Corporation
# #
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
# pylint: disable=line-too-long
""" """
Tests for testinstance class Tests for testinstance class
""" """
@ -14,7 +13,7 @@ import pytest
ZEPHYR_BASE = os.getenv("ZEPHYR_BASE") ZEPHYR_BASE = os.getenv("ZEPHYR_BASE")
sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts/pylib/twister")) sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts/pylib/twister"))
from twister.testsuite import scan_file, ScanPathResult from twisterlib.testsuite import scan_file, ScanPathResult
TESTDATA_5 = [ TESTDATA_5 = [
("testsuites/tests/test_ztest.c", ("testsuites/tests/test_ztest.c",
@ -59,4 +58,3 @@ def test_scan_file(test_data, test_file, class_env, expected: ScanPathResult):
result: ScanPathResult = scan_file(os.path.join(test_data, test_file)) result: ScanPathResult = scan_file(os.path.join(test_data, test_file))
assert result == expected assert result == expected

View file

@ -14,7 +14,7 @@ ZEPHYR_BASE = os.getenv("ZEPHYR_BASE")
sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts/pylib/twister")) sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts/pylib/twister"))
import scl import scl
from twister.testplan import TwisterConfigParser from twisterlib.testplan import TwisterConfigParser
def test_yamlload(): def test_yamlload():
""" Test to check if loading the non-existent files raises the errors """ """ Test to check if loading the non-existent files raises the errors """

View file

@ -187,20 +187,14 @@ if not ZEPHYR_BASE:
print(f'ZEPHYR_BASE unset, using "{ZEPHYR_BASE}"') print(f'ZEPHYR_BASE unset, using "{ZEPHYR_BASE}"')
sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts/pylib/twister/"))
try: from twisterlib.testplan import TestPlan
from tabulate import tabulate from twisterlib.enviornment import TwisterEnv, parse_arguments
except ImportError: from twisterlib.reports import Reporting
print("Install tabulate python module with pip to use --device-testing option.") from twisterlib.hardwaremap import HardwareMap
from twisterlib.coverage import run_coverage
sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts/pylib/twister")) from twisterlib.runner import TwisterRunner
from twister.testplan import TestPlan
from twister.enviornment import TwisterEnv, parse_arguments
from twister.reports import Reporting
from twister.hardwaremap import HardwareMap
from twister.coverage import run_coverage
from twister.runner import TwisterRunner
logger = logging.getLogger('twister') logger = logging.getLogger('twister')
logger.setLevel(logging.DEBUG) logger.setLevel(logging.DEBUG)