File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change 1111from textwrap import dedent
1212
1313from test import support
14+ from test .support import os_helper , script_helper
1415from test .support .ast_helper import ASTTestMixin
1516
1617def to_tuple (t ):
@@ -2564,6 +2565,25 @@ def test_subinterpreter(self):
25642565 self .assertEqual (res , 0 )
25652566
25662567
2568+ class ASTMainTests (unittest .TestCase ):
2569+ # Tests `ast.main()` function.
2570+
2571+ def test_cli_file_input (self ):
2572+ code = "print(1, 2, 3)"
2573+ expected = ast .dump (ast .parse (code ), indent = 3 )
2574+
2575+ with os_helper .temp_dir () as tmp_dir :
2576+ filename = os .path .join (tmp_dir , "test_module.py" )
2577+ with open (filename , 'w' , encoding = 'utf-8' ) as f :
2578+ f .write (code )
2579+ res , _ = script_helper .run_python_until_end ("-m" , "ast" , filename )
2580+
2581+ self .assertEqual (res .err , b"" )
2582+ self .assertEqual (expected .splitlines (),
2583+ res .out .decode ("utf8" ).splitlines ())
2584+ self .assertEqual (res .rc , 0 )
2585+
2586+
25672587def main ():
25682588 if __name__ != '__main__' :
25692589 return
You can’t perform that action at this time.
0 commit comments