summaryrefslogtreecommitdiff
path: root/yaksh
diff options
context:
space:
mode:
authormaheshgudi2017-01-09 12:48:37 +0530
committermaheshgudi2017-01-09 18:10:30 +0530
commitcf4f207f710b9f67e0973a99f5894c4a866bca4c (patch)
tree8426a0d1611a406e2fbbf3cc5d8e4a1ae91bcb10 /yaksh
parent6b8f8f53d7110e27bc44f0d50b8b3155155932f6 (diff)
downloadonline_test-cf4f207f710b9f67e0973a99f5894c4a866bca4c.tar.gz
online_test-cf4f207f710b9f67e0973a99f5894c4a866bca4c.tar.bz2
online_test-cf4f207f710b9f67e0973a99f5894c4a866bca4c.zip
modified tests and hook evaluator for python 3
Diffstat (limited to 'yaksh')
-rw-r--r--yaksh/evaluator_tests/test_bash_evaluation.py10
-rw-r--r--yaksh/evaluator_tests/test_c_cpp_evaluation.py8
-rw-r--r--yaksh/evaluator_tests/test_java_evaluation.py8
-rw-r--r--yaksh/evaluator_tests/test_python_evaluation.py8
-rw-r--r--yaksh/hook_evaluator.py2
5 files changed, 19 insertions, 17 deletions
diff --git a/yaksh/evaluator_tests/test_bash_evaluation.py b/yaksh/evaluator_tests/test_bash_evaluation.py
index 0662831..482d45e 100644
--- a/yaksh/evaluator_tests/test_bash_evaluation.py
+++ b/yaksh/evaluator_tests/test_bash_evaluation.py
@@ -303,7 +303,7 @@ class BashHookEvaluationTestCases(EvaluatorBaseTest):
stderr=subprocess.PIPE
)
stdout,stderr = proc.communicate()
- if stdout == "Hello, world!":
+ if stdout.decode("utf-8") == "Hello, world!":
success, err, mark_fraction = True, "", 1.0
return success, err, mark_fraction
"""
@@ -346,7 +346,7 @@ class BashHookEvaluationTestCases(EvaluatorBaseTest):
stderr=subprocess.PIPE
)
stdout,stderr = proc.communicate()
- if stdout == "Hello, world!":
+ if stdout.decode("utf-8") == "Hello, world!":
success, err, mark_fraction = True, "", 1.0
return success, err, mark_fraction
"""
@@ -444,6 +444,7 @@ class BashHookEvaluationTestCases(EvaluatorBaseTest):
hook_code_2 = dedent("""\
def check_answer(user_answer):
import subprocess
+ import sys
success = False
err = "Incorrect Answer"
mark_fraction = 0.0
@@ -452,7 +453,8 @@ class BashHookEvaluationTestCases(EvaluatorBaseTest):
stderr=subprocess.PIPE
)
stdout,stderr = proc.communicate()
- if stdout == "Hello, world!":
+
+ if stdout.decode('utf-8') == "Hello, world!":
success, err, mark_fraction = True, "", 1.0
return success, err, mark_fraction
"""
@@ -498,7 +500,7 @@ class BashHookEvaluationTestCases(EvaluatorBaseTest):
stderr=subprocess.PIPE
)
stdout,stderr = proc.communicate()
- if stdout == "Hello, world!":
+ if stdout.decode("utf-8") == "Hello, world!":
success, err, mark_fraction = True, "", 1.0
return success, err, mark_fraction
"""
diff --git a/yaksh/evaluator_tests/test_c_cpp_evaluation.py b/yaksh/evaluator_tests/test_c_cpp_evaluation.py
index bba7bc7..304f1cb 100644
--- a/yaksh/evaluator_tests/test_c_cpp_evaluation.py
+++ b/yaksh/evaluator_tests/test_c_cpp_evaluation.py
@@ -684,7 +684,7 @@ class CppHookEvaluationTestCases(EvaluatorBaseTest):
cmds = ["gcc Test.c", "./a.out"]
for cmd in cmds:
stdout, stderr = _run_command(cmd)
- if stdout == "Hello, world!":
+ if stdout.decode("utf-8") == "Hello, world!":
success, err, mark_fraction = True, "", 1.0
return success, err, mark_fraction
"""
@@ -738,7 +738,7 @@ class CppHookEvaluationTestCases(EvaluatorBaseTest):
cmds = ["gcc Test.c", "./a.out"]
for cmd in cmds:
stdout, stderr = _run_command(cmd)
- if stdout == "Hello, world!":
+ if stdout.decode("utf-8") == "Hello, world!":
success, err, mark_fraction = True, "", 1.0
return success, err, mark_fraction
"""
@@ -871,7 +871,7 @@ class CppHookEvaluationTestCases(EvaluatorBaseTest):
cmds = ["gcc Test.c", "./a.out"]
for cmd in cmds:
stdout, stderr = _run_command(cmd)
- if stdout == "Hello, world!":
+ if stdout.decode("utf-8") == "Hello, world!":
success, err, mark_fraction = True, "", 1.0
return success, err, mark_fraction
"""
@@ -940,7 +940,7 @@ class CppHookEvaluationTestCases(EvaluatorBaseTest):
cmds = ["gcc Test.c", "./a.out"]
for cmd in cmds:
stdout, stderr = _run_command(cmd)
- if stdout == "Hello, world!":
+ if stdout.decode("utf-8") == "Hello, world!":
success, err, mark_fraction = True, "", 1.0
return success, err, mark_fraction
"""
diff --git a/yaksh/evaluator_tests/test_java_evaluation.py b/yaksh/evaluator_tests/test_java_evaluation.py
index 8c9fe90..3d127af 100644
--- a/yaksh/evaluator_tests/test_java_evaluation.py
+++ b/yaksh/evaluator_tests/test_java_evaluation.py
@@ -553,7 +553,7 @@ class JavaHookEvaluationTestCases(EvaluatorBaseTest):
cmds = ["javac Test.java", "java Test"]
for cmd in cmds:
stdout, stderr = _run_command(cmd)
- if stdout == "Hello, world!":
+ if stdout.decode("utf-8") == "Hello, world!":
success, err, mark_fraction = True, "", 1.0
return success, err, mark_fraction
"""
@@ -606,7 +606,7 @@ class JavaHookEvaluationTestCases(EvaluatorBaseTest):
cmds = ["javac Test.java", "java Test"]
for cmd in cmds:
stdout, stderr = _run_command(cmd)
- if stdout == "Hello, world!":
+ if stdout.decode("utf-8") == "Hello, world!":
success, err, mark_fraction = True, "", 1.0
return success, err, mark_fraction
"""
@@ -736,7 +736,7 @@ class JavaHookEvaluationTestCases(EvaluatorBaseTest):
cmds = ["javac Test.java", "java Test"]
for cmd in cmds:
stdout, stderr = _run_command(cmd)
- if stdout == "Hello, world!":
+ if stdout.decode("utf-8") == "Hello, world!":
success, err, mark_fraction = True, "", 1.0
return success, err, mark_fraction
"""
@@ -806,7 +806,7 @@ class JavaHookEvaluationTestCases(EvaluatorBaseTest):
cmds = ["javac Test.java", "java Test"]
for cmd in cmds:
stdout, stderr = _run_command(cmd)
- if stdout == "Hello, world!":
+ if stdout.decode("utf-8") == "Hello, world!":
success, err, mark_fraction = True, "", 1.0
return success, err, mark_fraction
"""
diff --git a/yaksh/evaluator_tests/test_python_evaluation.py b/yaksh/evaluator_tests/test_python_evaluation.py
index a9f8122..ef155e8 100644
--- a/yaksh/evaluator_tests/test_python_evaluation.py
+++ b/yaksh/evaluator_tests/test_python_evaluation.py
@@ -665,7 +665,7 @@ class PythonHookEvaluationTestCases(EvaluatorBaseTest):
success = False
err = "Incorrect Answer"
mark_fraction = 0.0
- exec(user_answer)
+ exec(user_answer, globals())
if add(1,2) == 3:
success, err, mark_fraction = True, "", 1.0
return success, err, mark_fraction
@@ -700,7 +700,7 @@ class PythonHookEvaluationTestCases(EvaluatorBaseTest):
success = False
err = "Incorrect Answer"
mark_fraction = 0.0
- exec user_answer
+ exec(user_answer, globals())
if add(1,2) == 3:
success, err, mark_fraction = True, "", 1.0
return success, err, mark_fraction
@@ -785,7 +785,7 @@ class PythonHookEvaluationTestCases(EvaluatorBaseTest):
success = False
err = "Incorrect Answer"
mark_fraction = 0.0
- exec(user_answer)
+ exec(user_answer, globals())
if add(1,2) == 3:
success, err, mark_fraction = True, "", 1.0
return success, err, mark_fraction
@@ -824,7 +824,7 @@ class PythonHookEvaluationTestCases(EvaluatorBaseTest):
success = False
err = "Incorrect Answer"
mark_fraction = 0.0
- exec(user_answer)
+ exec(user_answer, globals())
if add(1,2) == 3:
success, err, mark_fraction = True, "", 1.0
return success, err, mark_fraction
diff --git a/yaksh/hook_evaluator.py b/yaksh/hook_evaluator.py
index 6c8b2c3..c125b21 100644
--- a/yaksh/hook_evaluator.py
+++ b/yaksh/hook_evaluator.py
@@ -53,7 +53,7 @@ class HookEvaluator(BaseEvaluator):
try:
tb = None
_tests = compile(self.hook_code, '<string>', mode='exec')
- exec(_tests, locals())
+ exec(_tests, globals())
success, err, mark_fraction = check_answer(self.user_answer)
except TimeoutException:
raise