diff options
author | ankitjavalkar | 2016-09-27 15:08:18 +0530 |
---|---|---|
committer | ankitjavalkar | 2016-09-30 10:36:25 +0530 |
commit | 6b6e58b06bd49e36edd87a027c08d223571a0c0b (patch) | |
tree | 0395d79de3f06204309d933415e38bc215e231f6 /yaksh | |
parent | ac8d6720bc75676e05462cc38ad144d5aedc14e7 (diff) | |
download | online_test-6b6e58b06bd49e36edd87a027c08d223571a0c0b.tar.gz online_test-6b6e58b06bd49e36edd87a027c08d223571a0c0b.tar.bz2 online_test-6b6e58b06bd49e36edd87a027c08d223571a0c0b.zip |
Fix test cases and corresponding changes in evaluators for Python 2/3 compatibility
Diffstat (limited to 'yaksh')
-rw-r--r-- | yaksh/code_evaluator.py | 3 | ||||
-rw-r--r-- | yaksh/cpp_code_evaluator.py | 22 | ||||
-rw-r--r-- | yaksh/cpp_stdio_evaluator.py | 4 | ||||
-rwxr-xr-x | yaksh/evaluator_tests/test_bash_evaluation.py | 14 | ||||
-rwxr-xr-x | yaksh/evaluator_tests/test_c_cpp_evaluation.py | 22 | ||||
-rwxr-xr-x | yaksh/evaluator_tests/test_java_evaluation.py | 21 | ||||
-rwxr-xr-x | yaksh/evaluator_tests/test_python_evaluation.py | 137 | ||||
-rw-r--r-- | yaksh/evaluator_tests/test_scilab_evaluation.py | 14 | ||||
-rw-r--r-- | yaksh/java_code_evaluator.py | 5 | ||||
-rw-r--r-- | yaksh/java_stdio_evaluator.py | 2 | ||||
-rw-r--r-- | yaksh/python_assertion_evaluator.py | 3 | ||||
-rw-r--r-- | yaksh/python_stdio_evaluator.py | 2 | ||||
-rw-r--r-- | yaksh/scilab_code_evaluator.py | 2 | ||||
-rw-r--r-- | yaksh/stdio_evaluator.py | 8 | ||||
-rw-r--r-- | yaksh/test.txt | 1 |
15 files changed, 143 insertions, 117 deletions
diff --git a/yaksh/code_evaluator.py b/yaksh/code_evaluator.py index a55aed3..b4740c0 100644 --- a/yaksh/code_evaluator.py +++ b/yaksh/code_evaluator.py @@ -135,6 +135,7 @@ class CodeEvaluator(object): def teardown(self): # Cancel the signal delete_signal_handler() + self._change_dir(MY_DIR) def check_code(self): raise NotImplementedError("check_code method not implemented") @@ -184,7 +185,7 @@ class CodeEvaluator(object): proc.kill() # Re-raise exception. raise - return proc, stdout, stderr + return proc, stdout.decode('utf-8'), stderr.decode('utf-8') def _change_dir(self, in_dir): if in_dir is not None and isdir(in_dir): diff --git a/yaksh/cpp_code_evaluator.py b/yaksh/cpp_code_evaluator.py index 31b84b2..adef658 100644 --- a/yaksh/cpp_code_evaluator.py +++ b/yaksh/cpp_code_evaluator.py @@ -19,9 +19,10 @@ class CppCodeEvaluator(CodeEvaluator): self.submit_code_path = self.create_submit_code_file('submit.c') self.compiled_user_answer = None self.compiled_test_code = None + self.user_output_path = "" + self.ref_output_path = "" def teardown(self): - super(CppCodeEvaluator, self).teardown() # Delete the created file. os.remove(self.submit_code_path) if os.path.exists(self.ref_output_path): @@ -30,9 +31,11 @@ class CppCodeEvaluator(CodeEvaluator): os.remove(self.user_output_path) if self.files: delete_files(self.files) + super(CppCodeEvaluator, self).teardown() + def set_file_paths(self): - user_output_path = os.getcwd() + '/output' + user_output_path = os.getcwd() + '/output_file' ref_output_path = os.getcwd() + '/executable' return user_output_path, ref_output_path @@ -105,7 +108,6 @@ class CppCodeEvaluator(CodeEvaluator): Returns (False, error_msg): If mandatory arguments are not files or if the required permissions are not given to the file(s). """ - success = False proc, stdnt_out, stdnt_stderr = self.compiled_user_answer stdnt_stderr = self._remove_null_substitute_char(stdnt_stderr) @@ -126,28 +128,28 @@ class CppCodeEvaluator(CodeEvaluator): if proc.returncode == 0: success, err = True, "Correct answer" else: - err = stdout + "\n" + stderr + err = "{0} \n {1}".format(stdout, stderr) else: err = "Error:" try: error_lines = main_err.splitlines() for e in error_lines: if ':' in e: - err = err + "\n" + e.split(":", 1)[1] + err = "{0} \n {1}".format(err, e.split(":", 1)[1]) else: - err = err + "\n" + e + err = "{0} \n {1}".format(err, e) except: - err = err + "\n" + main_err + err = "{0} \n {1}".format(err, main_err) else: err = "Compilation Error:" try: error_lines = stdnt_stderr.splitlines() for e in error_lines: if ':' in e: - err = err + "\n" + e.split(":", 1)[1] + err = "{0} \n {1}".format(err, e.split(":", 1)[1]) else: - err = err + "\n" + e + err = "{0} \n {1}".format(err, e) except: - err = err + "\n" + stdnt_stderr + err = "{0} \n {1}".format(err, stdnt_stderr) return success, err diff --git a/yaksh/cpp_stdio_evaluator.py b/yaksh/cpp_stdio_evaluator.py index dab3499..64de54d 100644 --- a/yaksh/cpp_stdio_evaluator.py +++ b/yaksh/cpp_stdio_evaluator.py @@ -18,13 +18,13 @@ class CppStdioEvaluator(StdIOEvaluator): self.submit_code_path = self.create_submit_code_file('main.c') def teardown(self): - super(CppStdioEvaluator, self).teardown() os.remove(self.submit_code_path) if self.files: delete_files(self.files) + super(CppStdioEvaluator, self).teardown() def set_file_paths(self): - user_output_path = os.getcwd() + '/output' + user_output_path = os.getcwd() + '/output_file' ref_output_path = os.getcwd() + '/executable' return user_output_path, ref_output_path diff --git a/yaksh/evaluator_tests/test_bash_evaluation.py b/yaksh/evaluator_tests/test_bash_evaluation.py index 01e248f..7fdff48 100755 --- a/yaksh/evaluator_tests/test_bash_evaluation.py +++ b/yaksh/evaluator_tests/test_bash_evaluation.py @@ -1,6 +1,8 @@ from __future__ import absolute_import import unittest import os +import shutil +import tempfile from yaksh.bash_code_evaluator import BashCodeEvaluator from yaksh.bash_stdio_evaluator import BashStdioEvaluator from yaksh.settings import SERVER_TIMEOUT @@ -9,15 +11,23 @@ from textwrap import dedent class BashAssertionEvaluationTestCases(unittest.TestCase): def setUp(self): + with open('/tmp/test.txt', 'wb') as f: + f.write('2'.encode('ascii')) + tmp_in_dir_path = tempfile.mkdtemp() self.test_case_data = [ {"test_case": "bash_files/sample.sh,bash_files/sample.args"} ] - self.in_dir = os.getcwd() + tmp_in_dir_path = tempfile.mkdtemp() + self.in_dir = tmp_in_dir_path self.timeout_msg = ("Code took more than {0} seconds to run. " "You probably have an infinite loop in your" " code.").format(SERVER_TIMEOUT) self.file_paths = None + def tearDown(self): + os.remove('/tmp/test.txt') + shutil.rmtree(self.in_dir) + def test_correct_answer(self): user_answer = ("#!/bin/bash\n[[ $# -eq 2 ]]" " && echo $(( $1 + $2 )) && exit $(( $1 + $2 ))" @@ -56,7 +66,7 @@ class BashAssertionEvaluationTestCases(unittest.TestCase): self.assertEqual(result.get("error"), self.timeout_msg) def test_file_based_assert(self): - self.file_paths = [(os.getcwd()+"/yaksh/test.txt", False)] + self.file_paths = [('/tmp/test.txt', False)] self.test_case_data = [ {"test_case": "bash_files/sample1.sh,bash_files/sample1.args"} ] diff --git a/yaksh/evaluator_tests/test_c_cpp_evaluation.py b/yaksh/evaluator_tests/test_c_cpp_evaluation.py index d57affa..b3551bf 100755 --- a/yaksh/evaluator_tests/test_c_cpp_evaluation.py +++ b/yaksh/evaluator_tests/test_c_cpp_evaluation.py @@ -1,6 +1,8 @@ from __future__ import absolute_import import unittest import os +import shutil +import tempfile from yaksh.cpp_code_evaluator import CppCodeEvaluator from yaksh.cpp_stdio_evaluator import CppStdioEvaluator from yaksh.settings import SERVER_TIMEOUT @@ -9,13 +11,20 @@ from textwrap import dedent class CAssertionEvaluationTestCases(unittest.TestCase): def setUp(self): + with open('/tmp/test.txt', 'wb') as f: + f.write('2'.encode('ascii')) + tmp_in_dir_path = tempfile.mkdtemp() self.test_case_data = [{"test_case": "c_cpp_files/main.cpp"}] - self.in_dir = os.getcwd() + self.in_dir = tmp_in_dir_path self.timeout_msg = ("Code took more than {0} seconds to run. " "You probably have an infinite loop in your" " code.").format(SERVER_TIMEOUT) self.file_paths = None + def tearDown(self): + os.remove('/tmp/test.txt') + shutil.rmtree(self.in_dir) + def test_correct_answer(self): user_answer = "int add(int a, int b)\n{return a+b;}" get_class = CppCodeEvaluator(self.in_dir) @@ -35,9 +44,10 @@ class CAssertionEvaluationTestCases(unittest.TestCase): 'file_paths': self.file_paths } result = get_class.evaluate(**kwargs) + lines_of_error = len(result.get('error').splitlines()) self.assertFalse(result.get('success')) self.assertIn("Incorrect:", result.get('error')) - self.assertTrue(result.get('error').splitlines > 1) + self.assertTrue(lines_of_error > 1) def test_compilation_error(self): user_answer = "int add(int a, int b)\n{return a+b}" @@ -62,7 +72,7 @@ class CAssertionEvaluationTestCases(unittest.TestCase): self.assertEqual(result.get("error"), self.timeout_msg) def test_file_based_assert(self): - self.file_paths = [(os.getcwd()+"/yaksh/test.txt", False)] + self.file_paths = [('/tmp/test.txt', False)] self.test_case_data = [{"test_case": "c_cpp_files/file_data.c"}] user_answer = dedent(""" #include<stdio.h> @@ -160,9 +170,10 @@ class CppStdioEvaluationTestCases(unittest.TestCase): 'test_case_data': self.test_case_data } result = get_class.evaluate(**kwargs) + lines_of_error = len(result.get('error').splitlines()) self.assertFalse(result.get('success')) self.assertIn("Incorrect", result.get('error')) - self.assertTrue(result.get('error').splitlines > 1) + self.assertTrue(lines_of_error > 1) def test_error(self): user_answer = dedent(""" @@ -281,9 +292,10 @@ class CppStdioEvaluationTestCases(unittest.TestCase): 'test_case_data': self.test_case_data } result = get_class.evaluate(**kwargs) + lines_of_error = len(result.get('error').splitlines()) self.assertFalse(result.get('success')) self.assertIn("Incorrect", result.get('error')) - self.assertTrue(result.get('error').splitlines > 1) + self.assertTrue(lines_of_error > 1) def test_cpp_error(self): user_answer = dedent(""" diff --git a/yaksh/evaluator_tests/test_java_evaluation.py b/yaksh/evaluator_tests/test_java_evaluation.py index f94c6d1..a9708e8 100755 --- a/yaksh/evaluator_tests/test_java_evaluation.py +++ b/yaksh/evaluator_tests/test_java_evaluation.py @@ -1,6 +1,8 @@ from __future__ import absolute_import import unittest import os +import shutil +import tempfile from yaksh import code_evaluator as evaluator from yaksh.java_code_evaluator import JavaCodeEvaluator from yaksh.java_stdio_evaluator import JavaStdioEvaluator @@ -10,10 +12,13 @@ from textwrap import dedent class JavaAssertionEvaluationTestCases(unittest.TestCase): def setUp(self): + with open('/tmp/test.txt', 'wb') as f: + f.write('2'.encode('ascii')) + tmp_in_dir_path = tempfile.mkdtemp() self.test_case_data = [ {"test_case": "java_files/main_square.java"} ] - self.in_dir = os.getcwd() + self.in_dir = tmp_in_dir_path evaluator.SERVER_TIMEOUT = 9 self.timeout_msg = ("Code took more than {0} seconds to run. " "You probably have an infinite loop in" @@ -21,7 +26,8 @@ class JavaAssertionEvaluationTestCases(unittest.TestCase): self.file_paths = None def tearDown(self): - evaluator.SERVER_TIMEOUT = 2 + os.remove('/tmp/test.txt') + shutil.rmtree(self.in_dir) def test_correct_answer(self): user_answer = "class Test {\n\tint square_num(int a) {\n\treturn a*a;\n\t}\n}" @@ -43,8 +49,10 @@ class JavaAssertionEvaluationTestCases(unittest.TestCase): } result = get_class.evaluate(**kwargs) self.assertFalse(result.get('success')) - self.assertIn("Incorrect:", result.get('error')) - self.assertTrue(result.get('error').splitlines > 1) + lines_of_error = len(result.get('error').splitlines()) + self.assertFalse(result.get('success')) + self.assertIn("Incorrect", result.get('error')) + self.assertTrue(lines_of_error > 1) def test_error(self): user_answer = "class Test {\n\tint square_num(int a) {\n\treturn a*a" @@ -69,7 +77,7 @@ class JavaAssertionEvaluationTestCases(unittest.TestCase): self.assertEqual(result.get("error"), self.timeout_msg) def test_file_based_assert(self): - self.file_paths = [(os.getcwd()+"/yaksh/test.txt", False)] + self.file_paths = [("/tmp/test.txt", False)] self.test_case_data = [ {"test_case": "java_files/read_file.java"} ] @@ -169,9 +177,10 @@ class JavaStdioEvaluationTestCases(unittest.TestCase): 'test_case_data': self.test_case_data } result = get_class.evaluate(**kwargs) + lines_of_error = len(result.get('error').splitlines()) self.assertFalse(result.get('success')) self.assertIn("Incorrect", result.get('error')) - self.assertTrue(result.get('error').splitlines > 1) + self.assertTrue(lines_of_error > 1) def test_error(self): diff --git a/yaksh/evaluator_tests/test_python_evaluation.py b/yaksh/evaluator_tests/test_python_evaluation.py index 6852136..b93aa13 100755 --- a/yaksh/evaluator_tests/test_python_evaluation.py +++ b/yaksh/evaluator_tests/test_python_evaluation.py @@ -1,14 +1,23 @@ from __future__ import absolute_import +from six.moves import input import unittest import os +import tempfile +import shutil +from textwrap import dedent + +# Local import from yaksh.python_assertion_evaluator import PythonAssertionEvaluator from yaksh.python_stdio_evaluator import PythonStdioEvaluator from yaksh.settings import SERVER_TIMEOUT -from textwrap import dedent class PythonAssertionEvaluationTestCases(unittest.TestCase): def setUp(self): + with open('/tmp/test.txt', 'wb') as f: + f.write('2'.encode('ascii')) + tmp_in_dir_path = tempfile.mkdtemp() + self.in_dir = tmp_in_dir_path self.test_case_data = [{"test_case": 'assert(add(1,2)==3)'}, {"test_case": 'assert(add(-1,2)==1)'}, {"test_case": 'assert(add(-1,-2)==-3)'}, @@ -18,6 +27,10 @@ class PythonAssertionEvaluationTestCases(unittest.TestCase): " your code.").format(SERVER_TIMEOUT) self.file_paths = None + def tearDown(self): + os.remove('/tmp/test.txt') + shutil.rmtree(self.in_dir) + def test_correct_answer(self): # Given user_answer = "def add(a,b):\n\treturn a + b" @@ -160,7 +173,6 @@ class PythonAssertionEvaluationTestCases(unittest.TestCase): """) recursion_error_msg = ["Traceback", "call", - "RuntimeError", "maximum recursion depth exceeded" ] kwargs = {'user_answer': user_answer, @@ -175,7 +187,6 @@ class PythonAssertionEvaluationTestCases(unittest.TestCase): # Then self.assertFalse(result.get("success")) - self.assertEqual(969, len(err)) for msg in recursion_error_msg: self.assertIn(msg, result.get("error")) @@ -188,7 +199,6 @@ class PythonAssertionEvaluationTestCases(unittest.TestCase): type_error_msg = ["Traceback", "call", "TypeError", - "exactly", "argument" ] kwargs = {'user_answer': user_answer, @@ -239,7 +249,7 @@ class PythonAssertionEvaluationTestCases(unittest.TestCase): def test_file_based_assert(self): # Given self.test_case_data = [{"test_case": "assert(ans()=='2')"}] - self.file_paths = [(os.getcwd()+"/yaksh/test.txt", False)] + self.file_paths = [('/tmp/test.txt', False)] user_answer = dedent(""" def ans(): with open("test.txt") as f: @@ -323,65 +333,10 @@ class PythonAssertionEvaluationTestCases(unittest.TestCase): self.assertIn(msg, result.get("error")) -class PythonStdoutEvaluationTestCases(unittest.TestCase): - def setUp(self): - self.test_case_data = [{"expected_input": None, - "expected_output": "0 1 1 2 3" - }] - - self.timeout_msg = ("Code took more than {0} seconds to run. " - "You probably have an infinite loop" - " in your code.").format(SERVER_TIMEOUT) - - def test_correct_answer(self): - # Given - user_answer = "a,b=0,1\nfor i in range(5):\n\tprint a,\n\ta,b=b,a+b" - kwargs = {'user_answer': user_answer, - 'test_case_data': self.test_case_data, - } - - # When - evaluator = PythonStdioEvaluator() - result = evaluator.evaluate(**kwargs) - - # Then - self.assertEqual(result.get('error'), "Correct answer") - self.assertTrue(result.get('success')) - - def test_incorrect_answer(self): - # Given - user_answer = "a,b=0,1\nfor i in range(5):\n\tprint b,\n\ta,b=b,a+b" - kwargs = {'user_answer': user_answer, - 'test_case_data': self.test_case_data, - } - - # When - evaluator = PythonStdioEvaluator() - result = evaluator.evaluate(**kwargs) - - # Then - self.assertFalse(result.get('success')) - self.assertIn("Incorrect answer", result.get('error')) - - def test_infinite_loop(self): - # Given - user_answer = "def add(a, b):\n\twhile True:\n\t\tpass\nadd(1,2)" - kwargs = {'user_answer': user_answer, - 'test_case_data': self.test_case_data - } - - # When - evaluator = PythonStdioEvaluator() - result = evaluator.evaluate(**kwargs) - - # Then - self.assertEqual(result.get('error'), self.timeout_msg) - self.assertFalse(result.get('success')) - - class PythonStdIOEvaluationTestCases(unittest.TestCase): - def setUp(self): + with open('/tmp/test.txt', 'wb') as f: + f.write('2'.encode('ascii')) self.file_paths = None def test_correct_answer_integer(self): @@ -390,9 +345,9 @@ class PythonStdIOEvaluationTestCases(unittest.TestCase): "expected_output": "3" }] user_answer = dedent(""" - a = input() - b = input() - print a+b + a = int(input()) + b = int(input()) + print(a+b) """ ) kwargs = {'user_answer': user_answer, @@ -409,13 +364,16 @@ class PythonStdIOEvaluationTestCases(unittest.TestCase): def test_correct_answer_list(self): # Given - self.test_case_data = [{"expected_input": "[1,2,3]\n[5,6,7]", + self.test_case_data = [{"expected_input": "1,2,3\n5,6,7", "expected_output": "[1, 2, 3, 5, 6, 7]" }] user_answer = dedent(""" - a = input() - b = input() - print a+b + from six.moves import input + input_a = input() + input_b = input() + a = [int(i) for i in input_a.split(',')] + b = [int(i) for i in input_b.split(',')] + print(a+b) """ ) kwargs = {'user_answer': user_answer, @@ -432,14 +390,14 @@ class PythonStdIOEvaluationTestCases(unittest.TestCase): def test_correct_answer_string(self): # Given - self.test_case_data = [{"expected_input": """the quick brown fox jumps\ - over the lazy dog\nthe""", + self.test_case_data = [{"expected_input": ("the quick brown fox jumps over the lazy dog\nthe"), "expected_output": "2" }] user_answer = dedent(""" - a = raw_input() - b = raw_input() - print (a.count(b)) + from six.moves import input + a = str(input()) + b = str(input()) + print(a.count(b)) """ ) kwargs = {'user_answer': user_answer, @@ -460,9 +418,9 @@ class PythonStdIOEvaluationTestCases(unittest.TestCase): "expected_output": "3" }] user_answer = dedent(""" - a = input() - b = input() - print a-b + a = int(input()) + b = int(input()) + print(a-b) """ ) kwargs = {'user_answer': user_answer, @@ -480,12 +438,12 @@ class PythonStdIOEvaluationTestCases(unittest.TestCase): def test_file_based_answer(self): # Given self.test_case_data = [{"expected_input": "", "expected_output": "2"}] - self.file_paths = [(os.getcwd()+"/yaksh/test.txt", False)] + self.file_paths = [('/tmp/test.txt', False)] user_answer = dedent(""" with open("test.txt") as f: a = f.read() - print a[0] + print(a[0]) """ ) kwargs = {'user_answer': user_answer, @@ -501,5 +459,26 @@ class PythonStdIOEvaluationTestCases(unittest.TestCase): self.assertEqual(result.get('error'), "Correct answer") self.assertTrue(result.get('success')) + def test_infinite_loop(self): + # Given + test_case_data = [{"expected_input": "1\n2", + "expected_output": "3" + }] + timeout_msg = ("Code took more than {0} seconds to run. " + "You probably have an infinite loop in" + " your code.").format(SERVER_TIMEOUT) + user_answer = "while True:\n\tpass" + kwargs = {'user_answer': user_answer, + 'test_case_data': test_case_data + } + + # When + evaluator = PythonStdioEvaluator() + result = evaluator.evaluate(**kwargs) + + # Then + self.assertEqual(result.get('error'), timeout_msg) + self.assertFalse(result.get('success')) + if __name__ == '__main__': unittest.main() diff --git a/yaksh/evaluator_tests/test_scilab_evaluation.py b/yaksh/evaluator_tests/test_scilab_evaluation.py index f1b29dd..0bb7bfd 100644 --- a/yaksh/evaluator_tests/test_scilab_evaluation.py +++ b/yaksh/evaluator_tests/test_scilab_evaluation.py @@ -1,19 +1,26 @@ from __future__ import absolute_import import unittest import os +import shutil +import tempfile + from yaksh import code_evaluator as evaluator from yaksh.scilab_code_evaluator import ScilabCodeEvaluator from yaksh.settings import SERVER_TIMEOUT class ScilabEvaluationTestCases(unittest.TestCase): def setUp(self): + tmp_in_dir_path = tempfile.mkdtemp() self.test_case_data = [{"test_case": "scilab_files/test_add.sce"}] - self.in_dir = os.getcwd() + self.in_dir = tmp_in_dir_path self.timeout_msg = ("Code took more than {0} seconds to run. " "You probably have an infinite loop" " in your code.").format(SERVER_TIMEOUT) self.file_paths = None + def tearDown(self): + shutil.rmtree(self.in_dir) + def test_correct_answer(self): user_answer = ("funcprot(0)\nfunction[c]=add(a,b)" "\n\tc=a+b;\nendfunction") @@ -36,7 +43,7 @@ class ScilabEvaluationTestCases(unittest.TestCase): } result = get_class.evaluate(**kwargs) self.assertFalse(result.get("success")) - self.assertTrue("error" in result.get("error")) + self.assertTrue('error' in result.get("error")) def test_incorrect_answer(self): @@ -48,9 +55,10 @@ class ScilabEvaluationTestCases(unittest.TestCase): 'file_paths': self.file_paths } result = get_class.evaluate(**kwargs) + lines_of_error = len(result.get('error').splitlines()) self.assertFalse(result.get('success')) self.assertIn("Message", result.get('error')) - self.assertTrue(result.get('error').splitlines > 1) + self.assertTrue(lines_of_error > 1) def test_infinite_loop(self): user_answer = ("funcprot(0)\nfunction[c]=add(a,b)" diff --git a/yaksh/java_code_evaluator.py b/yaksh/java_code_evaluator.py index 2e8c0c6..a294b8e 100644 --- a/yaksh/java_code_evaluator.py +++ b/yaksh/java_code_evaluator.py @@ -19,9 +19,10 @@ class JavaCodeEvaluator(CodeEvaluator): self.submit_code_path = self.create_submit_code_file('Test.java') self.compiled_user_answer = None self.compiled_test_code = None + self.user_output_path = "" + self.ref_output_path = "" def teardown(self): - super(JavaCodeEvaluator, self).teardown() # Delete the created file. os.remove(self.submit_code_path) if os.path.exists(self.user_output_path): @@ -30,6 +31,8 @@ class JavaCodeEvaluator(CodeEvaluator): os.remove(self.ref_output_path) if self.files: delete_files(self.files) + super(JavaCodeEvaluator, self).teardown() + def get_commands(self, clean_ref_code_path, user_code_directory): compile_command = 'javac {0}'.format(self.submit_code_path), diff --git a/yaksh/java_stdio_evaluator.py b/yaksh/java_stdio_evaluator.py index 71768ef..b5a52f3 100644 --- a/yaksh/java_stdio_evaluator.py +++ b/yaksh/java_stdio_evaluator.py @@ -18,10 +18,10 @@ class JavaStdioEvaluator(StdIOEvaluator): self.submit_code_path = self.create_submit_code_file('Test.java') def teardown(self): - super(JavaStdioEvaluator, self).teardown() os.remove(self.submit_code_path) if self.files: delete_files(self.files) + super(JavaStdioEvaluator, self).teardown() def set_file_paths(self, directory, file_name): output_path = "{0}{1}.class".format(directory, file_name) diff --git a/yaksh/python_assertion_evaluator.py b/yaksh/python_assertion_evaluator.py index 78154a3..4f159bf 100644 --- a/yaksh/python_assertion_evaluator.py +++ b/yaksh/python_assertion_evaluator.py @@ -1,5 +1,6 @@ #!/usr/bin/env python from __future__ import absolute_import +from six.moves import input import sys import traceback import os @@ -19,10 +20,10 @@ class PythonAssertionEvaluator(CodeEvaluator): self.exec_scope = None def teardown(self): - super(PythonAssertionEvaluator, self).teardown() # Delete the created file. if self.files: delete_files(self.files) + super(PythonAssertionEvaluator, self).teardown() def compile_code(self, user_answer, file_paths, test_case): self.files = [] diff --git a/yaksh/python_stdio_evaluator.py b/yaksh/python_stdio_evaluator.py index 3011179..5f672e2 100644 --- a/yaksh/python_stdio_evaluator.py +++ b/yaksh/python_stdio_evaluator.py @@ -32,10 +32,10 @@ class PythonStdioEvaluator(CodeEvaluator): """Tests the Python code obtained from Code Server""" def teardown(self): - super(PythonStdioEvaluator, self).teardown() # Delete the created file. if self.files: delete_files(self.files) + super(PythonStdioEvaluator, self).teardown() def compile_code(self, user_answer, file_paths, expected_input, expected_output): diff --git a/yaksh/scilab_code_evaluator.py b/yaksh/scilab_code_evaluator.py index 011cb69..075bf6b 100644 --- a/yaksh/scilab_code_evaluator.py +++ b/yaksh/scilab_code_evaluator.py @@ -20,11 +20,11 @@ class ScilabCodeEvaluator(CodeEvaluator): self.create_submit_code_file('function.sci') def teardown(self): - super(ScilabCodeEvaluator, self).teardown() # Delete the created file. os.remove(self.submit_code_path) if self.files: delete_files(self.files) + super(ScilabCodeEvaluator, self).teardown() def check_code(self, user_answer, file_paths, test_case): self.files = [] diff --git a/yaksh/stdio_evaluator.py b/yaksh/stdio_evaluator.py index f1def95..b5924ff 100644 --- a/yaksh/stdio_evaluator.py +++ b/yaksh/stdio_evaluator.py @@ -15,8 +15,10 @@ class StdIOEvaluator(CodeEvaluator): def evaluate_stdio(self, user_answer, proc, expected_input, expected_output): success = False ip = expected_input.replace(",", " ") - print (type(expected_input), type(ip)) - user_output, output_err = proc.communicate(input='{0}\n'.format(ip)) + encoded_input = '{0}\n'.format(ip).encode('utf-8') + user_output_bytes, output_err_bytes = proc.communicate(encoded_input) + user_output = user_output_bytes.decode('utf-8') + output_err = output_err_bytes.decode('utf-8') expected_output = expected_output.replace("\r", "") if not expected_input: error_msg = "Expected Output is {0} ".\ @@ -31,5 +33,5 @@ class StdIOEvaluator(CodeEvaluator): err = " Incorrect answer\n" + error_msg +\ "\n Your output is {0}".format(repr(user_output)) else: - err = "Error:"+"\n"+output_err + err = "Error:\n {0}".format(output_err) return success, err diff --git a/yaksh/test.txt b/yaksh/test.txt deleted file mode 100644 index 0cfbf08..0000000 --- a/yaksh/test.txt +++ /dev/null @@ -1 +0,0 @@ -2 |