Skip to content

Commit

Permalink
Merge pull request #302 from mtreinish/upgrade-python-to-latest-suppo…
Browse files Browse the repository at this point in the history
…rted

Update python syntax to latest
  • Loading branch information
masayukig committed Mar 9, 2021
2 parents d731647 + 65289ba commit fc503ee
Show file tree
Hide file tree
Showing 35 changed files with 63 additions and 69 deletions.
4 changes: 2 additions & 2 deletions stestr/bisect_tests.py
Expand Up @@ -17,12 +17,12 @@
from stestr import output


class IsolationAnalyzer(object):
class IsolationAnalyzer:

def __init__(self, latest_run, conf, run_func, repo, test_path=None,
top_dir=None, group_regex=None, repo_type='file',
repo_url=None, serial=False, concurrency=0):
super(IsolationAnalyzer, self).__init__()
super().__init__()
self._worker_to_test = None
self._test_to_worker = None
self.latest_run = latest_run
Expand Down
7 changes: 3 additions & 4 deletions stestr/cli.py
Expand Up @@ -22,7 +22,7 @@
class StestrCLI(app.App):

def __init__(self):
super(StestrCLI, self).__init__(
super().__init__(
description="A parallel Python test runner built around subunit",
version=__version__,
command_manager=commandmanager.CommandManager('stestr.cm'),
Expand All @@ -45,9 +45,8 @@ def clean_up(self, cmd, result, err):
self.LOG.debug('got an error: %s', err)

def build_option_parser(self, description, version, argparse_kwargs=None):
parser = super(StestrCLI,
self).build_option_parser(description, version,
argparse_kwargs)
parser = super().build_option_parser(description, version,
argparse_kwargs)
parser = self._set_common_opts(parser)
return parser

Expand Down
4 changes: 2 additions & 2 deletions stestr/colorizer.py
Expand Up @@ -37,7 +37,7 @@
import sys


class AnsiColorizer(object):
class AnsiColorizer:
"""A colorizer is an object that loosely wraps around a stream
allowing callers to write text to the stream in a particular color.
Expand Down Expand Up @@ -85,7 +85,7 @@ def write(self, text, color):
self.stream.write('\x1b[{};1m{}\x1b[0m'.format(color, text))


class NullColorizer(object):
class NullColorizer:
"""See _AnsiColorizer docstring."""
def __init__(self, stream):
self.stream = stream
Expand Down
2 changes: 1 addition & 1 deletion stestr/commands/failing.py
Expand Up @@ -38,7 +38,7 @@ class Failing(command.Command):
"""

def get_parser(self, prog_name):
parser = super(Failing, self).get_parser(prog_name)
parser = super().get_parser(prog_name)
parser.add_argument(
"--subunit", action="store_true",
default=False, help="Show output as a subunit stream.")
Expand Down
2 changes: 1 addition & 1 deletion stestr/commands/last.py
Expand Up @@ -39,7 +39,7 @@ class Last(command.Command):
"""

def get_parser(self, prog_name):
parser = super(Last, self).get_parser(prog_name)
parser = super().get_parser(prog_name)
parser.add_argument(
"--subunit", action="store_true",
default=False, help="Show output as a subunit stream.")
Expand Down
2 changes: 1 addition & 1 deletion stestr/commands/list.py
Expand Up @@ -30,7 +30,7 @@ class List(command.Command):
"""

def get_parser(self, prog_name):
parser = super(List, self).get_parser(prog_name)
parser = super().get_parser(prog_name)
parser.add_argument("filters", nargs="*", default=None,
help="A list of string regex filters to initially "
"apply on the test list. Tests that match any of "
Expand Down
2 changes: 1 addition & 1 deletion stestr/commands/load.py
Expand Up @@ -47,7 +47,7 @@ class Load(command.Command):
"""

def get_parser(self, prog_name):
parser = super(Load, self).get_parser(prog_name)
parser = super().get_parser(prog_name)
parser.add_argument("files", nargs="*", default=False,
help="The subunit v2 stream files to load into the"
" repository")
Expand Down
2 changes: 1 addition & 1 deletion stestr/commands/run.py
Expand Up @@ -61,7 +61,7 @@ class Run(command.Command):
"""

def get_parser(self, prog_name):
parser = super(Run, self).get_parser(prog_name)
parser = super().get_parser(prog_name)
parser.add_argument("filters", nargs="*", default=None,
help="A list of string regex filters to initially "
"apply on the test list. Tests that match any of "
Expand Down
2 changes: 1 addition & 1 deletion stestr/commands/slowest.py
Expand Up @@ -29,7 +29,7 @@ class Slowest(command.Command):
"""

def get_parser(self, prog_name):
parser = super(Slowest, self).get_parser(prog_name)
parser = super().get_parser(prog_name)
parser.add_argument(
"--all", action="store_true",
default=False, help="Show timing for all tests.")
Expand Down
2 changes: 1 addition & 1 deletion stestr/config_file.py
Expand Up @@ -20,7 +20,7 @@
from stestr import test_processor


class TestrConf(object):
class TestrConf:
"""Create a TestrConf object to represent a specified config file
This class is used to represent an stestr config file. It
Expand Down
2 changes: 1 addition & 1 deletion stestr/output.py
Expand Up @@ -151,7 +151,7 @@ def output_stream(stream, output=sys.stdout):
_binary_stdout.flush()


class ReturnCodeToSubunit(object):
class ReturnCodeToSubunit:
"""Converts a process return code to a subunit error on the process stdout.
The ReturnCodeToSubunit object behaves as a read-only stream, supplying
Expand Down
6 changes: 3 additions & 3 deletions stestr/repository/abstract.py
Expand Up @@ -29,7 +29,7 @@
from testtools import StreamToDict


class AbstractRepositoryFactory(object):
class AbstractRepositoryFactory:
"""Interface for making or opening repositories."""

def initialise(self, url):
Expand All @@ -47,7 +47,7 @@ def open(self, url):
raise NotImplementedError(self.open)


class AbstractRepository(object):
class AbstractRepository:
"""The base class for Repository implementations.
There are no interesting attributes or methods as yet.
Expand Down Expand Up @@ -165,7 +165,7 @@ def find_metadata(self, metadata):
raise NotImplementedError(self.find_metadata)


class AbstractTestRun(object):
class AbstractTestRun:
"""A test run that has been stored in a repository.
Should implement the StreamResult protocol as well
Expand Down
14 changes: 7 additions & 7 deletions stestr/repository/file.py
Expand Up @@ -58,8 +58,8 @@ def open(self, url):
path = os.path.expanduser(url)
base = os.path.join(path, '.stestr')
try:
stream = open(os.path.join(base, 'format'), 'rt')
except (IOError, OSError) as e:
stream = open(os.path.join(base, 'format'))
except OSError as e:
if e.errno == errno.ENOENT:
raise repository.RepositoryNotFound(url)
raise
Expand Down Expand Up @@ -94,7 +94,7 @@ def _allocate(self):
return value

def _next_stream(self):
with open(os.path.join(self.base, 'next-stream'), 'rt') as fp:
with open(os.path.join(self.base, 'next-stream')) as fp:
next_content = fp.read()
try:
return int(next_content)
Expand All @@ -114,7 +114,7 @@ def get_failing(self):
try:
with open(os.path.join(self.base, "failing"), 'rb') as fp:
run_subunit_content = fp.read()
except IOError:
except OSError:
err = sys.exc_info()[1]
if err.errno == errno.ENOENT:
run_subunit_content = _b('')
Expand All @@ -134,7 +134,7 @@ def get_test_run(self, run_id):
try:
with open(os.path.join(self.base, str(run_id)), 'rb') as fp:
run_subunit_content = fp.read()
except IOError as e:
except OSError as e:
if e.errno == errno.ENOENT:
raise KeyError("No such run.")
else:
Expand Down Expand Up @@ -243,7 +243,7 @@ def get_metadata(self):
return self._metadata


class _SafeInserter(object):
class _SafeInserter:

def __init__(self, repository, partial=False, run_id=None, metadata=None):
# XXX: Perhaps should factor into a decorator and use an unaltered
Expand Down Expand Up @@ -342,7 +342,7 @@ def _name(self):
return self._run_id

def stopTestRun(self):
super(_Inserter, self).stopTestRun()
super().stopTestRun()
# XXX: locking (other inserts may happen while we update the failing
# file).
# Combine failing + this run : strip passed tests, add failures.
Expand Down
3 changes: 1 addition & 2 deletions stestr/repository/sql.py
Expand Up @@ -11,7 +11,6 @@
# under the License.

"""Persistent storage of test results."""
from __future__ import print_function

import datetime
import io
Expand Down Expand Up @@ -91,7 +90,7 @@ def __init__(self, url):

# TODO(mtreinish): We need to add a subunit2sql api to get the count
def count(self):
super(Repository, self).count()
super().count()

def _get_latest_run(self):
session = self.session_factory()
Expand Down
16 changes: 8 additions & 8 deletions stestr/results.py
Expand Up @@ -24,10 +24,10 @@ def wasSuccessful(summary):
class SummarizingResult(testtools.StreamSummary):

def __init__(self):
super(SummarizingResult, self).__init__()
super().__init__()

def startTestRun(self):
super(SummarizingResult, self).startTestRun()
super().startTestRun()
self._first_time = None
self._last_time = None

Expand All @@ -41,7 +41,7 @@ def status(self, *args, **kwargs):
self._first_time = timestamp
if timestamp > self._last_time:
self._last_time = timestamp
super(SummarizingResult, self).status(*args, **kwargs)
super().status(*args, **kwargs)

def get_num_failures(self):
return len(self.failures) + len(self.errors)
Expand Down Expand Up @@ -84,7 +84,7 @@ def __init__(self, get_id, stream, previous_run=None):
:param stream: The stream to use for result
:param previous_run: The CLITestResult for the previous run
"""
super(CLITestResult, self).__init__()
super().__init__()
self._previous_run = previous_run
self._summary = SummarizingResult()
self.stream = testtools.compat.unicode_output_stream(stream)
Expand All @@ -107,13 +107,13 @@ def _format_error(self, label, test, error_text, test_tags=None):
]))

def status(self, **kwargs):
super(CLITestResult, self).status(**kwargs)
super().status(**kwargs)
self._summary.status(**kwargs)
test_status = kwargs.get('test_status')
test_tags = kwargs.get('test_tags')
if test_status == 'fail':
self.stream.write(
self._format_error(str('FAIL'),
self._format_error('FAIL',
*(self._summary.errors[-1]),
test_tags=test_tags))
if test_status not in self.filterable_states:
Expand Down Expand Up @@ -161,11 +161,11 @@ def _output_summary(self, run_id):
time, time_delta, values, output=self.stream)

def startTestRun(self):
super(CLITestResult, self).startTestRun()
super().startTestRun()
self._summary.startTestRun()

def stopTestRun(self):
super(CLITestResult, self).stopTestRun()
super().stopTestRun()
run_id = self.get_id()
self._summary.stopTestRun()
self._output_summary(run_id)
Expand Down
2 changes: 1 addition & 1 deletion stestr/scheduler.py
Expand Up @@ -157,7 +157,7 @@ def generate_worker_partitions(ids, worker_path, repository=None,
:returns: A list where each element is a distinct subset of test_ids.
"""
with open(worker_path, 'r') as worker_file:
with open(worker_path) as worker_file:
workers_desc = yaml.safe_load(worker_file.read())
worker_groups = []
for worker in workers_desc:
Expand Down
3 changes: 1 addition & 2 deletions stestr/selection.py
Expand Up @@ -9,7 +9,6 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from __future__ import print_function

import contextlib
import re
Expand Down Expand Up @@ -50,7 +49,7 @@ def include(test_id):


def exclusion_reader(exclude_list):
with contextlib.closing(open(exclude_list, 'r')) as exclude_file:
with contextlib.closing(open(exclude_list)) as exclude_file:
regex_comment_lst = [] # tuple of (regex_compiled, msg, skipped_lst)
for line in exclude_file:
raw_line = line.strip()
Expand Down
3 changes: 0 additions & 3 deletions stestr/subunit_trace.py
Expand Up @@ -15,9 +15,6 @@
# under the License.

"""Trace a subunit stream in reasonable detail and high accuracy."""
from __future__ import absolute_import
from __future__ import print_function

import argparse
import functools
import os
Expand Down
2 changes: 1 addition & 1 deletion stestr/test_processor.py
Expand Up @@ -112,7 +112,7 @@ def __init__(self, test_ids, cmd_template, listopt, idoption,
self.randomize = randomize

def setUp(self):
super(TestProcessorFixture, self).setUp()
super().setUp()
variable_regex = r'\$(IDOPTION|IDFILE|IDLIST|LISTOPT)'
variables = {}
list_variables = {'LISTOPT': self.listopt}
Expand Down
2 changes: 1 addition & 1 deletion stestr/testlist.py
Expand Up @@ -46,7 +46,7 @@ def parse_enumeration(enumeration_bytes):

def _v1(list_bytes):
return [id.strip() for id in list_bytes.decode('utf8').split(
str('\n')) if id.strip()]
'\n') if id.strip()]


def _v2(list_bytes):
Expand Down
2 changes: 1 addition & 1 deletion stestr/tests/base.py
Expand Up @@ -17,7 +17,7 @@
class TestCase(testtools.TestCase):

def setUp(self):
super(TestCase, self).setUp()
super().setUp()
stdout = self.useFixture(fixtures.StringStream('stdout')).stream
self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout))
stderr = self.useFixture(fixtures.StringStream('stderr')).stream
Expand Down

0 comments on commit fc503ee

Please sign in to comment.