Skip to content

Commit

Permalink
Merge pull request #454 from dodona-edu/enhance/ignore-prompt
Browse files Browse the repository at this point in the history
Ignore "input" prompt in Python
  • Loading branch information
niknetniko authored Nov 9, 2023
2 parents f6084c5 + ba1c920 commit 3e24d64
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tested/languages/python/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ def convert_execution_unit(pu: PreparedExecutionUnit) -> str:
import sys
import importlib
from decimal import Decimal
import builtins
"""

# Import the language specific functions we will need.
Expand All @@ -152,6 +153,14 @@ def convert_execution_unit(pu: PreparedExecutionUnit) -> str:
value_file = open("{pu.value_file}", "w")
exception_file = open("{pu.exception_file}", "w")
# Overwrite the input function
__old_input = builtins.input
def _our_input(_prompt=None):
return __old_input()
builtins.input = _our_input
def write_separator():
value_file.write("--{pu.testcase_separator_secret}-- SEP")
exception_file.write("--{pu.testcase_separator_secret}-- SEP")
Expand Down
2 changes: 2 additions & 0 deletions tests/exercises/echo/solution/input-prompt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
i = input("This is a prompt: ")
print(i)
15 changes: 15 additions & 0 deletions tests/test_functionality.py
Original file line number Diff line number Diff line change
Expand Up @@ -986,3 +986,18 @@ def test_language_literals_work(language: str, tmp_path: Path, pytestconfig):
result = execute_config(conf)
updates = assert_valid_output(result, pytestconfig)
assert updates.find_status_enum() == ["correct"]


def test_python_input_prompt_is_ignored(tmp_path: Path, pytestconfig):
conf = configuration(
pytestconfig,
"echo",
"python",
tmp_path,
"one.tson",
"input-prompt",
)

result = execute_config(conf)
updates = assert_valid_output(result, pytestconfig)
assert updates.find_status_enum() == ["correct"]

0 comments on commit 3e24d64

Please sign in to comment.