Skip to content

Commit df1883a

Browse files
committed
Apply some unsafe ruff fixes
1 parent c4763ff commit df1883a

File tree

9 files changed

+28
-16
lines changed

9 files changed

+28
-16
lines changed

testtools/content.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,8 @@ def content_from_stream(stream, content_type=None,
302302
"""
303303
if content_type is None:
304304
content_type = UTF8_TEXT
305-
reader = lambda: _iter_chunks(stream, chunk_size, seek_offset, seek_whence)
305+
def reader():
306+
return _iter_chunks(stream, chunk_size, seek_offset, seek_whence)
306307
return content_from_reader(reader, content_type, buffer_now)
307308

308309

@@ -319,7 +320,8 @@ def content_from_reader(reader, content_type, buffer_now):
319320
content_type = UTF8_TEXT
320321
if buffer_now:
321322
contents = list(reader())
322-
reader = lambda: contents
323+
def reader():
324+
return contents
323325
return Content(content_type, reader)
324326

325327

testtools/matchers/_filesystem.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def __init__(self, filenames=None, matcher=None):
7171
:param matcher: If specified, match the sorted directory listing
7272
against this matcher.
7373
"""
74-
if filenames == matcher == None:
74+
if filenames == matcher is None:
7575
raise AssertionError(
7676
"Must provide one of `filenames` or `matcher`.")
7777
if None not in (filenames, matcher):
@@ -105,7 +105,7 @@ def __init__(self, contents=None, matcher=None):
105105
:param matcher: If specified, match the contents of the file against
106106
this matcher.
107107
"""
108-
if contents == matcher == None:
108+
if contents == matcher is None:
109109
raise AssertionError(
110110
"Must provide one of `contents` or `matcher`.")
111111
if None not in (contents, matcher):
@@ -163,7 +163,8 @@ def __init__(self, path):
163163
self.path = path
164164

165165
def match(self, other_path):
166-
f = lambda x: os.path.abspath(os.path.realpath(x))
166+
def f(x):
167+
return os.path.abspath(os.path.realpath(x))
167168
return Equals(f(self.path)).match(f(other_path))
168169

169170

testtools/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ def _get_runner(self):
252252
################
253253

254254
def main(argv, stdout):
255-
program = TestProgram(argv=argv, testRunner=partial(TestToolsTestRunner, stdout=stdout),
255+
TestProgram(argv=argv, testRunner=partial(TestToolsTestRunner, stdout=stdout),
256256
stdout=stdout)
257257

258258
if __name__ == '__main__':

testtools/testcase.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ def _copy_content(content_object):
142142
``content_object`` and a non-volatile copy of its content.
143143
"""
144144
content_bytes = list(content_object.iter_bytes())
145-
content_callback = lambda: content_bytes
145+
def content_callback():
146+
return content_bytes
146147
return content.Content(content_object.content_type, content_callback)
147148

148149

testtools/tests/matchers/test_filesystem.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ class TestTarballContains(TestCase, PathHelpers):
179179

180180
def test_match(self):
181181
tempdir = self.mkdtemp()
182-
in_temp_dir = lambda x: os.path.join(tempdir, x)
182+
def in_temp_dir(x):
183+
return os.path.join(tempdir, x)
183184
self.touch(in_temp_dir('a'))
184185
self.touch(in_temp_dir('b'))
185186
tarball = tarfile.open(in_temp_dir('foo.tar.gz'), 'w')
@@ -191,7 +192,8 @@ def test_match(self):
191192

192193
def test_mismatch(self):
193194
tempdir = self.mkdtemp()
194-
in_temp_dir = lambda x: os.path.join(tempdir, x)
195+
def in_temp_dir(x):
196+
return os.path.join(tempdir, x)
195197
self.touch(in_temp_dir('a'))
196198
self.touch(in_temp_dir('b'))
197199
tarball = tarfile.open(in_temp_dir('foo.tar.gz'), 'w')

testtools/tests/test_content.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,10 @@ def test___init___sets_ivars(self):
5555

5656
def test___eq__(self):
5757
content_type = ContentType("foo", "bar")
58-
one_chunk = lambda: [_b("bytes")]
59-
two_chunk = lambda: [_b("by"), _b("tes")]
58+
def one_chunk():
59+
return [_b("bytes")]
60+
def two_chunk():
61+
return [_b("by"), _b("tes")]
6062
content1 = Content(content_type, one_chunk)
6163
content2 = Content(content_type, one_chunk)
6264
content3 = Content(content_type, two_chunk)

testtools/tests/test_testcase.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ class Test(TestCase):
654654
def test(self):
655655
self.expectThat("foo", Equals("bar"))
656656
test = Test("test")
657-
result = test.run()
657+
test.run()
658658
details = test.getDetails()
659659
self.assertIn('Failed expectation', details)
660660

testtools/tests/test_testsuite.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ def test_trivial(self):
9797
result = LoggingStream()
9898
test1 = Sample('test_method1')
9999
test2 = Sample('test_method2')
100-
cases = lambda:[(test1, '0'), (test2, '1')]
100+
def cases():
101+
return [(test1, '0'), (test2, '1')]
101102
suite = ConcurrentStreamTestSuite(cases)
102103
suite.run(result)
103104
def freeze(set_or_none):
@@ -169,7 +170,8 @@ def __call__(self):
169170
def run(self):
170171
pass
171172
result = LoggingStream()
172-
cases = lambda:[(BrokenTest(), '0')]
173+
def cases():
174+
return [(BrokenTest(), '0')]
173175
suite = ConcurrentStreamTestSuite(cases)
174176
suite.run(result)
175177
events = result._events
@@ -299,7 +301,8 @@ def sort_tests(self):
299301
def test_custom_suite_without_sort_tests_works(self):
300302
a = PlaceHolder('a')
301303
b = PlaceHolder('b')
302-
class Subclass(unittest.TestSuite):pass
304+
class Subclass(unittest.TestSuite):
305+
pass
303306
input_suite = Subclass([b, a])
304307
suite = sorted_tests(input_suite)
305308
self.assertEqual([b, a], list(iterate_tests(suite)))

testtools/tests/twistedsupport/test_spinner.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ def test_exception_reraised(self):
114114
def test_keyword_arguments(self):
115115
# run_in_reactor passes keyword arguments on.
116116
calls = []
117-
function = lambda *a, **kw: calls.extend([a, kw])
117+
def function(*a, **kw):
118+
return calls.extend([a, kw])
118119
self.make_spinner().run(self.make_timeout(), function, foo=42)
119120
self.assertThat(calls, Equals([(), {'foo': 42}]))
120121

0 commit comments

Comments
 (0)