misc,python: Run pre-commit run --all-files
Applies the `pyupgrade` hook to all files in the repo. Change-Id: I9879c634a65c5fcaa9567c63bc5977ff97d5d3bf
This commit is contained in:
@@ -105,7 +105,7 @@ class UninitializedConfigException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class TagRegex(object):
|
||||
class TagRegex:
|
||||
def __init__(self, include, regex):
|
||||
self.include = include
|
||||
self.regex = re.compile(regex)
|
||||
@@ -115,7 +115,7 @@ class TagRegex(object):
|
||||
return "%10s: %s" % (type_, self.regex.pattern)
|
||||
|
||||
|
||||
class _Config(object):
|
||||
class _Config:
|
||||
_initialized = False
|
||||
|
||||
__shared_dict = {}
|
||||
@@ -185,8 +185,8 @@ class _Config(object):
|
||||
return (getattr(self._defaults, attr),)
|
||||
|
||||
def __getattr__(self, attr):
|
||||
if attr in dir(super(_Config, self)):
|
||||
return getattr(super(_Config, self), attr)
|
||||
if attr in dir(super()):
|
||||
return getattr(super(), attr)
|
||||
elif not self._initialized:
|
||||
raise UninitializedConfigException(
|
||||
"Cannot directly access elements from the config before it is"
|
||||
@@ -434,7 +434,7 @@ def define_post_processors(config):
|
||||
)
|
||||
|
||||
|
||||
class Argument(object):
|
||||
class Argument:
|
||||
"""
|
||||
Class represents a cli argument/flag for a argparse parser.
|
||||
|
||||
@@ -651,7 +651,7 @@ def define_common_args(config):
|
||||
common_args = AttrDict({arg.name: arg for arg in common_args})
|
||||
|
||||
|
||||
class ArgParser(object, metaclass=abc.ABCMeta):
|
||||
class ArgParser(metaclass=abc.ABCMeta):
|
||||
class ExtendAction(argparse.Action):
|
||||
def __call__(self, parser, namespace, values, option_string=None):
|
||||
items = getattr(namespace, self.dest, [])
|
||||
@@ -679,7 +679,7 @@ class CommandParser(ArgParser):
|
||||
|
||||
def __init__(self):
|
||||
parser = argparse.ArgumentParser()
|
||||
super(CommandParser, self).__init__(parser)
|
||||
super().__init__(parser)
|
||||
self.subparser = self.add_subparsers(dest="command")
|
||||
|
||||
|
||||
@@ -691,7 +691,7 @@ class RunParser(ArgParser):
|
||||
def __init__(self, subparser):
|
||||
parser = subparser.add_parser("run", help="""Run Tests.""")
|
||||
|
||||
super(RunParser, self).__init__(parser)
|
||||
super().__init__(parser)
|
||||
|
||||
common_args.uid.add_to(parser)
|
||||
common_args.skip_build.add_to(parser)
|
||||
@@ -718,7 +718,7 @@ class ListParser(ArgParser):
|
||||
parser = subparser.add_parser(
|
||||
"list", help="""List and query test metadata."""
|
||||
)
|
||||
super(ListParser, self).__init__(parser)
|
||||
super().__init__(parser)
|
||||
|
||||
Argument(
|
||||
"--suites",
|
||||
@@ -777,7 +777,7 @@ class ListParser(ArgParser):
|
||||
class RerunParser(ArgParser):
|
||||
def __init__(self, subparser):
|
||||
parser = subparser.add_parser("rerun", help="""Rerun failed tests.""")
|
||||
super(RerunParser, self).__init__(parser)
|
||||
super().__init__(parser)
|
||||
|
||||
common_args.skip_build.add_to(parser)
|
||||
common_args.directories.add_to(parser)
|
||||
|
||||
@@ -34,14 +34,14 @@ from typing import Optional
|
||||
|
||||
class SkipException(Exception):
|
||||
def __init__(self, fixture, testitem):
|
||||
self.msg = 'Fixture "%s" raised SkipException for "%s".' % (
|
||||
self.msg = 'Fixture "{}" raised SkipException for "{}".'.format(
|
||||
fixture.name,
|
||||
testitem.name,
|
||||
)
|
||||
super(SkipException, self).__init__(self.msg)
|
||||
super().__init__(self.msg)
|
||||
|
||||
|
||||
class Fixture(object):
|
||||
class Fixture:
|
||||
"""
|
||||
Base Class for a test Fixture.
|
||||
|
||||
@@ -60,7 +60,7 @@ class Fixture(object):
|
||||
collector = helper.InstanceCollector()
|
||||
|
||||
def __new__(klass, *args, **kwargs):
|
||||
obj = super(Fixture, klass).__new__(klass)
|
||||
obj = super().__new__(klass)
|
||||
Fixture.collector.collect(obj)
|
||||
return obj
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ from queue import Queue, Empty
|
||||
from testlib.configuration import constants
|
||||
|
||||
|
||||
class _TestStreamManager(object):
|
||||
class _TestStreamManager:
|
||||
def __init__(self):
|
||||
self._writers = {}
|
||||
|
||||
@@ -75,7 +75,7 @@ class _TestStreamManager(object):
|
||||
self._writers.clear()
|
||||
|
||||
|
||||
class _TestStreams(object):
|
||||
class _TestStreams:
|
||||
def __init__(self, stdout, stderr):
|
||||
helper.mkdir_p(os.path.dirname(stdout))
|
||||
helper.mkdir_p(os.path.dirname(stderr))
|
||||
@@ -87,7 +87,7 @@ class _TestStreams(object):
|
||||
self.stderr.close()
|
||||
|
||||
|
||||
class ResultHandler(object):
|
||||
class ResultHandler:
|
||||
"""
|
||||
Log handler which listens for test results and output saving data as
|
||||
it is reported.
|
||||
@@ -184,7 +184,7 @@ class ResultHandler(object):
|
||||
|
||||
# TODO Change from a handler to an internal post processor so it can be used
|
||||
# to reprint results
|
||||
class SummaryHandler(object):
|
||||
class SummaryHandler:
|
||||
"""
|
||||
A log handler which listens to the log for test results
|
||||
and reports the aggregate results when closed.
|
||||
@@ -255,7 +255,7 @@ class SummaryHandler(object):
|
||||
string = (
|
||||
" Results:"
|
||||
+ string
|
||||
+ " in {:.2} seconds ".format(self._timer.active_time())
|
||||
+ f" in {self._timer.active_time():.2} seconds "
|
||||
)
|
||||
string += " "
|
||||
return terminal.insert_separator(
|
||||
@@ -263,7 +263,7 @@ class SummaryHandler(object):
|
||||
)
|
||||
|
||||
|
||||
class TerminalHandler(object):
|
||||
class TerminalHandler:
|
||||
color = terminal.get_termcap()
|
||||
verbosity_mapping = {
|
||||
log.LogLevel.Warn: color.Yellow,
|
||||
@@ -339,7 +339,7 @@ class TerminalHandler(object):
|
||||
)
|
||||
|
||||
def _colorize(self, message, level, bold=False):
|
||||
return "%s%s%s%s" % (
|
||||
return "{}{}{}{}".format(
|
||||
self.color.Bold if bold else "",
|
||||
self.verbosity_mapping.get(level, ""),
|
||||
message,
|
||||
@@ -355,7 +355,7 @@ class TerminalHandler(object):
|
||||
pass
|
||||
|
||||
|
||||
class MultiprocessingHandlerWrapper(object):
|
||||
class MultiprocessingHandlerWrapper:
|
||||
"""
|
||||
A handler class which forwards log records to subhandlers, enabling
|
||||
logging across multiprocessing python processes.
|
||||
|
||||
@@ -56,7 +56,7 @@ import threading
|
||||
import time
|
||||
|
||||
|
||||
class TimedWaitPID(object):
|
||||
class TimedWaitPID:
|
||||
"""Utility to monkey-patch os.waitpid() with os.wait4().
|
||||
|
||||
This allows process usage time to be obtained directly from the OS
|
||||
@@ -73,7 +73,7 @@ class TimedWaitPID(object):
|
||||
|
||||
TimeRecord = namedtuple("_TimeRecord", "user_time system_time")
|
||||
|
||||
class Wrapper(object):
|
||||
class Wrapper:
|
||||
def __init__(self):
|
||||
self._time_for_pid = {}
|
||||
self._access_lock = threading.Lock()
|
||||
@@ -93,7 +93,7 @@ class TimedWaitPID(object):
|
||||
def get_time_for_pid(self, pid):
|
||||
with self._access_lock:
|
||||
if pid not in self._time_for_pid:
|
||||
raise Exception("No resource usage for pid {}".format(pid))
|
||||
raise Exception(f"No resource usage for pid {pid}")
|
||||
time_for_pid = self._time_for_pid[pid]
|
||||
del self._time_for_pid[pid]
|
||||
return time_for_pid
|
||||
@@ -346,8 +346,8 @@ class OrderedSet(MutableSet):
|
||||
|
||||
def __repr__(self):
|
||||
if not self:
|
||||
return "%s()" % (self.__class__.__name__,)
|
||||
return "%s(%r)" % (self.__class__.__name__, list(self))
|
||||
return f"{self.__class__.__name__}()"
|
||||
return f"{self.__class__.__name__}({list(self)!r})"
|
||||
|
||||
def __eq__(self, other):
|
||||
if isinstance(other, OrderedSet):
|
||||
@@ -386,7 +386,7 @@ class FrozenSetException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class AttrDict(object):
|
||||
class AttrDict:
|
||||
"""Object which exposes its own internal dictionary through attributes."""
|
||||
|
||||
def __init__(self, dict_={}):
|
||||
@@ -417,7 +417,7 @@ class FrozenAttrDict(AttrDict):
|
||||
__initialized = False
|
||||
|
||||
def __init__(self, dict_={}):
|
||||
super(FrozenAttrDict, self).__init__(dict_)
|
||||
super().__init__(dict_)
|
||||
self.__initialized = True
|
||||
|
||||
def __setattr__(self, attr, val):
|
||||
@@ -426,7 +426,7 @@ class FrozenAttrDict(AttrDict):
|
||||
"Cannot modify an attribute in a FozenAttrDict"
|
||||
)
|
||||
else:
|
||||
super(FrozenAttrDict, self).__setattr__(attr, val)
|
||||
super().__setattr__(attr, val)
|
||||
|
||||
def update(self, items):
|
||||
if self.__initialized:
|
||||
@@ -434,10 +434,10 @@ class FrozenAttrDict(AttrDict):
|
||||
"Cannot modify an attribute in a FozenAttrDict"
|
||||
)
|
||||
else:
|
||||
super(FrozenAttrDict, self).update(items)
|
||||
super().update(items)
|
||||
|
||||
|
||||
class InstanceCollector(object):
|
||||
class InstanceCollector:
|
||||
"""
|
||||
A class used to simplify collecting of Classes.
|
||||
|
||||
@@ -475,7 +475,7 @@ def append_dictlist(dict_, key, value):
|
||||
|
||||
|
||||
def _filter_file(fname, filters):
|
||||
with open(fname, "r") as file_:
|
||||
with open(fname) as file_:
|
||||
for line in file_:
|
||||
for regex in filters:
|
||||
if re.match(regex, line):
|
||||
@@ -529,7 +529,7 @@ def diff_out_file(ref_file, out_file, logger, ignore_regexes=tuple()):
|
||||
except OSError:
|
||||
# Likely signals that diff does not exist on this system. fallback
|
||||
# to difflib
|
||||
with open(out_file, "r") as outf, open(ref_file, "r") as reff:
|
||||
with open(out_file) as outf, open(ref_file) as reff:
|
||||
diff = difflib.unified_diff(
|
||||
iter(reff.readline, ""),
|
||||
iter(outf.readline, ""),
|
||||
|
||||
@@ -110,7 +110,7 @@ def path_as_modulename(filepath):
|
||||
|
||||
|
||||
def path_as_suitename(filepath):
|
||||
return os.path.split(os.path.dirname(os.path.abspath((filepath))))[-1]
|
||||
return os.path.split(os.path.dirname(os.path.abspath(filepath)))[-1]
|
||||
|
||||
|
||||
def _assert_files_in_same_dir(files):
|
||||
@@ -121,7 +121,7 @@ def _assert_files_in_same_dir(files):
|
||||
assert os.path.dirname(f) == directory
|
||||
|
||||
|
||||
class Loader(object):
|
||||
class Loader:
|
||||
"""
|
||||
Class for discovering tests.
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ class RecordTypeCounterMetaclass(type):
|
||||
RecordTypeCounterMetaclass.counter += 1
|
||||
|
||||
|
||||
class Record(object, metaclass=RecordTypeCounterMetaclass):
|
||||
class Record(metaclass=RecordTypeCounterMetaclass):
|
||||
"""
|
||||
A generic object that is passed to the :class:`Log` and its handlers.
|
||||
|
||||
@@ -70,9 +70,7 @@ class Record(object, metaclass=RecordTypeCounterMetaclass):
|
||||
|
||||
def __getitem__(self, item):
|
||||
if item not in self.data:
|
||||
raise KeyError(
|
||||
"%s not in record %s" % (item, self.__class__.__name__)
|
||||
)
|
||||
raise KeyError(f"{item} not in record {self.__class__.__name__}")
|
||||
return self.data[item]
|
||||
|
||||
def __str__(self):
|
||||
@@ -132,7 +130,7 @@ class LibraryMessage(Record):
|
||||
pass
|
||||
|
||||
|
||||
class Log(object):
|
||||
class Log:
|
||||
_result_typemap = {
|
||||
wrappers.LoadedLibrary.__name__: LibraryResult,
|
||||
wrappers.LoadedSuite.__name__: SuiteResult,
|
||||
|
||||
@@ -141,7 +141,7 @@ def filter_with_config_tags(loaded_library):
|
||||
|
||||
filters = list(itertools.chain(final_tags, tags))
|
||||
string = "Filtering suites with tags as follows:\n"
|
||||
filter_string = "\t\n".join((str(f) for f in filters))
|
||||
filter_string = "\t\n".join(str(f) for f in filters)
|
||||
log.test_log.trace(string + filter_string)
|
||||
|
||||
return filter_with_tags(loaded_library, filters)
|
||||
@@ -307,11 +307,11 @@ def run_schedule(test_schedule, log_handler):
|
||||
|
||||
log.test_log.message(terminal.separator())
|
||||
log.test_log.message(
|
||||
"Running Tests from {} suites".format(len(test_schedule.suites)),
|
||||
f"Running Tests from {len(test_schedule.suites)} suites",
|
||||
bold=True,
|
||||
)
|
||||
log.test_log.message(
|
||||
"Results will be stored in {}".format(configuration.config.result_path)
|
||||
f"Results will be stored in {configuration.config.result_path}"
|
||||
)
|
||||
log.test_log.message(terminal.separator())
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ import testlib.log as log
|
||||
|
||||
# TODO Refactor print logic out of this so the objects
|
||||
# created are separate from print logic.
|
||||
class QueryRunner(object):
|
||||
class QueryRunner:
|
||||
def __init__(self, test_schedule):
|
||||
self.schedule = test_schedule
|
||||
|
||||
|
||||
@@ -189,7 +189,7 @@ class InternalSavedResults:
|
||||
return pickle.load(f)
|
||||
|
||||
|
||||
class XMLElement(object):
|
||||
class XMLElement:
|
||||
def write(self, file_):
|
||||
self.begin(file_)
|
||||
self.end(file_)
|
||||
@@ -219,15 +219,13 @@ class XMLElement(object):
|
||||
file_.write("</%s>" % self.name)
|
||||
|
||||
|
||||
class XMLAttribute(object):
|
||||
class XMLAttribute:
|
||||
def __init__(self, name, value):
|
||||
self.name = name
|
||||
self.value = value
|
||||
|
||||
def write(self, file_):
|
||||
file_.write(
|
||||
"%s=%s" % (self.name, xml.sax.saxutils.quoteattr(self.value))
|
||||
)
|
||||
file_.write(f"{self.name}={xml.sax.saxutils.quoteattr(self.value)}")
|
||||
|
||||
|
||||
class JUnitTestSuites(XMLElement):
|
||||
@@ -328,10 +326,10 @@ class LargeFileElement(XMLElement):
|
||||
|
||||
def body(self, file_):
|
||||
try:
|
||||
with open(self.filename, "r") as f:
|
||||
with open(self.filename) as f:
|
||||
for line in f:
|
||||
file_.write(xml.sax.saxutils.escape(line))
|
||||
except IOError:
|
||||
except OSError:
|
||||
# TODO Better error logic, this is sometimes O.K.
|
||||
# if there was no stdout/stderr captured for the test
|
||||
#
|
||||
|
||||
@@ -75,7 +75,7 @@ def compute_aggregate_result(iterable):
|
||||
return Result(Result.Passed)
|
||||
|
||||
|
||||
class TestParameters(object):
|
||||
class TestParameters:
|
||||
def __init__(self, test, suite):
|
||||
self.test = test
|
||||
self.suite = suite
|
||||
@@ -188,10 +188,10 @@ class BrokenFixtureException(Exception):
|
||||
'Exception raised building "%s" raised SkipException'
|
||||
' for "%s".' % (trace, fixture.name, testitem.name)
|
||||
)
|
||||
super(BrokenFixtureException, self).__init__(self.msg)
|
||||
super().__init__(self.msg)
|
||||
|
||||
|
||||
class FixtureBuilder(object):
|
||||
class FixtureBuilder:
|
||||
def __init__(self, fixtures):
|
||||
self.fixtures = fixtures
|
||||
self.built_fixtures = []
|
||||
@@ -211,7 +211,7 @@ class FixtureBuilder(object):
|
||||
"Exception raised while setting up fixture for %s"
|
||||
% testitem.uid
|
||||
)
|
||||
log.test_log.warn("%s\n%s" % (exc, msg))
|
||||
log.test_log.warn(f"{exc}\n{msg}")
|
||||
|
||||
raise BrokenFixtureException(
|
||||
fixture, testitem, traceback.format_exc()
|
||||
@@ -232,4 +232,4 @@ class FixtureBuilder(object):
|
||||
"Exception raised while tearing down fixture for %s"
|
||||
% testitem.uid
|
||||
)
|
||||
log.test_log.warn("%s\n%s" % (exc, msg))
|
||||
log.test_log.warn(f"{exc}\n{msg}")
|
||||
|
||||
@@ -31,7 +31,7 @@ import testlib.helper as helper
|
||||
import testlib.runner as runner_mod
|
||||
|
||||
|
||||
class TestSuite(object):
|
||||
class TestSuite:
|
||||
"""
|
||||
An object grouping a collection of tests. It provides tags which enable
|
||||
filtering during list and run selection. All tests held in the suite must
|
||||
@@ -54,7 +54,7 @@ class TestSuite(object):
|
||||
tags = set()
|
||||
|
||||
def __new__(klass, *args, **kwargs):
|
||||
obj = super(TestSuite, klass).__new__(klass)
|
||||
obj = super().__new__(klass)
|
||||
TestSuite.collector.collect(obj)
|
||||
return obj
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ except:
|
||||
cap_string = null_cap_string
|
||||
|
||||
|
||||
class ColorStrings(object):
|
||||
class ColorStrings:
|
||||
def __init__(self, cap_string):
|
||||
for i, c in enumerate(color_names):
|
||||
setattr(self, c, cap_string("setaf", i))
|
||||
@@ -123,7 +123,7 @@ def terminal_size():
|
||||
),
|
||||
)
|
||||
return w, h
|
||||
except IOError:
|
||||
except OSError:
|
||||
# It's possible that in sandboxed environments the above ioctl is not
|
||||
# allowed (e.g., some jenkins setups)
|
||||
return 80, 24
|
||||
|
||||
@@ -30,7 +30,7 @@ import testlib.helper as helper
|
||||
import testlib.runner as runner_mod
|
||||
|
||||
|
||||
class TestCase(object):
|
||||
class TestCase:
|
||||
"""
|
||||
Base class for all tests.
|
||||
|
||||
@@ -47,7 +47,7 @@ class TestCase(object):
|
||||
collector = helper.InstanceCollector()
|
||||
|
||||
def __new__(cls, *args, **kwargs):
|
||||
obj = super(TestCase, cls).__new__(cls)
|
||||
obj = super().__new__(cls)
|
||||
TestCase.collector.collect(obj)
|
||||
return obj
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ import itertools
|
||||
import testlib.configuration as configuration
|
||||
|
||||
|
||||
class UID(object):
|
||||
class UID:
|
||||
sep = ":"
|
||||
type_idx, path_idx = range(2)
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ class LibraryMetadata:
|
||||
self.status = status
|
||||
|
||||
|
||||
class LoadedTestable(object):
|
||||
class LoadedTestable:
|
||||
"""
|
||||
Base class for loaded test items.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user