Skip to content

Commit

Permalink
Merge pull request #364 from jelmer/ruff
Browse files Browse the repository at this point in the history
Various linting cleanups
  • Loading branch information
jelmer authored Nov 2, 2023
2 parents 87ab359 + df1883a commit 604d4fc
Show file tree
Hide file tree
Showing 17 changed files with 34 additions and 56 deletions.
1 change: 0 additions & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import sys, os

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
Expand Down
6 changes: 4 additions & 2 deletions testtools/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,8 @@ def content_from_stream(stream, content_type=None,
"""
if content_type is None:
content_type = UTF8_TEXT
reader = lambda: _iter_chunks(stream, chunk_size, seek_offset, seek_whence)
def reader():
return _iter_chunks(stream, chunk_size, seek_offset, seek_whence)
return content_from_reader(reader, content_type, buffer_now)


Expand All @@ -319,7 +320,8 @@ def content_from_reader(reader, content_type, buffer_now):
content_type = UTF8_TEXT
if buffer_now:
contents = list(reader())
reader = lambda: contents
def reader():
return contents
return Content(content_type, reader)


Expand Down
27 changes: 0 additions & 27 deletions testtools/deferredruntest.py

This file was deleted.

2 changes: 1 addition & 1 deletion testtools/matchers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@

# XXX: These are not explicitly included in __all__. It's unclear how much of
# the public interface they really are.
from ._impl import (
from ._impl import ( # noqa: F401
Matcher,
Mismatch,
MismatchError,
Expand Down
7 changes: 4 additions & 3 deletions testtools/matchers/_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def __init__(self, filenames=None, matcher=None):
:param matcher: If specified, match the sorted directory listing
against this matcher.
"""
if filenames == matcher == None:
if filenames == matcher is None:
raise AssertionError(
"Must provide one of `filenames` or `matcher`.")
if None not in (filenames, matcher):
Expand Down Expand Up @@ -105,7 +105,7 @@ def __init__(self, contents=None, matcher=None):
:param matcher: If specified, match the contents of the file against
this matcher.
"""
if contents == matcher == None:
if contents == matcher is None:
raise AssertionError(
"Must provide one of `contents` or `matcher`.")
if None not in (contents, matcher):
Expand Down Expand Up @@ -163,7 +163,8 @@ def __init__(self, path):
self.path = path

def match(self, other_path):
f = lambda x: os.path.abspath(os.path.realpath(x))
def f(x):
return os.path.abspath(os.path.realpath(x))
return Equals(f(self.path)).match(f(other_path))


Expand Down
2 changes: 0 additions & 2 deletions testtools/matchers/_warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
from ._higherorder import (
AfterPreprocessing,
Annotate,
MatchesAll,
Not,
)
from ._impl import Mismatch

Expand Down
3 changes: 1 addition & 2 deletions testtools/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
$ python -m testtools.run testtools.tests.test_suite
"""

import argparse
from functools import partial
import os.path
import sys
Expand Down Expand Up @@ -253,7 +252,7 @@ def _get_runner(self):
################

def main(argv, stdout):
program = TestProgram(argv=argv, testRunner=partial(TestToolsTestRunner, stdout=stdout),
TestProgram(argv=argv, testRunner=partial(TestToolsTestRunner, stdout=stdout),
stdout=stdout)

if __name__ == '__main__':
Expand Down
3 changes: 2 additions & 1 deletion testtools/testcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ def _copy_content(content_object):
``content_object`` and a non-volatile copy of its content.
"""
content_bytes = list(content_object.iter_bytes())
content_callback = lambda: content_bytes
def content_callback():
return content_bytes
return content.Content(content_object.content_type, content_callback)


Expand Down
6 changes: 4 additions & 2 deletions testtools/tests/matchers/test_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ class TestTarballContains(TestCase, PathHelpers):

def test_match(self):
tempdir = self.mkdtemp()
in_temp_dir = lambda x: os.path.join(tempdir, x)
def in_temp_dir(x):
return os.path.join(tempdir, x)
self.touch(in_temp_dir('a'))
self.touch(in_temp_dir('b'))
tarball = tarfile.open(in_temp_dir('foo.tar.gz'), 'w')
Expand All @@ -191,7 +192,8 @@ def test_match(self):

def test_mismatch(self):
tempdir = self.mkdtemp()
in_temp_dir = lambda x: os.path.join(tempdir, x)
def in_temp_dir(x):
return os.path.join(tempdir, x)
self.touch(in_temp_dir('a'))
self.touch(in_temp_dir('b'))
tarball = tarfile.open(in_temp_dir('foo.tar.gz'), 'w')
Expand Down
8 changes: 5 additions & 3 deletions testtools/tests/test_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import tempfile
import unittest

from testtools import TestCase, skipUnless
from testtools import TestCase
from testtools.compat import (
_b,
)
Expand Down Expand Up @@ -55,8 +55,10 @@ def test___init___sets_ivars(self):

def test___eq__(self):
content_type = ContentType("foo", "bar")
one_chunk = lambda: [_b("bytes")]
two_chunk = lambda: [_b("by"), _b("tes")]
def one_chunk():
return [_b("bytes")]
def two_chunk():
return [_b("by"), _b("tes")]
content1 = Content(content_type, one_chunk)
content2 = Content(content_type, one_chunk)
content3 = Content(content_type, two_chunk)
Expand Down
2 changes: 1 addition & 1 deletion testtools/tests/test_testcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ class Test(TestCase):
def test(self):
self.expectThat("foo", Equals("bar"))
test = Test("test")
result = test.run()
test.run()
details = test.getDetails()
self.assertIn('Failed expectation', details)

Expand Down
9 changes: 6 additions & 3 deletions testtools/tests/test_testsuite.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ def test_trivial(self):
result = LoggingStream()
test1 = Sample('test_method1')
test2 = Sample('test_method2')
cases = lambda:[(test1, '0'), (test2, '1')]
def cases():
return [(test1, '0'), (test2, '1')]
suite = ConcurrentStreamTestSuite(cases)
suite.run(result)
def freeze(set_or_none):
Expand Down Expand Up @@ -169,7 +170,8 @@ def __call__(self):
def run(self):
pass
result = LoggingStream()
cases = lambda:[(BrokenTest(), '0')]
def cases():
return [(BrokenTest(), '0')]
suite = ConcurrentStreamTestSuite(cases)
suite.run(result)
events = result._events
Expand Down Expand Up @@ -299,7 +301,8 @@ def sort_tests(self):
def test_custom_suite_without_sort_tests_works(self):
a = PlaceHolder('a')
b = PlaceHolder('b')
class Subclass(unittest.TestSuite):pass
class Subclass(unittest.TestSuite):
pass
input_suite = Subclass([b, a])
suite = sorted_tests(input_suite)
self.assertEqual([b, a], list(iterate_tests(suite)))
Expand Down
2 changes: 1 addition & 1 deletion testtools/tests/twistedsupport/test_deferred.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ def test_failure(self):


def test_suite():
from unittest import TestLoader, TestSuite
from unittest import TestLoader
return TestLoader().loadTestsFromName(__name__)
2 changes: 1 addition & 1 deletion testtools/tests/twistedsupport/test_matchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,5 +199,5 @@ def test_no_result_fails(self):


def test_suite():
from unittest import TestLoader, TestSuite
from unittest import TestLoader
return TestLoader().loadTestsFromName(__name__)
6 changes: 2 additions & 4 deletions testtools/tests/twistedsupport/test_runtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@
Is,
KeysEqual,
MatchesDict,
MatchesException,
MatchesListwise,
Not,
Raises,
)
from testtools.runtest import RunTest
from testtools.testresult.doubles import ExtendedTestResult
Expand Down Expand Up @@ -875,7 +873,7 @@ def check_result(failure):
class TestRunWithLogObservers(NeedsTwistedTestCase):

def test_restores_observers(self):
from testtools.deferredruntest import run_with_log_observers
from testtools.twistedsupport._runtest import run_with_log_observers
from twisted.python import log
# Make sure there's at least one observer. This reproduces bug
# #926189.
Expand Down Expand Up @@ -1015,7 +1013,7 @@ def test_something(self):


def test_suite():
from unittest import TestLoader, TestSuite
from unittest import TestLoader
return TestLoader().loadTestsFromName(__name__)


Expand Down
3 changes: 2 additions & 1 deletion testtools/tests/twistedsupport/test_spinner.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ def test_exception_reraised(self):
def test_keyword_arguments(self):
# run_in_reactor passes keyword arguments on.
calls = []
function = lambda *a, **kw: calls.extend([a, kw])
def function(*a, **kw):
return calls.extend([a, kw])
self.make_spinner().run(self.make_timeout(), function, foo=42)
self.assertThat(calls, Equals([(), {'foo': 42}]))

Expand Down
1 change: 0 additions & 1 deletion testtools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@
warnings.warn("Please import iterate_tests from testtools.testsuite - "
"testtools.utils is deprecated.", DeprecationWarning, stacklevel=2)

from testtools.testsuite import iterate_tests

0 comments on commit 604d4fc

Please sign in to comment.