@@ -64,23 +64,29 @@ def test_commandline_executor_execute_code(cls) -> None:
64
64
65
65
66
66
def _test_execute_code (executor : CodeExecutor ) -> None :
67
+
68
+ # Python executable variants
69
+ python_variants = ["python" , "Python" , "py" ]
70
+
67
71
# Test single code block.
68
- code_blocks = [CodeBlock (code = "import sys; print('hello world!')" , language = "python" )]
69
- code_result = executor .execute_code_blocks (code_blocks )
70
- assert code_result .exit_code == 0 and "hello world!" in code_result .output and code_result .code_file is not None
72
+ for py_variant in python_variants :
73
+ code_blocks = [CodeBlock (code = "import sys; print('hello world!')" , language = py_variant )]
74
+ code_result = executor .execute_code_blocks (code_blocks )
75
+ assert code_result .exit_code == 0 and "hello world!" in code_result .output and code_result .code_file is not None
71
76
72
77
# Test multiple code blocks.
73
- code_blocks = [
74
- CodeBlock (code = "import sys; print('hello world!')" , language = "python" ),
75
- CodeBlock (code = "a = 100 + 100; print(a)" , language = "python" ),
76
- ]
77
- code_result = executor .execute_code_blocks (code_blocks )
78
- assert (
79
- code_result .exit_code == 0
80
- and "hello world!" in code_result .output
81
- and "200" in code_result .output
82
- and code_result .code_file is not None
83
- )
78
+ for py_variant in python_variants :
79
+ code_blocks = [
80
+ CodeBlock (code = "import sys; print('hello world!')" , language = py_variant ),
81
+ CodeBlock (code = "a = 100 + 100; print(a)" , language = py_variant ),
82
+ ]
83
+ code_result = executor .execute_code_blocks (code_blocks )
84
+ assert (
85
+ code_result .exit_code == 0
86
+ and "hello world!" in code_result .output
87
+ and "200" in code_result .output
88
+ and code_result .code_file is not None
89
+ )
84
90
85
91
# Test bash script.
86
92
if sys .platform not in ["win32" ]:
@@ -89,15 +95,16 @@ def _test_execute_code(executor: CodeExecutor) -> None:
89
95
assert code_result .exit_code == 0 and "hello world!" in code_result .output and code_result .code_file is not None
90
96
91
97
# Test running code.
92
- file_lines = ["import sys" , "print('hello world!')" , "a = 100 + 100" , "print(a)" ]
93
- code_blocks = [CodeBlock (code = "\n " .join (file_lines ), language = "python" )]
94
- code_result = executor .execute_code_blocks (code_blocks )
95
- assert (
96
- code_result .exit_code == 0
97
- and "hello world!" in code_result .output
98
- and "200" in code_result .output
99
- and code_result .code_file is not None
100
- )
98
+ for py_variant in python_variants :
99
+ file_lines = ["import sys" , "print('hello world!')" , "a = 100 + 100" , "print(a)" ]
100
+ code_blocks = [CodeBlock (code = "\n " .join (file_lines ), language = py_variant )]
101
+ code_result = executor .execute_code_blocks (code_blocks )
102
+ assert (
103
+ code_result .exit_code == 0
104
+ and "hello world!" in code_result .output
105
+ and "200" in code_result .output
106
+ and code_result .code_file is not None
107
+ )
101
108
102
109
# Check saved code file.
103
110
with open (code_result .code_file ) as f :
0 commit comments