From df1883acfab229f7a020d8434b55c436ee2a7940 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jelmer=20Vernoo=C4=B3?= Date: Wed, 1 Nov 2023 23:38:42 +0000 Subject: [PATCH] Apply some unsafe ruff fixes --- testtools/content.py | 6 ++++-- testtools/matchers/_filesystem.py | 7 ++++--- testtools/run.py | 2 +- testtools/testcase.py | 3 ++- testtools/tests/matchers/test_filesystem.py | 6 ++++-- testtools/tests/test_content.py | 6 ++++-- testtools/tests/test_testcase.py | 2 +- testtools/tests/test_testsuite.py | 9 ++++++--- testtools/tests/twistedsupport/test_spinner.py | 3 ++- 9 files changed, 28 insertions(+), 16 deletions(-) diff --git a/testtools/content.py b/testtools/content.py index 1efe329f..8ed573cd 100644 --- a/testtools/content.py +++ b/testtools/content.py @@ -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) @@ -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) diff --git a/testtools/matchers/_filesystem.py b/testtools/matchers/_filesystem.py index 3dd1ba57..0b3eb537 100644 --- a/testtools/matchers/_filesystem.py +++ b/testtools/matchers/_filesystem.py @@ -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): @@ -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): @@ -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)) diff --git a/testtools/run.py b/testtools/run.py index c1d7c91d..baa1230e 100755 --- a/testtools/run.py +++ b/testtools/run.py @@ -252,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__': diff --git a/testtools/testcase.py b/testtools/testcase.py index 5bbff252..004fdb5c 100644 --- a/testtools/testcase.py +++ b/testtools/testcase.py @@ -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) diff --git a/testtools/tests/matchers/test_filesystem.py b/testtools/tests/matchers/test_filesystem.py index a156bbba..d1d0ea9b 100644 --- a/testtools/tests/matchers/test_filesystem.py +++ b/testtools/tests/matchers/test_filesystem.py @@ -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') @@ -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') diff --git a/testtools/tests/test_content.py b/testtools/tests/test_content.py index c7bac990..2b8937d7 100644 --- a/testtools/tests/test_content.py +++ b/testtools/tests/test_content.py @@ -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) diff --git a/testtools/tests/test_testcase.py b/testtools/tests/test_testcase.py index fa38d445..20799115 100644 --- a/testtools/tests/test_testcase.py +++ b/testtools/tests/test_testcase.py @@ -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) diff --git a/testtools/tests/test_testsuite.py b/testtools/tests/test_testsuite.py index 26d2152c..c490409e 100644 --- a/testtools/tests/test_testsuite.py +++ b/testtools/tests/test_testsuite.py @@ -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): @@ -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 @@ -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))) diff --git a/testtools/tests/twistedsupport/test_spinner.py b/testtools/tests/twistedsupport/test_spinner.py index caafc6d3..c2f055bd 100644 --- a/testtools/tests/twistedsupport/test_spinner.py +++ b/testtools/tests/twistedsupport/test_spinner.py @@ -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}]))