summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikita Sobolev <mail@sobolevn.me>2023-03-11 19:10:52 (GMT)
committerGitHub <noreply@github.com>2023-03-11 19:10:52 (GMT)
commitbb396eece44036a71427e7766fbb8e0247373102 (patch)
tree7a6628706b2836574a09bdc6e19b6022e2406411
parent534660f1680955c7a6a47d5c6bd9649704b74a87 (diff)
downloadcpython-bb396eece44036a71427e7766fbb8e0247373102.zip
cpython-bb396eece44036a71427e7766fbb8e0247373102.tar.gz
cpython-bb396eece44036a71427e7766fbb8e0247373102.tar.bz2
gh-101821: Test coverage for `ast.main` function (#101822)
-rw-r--r--Lib/test/test_ast.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py
index 7c9a57c..6c932e1 100644
--- a/Lib/test/test_ast.py
+++ b/Lib/test/test_ast.py
@@ -11,6 +11,7 @@ import weakref
from textwrap import dedent
from test import support
+from test.support import os_helper, script_helper
from test.support.ast_helper import ASTTestMixin
def to_tuple(t):
@@ -2564,6 +2565,25 @@ class ModuleStateTests(unittest.TestCase):
self.assertEqual(res, 0)
+class ASTMainTests(unittest.TestCase):
+ # Tests `ast.main()` function.
+
+ def test_cli_file_input(self):
+ code = "print(1, 2, 3)"
+ expected = ast.dump(ast.parse(code), indent=3)
+
+ with os_helper.temp_dir() as tmp_dir:
+ filename = os.path.join(tmp_dir, "test_module.py")
+ with open(filename, 'w', encoding='utf-8') as f:
+ f.write(code)
+ res, _ = script_helper.run_python_until_end("-m", "ast", filename)
+
+ self.assertEqual(res.err, b"")
+ self.assertEqual(expected.splitlines(),
+ res.out.decode("utf8").splitlines())
+ self.assertEqual(res.rc, 0)
+
+
def main():
if __name__ != '__main__':
return