Skip to content

Commit

Permalink
Apply some unsafe ruff fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jelmer committed Nov 1, 2023
1 parent c4763ff commit df1883a
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 16 deletions.
6 changes: 4 additions & 2 deletions testtools/content.py
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
7 changes: 4 additions & 3 deletions testtools/matchers/_filesystem.py
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: 1 addition & 1 deletion testtools/run.py
Expand Up @@ -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__':
Expand Down
3 changes: 2 additions & 1 deletion testtools/testcase.py
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
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
6 changes: 4 additions & 2 deletions testtools/tests/test_content.py
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
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
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
3 changes: 2 additions & 1 deletion testtools/tests/twistedsupport/test_spinner.py
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

0 comments on commit df1883a

Please sign in to comment.