Skip to content

Commit e34530c

Browse files
committed
Make testtools ruff-clean
1 parent ad2e490 commit e34530c

File tree

12 files changed

+41
-35
lines changed

12 files changed

+41
-35
lines changed

testtools/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@
4747
]
4848

4949
from testtools.helpers import try_import
50-
from testtools.matchers._impl import Matcher
51-
# Shut up, pyflakes. We are importing for documentation, not for namespacing.
52-
Matcher
50+
from testtools.matchers._impl import Matcher # noqa: F401
5351

5452
from testtools.runtest import (
5553
MultipleExceptions,

testtools/compat.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ def text_repr(text, multiline=None):
8383
# making sure that quotes are not escaped.
8484
offset = len(prefix) + 1
8585
lines = []
86-
for l in text.split(nl):
87-
r = repr(l)
86+
for line in text.split(nl):
87+
r = repr(line)
8888
q = r[-1]
8989
lines.append(r[offset:-1].replace("\\" + q, q))
9090
# Combine the escaped lines and append two of the closing quotes,

testtools/matchers/_datastructures.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
# Copyright (c) 2009-2015 testtools developers. See LICENSE for details.
22

3-
__all__ = [
4-
'ContainsAll',
5-
'MatchesListwise',
6-
'MatchesSetwise',
7-
'MatchesStructure',
8-
]
9-
103
"""Matchers that operate with knowledge of Python data structures."""
114

125
from ..helpers import map_values
@@ -17,6 +10,15 @@
1710
)
1811
from ._impl import Mismatch
1912

13+
__all__ = [
14+
'ContainsAll',
15+
'MatchesListwise',
16+
'MatchesSetwise',
17+
'MatchesStructure',
18+
]
19+
20+
21+
2022

2123
def ContainsAll(items):
2224
"""Make a matcher that checks whether a list of things is contained

testtools/matchers/_dict.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ class MatchesDict(_CombinedMatcher):
180180
'Differences': _MatchCommonKeys,
181181
}
182182

183-
format_expected = lambda self, expected: _format_matcher_dict(expected)
183+
def format_expected(self, expected) -> str:
184+
return _format_matcher_dict(expected)
184185

185186

186187
class ContainsDict(_CombinedMatcher):
@@ -203,7 +204,8 @@ class ContainsDict(_CombinedMatcher):
203204
'Differences': _MatchCommonKeys,
204205
}
205206

206-
format_expected = lambda self, expected: _format_matcher_dict(expected)
207+
def format_expected(self, expected):
208+
return _format_matcher_dict(expected)
207209

208210

209211
class ContainedByDict(_CombinedMatcher):
@@ -226,7 +228,8 @@ class ContainedByDict(_CombinedMatcher):
226228
'Differences': _MatchCommonKeys,
227229
}
228230

229-
format_expected = lambda self, expected: _format_matcher_dict(expected)
231+
def format_expected(self, expected):
232+
return _format_matcher_dict(expected)
230233

231234

232235
class KeysEqual(Matcher):

testtools/matchers/_exception.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def match(self, matchee):
9898
return Mismatch(f'{matchee!r} returned {result!r}')
9999
# Catch all exceptions: Raises() should be able to match a
100100
# KeyboardInterrupt or SystemExit.
101-
except:
101+
except BaseException:
102102
exc_info = sys.exc_info()
103103
if self.exception_matcher:
104104
mismatch = self.exception_matcher.match(exc_info)

testtools/runtest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def _run_user(self, fn, *args, **kwargs):
191191
"""
192192
try:
193193
return fn(*args, **kwargs)
194-
except:
194+
except BaseException:
195195
return self._got_user_exception(sys.exc_info())
196196

197197
def _got_user_exception(self, exc_info, tb_label='traceback'):

testtools/testcase.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ def useFixture(self, fixture):
737737
e.args[-1][0] is fixtures.fixture.SetupError):
738738
gather_details(e.args[-1][1].args[0], self.getDetails())
739739
raise
740-
except:
740+
except BaseException:
741741
exc_info = sys.exc_info()
742742
try:
743743
# fixture._details is not available if using the newer
@@ -750,7 +750,7 @@ def useFixture(self, fixture):
750750
fixture._details is not None
751751
):
752752
gather_details(fixture.getDetails(), self.getDetails())
753-
except:
753+
except BaseException:
754754
# Report the setUp exception, then raise the error during
755755
# gather_details.
756756
self._report_traceback(exc_info)

testtools/tests/matchers/test_basic.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ class TestIsInterface(TestCase, TestMatchersInterface):
157157

158158
class TestIsInstanceInterface(TestCase, TestMatchersInterface):
159159

160-
class Foo:pass
160+
class Foo:
161+
pass
161162

162163
matches_matcher = IsInstance(Foo)
163164
matches_matches = [Foo()]

testtools/tests/test_run.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def list(self, test):
146146
in testtools.testsuite.iterate_tests(test)})
147147
out = io.StringIO()
148148
try:
149-
program = run.TestProgram(
149+
run.TestProgram(
150150
argv=['prog', '-l', 'testtools.runexample.test_suite'],
151151
stdout=out, testRunner=CaptureList)
152152
except SystemExit:
@@ -310,7 +310,7 @@ def test_run_locals(self):
310310

311311
class Failing(TestCase):
312312
def test_a(self):
313-
a = 1
313+
a = 1 # noqa: F841
314314
self.fail('a')
315315
runner = run.TestToolsTestRunner(tb_locals=True, stdout=stdout.stream)
316316
runner.run(Failing('test_a'))
@@ -319,7 +319,6 @@ def test_a(self):
319319

320320
def test_stdout_honoured(self):
321321
self.useFixture(SampleTestFixture())
322-
tests = []
323322
out = io.StringIO()
324323
exc = self.assertRaises(SystemExit, run.main,
325324
argv=['prog', 'testtools.runexample.test_suite'],

testtools/tests/test_testcase.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ class TestErrorHolder(TestCase):
205205
def makeException(self):
206206
try:
207207
raise RuntimeError("danger danger")
208-
except:
208+
except BaseException:
209209
return sys.exc_info()
210210

211211
def makePlaceHolder(self, test_id="foo", error=None,
@@ -1909,12 +1909,12 @@ def foo():
19091909
def test_called_with_arguments(self):
19101910
# The function is called with the arguments given to Nullary's
19111911
# constructor.
1912-
l = []
1912+
line = []
19131913
def foo(*args, **kwargs):
1914-
l.append((args, kwargs))
1914+
line.append((args, kwargs))
19151915
wrapped = Nullary(foo, 1, 2, a="b")
19161916
wrapped()
1917-
self.assertEqual(l, [((1, 2), {'a': 'b'})])
1917+
self.assertEqual(line, [((1, 2), {'a': 'b'})])
19181918

19191919
def test_returns_wrapped(self):
19201920
# Calling Nullary returns whatever the function returns.

0 commit comments

Comments
 (0)