Skip to content

Commit

Permalink
Merge pull request #69 from jelmer/ruff
Browse files Browse the repository at this point in the history
Fix/silence remaining ruff issues
  • Loading branch information
jelmer authored Sep 17, 2023
2 parents 21de5e4 + 8e86150 commit 0cac682
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 20 deletions.
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[build-system]
requires = ["setuptools>=43.0.0"]
build-backend = "setuptools.build_meta"

[tool.ruff]
line-length = 120
target-version = "py37"
18 changes: 12 additions & 6 deletions python/subunit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ def _write_details(self, details):
:param details: An extended details dict for a test outcome.
"""
self._stream.write(_b(" [ multipart\n"))
for name, content in sorted(details.items()):
for name, content in sorted(details.items()): # noqa: F402
self._stream.write(_b("Content-Type: %s/%s" %
(content.content_type.type, content.content_type.subtype)))
parameters = content.content_type.parameters
Expand Down Expand Up @@ -893,7 +893,8 @@ def __repr__(self):
(self._strclass(), self.__description)

def run(self, result=None):
if result is None: result = self.defaultTestResult()
if result is None:
result = self.defaultTestResult()
result.startTest(self)
result.addError(self, RemoteError(_u("Cannot run RemotedTestCases.\n")))
result.stopTest(self)
Expand All @@ -920,7 +921,8 @@ def countTestCases(self):
return 1

def run(self, result=None):
if result is None: result = self.defaultTestResult()
if result is None:
result = self.defaultTestResult()
self._run(result)

def debug(self):
Expand All @@ -945,7 +947,8 @@ class IsolatedTestCase(unittest.TestCase):
"""

def run(self, result=None):
if result is None: result = self.defaultTestResult()
if result is None:
result = self.defaultTestResult()
run_isolated(unittest.TestCase, self, result)


Expand All @@ -959,7 +962,8 @@ class IsolatedTestSuite(unittest.TestSuite):
"""

def run(self, result=None):
if result is None: result = testresult.TestResult()
if result is None:
result = testresult.TestResult()
run_isolated(unittest.TestSuite, self, result)


Expand Down Expand Up @@ -1062,7 +1066,9 @@ def _emit_test():
file_name='tap comment')
continue
# not a plan line, or have seen one before
match = re.match(r"(ok|not ok)(?:\s+(\d+)?)?(?:\s+([^#]*[^#\s]+)\s*)?(?:\s+#\s+(TODO|SKIP|skip|todo)(?:\s+(.*))?)?\n", line)
match = re.match(
r"(ok|not ok)(?:\s+(\d+)?)?(?:\s+([^#]*[^#\s]+)\s*)?"
r"(?:\s+#\s+(TODO|SKIP|skip|todo)(?:\s+(.*))?)?\n", line)
if match:
# new test, emit current one.
_emit_test()
Expand Down
8 changes: 4 additions & 4 deletions python/subunit/filter_scripts/subunit2gtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@
import gi

gi.require_version('Gtk', '3.0')
from gi.repository import GObject, Gtk
from testtools import StreamToExtendedDecorator
from gi.repository import GObject, Gtk # noqa: E402
from testtools import StreamToExtendedDecorator # noqa: E402

from subunit import (PROGRESS_POP, PROGRESS_PUSH, PROGRESS_SET,
from subunit import (PROGRESS_POP, PROGRESS_PUSH, PROGRESS_SET, # noqa: E402
ByteStreamToStreamResult)
from subunit.progress_model import ProgressModel
from subunit.progress_model import ProgressModel # noqa: E402


class GTKTestResult(unittest.TestResult):
Expand Down
4 changes: 2 additions & 2 deletions python/subunit/filter_scripts/subunit_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ def only_genuine_failures_callback(option, opt, value, parser):
parser.rargs.insert(0, '--no-success')


def _compile_re_from_list(l):
return re.compile("|".join(l), re.MULTILINE)
def _compile_re_from_list(list):
return re.compile("|".join(list), re.MULTILINE)


def _make_regexp_filter(with_regexps, without_regexps):
Expand Down
9 changes: 5 additions & 4 deletions python/subunit/filter_scripts/subunit_notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
"""Notify the user of a finished test run."""

import gi
import sys

gi.require_version('Gtk', '3.0')
from gi.repository import Notify
from testtools import StreamToExtendedDecorator
from gi.repository import Notify # noqa: E402
from testtools import StreamToExtendedDecorator # noqa: E402

from subunit import TestResultStats
from subunit.filters import run_filter_script
from subunit import TestResultStats # noqa: E402
from subunit.filters import run_filter_script # noqa: E402

if not Notify.init("Subunit-notify"):
sys.exit(1)
Expand Down
2 changes: 1 addition & 1 deletion python/subunit/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def _list(self, test):
test_ids, errors = list_test(test)
try:
fileno = self.stream.fileno()
except:
except: # noqa: E722
fileno = None
if fileno is not None:
stream = os.fdopen(fileno, 'wb', 0)
Expand Down
1 change: 0 additions & 1 deletion python/subunit/test_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import iso8601
import subunit
from subunit import iso8601


# NOT a TestResult, because we are implementing the interface, not inheriting
Expand Down
2 changes: 1 addition & 1 deletion python/subunit/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
_remote_exception_str_chunked = "57\r\n" + _remote_exception_str + ": boo qux\n0\r\n"


from subunit.tests import (test_chunked, test_details, test_filter_to_disk,
from subunit.tests import (test_chunked, test_details, test_filter_to_disk, # noqa: E402
test_filters, test_output_filter,
test_progress_model, test_run, test_subunit_filter,
test_subunit_stats, test_subunit_tags,
Expand Down
2 changes: 1 addition & 1 deletion python/subunit/v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def run(self, result):

try:
self.source.fileno()
except:
except: # noqa: E722
# Won't be able to select, fallback to
# one-byte-at-a-time.
break
Expand Down

0 comments on commit 0cac682

Please sign in to comment.