diff options
author | ankitjavalkar | 2016-09-21 15:07:43 +0530 |
---|---|---|
committer | ankitjavalkar | 2016-09-30 10:33:42 +0530 |
commit | ac8d6720bc75676e05462cc38ad144d5aedc14e7 (patch) | |
tree | e2e527e159a0704ecdaa2f15ae13900f4555ea63 /yaksh | |
parent | 6b08e56fe3cf70ffbcbd1ed432dde25babe48148 (diff) | |
download | online_test-ac8d6720bc75676e05462cc38ad144d5aedc14e7.tar.gz online_test-ac8d6720bc75676e05462cc38ad144d5aedc14e7.tar.bz2 online_test-ac8d6720bc75676e05462cc38ad144d5aedc14e7.zip |
Migrate python code server and evaluators to python 2/3 compatible
Diffstat (limited to 'yaksh')
-rw-r--r-- | yaksh/bash_code_evaluator.py | 5 | ||||
-rw-r--r-- | yaksh/bash_stdio_evaluator.py | 8 | ||||
-rw-r--r-- | yaksh/code_evaluator.py | 14 | ||||
-rwxr-xr-x | yaksh/code_server.py | 14 | ||||
-rw-r--r-- | yaksh/cpp_code_evaluator.py | 7 | ||||
-rw-r--r-- | yaksh/cpp_stdio_evaluator.py | 9 | ||||
-rwxr-xr-x | yaksh/evaluator_tests/test_bash_evaluation.py | 13 | ||||
-rwxr-xr-x | yaksh/evaluator_tests/test_c_cpp_evaluation.py | 27 | ||||
-rw-r--r-- | yaksh/evaluator_tests/test_code_evaluation.py | 3 | ||||
-rwxr-xr-x | yaksh/evaluator_tests/test_java_evaluation.py | 17 | ||||
-rwxr-xr-x | yaksh/evaluator_tests/test_python_evaluation.py | 1 | ||||
-rw-r--r-- | yaksh/evaluator_tests/test_scilab_evaluation.py | 5 | ||||
-rw-r--r-- | yaksh/file_utils.py | 1 | ||||
-rw-r--r-- | yaksh/java_code_evaluator.py | 7 | ||||
-rw-r--r-- | yaksh/java_stdio_evaluator.py | 8 | ||||
-rw-r--r-- | yaksh/language_registry.py | 8 | ||||
-rw-r--r-- | yaksh/python_assertion_evaluator.py | 11 | ||||
-rw-r--r-- | yaksh/python_stdio_evaluator.py | 19 | ||||
-rw-r--r-- | yaksh/scilab_code_evaluator.py | 7 | ||||
-rw-r--r-- | yaksh/stdio_evaluator.py | 1 | ||||
-rw-r--r-- | yaksh/tests/test_code_server.py | 8 | ||||
-rw-r--r-- | yaksh/xmlrpc_clients.py | 15 |
22 files changed, 131 insertions, 77 deletions
diff --git a/yaksh/bash_code_evaluator.py b/yaksh/bash_code_evaluator.py index bce7f07..0cbce89 100644 --- a/yaksh/bash_code_evaluator.py +++ b/yaksh/bash_code_evaluator.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +from __future__ import absolute_import import traceback import pwd import os @@ -8,8 +9,8 @@ import subprocess import importlib # local imports -from code_evaluator import CodeEvaluator -from file_utils import copy_files, delete_files +from .code_evaluator import CodeEvaluator +from .file_utils import copy_files, delete_files class BashCodeEvaluator(CodeEvaluator): diff --git a/yaksh/bash_stdio_evaluator.py b/yaksh/bash_stdio_evaluator.py index 8ff0743..fbb94ec 100644 --- a/yaksh/bash_stdio_evaluator.py +++ b/yaksh/bash_stdio_evaluator.py @@ -1,11 +1,13 @@ #!/usr/bin/env python +from __future__ import absolute_import import subprocess import os from os.path import isfile -# local imports -from stdio_evaluator import StdIOEvaluator -from file_utils import copy_files, delete_files +#local imports +from .code_evaluator import CodeEvaluator +from .stdio_evaluator import Evaluator +from .file_utils import copy_files, delete_files class BashStdioEvaluator(StdIOEvaluator): diff --git a/yaksh/code_evaluator.py b/yaksh/code_evaluator.py index 8a9b7a6..a55aed3 100644 --- a/yaksh/code_evaluator.py +++ b/yaksh/code_evaluator.py @@ -1,5 +1,6 @@ +#!/usr/bin/env python +from __future__ import absolute_import import sys -from SimpleXMLRPCServer import SimpleXMLRPCServer import pwd import os import stat @@ -9,8 +10,15 @@ import traceback from multiprocessing import Process, Queue import subprocess import re -# Local imports. -from settings import SERVER_TIMEOUT + +try: + from SimpleXMLRPCServer import SimpleXMLRPCServer +except ImportError: + # The above import will not work on Python-3.x. + from xmlrpc.server import SimpleXMLRPCServer + +# Local imports +from .settings import SERVER_TIMEOUT MY_DIR = abspath(dirname(__file__)) diff --git a/yaksh/code_server.py b/yaksh/code_server.py index e19e9c8..b753ac7 100755 --- a/yaksh/code_server.py +++ b/yaksh/code_server.py @@ -23,7 +23,7 @@ that returns an available server. """ # Standard library imports -from SimpleXMLRPCServer import SimpleXMLRPCServer +from __future__ import absolute_import import json from multiprocessing import Process, Queue import os @@ -36,6 +36,12 @@ import subprocess import sys try: + from SimpleXMLRPCServer import SimpleXMLRPCServer +except ImportError: + # The above import will not work on Python-3.x. + from xmlrpc.server import SimpleXMLRPCServer + +try: from urllib import unquote except ImportError: # The above import will not work on Python-3.x. @@ -45,9 +51,9 @@ except ImportError: from tornado.ioloop import IOLoop from tornado.web import Application, RequestHandler -# Local imports. -from settings import SERVER_PORTS, SERVER_POOL_PORT -from language_registry import create_evaluator_instance, unpack_json +# Local imports +from .settings import SERVER_PORTS, SERVER_POOL_PORT +from .language_registry import create_evaluator_instance, unpack_json MY_DIR = abspath(dirname(__file__)) diff --git a/yaksh/cpp_code_evaluator.py b/yaksh/cpp_code_evaluator.py index c65242d..31b84b2 100644 --- a/yaksh/cpp_code_evaluator.py +++ b/yaksh/cpp_code_evaluator.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +from __future__ import absolute_import import traceback import pwd import os @@ -6,9 +7,9 @@ from os.path import join, isfile import subprocess import importlib -# local imports -from code_evaluator import CodeEvaluator -from file_utils import copy_files, delete_files +# Local imports +from .code_evaluator import CodeEvaluator +from .file_utils import copy_files, delete_files class CppCodeEvaluator(CodeEvaluator): diff --git a/yaksh/cpp_stdio_evaluator.py b/yaksh/cpp_stdio_evaluator.py index 720ed0f..dab3499 100644 --- a/yaksh/cpp_stdio_evaluator.py +++ b/yaksh/cpp_stdio_evaluator.py @@ -1,12 +1,13 @@ #!/usr/bin/env python +from __future__ import absolute_import import subprocess import os from os.path import isfile -#local imports - -from stdio_evaluator import StdIOEvaluator -from file_utils import copy_files, delete_files +#Local imports +from .code_evaluator import CodeEvaluator +from .stdio_evaluator import Evaluator +from .file_utils import copy_files, delete_files class CppStdioEvaluator(StdIOEvaluator): diff --git a/yaksh/evaluator_tests/test_bash_evaluation.py b/yaksh/evaluator_tests/test_bash_evaluation.py index 084e5e4..01e248f 100755 --- a/yaksh/evaluator_tests/test_bash_evaluation.py +++ b/yaksh/evaluator_tests/test_bash_evaluation.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import import unittest import os from yaksh.bash_code_evaluator import BashCodeEvaluator @@ -28,7 +29,7 @@ class BashAssertionEvaluationTestCases(unittest.TestCase): } result = get_class.evaluate(**kwargs) self.assertTrue(result.get('success')) - self.assertEquals(result.get('error'), "Correct answer") + self.assertEqual(result.get('error'), "Correct answer") def test_error(self): user_answer = ("#!/bin/bash\n[[ $# -eq 2 ]] " @@ -52,7 +53,7 @@ class BashAssertionEvaluationTestCases(unittest.TestCase): } result = get_class.evaluate(**kwargs) self.assertFalse(result.get("success")) - self.assertEquals(result.get("error"), self.timeout_msg) + self.assertEqual(result.get("error"), self.timeout_msg) def test_file_based_assert(self): self.file_paths = [(os.getcwd()+"/yaksh/test.txt", False)] @@ -67,7 +68,7 @@ class BashAssertionEvaluationTestCases(unittest.TestCase): } result = get_class.evaluate(**kwargs) self.assertTrue(result.get("success")) - self.assertEquals(result.get("error"), "Correct answer") + self.assertEqual(result.get("error"), "Correct answer") class BashStdioEvaluationTestCases(unittest.TestCase): def setUp(self): @@ -88,7 +89,7 @@ class BashStdioEvaluationTestCases(unittest.TestCase): "test_case_data": test_case_data } result = get_class.evaluate(**kwargs) - self.assertEquals(result.get('error'), "Correct answer") + self.assertEqual(result.get('error'), "Correct Answer") self.assertTrue(result.get('success')) def test_array_input(self): @@ -108,7 +109,7 @@ class BashStdioEvaluationTestCases(unittest.TestCase): "test_case_data": test_case_data } result = get_class.evaluate(**kwargs) - self.assertEquals(result.get('error'), "Correct answer") + self.assertEqual(result.get('error'), "Correct Answer") self.assertTrue(result.get('success')) def test_incorrect_answer(self): @@ -142,7 +143,7 @@ class BashStdioEvaluationTestCases(unittest.TestCase): "test_case_data": test_case_data } result = get_class.evaluate(**kwargs) - self.assertEquals(result.get('error'), "Correct answer") + self.assertEqual(result.get('error'), "Correct Answer") self.assertTrue(result.get('success')) if __name__ == '__main__': diff --git a/yaksh/evaluator_tests/test_c_cpp_evaluation.py b/yaksh/evaluator_tests/test_c_cpp_evaluation.py index c6994f6..d57affa 100755 --- a/yaksh/evaluator_tests/test_c_cpp_evaluation.py +++ b/yaksh/evaluator_tests/test_c_cpp_evaluation.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import import unittest import os from yaksh.cpp_code_evaluator import CppCodeEvaluator @@ -24,7 +25,7 @@ class CAssertionEvaluationTestCases(unittest.TestCase): } result = get_class.evaluate(**kwargs) self.assertTrue(result.get('success')) - self.assertEquals(result.get('error'), "Correct answer") + self.assertEqual(result.get('error'), "Correct answer") def test_incorrect_answer(self): user_answer = "int add(int a, int b)\n{return a-b;}" @@ -58,7 +59,7 @@ class CAssertionEvaluationTestCases(unittest.TestCase): } result = get_class.evaluate(**kwargs) self.assertFalse(result.get("success")) - self.assertEquals(result.get("error"), self.timeout_msg) + self.assertEqual(result.get("error"), self.timeout_msg) def test_file_based_assert(self): self.file_paths = [(os.getcwd()+"/yaksh/test.txt", False)] @@ -82,7 +83,7 @@ class CAssertionEvaluationTestCases(unittest.TestCase): } result = get_class.evaluate(**kwargs) self.assertTrue(result.get('success')) - self.assertEquals(result.get('error'), "Correct answer") + self.assertEqual(result.get('error'), "Correct answer") class CppStdioEvaluationTestCases(unittest.TestCase): @@ -106,7 +107,7 @@ class CppStdioEvaluationTestCases(unittest.TestCase): 'test_case_data': self.test_case_data } result = get_class.evaluate(**kwargs) - self.assertEquals(result.get('error'), "Correct answer") + self.assertEqual(result.get('error'), "Correct Answer") self.assertTrue(result.get('success')) def test_array_input(self): @@ -126,7 +127,7 @@ class CppStdioEvaluationTestCases(unittest.TestCase): 'test_case_data': self.test_case_data } result = get_class.evaluate(**kwargs) - self.assertEquals(result.get('error'), "Correct answer") + self.assertEqual(result.get('error'), "Correct Answer") self.assertTrue(result.get('success')) def test_string_input(self): @@ -144,7 +145,7 @@ class CppStdioEvaluationTestCases(unittest.TestCase): 'test_case_data': self.test_case_data } result = get_class.evaluate(**kwargs) - self.assertEquals(result.get('error'), "Correct answer") + self.assertEqual(result.get('error'), "Correct Answer") self.assertTrue(result.get('success')) def test_incorrect_answer(self): @@ -191,7 +192,7 @@ class CppStdioEvaluationTestCases(unittest.TestCase): } result = get_class.evaluate(**kwargs) self.assertFalse(result.get("success")) - self.assertEquals(result.get("error"), self.timeout_msg) + self.assertEqual(result.get("error"), self.timeout_msg) def test_only_stdout(self): self.test_case_data = [{'expected_output': '11', @@ -207,7 +208,7 @@ class CppStdioEvaluationTestCases(unittest.TestCase): 'test_case_data': self.test_case_data } result = get_class.evaluate(**kwargs) - self.assertEquals(result.get('error'), "Correct answer") + self.assertEqual(result.get('error'), "Correct Answer") self.assertTrue(result.get('success')) def test_cpp_correct_answer(self): @@ -224,7 +225,7 @@ class CppStdioEvaluationTestCases(unittest.TestCase): 'test_case_data': self.test_case_data } result = get_class.evaluate(**kwargs) - self.assertEquals(result.get('error'), "Correct answer") + self.assertEqual(result.get('error'), "Correct Answer") self.assertTrue(result.get('success')) def test_cpp_array_input(self): @@ -245,7 +246,7 @@ class CppStdioEvaluationTestCases(unittest.TestCase): 'test_case_data': self.test_case_data } result = get_class.evaluate(**kwargs) - self.assertEquals(result.get('error'), "Correct answer") + self.assertEqual(result.get('error'), "Correct Answer") self.assertTrue(result.get('success')) def test_cpp_string_input(self): @@ -264,7 +265,7 @@ class CppStdioEvaluationTestCases(unittest.TestCase): 'test_case_data': self.test_case_data } result = get_class.evaluate(**kwargs) - self.assertEquals(result.get('error'), "Correct answer") + self.assertEqual(result.get('error'), "Correct Answer") self.assertTrue(result.get('success')) def test_cpp_incorrect_answer(self): @@ -314,7 +315,7 @@ class CppStdioEvaluationTestCases(unittest.TestCase): } result = get_class.evaluate(**kwargs) self.assertFalse(result.get("success")) - self.assertEquals(result.get("error"), self.timeout_msg) + self.assertEqual(result.get("error"), self.timeout_msg) def test_cpp_only_stdout(self): self.test_case_data = [{'expected_output': '11', @@ -331,7 +332,7 @@ class CppStdioEvaluationTestCases(unittest.TestCase): 'test_case_data': self.test_case_data } result = get_class.evaluate(**kwargs) - self.assertEquals(result.get('error'), "Correct answer") + self.assertEqual(result.get('error'), "Correct Answer") self.assertTrue(result.get('success')) if __name__ == '__main__': diff --git a/yaksh/evaluator_tests/test_code_evaluation.py b/yaksh/evaluator_tests/test_code_evaluation.py index cbca32d..4efe119 100644 --- a/yaksh/evaluator_tests/test_code_evaluation.py +++ b/yaksh/evaluator_tests/test_code_evaluation.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import import unittest import os from yaksh import python_assertion_evaluator @@ -38,7 +39,7 @@ class RegistryTestCase(unittest.TestCase): "stdiobasedtestcase": stdout_evaluator_path } ) - self.assertEquals(evaluator_class, class_name) + self.assertEqual(evaluator_class, class_name) def tearDown(self): self.registry_object = None diff --git a/yaksh/evaluator_tests/test_java_evaluation.py b/yaksh/evaluator_tests/test_java_evaluation.py index 60afb3b..f94c6d1 100755 --- a/yaksh/evaluator_tests/test_java_evaluation.py +++ b/yaksh/evaluator_tests/test_java_evaluation.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import import unittest import os from yaksh import code_evaluator as evaluator @@ -30,7 +31,7 @@ class JavaAssertionEvaluationTestCases(unittest.TestCase): 'file_paths': self.file_paths } result = get_class.evaluate(**kwargs) - self.assertEquals(result.get('error'), "Correct answer") + self.assertEqual(result.get('error'), "Correct answer") self.assertTrue(result.get('success')) def test_incorrect_answer(self): @@ -65,7 +66,7 @@ class JavaAssertionEvaluationTestCases(unittest.TestCase): } result = get_class.evaluate(**kwargs) self.assertFalse(result.get("success")) - self.assertEquals(result.get("error"), self.timeout_msg) + self.assertEqual(result.get("error"), self.timeout_msg) def test_file_based_assert(self): self.file_paths = [(os.getcwd()+"/yaksh/test.txt", False)] @@ -97,7 +98,7 @@ class JavaAssertionEvaluationTestCases(unittest.TestCase): } result = get_class.evaluate(**kwargs) self.assertTrue(result.get("success")) - self.assertEquals(result.get("error"), "Correct answer") + self.assertEqual(result.get("error"), "Correct answer") class JavaStdioEvaluationTestCases(unittest.TestCase): @@ -127,7 +128,7 @@ class JavaStdioEvaluationTestCases(unittest.TestCase): 'test_case_data': self.test_case_data } result = get_class.evaluate(**kwargs) - self.assertEquals(result.get('error'), "Correct answer") + self.assertEqual(result.get('error'), "Correct Answer") self.assertTrue(result.get('success')) def test_array_input(self): @@ -149,7 +150,7 @@ class JavaStdioEvaluationTestCases(unittest.TestCase): 'test_case_data': self.test_case_data } result = get_class.evaluate(**kwargs) - self.assertEquals(result.get('error'), "Correct answer") + self.assertEqual(result.get('error'), "Correct Answer") self.assertTrue(result.get('success')) def test_incorrect_answer(self): @@ -202,7 +203,7 @@ class JavaStdioEvaluationTestCases(unittest.TestCase): } result = get_class.evaluate(**kwargs) self.assertFalse(result.get("success")) - self.assertEquals(result.get("error"), self.timeout_msg) + self.assertEqual(result.get("error"), self.timeout_msg) def test_only_stdout(self): self.test_case_data = [{'expected_output': '11', @@ -219,7 +220,7 @@ class JavaStdioEvaluationTestCases(unittest.TestCase): 'test_case_data': self.test_case_data } result = get_class.evaluate(**kwargs) - self.assertEquals(result.get('error'), "Correct answer") + self.assertEqual(result.get('error'), "Correct Answer") self.assertTrue(result.get('success')) def test_string_input(self): @@ -239,7 +240,7 @@ class JavaStdioEvaluationTestCases(unittest.TestCase): 'test_case_data': self.test_case_data } result = get_class.evaluate(**kwargs) - self.assertEquals(result.get('error'), "Correct answer") + self.assertEqual(result.get('error'), "Correct Answer") self.assertTrue(result.get('success')) if __name__ == '__main__': diff --git a/yaksh/evaluator_tests/test_python_evaluation.py b/yaksh/evaluator_tests/test_python_evaluation.py index b72d26b..6852136 100755 --- a/yaksh/evaluator_tests/test_python_evaluation.py +++ b/yaksh/evaluator_tests/test_python_evaluation.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import import unittest import os from yaksh.python_assertion_evaluator import PythonAssertionEvaluator diff --git a/yaksh/evaluator_tests/test_scilab_evaluation.py b/yaksh/evaluator_tests/test_scilab_evaluation.py index f5e3767..f1b29dd 100644 --- a/yaksh/evaluator_tests/test_scilab_evaluation.py +++ b/yaksh/evaluator_tests/test_scilab_evaluation.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import import unittest import os from yaksh import code_evaluator as evaluator @@ -22,7 +23,7 @@ class ScilabEvaluationTestCases(unittest.TestCase): 'file_paths': self.file_paths } result = get_class.evaluate(**kwargs) - self.assertEquals(result.get('error'), "Correct answer") + self.assertEqual(result.get('error'), "Correct answer") self.assertTrue(result.get('success')) def test_error(self): @@ -61,7 +62,7 @@ class ScilabEvaluationTestCases(unittest.TestCase): } result = get_class.evaluate(**kwargs) self.assertFalse(result.get("success")) - self.assertEquals(result.get("error"), self.timeout_msg) + self.assertEqual(result.get("error"), self.timeout_msg) if __name__ == '__main__': unittest.main() diff --git a/yaksh/file_utils.py b/yaksh/file_utils.py index afcf9e8..82956bf 100644 --- a/yaksh/file_utils.py +++ b/yaksh/file_utils.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import import shutil import os import zipfile diff --git a/yaksh/java_code_evaluator.py b/yaksh/java_code_evaluator.py index ff76317..2e8c0c6 100644 --- a/yaksh/java_code_evaluator.py +++ b/yaksh/java_code_evaluator.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +from __future__ import absolute_import import traceback import pwd import os @@ -6,9 +7,9 @@ from os.path import join, isfile import subprocess import importlib -# local imports -from code_evaluator import CodeEvaluator -from file_utils import copy_files, delete_files +# Local imports +from .code_evaluator import CodeEvaluator +from .file_utils import copy_files, delete_files class JavaCodeEvaluator(CodeEvaluator): diff --git a/yaksh/java_stdio_evaluator.py b/yaksh/java_stdio_evaluator.py index f4b8773..71768ef 100644 --- a/yaksh/java_stdio_evaluator.py +++ b/yaksh/java_stdio_evaluator.py @@ -1,11 +1,13 @@ #!/usr/bin/env python +from __future__ import absolute_import import subprocess import os from os.path import isfile -#local imports -from stdio_evaluator import StdIOEvaluator -from file_utils import copy_files, delete_files +#Local imports +from .code_evaluator import CodeEvaluator +from .stdio_evaluator import Evaluator +from .file_utils import copy_files, delete_files class JavaStdioEvaluator(StdIOEvaluator): diff --git a/yaksh/language_registry.py b/yaksh/language_registry.py index 398e1aa..5b2b519 100644 --- a/yaksh/language_registry.py +++ b/yaksh/language_registry.py @@ -1,6 +1,10 @@ -from settings import code_evaluators +from __future__ import absolute_import import importlib import json +import six + +# Local imports +from .settings import code_evaluators registry = None @@ -24,7 +28,7 @@ def create_evaluator_instance(language, test_case_type, json_data, in_dir): class _LanguageRegistry(object): def __init__(self): self._register = {} - for language, module in code_evaluators.iteritems(): + for language, module in six.iteritems(code_evaluators): self._register[language] = None # Public Protocol ########## diff --git a/yaksh/python_assertion_evaluator.py b/yaksh/python_assertion_evaluator.py index 1b66fd2..78154a3 100644 --- a/yaksh/python_assertion_evaluator.py +++ b/yaksh/python_assertion_evaluator.py @@ -1,13 +1,14 @@ #!/usr/bin/env python +from __future__ import absolute_import import sys import traceback import os from os.path import join import importlib -# local imports -from code_evaluator import CodeEvaluator, TimeoutException -from file_utils import copy_files, delete_files +# Local imports +from .code_evaluator import CodeEvaluator, TimeoutException +from .file_utils import copy_files, delete_files class PythonAssertionEvaluator(CodeEvaluator): @@ -32,7 +33,7 @@ class PythonAssertionEvaluator(CodeEvaluator): else: submitted = compile(user_answer, '<string>', mode='exec') self.exec_scope = {} - exec submitted in self.exec_scope + exec(submitted, self.exec_scope) return self.exec_scope def check_code(self, user_answer, file_paths, test_case): @@ -40,7 +41,7 @@ class PythonAssertionEvaluator(CodeEvaluator): try: tb = None _tests = compile(test_case, '<string>', mode='exec') - exec _tests in self.exec_scope + exec(_tests, self.exec_scope) except AssertionError: type, value, tb = sys.exc_info() info = traceback.extract_tb(tb) diff --git a/yaksh/python_stdio_evaluator.py b/yaksh/python_stdio_evaluator.py index 2cfd9c8..3011179 100644 --- a/yaksh/python_stdio_evaluator.py +++ b/yaksh/python_stdio_evaluator.py @@ -1,16 +1,23 @@ #!/usr/bin/env python +from __future__ import absolute_import import sys import traceback import os from os.path import join import importlib from contextlib import contextmanager -from ast import literal_eval -# local imports -from code_evaluator import CodeEvaluator -from StringIO import StringIO -from file_utils import copy_files, delete_files from textwrap import dedent + +try: + from StringIO import StringIO +except ImportError: + from io import StringIO + +# Local imports +from .code_evaluator import CodeEvaluator +from .file_utils import copy_files, delete_files + + @contextmanager def redirect_stdout(): new_target = StringIO() @@ -43,7 +50,7 @@ class PythonStdioEvaluator(CodeEvaluator): sys.stdin = input_buffer with redirect_stdout() as output_buffer: exec_scope = {} - exec submitted in exec_scope + exec(submitted, exec_scope) self.output_value = output_buffer.getvalue().rstrip("\n") return self.output_value diff --git a/yaksh/scilab_code_evaluator.py b/yaksh/scilab_code_evaluator.py index 53fa343..011cb69 100644 --- a/yaksh/scilab_code_evaluator.py +++ b/yaksh/scilab_code_evaluator.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +from __future__ import absolute_import import traceback import os from os.path import join, isfile @@ -6,9 +7,9 @@ import subprocess import re import importlib -# local imports -from code_evaluator import CodeEvaluator -from file_utils import copy_files, delete_files +# Local imports +from .code_evaluator import CodeEvaluator +from .file_utils import copy_files, delete_files class ScilabCodeEvaluator(CodeEvaluator): diff --git a/yaksh/stdio_evaluator.py b/yaksh/stdio_evaluator.py index efb2ae5..f1def95 100644 --- a/yaksh/stdio_evaluator.py +++ b/yaksh/stdio_evaluator.py @@ -15,6 +15,7 @@ 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)) expected_output = expected_output.replace("\r", "") if not expected_input: diff --git a/yaksh/tests/test_code_server.py b/yaksh/tests/test_code_server.py index a73f073..1d6584b 100644 --- a/yaksh/tests/test_code_server.py +++ b/yaksh/tests/test_code_server.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import import json try: from Queue import Queue @@ -5,7 +6,7 @@ except ImportError: from queue import Queue from threading import Thread import unittest -import urllib +from six.moves import urllib from yaksh.code_server import ServerPool, SERVER_POOL_PORT from yaksh import settings @@ -18,7 +19,7 @@ class TestCodeServer(unittest.TestCase): def setUpClass(cls): settings.code_evaluators['python']['standardtestcase'] = \ "yaksh.python_assertion_evaluator.PythonAssertionEvaluator" - ports = range(8001, 8006) + ports = range(8001, 8006) server_pool = ServerPool(ports=ports, pool_port=SERVER_POOL_PORT) cls.server_pool = server_pool cls.server_thread = t = Thread(target=server_pool.run) @@ -117,7 +118,8 @@ class TestCodeServer(unittest.TestCase): url = "http://localhost:%s/status"%SERVER_POOL_PORT # When - data = urllib.urlopen(url).read() + response = urllib.request.urlopen(url) + data = response.read().decode('utf-8') # Then expect = 'out of 5 are free' diff --git a/yaksh/xmlrpc_clients.py b/yaksh/xmlrpc_clients.py index 6bfe0d6..83ba277 100644 --- a/yaksh/xmlrpc_clients.py +++ b/yaksh/xmlrpc_clients.py @@ -1,11 +1,19 @@ -from xmlrpclib import ServerProxy +from __future__ import absolute_import import time import random import socket import json import urllib +from six.moves import urllib -from settings import SERVER_PORTS, SERVER_POOL_PORT +try: + from xmlrpclib import ServerProxy +except ImportError: + # The above import will not work on Python-3.x. + from xmlrpc.client import ServerProxy + +# Local imports +from .settings import SERVER_PORTS, SERVER_POOL_PORT class ConnectionError(Exception): @@ -58,7 +66,8 @@ class CodeServerProxy(object): return result def _get_server(self): - port = json.loads(urllib.urlopen(self.pool_url).read()) + response = urllib.request.urlopen(self.pool_url) + port = json.loads(response.read().decode('utf-8')) proxy = ServerProxy('http://localhost:%d' % port) return proxy |