Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
check unknown flag output
  • Loading branch information
donbarbos committed May 3, 2025
commit bc12715b56572dc77eedb03df3bd0d2206df5a0a
9 changes: 5 additions & 4 deletions Lib/test/test_ast/test_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import copy
import dis
import enum
import io
import itertools
import os
import re
Expand All @@ -15,6 +14,7 @@
import types
import unittest
import weakref
from io import StringIO
from pathlib import Path
from textwrap import dedent
try:
Expand Down Expand Up @@ -3197,7 +3197,7 @@ def set_source(self, content):
f.write(self.text_normalize(content))

def invoke_ast(self, *flags):
output = io.StringIO()
output = StringIO()
with contextlib.redirect_stdout(output):
Comment thread
donbarbos marked this conversation as resolved.
Outdated
ast._main(args=[*flags, self.filename])
return self.text_normalize(output.getvalue())
Expand Down Expand Up @@ -3232,8 +3232,9 @@ def f(x):

with self.assertRaises(SystemExit):
Comment thread
donbarbos marked this conversation as resolved.
Outdated
# suppress argparse error message
with contextlib.redirect_stderr(io.StringIO()):
_ = self.invoke_ast('--unknown')
with contextlib.redirect_stderr(StringIO()):
output = self.invoke_ast('--unknown')
self.assertStartsWith(output, 'usage: ')

def test_mode_flag(self):
# test 'python -m ast -m/--mode'
Expand Down
Loading