Skip to content

Commit

Permalink
Merge pull request #68 from jelmer/ruff
Browse files Browse the repository at this point in the history
Fix some issues reported by ruff
  • Loading branch information
jelmer authored Sep 17, 2023
2 parents 6924912 + 6ded8d3 commit 21de5e4
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 33 deletions.
24 changes: 22 additions & 2 deletions python/subunit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def test_script_two(self):
import subprocess
import sys
import unittest
from io import BytesIO, StringIO
from io import BytesIO
from io import UnsupportedOperation as _UnsupportedOperation

import iso8601
Expand All @@ -136,7 +136,7 @@ def test_script_two(self):
"_StringException, check your version.")
from testtools import CopyStreamResult, testresult

from subunit import chunked, details, test_results
from subunit import chunked, details
from subunit.v2 import ByteStreamToStreamResult, StreamResultToBytes

# same format as sys.version_info: "A tuple containing the five components of
Expand All @@ -153,6 +153,26 @@ def test_script_two(self):

__version__ = (1, 4, 3, 'dev', 0)

__all__ = [
'join_dir',
'tags_to_new_gone',
'content',
'content_type',
'TestProtocolServer',
'TestProtocolClient',
'RemoteError',
'RemotedTestCase',
'IsolatedTestCase',
'IsolatedTestSuite',
'run_isolated',
'TAP2SubUnit',
'tag_stream',
'ProtocolTestCase',
'make_stream_binary',
'read_test_list',
'TestResultStats',
]

PROGRESS_SET = 0
PROGRESS_CUR = 1
PROGRESS_PUSH = 2
Expand Down
2 changes: 1 addition & 1 deletion python/subunit/details.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

"""Handlers for outcome details."""

from io import BytesIO, StringIO
from io import BytesIO

from testtools import content, content_type
from testtools.compat import _b
Expand Down
6 changes: 3 additions & 3 deletions python/subunit/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ def usageExit(self, msg=None):
print (msg)
usage = {'progName': self.progName, 'catchbreak': '', 'failfast': '',
'buffer': ''}
if self.failfast != False:
if self.failfast is not False:
usage['failfast'] = FAILFAST
if self.catchbreak != False:
if self.catchbreak is not False:
usage['catchbreak'] = CATCHBREAK
if self.buffer != False:
if self.buffer is not False:
usage['buffer'] = BUFFEROUTPUT
usage_text = self.USAGE % usage
usage_lines = usage_text.split('\n')
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 @@ -22,7 +22,6 @@
import testtools
from testtools import StreamResult
from testtools.content import TracebackContent, text_content
from testtools.testcase import PlaceHolder

import iso8601
import subunit
Expand Down
1 change: 0 additions & 1 deletion python/subunit/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# limitations under that license.
#

import sys
from unittest import TestLoader

from testscenarios import generate_scenarios
Expand Down
4 changes: 0 additions & 4 deletions python/subunit/tests/test_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

from testtools.compat import _b

import subunit.tests
from subunit import content, content_type, details


Expand All @@ -43,7 +42,6 @@ def test_get_message(self):

