Skip to content

Commit 2be1701

Browse files
committed
remove triple-nested withs for 3.14 coverage
see coveragepy/coveragepy#1987
1 parent 4c8d22a commit 2be1701

3 files changed

Lines changed: 42 additions & 30 deletions

File tree

‎tests/color_test.py‎

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,30 @@ def test_use_color_no_tty():
3636

3737

3838
def test_use_color_tty_with_color_support():
39-
with mock.patch.object(sys.stderr, 'isatty', return_value=True):
40-
with mock.patch('pre_commit.color.terminal_supports_color', True):
41-
with envcontext.envcontext((('TERM', envcontext.UNSET),)):
42-
assert use_color('auto') is True
39+
with (
40+
mock.patch.object(sys.stderr, 'isatty', return_value=True),
41+
mock.patch('pre_commit.color.terminal_supports_color', True),
42+
envcontext.envcontext((('TERM', envcontext.UNSET),)),
43+
):
44+
assert use_color('auto') is True
4345

4446

4547
def test_use_color_tty_without_color_support():
46-
with mock.patch.object(sys.stderr, 'isatty', return_value=True):
47-
with mock.patch('pre_commit.color.terminal_supports_color', False):
48-
with envcontext.envcontext((('TERM', envcontext.UNSET),)):
49-
assert use_color('auto') is False
48+
with (
49+
mock.patch.object(sys.stderr, 'isatty', return_value=True),
50+
mock.patch('pre_commit.color.terminal_supports_color', False),
51+
envcontext.envcontext((('TERM', envcontext.UNSET),)),
52+
):
53+
assert use_color('auto') is False
5054

5155

5256
def test_use_color_dumb_term():
53-
with mock.patch.object(sys.stderr, 'isatty', return_value=True):
54-
with mock.patch('pre_commit.color.terminal_supports_color', True):
55-
with envcontext.envcontext((('TERM', 'dumb'),)):
56-
assert use_color('auto') is False
57+
with (
58+
mock.patch.object(sys.stderr, 'isatty', return_value=True),
59+
mock.patch('pre_commit.color.terminal_supports_color', True),
60+
envcontext.envcontext((('TERM', 'dumb'),)),
61+
):
62+
assert use_color('auto') is False
5763

5864

5965
def test_use_color_raises_if_given_shenanigans():

‎tests/commands/run_test.py‎

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,20 +1123,24 @@ def test_classifier_removes_dne():
11231123

11241124

11251125
def test_classifier_normalizes_filenames_on_windows_to_forward_slashes(tmpdir):
1126-
with tmpdir.as_cwd():
1127-
tmpdir.join('a/b/c').ensure()
1128-
with mock.patch.object(os, 'altsep', '/'):
1129-
with mock.patch.object(os, 'sep', '\\'):
1130-
classifier = Classifier.from_config((r'a\b\c',), '', '^$')
1131-
assert classifier.filenames == ['a/b/c']
1126+
tmpdir.join('a/b/c').ensure()
1127+
with (
1128+
tmpdir.as_cwd(),
1129+
mock.patch.object(os, 'altsep', '/'),
1130+
mock.patch.object(os, 'sep', '\\'),
1131+
):
1132+
classifier = Classifier.from_config((r'a\b\c',), '', '^$')
1133+
assert classifier.filenames == ['a/b/c']
11321134

11331135

11341136
def test_classifier_does_not_normalize_backslashes_non_windows(tmpdir):
1135-
with mock.patch.object(os.path, 'lexists', return_value=True):
1136-
with mock.patch.object(os, 'altsep', None):
1137-
with mock.patch.object(os, 'sep', '/'):
1138-
classifier = Classifier.from_config((r'a/b\c',), '', '^$')
1139-
assert classifier.filenames == [r'a/b\c']
1137+
with (
1138+
mock.patch.object(os.path, 'lexists', return_value=True),
1139+
mock.patch.object(os, 'altsep', None),
1140+
mock.patch.object(os, 'sep', '/'),
1141+
):
1142+
classifier = Classifier.from_config((r'a/b\c',), '', '^$')
1143+
assert classifier.filenames == [r'a/b\c']
11401144

11411145

11421146
def test_classifier_empty_types_or(tmpdir):

‎tests/repository_test.py‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -239,14 +239,16 @@ class MyKeyboardInterrupt(KeyboardInterrupt):
239239
# To simulate a killed install, we'll make PythonEnv.run raise ^C
240240
# and then to simulate a second ^C during cleanup, we'll make shutil.rmtree
241241
# raise as well.
242-
with pytest.raises(MyKeyboardInterrupt):
243-
with mock.patch.object(
244-
lang_base, 'setup_cmd', side_effect=MyKeyboardInterrupt,
245-
):
246-
with mock.patch.object(
242+
with (
243+
pytest.raises(MyKeyboardInterrupt),
244+
mock.patch.object(
245+
lang_base, 'setup_cmd', side_effect=MyKeyboardInterrupt,
246+
),
247+
mock.patch.object(
247248
shutil, 'rmtree', side_effect=MyKeyboardInterrupt,
248-
):
249-
install_hook_envs(hooks, store)
249+
),
250+
):
251+
install_hook_envs(hooks, store)
250252

251253
# Should have made an environment, however this environment is broken!
252254
hook, = hooks

0 commit comments

Comments
 (0)