Skip to content

Commit 42ff309

Browse files
committed
Rewrite tests with help messages
1 parent 21097eb commit 42ff309

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

Lib/test/test_ast/test_ast.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3230,18 +3230,14 @@ def f(x: int) -> int:
32303230
with self.subTest(flags=args):
32313231
self.invoke_ast(*args)
32323232

3233-
def test_unknown_flag(self):
3234-
with self.assertRaises(SystemExit):
3235-
output = self.invoke_ast('--unknown')
3236-
self.assertStartsWith(output, 'usage: ')
3237-
3238-
def test_help_flag(self):
3239-
# test 'python -m ast -h/--help'
3240-
for flag in ('-h', '--help'):
3233+
def test_help_message(self):
3234+
for flag in ('-h', '--help', '--unknown'):
32413235
with self.subTest(flag=flag):
3236+
output = StringIO()
32423237
with self.assertRaises(SystemExit):
3243-
output = self.invoke_ast(flag)
3244-
self.assertStartsWith(output, 'usage: ')
3238+
with contextlib.redirect_stderr(output):
3239+
ast.main(args=(flag))
3240+
self.assertStartsWith(output.getvalue(), 'usage: ')
32453241

32463242
def test_exec_mode_flag(self):
32473243
# test 'python -m ast -m/--mode exec'

0 commit comments

Comments
 (0)