File tree 1 file changed +20
-0
lines changed
1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change 11
11
from textwrap import dedent
12
12
13
13
from test import support
14
+ from test .support import os_helper , script_helper
14
15
from test .support .ast_helper import ASTTestMixin
15
16
16
17
def to_tuple (t ):
@@ -2564,6 +2565,25 @@ def test_subinterpreter(self):
2564
2565
self .assertEqual (res , 0 )
2565
2566
2566
2567
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
+
2567
2587
def main ():
2568
2588
if __name__ != '__main__' :
2569
2589
return
You can’t perform that action at this time.
0 commit comments