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
import scl
from twisterlib.error import ConfigurationError
class TwisterConfigParser:
"""Class to read testsuite yaml files with semantic checking

View file

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

View file

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

View file

@ -14,7 +14,7 @@ import scl
import logging
from pathlib import Path
from twister.enviornment import ZEPHYR_BASE
from twisterlib.enviornment import ZEPHYR_BASE
try:
# 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:
self.load(self.options.hardware_map)
logger.info("Available devices:")
table = []
self.dump(connected_only=True)
return 0

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -7,12 +7,15 @@ import os
import hashlib
import random
import logging
from twister.testsuite import TestCase
from twister.error import BuildError
from twister.handlers import BinaryHandler, QEMUHandler, DeviceHandler
import shutil
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.setLevel(logging.DEBUG)

View file

@ -10,13 +10,10 @@ import subprocess
import glob
import json
import collections
from typing import List
from collections import OrderedDict
from itertools import islice
import logging
logger = logging.getLogger('twister')
logger.setLevel(logging.DEBUG)
@ -25,23 +22,15 @@ try:
except ImportError:
print("Install the anytree module to use the --test-tree option")
from twister.testsuite import TestSuite, scan_testsuite_path
from twister.error import TwisterRuntimeError
from twister.platform import Platform
from twister.config_parser import TwisterConfigParser
from twister.testinstance import TestInstance
from twisterlib.testsuite import TestSuite, scan_testsuite_path
from twisterlib.error import TwisterRuntimeError
from twisterlib.platform import Platform
from twisterlib.config_parser import TwisterConfigParser
from twisterlib.testinstance import TestInstance
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")
if not ZEPHYR_BASE:
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"))
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/"))
import scl
@ -208,7 +195,7 @@ class TestPlan:
s = self.options.subset
try:
subset, sets = (int(x) for x in s.split("/"))
except ValueError as e:
except ValueError:
raise TwisterRuntimeError("Bad subset value.")
if subset > sets:
@ -325,7 +312,7 @@ class TestPlan:
if not area:
area = Node(sec[1], parent=samples)
t = Node(test, parent=area)
Node(test, parent=area)
else:
sec = test.split(".")
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)
if not subarea:
subarea = Node(sec[1], parent=area)
t = Node(test, parent=subarea)
Node(test, parent=subarea)
for pre, _, node in RenderTree(testsuite):
print("%s%s" % (pre, node.name))
@ -355,14 +342,13 @@ class TestPlan:
def report_excluded_tests(self):
all_tests = self.get_all_tests()
to_be_run = set()
for i, p in self.instances.items():
for _, p in self.instances.items():
to_be_run.update(p.testsuite.cases)
if all_tests - to_be_run:
print("Tests that never build or run:")
for not_run in all_tests - to_be_run:
print("- {}".format(not_run))
return
def report_platform_tests(self, platforms=[]):
if len(platforms) > 1:
@ -378,8 +364,6 @@ class TestPlan:
count += 1
print(f"Tests found: {count}")
return
def get_platform_instances(self, platform):
filtered_dict = {k:v for k,v in self.instances.items() if k.startswith(platform + os.sep)}
return filtered_dict

View file

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

View file

@ -12,9 +12,9 @@ import pytest
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"))
from twister.testplan import TestPlan
from twister.testinstance import TestInstance
from twister.enviornment import TwisterEnv, parse_arguments
from twisterlib.testplan import TestPlan
from twisterlib.testinstance import TestInstance
from twisterlib.enviornment import TwisterEnv, parse_arguments
def new_get_toolchain(*args, **kwargs):
return 'zephyr'

View file

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

View file

@ -13,10 +13,10 @@ import pytest
ZEPHYR_BASE = os.getenv("ZEPHYR_BASE")
sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts/pylib/twister"))
from twister.testplan import TestPlan
from twister.testinstance import TestInstance
from twister.testsuite import TestSuite
from twister.platform import Platform
from twisterlib.testplan import TestPlan
from twisterlib.testinstance import TestInstance
from twisterlib.testsuite import TestSuite
from twisterlib.platform import Platform
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())]
assert all(isinstance(n, TestInstance) for n in list(plan.instances.values()))
assert list(plan.instances.values()) == instance_list

View file

@ -2,7 +2,6 @@
# Copyright (c) 2020 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
# pylint: disable=line-too-long
"""
Tests for testinstance class
"""
@ -14,7 +13,7 @@ import pytest
ZEPHYR_BASE = os.getenv("ZEPHYR_BASE")
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 = [
("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))
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"))
import scl
from twister.testplan import TwisterConfigParser
from twisterlib.testplan import TwisterConfigParser
def test_yamlload():
""" 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}"')
sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts/pylib/twister/"))
try:
from tabulate import tabulate
except ImportError:
print("Install tabulate python module with pip to use --device-testing option.")
sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts/pylib/twister"))
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
from twisterlib.testplan import TestPlan
from twisterlib.enviornment import TwisterEnv, parse_arguments
from twisterlib.reports import Reporting
from twisterlib.hardwaremap import HardwareMap
from twisterlib.coverage import run_coverage
from twisterlib.runner import TwisterRunner
logger = logging.getLogger('twister')
logger.setLevel(logging.DEBUG)