def test_get_details(self):
parser = details.SimpleDetailsParser(None)
traceback = ""
expected = {}
expected['traceback'] = content.Content(
content_type.ContentType("text", "x-traceback",
Expand All @@ -58,7 +56,6 @@ def test_get_details(self):

def test_get_details_skip(self):
parser = details.SimpleDetailsParser(None)
traceback = ""
expected = {}
expected['reason'] = content.Content(
content_type.ContentType("text", "plain"),
Expand All @@ -68,7 +65,6 @@ def test_get_details_skip(self):

def test_get_details_success(self):
parser = details.SimpleDetailsParser(None)
traceback = ""
expected = {}
expected['message'] = content.Content(
content_type.ContentType("text", "plain"),
Expand Down
1 change: 0 additions & 1 deletion python/subunit/tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# limitations under that license.
#

import sys
from tempfile import NamedTemporaryFile

from testtools import TestCase
Expand Down
24 changes: 13 additions & 11 deletions python/subunit/tests/test_output_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,21 @@

import datetime
import optparse
import sys
from contextlib import contextmanager
from functools import partial
from io import BytesIO, StringIO, TextIOWrapper
from io import BytesIO, TextIOWrapper
from tempfile import NamedTemporaryFile

from iso8601 import UTC

from testtools import TestCase
from testtools.compat import _u
from testtools.matchers import (Equals, Matcher, MatchesAny, MatchesListwise,
Mismatch, raises)
from testtools.testresult.doubles import StreamResult

import subunit._output as _o
from subunit._output import (_ALL_ACTIONS, _FINAL_ACTIONS,
generate_stream_results, parse_arguments)
from subunit.v2 import ByteStreamToStreamResult, StreamResultToBytes


class SafeOptionParser(optparse.OptionParser):
Expand Down Expand Up @@ -112,7 +109,8 @@ def test_can_override_stdin_filename(self):
self.assertThat(args.file_name, Equals("foo"))

def test_requires_test_id(self):
fn = lambda: safe_parse_arguments(args=[self.option])
def fn():
return safe_parse_arguments(args=[self.option])
self.assertThat(
fn,
raises(RuntimeError('argument %s: must specify a single TEST_ID.' % self.option))
Expand All @@ -129,24 +127,27 @@ def test_can_parse_attach_file_without_test_id(self):
self.assertThat(args.attach_file.name, Equals(tmp_file.name))

def test_can_run_without_args(self):
args = safe_parse_arguments([])
safe_parse_arguments([])

def test_cannot_specify_more_than_one_status_command(self):
fn = lambda: safe_parse_arguments(['--fail', 'foo', '--skip', 'bar'])
def fn():
return safe_parse_arguments(["--fail", "foo", "--skip", "bar"])
self.assertThat(
fn,
raises(RuntimeError('argument --skip: Only one status may be specified at once.'))
)

def test_cannot_specify_mimetype_without_attach_file(self):
fn = lambda: safe_parse_arguments(['--mimetype', 'foo'])
def fn():
return safe_parse_arguments(["--mimetype", "foo"])
self.assertThat(
fn,
raises(RuntimeError('Cannot specify --mimetype without --attach-file'))
)

def test_cannot_specify_filename_without_attach_file(self):
fn = lambda: safe_parse_arguments(['--file-name', 'foo'])
def fn():
return safe_parse_arguments(["--file-name", "foo"])
self.assertThat(
fn,
raises(RuntimeError('Cannot specify --file-name without --attach-file'))
Expand All @@ -157,7 +158,8 @@ def test_can_specify_tags_without_status_command(self):
self.assertEqual(['foo'], args.tags)

def test_must_specify_tags_with_tags_options(self):
fn = lambda: safe_parse_arguments(['--fail', 'foo', '--tag'])
def fn():
return safe_parse_arguments(["--fail", "foo", "--tag"])
self.assertThat(
fn,
MatchesAny(
Expand Down Expand Up @@ -516,7 +518,7 @@ def test_files_have_timestamp(self):
self.patch(_o, 'create_timestamp', lambda: _dummy_timestamp)

with temp_file_contents(b"Hello") as f:
specified_file_name = self.getUniqueString()
self.getUniqueString()
result = get_result_for([
'--attach-file',
f.name,
Expand Down
1 change: 0 additions & 1 deletion python/subunit/tests/test_progress_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import unittest

import subunit
from subunit.progress_model import ProgressModel


Expand Down
5 changes: 2 additions & 3 deletions python/subunit/tests/test_subunit_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

"""Tests for subunit.TestResultFilter."""

import os
import subprocess
import sys
import unittest
Expand Down Expand Up @@ -260,7 +259,7 @@ def test_time_passes_through_filtered_tests(self):
result_filter.startTestRun()
self.run_tests(result_filter, subunit_stream)
result_filter.stopTestRun()
foo = subunit.RemotedTestCase('foo')
subunit.RemotedTestCase('foo')
self.maxDiff = None
self.assertEqual(
[('startTestRun',),
Expand Down Expand Up @@ -322,7 +321,7 @@ def test_default(self):
output = self.run_command([], byte_stream.getvalue())
events = StreamResult()
ByteStreamToStreamResult(BytesIO(output)).run(events)
ids = {event[1] for event in events._events}
{event[1] for event in events._events}
self.assertEqual([
('status', 'foo', 'inprogress'),
('status', 'foo', 'skip'),
Expand Down
1 change: 0 additions & 1 deletion python/subunit/tests/test_tap2subunit.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

"""Tests for TAP2SubUnit."""

import unittest
from io import BytesIO, StringIO

from testtools import TestCase
Expand Down
8 changes: 4 additions & 4 deletions python/subunit/tests/test_test_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import os
import tempfile
import unittest
from io import BytesIO, StringIO
from io import BytesIO

from testtools import PlaceHolder, TestCase, TestResult, skipIf
from testtools.compat import _b, _u
Expand Down Expand Up @@ -87,9 +87,9 @@ def test__unwrap_text_BytesIO(self):
class TestTestImports(unittest.TestCase):

def test_imports(self):
from subunit import (DiscardStream, ExecTestCase, IsolatedTestCase,
ProtocolTestCase, RemotedTestCase, RemoteError,
TestProtocolClient, TestProtocolServer)
from subunit import (DiscardStream, ExecTestCase, IsolatedTestCase, # noqa: F401
ProtocolTestCase, RemotedTestCase, RemoteError, # noqa: F401
TestProtocolClient, TestProtocolServer) # noqa: F401


class TestDiscardStream(unittest.TestCase):
Expand Down

0 comments on commit 21de5e4

Please sign in to comment.