summaryrefslogtreecommitdiff
path: root/yaksh
diff options
context:
space:
mode:
authormaheshgudi2016-07-28 18:24:18 +0530
committermaheshgudi2016-07-28 18:24:18 +0530
commit1b71abc9437d721a41f017db406f312755f5a4c4 (patch)
treee4fac39cf722608c1f8bf0d208b8a3e8c39f2d9f /yaksh
parent9411ab221e007a6c3e2901ce34f38f2267288b6e (diff)
downloadonline_test-1b71abc9437d721a41f017db406f312755f5a4c4.tar.gz
online_test-1b71abc9437d721a41f017db406f312755f5a4c4.tar.bz2
online_test-1b71abc9437d721a41f017db406f312755f5a4c4.zip
added expected input in traceback for python and made minor changes in bash_stio_evaluator and stdio_evaluator
Diffstat (limited to 'yaksh')
-rw-r--r--yaksh/bash_stdio_evaluator.py2
-rw-r--r--yaksh/evaluator_tests/test_bash_evaluation.py4
-rw-r--r--yaksh/evaluator_tests/test_python_evaluation.py14
-rw-r--r--yaksh/python_stdio_evaluator.py26
-rw-r--r--yaksh/stdio_evaluator.py2
5 files changed, 15 insertions, 33 deletions
diff --git a/yaksh/bash_stdio_evaluator.py b/yaksh/bash_stdio_evaluator.py
index 25f35a1..5431e5d 100644
--- a/yaksh/bash_stdio_evaluator.py
+++ b/yaksh/bash_stdio_evaluator.py
@@ -30,7 +30,7 @@ class BashStdioEvaluator(CodeEvaluator):
def check_code(self, user_answer, expected_input, expected_output):
success = False
expected_input = str(expected_input).replace('\r', '')
- proc = subprocess.Popen(["bash ./Test.sh"],
+ proc = subprocess.Popen("bash ./Test.sh",
shell=True,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
diff --git a/yaksh/evaluator_tests/test_bash_evaluation.py b/yaksh/evaluator_tests/test_bash_evaluation.py
index f954ef0..ee6c1f0 100644
--- a/yaksh/evaluator_tests/test_bash_evaluation.py
+++ b/yaksh/evaluator_tests/test_bash_evaluation.py
@@ -97,10 +97,10 @@ class BashStdioEvaluationTestCases(unittest.TestCase):
user_answer = dedent(""" #!/bin/bash
read A
read B
- echo -n `expr $A + $B`
+ echo -n `expr $A - $B`
"""
)
- test_case_data = [{'expected_output': '12', 'expected_input': '5\n6'}]
+ test_case_data = [{'expected_output': '11', 'expected_input': '5\n6'}]
get_class = BashStdioEvaluator()
kwargs = {"user_answer": user_answer,
"test_case_data": test_case_data
diff --git a/yaksh/evaluator_tests/test_python_evaluation.py b/yaksh/evaluator_tests/test_python_evaluation.py
index a935f1d..40562db 100644
--- a/yaksh/evaluator_tests/test_python_evaluation.py
+++ b/yaksh/evaluator_tests/test_python_evaluation.py
@@ -211,20 +211,6 @@ class PythonStdoutEvaluationTestCases(unittest.TestCase):
self.assertFalse(result.get('success'))
self.assertIn("Incorrect Answer", result.get('error'))
- def test_direct_printed_answer(self):
- user_answer = "print '0 1 1 2 3'"
- error_msg = ("Incorrect Answer: Please avoid printing"
- " the expected output directly"
- )
- get_class = PythonStdioEvaluator()
-
- kwargs = {'user_answer': user_answer,
- 'test_case_data': self.test_case_data
- }
- result = get_class.evaluate(**kwargs)
- self.assertFalse(result.get('success'))
- self.assertEqual(result.get('error'), error_msg)
-
def test_infinite_loop(self):
user_answer = "def add(a, b):\n\twhile True:\n\t\tpass\nadd(1,2)"
get_class = PythonStdioEvaluator()
diff --git a/yaksh/python_stdio_evaluator.py b/yaksh/python_stdio_evaluator.py
index 003337d..aeec744 100644
--- a/yaksh/python_stdio_evaluator.py
+++ b/yaksh/python_stdio_evaluator.py
@@ -10,11 +10,10 @@ from ast import literal_eval
from code_evaluator import CodeEvaluator
from StringIO import StringIO
-
+from textwrap import dedent
@contextmanager
def redirect_stdout():
new_target = StringIO()
-
old_target, sys.stdout = sys.stdout, new_target # replace sys.stdout
try:
yield new_target # run some code with the replaced stdout
@@ -32,7 +31,6 @@ class PythonStdioEvaluator(CodeEvaluator):
input_buffer.write(expected_input)
input_buffer.seek(0)
sys.stdin = input_buffer
-
with redirect_stdout() as output_buffer:
exec_scope = {}
exec submitted in exec_scope
@@ -43,21 +41,19 @@ class PythonStdioEvaluator(CodeEvaluator):
success = False
tb = None
- if expected_output in user_answer:
- success = False
- err = ("Incorrect Answer: Please avoid "
- "printing the expected output directly"
- )
- elif self.output_value == expected_output:
-
+ if self.output_value == expected_output:
success = True
err = "Correct Answer"
-
else:
success = False
- err = """Incorrect Answer:\nExpected output - {0}
- and your output - {1}"""\
- .format(expected_output, self.output_value)
-
+ err = dedent("""
+ Incorrect Answer:
+ Given input - {0},
+ Expected output - {1} and your output - {2}
+ """
+ .format(expected_input,
+ expected_output, self.output_value
+ )
+ )
del tb
return success, err
diff --git a/yaksh/stdio_evaluator.py b/yaksh/stdio_evaluator.py
index 86b124c..4f5cfaf 100644
--- a/yaksh/stdio_evaluator.py
+++ b/yaksh/stdio_evaluator.py
@@ -9,7 +9,7 @@ class Evaluator(object):
error_msg = "Expected Output is {0} ".\
format(repr(expected_output))
else:
- error_msg = " Given Input is {0} \n Expected Output is {1} ".\
+ error_msg = " Given Input is\n {0} \n Expected Output is {1} ".\
format(expected_input, repr(expected_output))
if output_err == '':
if user_output == expected_output: