From 4a0f94084bc26559ef3e26470619e87314f9d70e Mon Sep 17 00:00:00 2001
From: ankitjavalkar
Date: Mon, 19 Dec 2016 19:18:35 +0530
Subject: Remove commented code
---
yaksh/bash_code_evaluator.py | 6 --
yaksh/bash_stdio_evaluator.py | 5 -
yaksh/code_evaluator.py | 138 ++----------------------
yaksh/code_server.py | 5 -
yaksh/cpp_code_evaluator.py | 9 --
yaksh/cpp_stdio_evaluator.py | 5 -
yaksh/evaluator_tests/test_bash_evaluation.py | 52 ---------
yaksh/evaluator_tests/test_c_cpp_evaluation.py | 116 --------------------
yaksh/evaluator_tests/test_java_evaluation.py | 86 ---------------
yaksh/evaluator_tests/test_python_evaluation.py | 88 ---------------
yaksh/evaluator_tests/test_scilab_evaluation.py | 28 -----
yaksh/java_code_evaluator.py | 14 +--
yaksh/java_stdio_evaluator.py | 5 -
yaksh/models.py | 28 -----
yaksh/python_assertion_evaluator.py | 11 --
yaksh/python_stdio_evaluator.py | 9 +-
16 files changed, 12 insertions(+), 593 deletions(-)
(limited to 'yaksh')
diff --git a/yaksh/bash_code_evaluator.py b/yaksh/bash_code_evaluator.py
index 03ec16a..43d7be7 100644
--- a/yaksh/bash_code_evaluator.py
+++ b/yaksh/bash_code_evaluator.py
@@ -27,12 +27,6 @@ class BashCodeEvaluator(BaseEvaluator):
self.test_case = test_case_data.get('test_case')
self.weight = test_case_data.get('weight')
- # def setup(self):
- # super(BashCodeEvaluator, self).setup()
- # self.files = []
- # self.submit_code_path = self.create_submit_code_file('submit.sh')
- # self._set_file_as_executable(self.submit_code_path)
-
def teardown(self):
# Delete the created file.
os.remove(self.submit_code_path)
diff --git a/yaksh/bash_stdio_evaluator.py b/yaksh/bash_stdio_evaluator.py
index 3344c57..38b48e6 100644
--- a/yaksh/bash_stdio_evaluator.py
+++ b/yaksh/bash_stdio_evaluator.py
@@ -24,11 +24,6 @@ class BashStdioEvaluator(StdIOEvaluator):
self.expected_output = test_case_data.get('expected_output')
self.weight = test_case_data.get('weight')
- # def setup(self):
- # super(BashStdioEvaluator, self).setup()
- # self.files = []
- # self.submit_code_path = self.create_submit_code_file('Test.sh')
-
def teardown(self):
os.remove(self.submit_code_path)
if self.files:
diff --git a/yaksh/code_evaluator.py b/yaksh/code_evaluator.py
index 52720df..ae61752 100644
--- a/yaksh/code_evaluator.py
+++ b/yaksh/code_evaluator.py
@@ -113,28 +113,24 @@ class CodeEvaluator(object):
if self.in_dir:
if not os.path.exists(self.in_dir):
os.makedirs(self.in_dir)
- # self._change_dir(self.in_dir)
def get_evaluator_objects(self, kwargs):
- metadata = kwargs.get('metadata') # metadata contains user_answer, language, partial_grading, file_paths
+ metadata = kwargs.get('metadata')
test_case_data = kwargs.get('test_case_data')
test_case_instances = []
for test_case in test_case_data:
- test_case_instance = create_evaluator_instance(metadata, test_case) #language, test_case
+ test_case_instance = create_evaluator_instance(metadata, test_case)
test_case_instances.append(test_case_instance)
return test_case_instances
- def safe_evaluate(self, test_case_instances): #user_answer, partial_grading, test_case_data, file_paths=None
+ def safe_evaluate(self, test_case_instances):
"""
Handles code evaluation along with compilation, signal handling
and Exception handling
"""
- # metadata = kwargs.get('metadata') # metadata contains user_answer, language, partial_grading, file_paths
- # test_case_data = kwargs.get('test_case_data')
-
# Add a new signal handler for the execution of this code.
prev_handler = create_signal_handler()
success = False
@@ -146,17 +142,9 @@ class CodeEvaluator(object):
try:
# Run evaluator selection registry here
for idx, test_case_instance in enumerate(test_case_instances):
- # test_case_instance = create_evaluator_instance(metadata, test_case) #language, test_case
- # self.setup()
test_case_success = False
- test_case_instance.compile_code() #user_answer, file_paths, test_case
- test_case_success, err, test_case_weight = test_case_instance.check_code() #**kwargs
- test_case_instance.teardown()
- # self.teardown()
- # user_answer,
- # file_paths,
- # partial_grading,
- # **test_case
+ test_case_instance.compile_code()
+ test_case_success, err, test_case_weight = test_case_instance.check_code()
if test_case_success:
weight += test_case_weight
@@ -165,6 +153,9 @@ class CodeEvaluator(object):
success = all(test_case_success_status)
+ for test_case_instance in test_case_instances:
+ test_case_instance.teardown()
+
except TimeoutException:
error = self.timeout_msg
except OSError:
@@ -182,119 +173,6 @@ class CodeEvaluator(object):
return success, error, weight
- # def safe_evaluate(self, user_answer, partial_grading, test_case_data, file_paths=None):
- # """
- # Handles code evaluation along with compilation, signal handling
- # and Exception handling
- # """
-
- # # Add a new signal handler for the execution of this code.
- # prev_handler = create_signal_handler()
- # success = False
- # test_case_success_status = [False] * len(test_case_data)
- # error = ""
- # weight = 0.0
-
- # # Do whatever testing needed.
- # try:
- # for idx, test_case in enumerate(test_case_data):
- # test_case_success = False
- # self.compile_code(user_answer, file_paths, **test_case)
- # test_case_success, err, test_case_weight = self.check_code(user_answer,
- # file_paths,
- # partial_grading,
- # **test_case
- # )
- # if test_case_success:
- # weight += test_case_weight
-
- # error += err + "\n"
- # test_case_success_status[idx] = test_case_success
-
- # success = all(test_case_success_status)
-
- # except TimeoutException:
- # error = self.timeout_msg
- # except OSError:
- # msg = traceback.format_exc(limit=0)
- # error = "Error: {0}".format(msg)
- # except Exception as e:
- # print "HELLOOOOO", e
- # exc_type, exc_value, exc_tb = sys.exc_info()
- # tb_list = traceback.format_exception(exc_type, exc_value, exc_tb)
- # if len(tb_list) > 2:
- # del tb_list[1:3]
- # error = "Error: {0}".format("".join(tb_list))
- # finally:
- # # Set back any original signal handler.
- # set_original_signal_handler(prev_handler)
-
- # return success, error, weight
-
-
def teardown(self):
# Cancel the signal
delete_signal_handler()
- # self._change_dir(dirname(MY_DIR))
-
- # def check_code(self):
- # raise NotImplementedError("check_code method not implemented")
-
- # def compile_code(self, user_answer, file_paths, **kwargs):
- # pass
-
- # def create_submit_code_file(self, file_name):
- # """ Set the file path for code (`answer`)"""
- # submit_path = abspath(file_name)
- # if not exists(submit_path):
- # submit_f = open(submit_path, 'w')
- # submit_f.close()
-
- # return submit_path
-
- # def write_to_submit_code_file(self, file_path, user_answer):
- # """ Write the code (`answer`) to a file"""
- # submit_f = open(file_path, 'w')
- # submit_f.write(user_answer.lstrip())
- # submit_f.close()
-
- # def _set_file_as_executable(self, fname):
- # os.chmod(fname, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR
- # | stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP
- # | stat.S_IROTH | stat.S_IWOTH | stat.S_IXOTH)
-
- # def _set_test_code_file_path(self, ref_path=None, test_case_path=None):
- # if ref_path and not ref_path.startswith('/'):
- # ref_path = join(MY_DIR, ref_path)
-
- # if test_case_path and not test_case_path.startswith('/'):
- # test_case_path = join(MY_DIR, test_case_path)
-
- # return ref_path, test_case_path
-
- # def _run_command(self, cmd_args, *args, **kw):
- # """Run a command in a subprocess while blocking, the process is killed
- # if it takes more than 2 seconds to run. Return the Popen object, the
- # stdout and stderr.
- # """
- # try:
- # proc = subprocess.Popen(cmd_args, *args, **kw)
- # stdout, stderr = proc.communicate()
- # except TimeoutException:
- # # Runaway code, so kill it.
- # proc.kill()
- # # Re-raise exception.
- # raise
- # 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):
- # os.chdir(in_dir)
-
- # def _remove_null_substitute_char(self, string):
- # """Returns a string without any null and substitute characters"""
- # stripped = ""
- # for c in string:
- # if ord(c) is not 26 and ord(c) is not 0:
- # stripped = stripped + c
- # return ''.join(stripped)
diff --git a/yaksh/code_server.py b/yaksh/code_server.py
index 3c1a3e3..815eb55 100644
--- a/yaksh/code_server.py
+++ b/yaksh/code_server.py
@@ -85,11 +85,6 @@ class CodeServer(object):
"""Calls relevant EvaluateCode class based on language to check the
answer code
"""
- # code_evaluator = create_evaluator_instance(language,
- # test_case_type,
- # json_data,
- # in_dir
- # )
data = self.unpack_json_to_python_obj(json_data)
code_eval_instance = CodeEvaluator(in_dir)
result = code_eval_instance.evaluate(data) #language, test_case_type,
diff --git a/yaksh/cpp_code_evaluator.py b/yaksh/cpp_code_evaluator.py
index c6f5a7e..f97f274 100644
--- a/yaksh/cpp_code_evaluator.py
+++ b/yaksh/cpp_code_evaluator.py
@@ -30,15 +30,6 @@ class CppCodeEvaluator(BaseEvaluator):
self.test_case = test_case_data.get('test_case')
self.weight = test_case_data.get('weight')
- # def setup(self):
- # super(CppCodeEvaluator, self).setup()
- # self.files = []
- # 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):
# Delete the created file.
os.remove(self.submit_code_path)
diff --git a/yaksh/cpp_stdio_evaluator.py b/yaksh/cpp_stdio_evaluator.py
index a57afbe..76c132d 100644
--- a/yaksh/cpp_stdio_evaluator.py
+++ b/yaksh/cpp_stdio_evaluator.py
@@ -25,11 +25,6 @@ class CppStdioEvaluator(StdIOEvaluator):
self.expected_output = test_case_data.get('expected_output')
self.weight = test_case_data.get('weight')
- # def setup(self):
- # super(CppStdioEvaluator, self).setup()
- # self.files = []
- # self.submit_code_path = self.create_submit_code_file('main.c')
-
def teardown(self):
os.remove(self.submit_code_path)
if self.files:
diff --git a/yaksh/evaluator_tests/test_bash_evaluation.py b/yaksh/evaluator_tests/test_bash_evaluation.py
index 8888ee6..142d7f0 100644
--- a/yaksh/evaluator_tests/test_bash_evaluation.py
+++ b/yaksh/evaluator_tests/test_bash_evaluation.py
@@ -34,13 +34,6 @@ class BashAssertionEvaluationTestCases(unittest.TestCase):
user_answer = ("#!/bin/bash\n[[ $# -eq 2 ]]"
" && echo $(( $1 + $2 )) && exit $(( $1 + $2 ))"
)
- # get_class = BashCodeEvaluator(self.in_dir)
- # kwargs = {'user_answer': user_answer,
- # 'partial_grading': True,
- # 'test_case_data': self.test_case_data,
- # 'file_paths': self.file_paths
- # }
- # result = get_class.evaluate(**kwargs)
kwargs = {
'metadata': {
'user_answer': user_answer,
@@ -60,13 +53,6 @@ class BashAssertionEvaluationTestCases(unittest.TestCase):
def test_error(self):
user_answer = ("#!/bin/bash\n[[ $# -eq 2 ]] "
"&& echo $(( $1 - $2 )) && exit $(( $1 - $2 ))")
- # get_class = BashCodeEvaluator(self.in_dir)
- # kwargs = {'user_answer': user_answer,
- # 'partial_grading': True,
- # 'test_case_data': self.test_case_data,
- # 'file_paths': self.file_paths
- # }
- # result = get_class.evaluate(**kwargs)
kwargs = {
'metadata': {
'user_answer': user_answer,
@@ -86,13 +72,6 @@ class BashAssertionEvaluationTestCases(unittest.TestCase):
def test_infinite_loop(self):
user_answer = ("#!/bin/bash\nwhile [ 1 ] ;"
" do echo "" > /dev/null ; done")
- # get_class = BashCodeEvaluator(self.in_dir)
- # kwargs = {'user_answer': user_answer,
- # 'partial_grading': True,
- # 'test_case_data': self.test_case_data,
- # 'file_paths': self.file_paths
- # }
- # result = get_class.evaluate(**kwargs)
kwargs = {
'metadata': {
'user_answer': user_answer,
@@ -118,13 +97,6 @@ class BashAssertionEvaluationTestCases(unittest.TestCase):
}
]
user_answer = ("#!/bin/bash\ncat $1")
- # get_class = BashCodeEvaluator()
- # kwargs = {'user_answer': user_answer,
- # 'partial_grading': True,
- # 'test_case_data': self.test_case_data,
- # 'file_paths': self.file_paths
- # }
- # result = get_class.evaluate(**kwargs)
kwargs = {
'metadata': {
'user_answer': user_answer,
@@ -162,12 +134,6 @@ class BashStdioEvaluationTestCases(unittest.TestCase):
'test_case_type': 'stdiobasedtestcase',
'weight': 0.0
}]
- # get_class = BashStdioEvaluator()
- # kwargs = {"user_answer": user_answer,
- # "partial_grading": True,
- # "test_case_data": test_case_data
- # }
- # result = get_class.evaluate(**kwargs)
kwargs = {
'metadata': {
'user_answer': user_answer,
@@ -198,12 +164,6 @@ class BashStdioEvaluationTestCases(unittest.TestCase):
'test_case_type': 'stdiobasedtestcase',
'weight': 0.0
}]
- # get_class = BashStdioEvaluator()
- # kwargs = {"user_answer": user_answer,
- # "partial_grading": True,
- # "test_case_data": test_case_data
- # }
- # result = get_class.evaluate(**kwargs)
kwargs = {
'metadata': {
'user_answer': user_answer,
@@ -232,12 +192,6 @@ class BashStdioEvaluationTestCases(unittest.TestCase):
'test_case_type': 'stdiobasedtestcase',
'weight': 0.0
}]
- # get_class = BashStdioEvaluator()
- # kwargs = {"user_answer": user_answer,
- # "partial_grading": True,
- # "test_case_data": test_case_data
- # }
- # result = get_class.evaluate(**kwargs)
kwargs = {
'metadata': {
'user_answer': user_answer,
@@ -265,12 +219,6 @@ class BashStdioEvaluationTestCases(unittest.TestCase):
'test_case_type': 'stdiobasedtestcase',
'weight': 0.0
}]
- # get_class = BashStdioEvaluator()
- # kwargs = {"user_answer": user_answer,
- # "partial_grading": True,
- # "test_case_data": test_case_data
- # }
- # result = get_class.evaluate(**kwargs)
kwargs = {
'metadata': {
'user_answer': user_answer,
diff --git a/yaksh/evaluator_tests/test_c_cpp_evaluation.py b/yaksh/evaluator_tests/test_c_cpp_evaluation.py
index 9080e88..4dd6a2f 100644
--- a/yaksh/evaluator_tests/test_c_cpp_evaluation.py
+++ b/yaksh/evaluator_tests/test_c_cpp_evaluation.py
@@ -34,12 +34,6 @@ class CAssertionEvaluationTestCases(unittest.TestCase):
def test_correct_answer(self):
user_answer = "int add(int a, int b)\n{return a+b;}"
- # kwargs = {'user_answer': user_answer,
- # 'partial_grading': False,
- # 'test_case_data': self.test_case_data,
- # 'file_paths': self.file_paths
- # }
- # result = get_class.evaluate(**kwargs)
kwargs = {
'metadata': {
'user_answer': user_answer,
@@ -58,12 +52,6 @@ class CAssertionEvaluationTestCases(unittest.TestCase):
def test_incorrect_answer(self):
user_answer = "int add(int a, int b)\n{return a-b;}"
- # kwargs = {'user_answer': user_answer,
- # 'partial_grading': False,
- # 'test_case_data': self.test_case_data,
- # 'file_paths': self.file_paths
- # }
- # result = get_class.evaluate(**kwargs)
kwargs = {
'metadata': {
'user_answer': user_answer,
@@ -84,12 +72,6 @@ class CAssertionEvaluationTestCases(unittest.TestCase):
def test_compilation_error(self):
user_answer = "int add(int a, int b)\n{return a+b}"
- # kwargs = {'user_answer': user_answer,
- # 'partial_grading': False,
- # 'test_case_data': self.test_case_data,
- # 'file_paths': self.file_paths
- # }
- # result = get_class.evaluate(**kwargs)
kwargs = {
'metadata': {
'user_answer': user_answer,
@@ -108,13 +90,6 @@ class CAssertionEvaluationTestCases(unittest.TestCase):
def test_infinite_loop(self):
user_answer = "int add(int a, int b)\n{while(1>0){}}"
- # get_class = CppCodeEvaluator(self.in_dir)
- # kwargs = {'user_answer': user_answer,
- # 'partial_grading': False,
- # 'test_case_data': self.test_case_data,
- # 'file_paths': self.file_paths
- # }
- # result = get_class.evaluate(**kwargs)
kwargs = {
'metadata': {
'user_answer': user_answer,
@@ -149,13 +124,6 @@ class CAssertionEvaluationTestCases(unittest.TestCase):
return buff[0];
}
""")
- # get_class = CppCodeEvaluator(self.in_dir)
- # kwargs = {'user_answer': user_answer,
- # 'partial_grading': False,
- # 'test_case_data': self.test_case_data,
- # 'file_paths': self.file_paths
- # }
- # result = get_class.evaluate(**kwargs)
kwargs = {
'metadata': {
'user_answer': user_answer,
@@ -193,12 +161,6 @@ class CppStdioEvaluationTestCases(unittest.TestCase):
scanf("%d%d",&a,&b);
printf("%d",a+b);
}""")
- # get_class = CppStdioEvaluator()
- # kwargs = {'user_answer': user_answer,
- # 'partial_grading': False,
- # 'test_case_data': self.test_case_data
- # }
- # result = get_class.evaluate(**kwargs)
kwargs = {
'metadata': {
'user_answer': user_answer,
@@ -230,12 +192,6 @@ class CppStdioEvaluationTestCases(unittest.TestCase):
for(i=0;i<3;i++){
printf("%d",a[i]);}
}""")
- # get_class = CppStdioEvaluator()
- # kwargs = {'user_answer': user_answer,
- # 'partial_grading': False,
- # 'test_case_data': self.test_case_data
- # }
- # result = get_class.evaluate(**kwargs)
kwargs = {
'metadata': {
'user_answer': user_answer,
@@ -265,12 +221,6 @@ class CppStdioEvaluationTestCases(unittest.TestCase):
scanf("%s",a);
printf("%s",a);
}""")
- # get_class = CppStdioEvaluator()
- # kwargs = {'user_answer': user_answer,
- # 'partial_grading': False,
- # 'test_case_data': self.test_case_data
- # }
- # result = get_class.evaluate(**kwargs)
kwargs = {
'metadata': {
'user_answer': user_answer,
@@ -294,12 +244,6 @@ class CppStdioEvaluationTestCases(unittest.TestCase):
int a=10;
printf("%d",a);
}""")
- # get_class = CppStdioEvaluator()
- # kwargs = {'user_answer': user_answer,
- # 'partial_grading': False,
- # 'test_case_data': self.test_case_data
- # }
- # result = get_class.evaluate(**kwargs)
kwargs = {
'metadata': {
'user_answer': user_answer,
@@ -325,12 +269,6 @@ class CppStdioEvaluationTestCases(unittest.TestCase):
int a=10;
printf("%d",a)
}""")
- # get_class = CppStdioEvaluator()
- # kwargs = {'user_answer': user_answer,
- # 'partial_grading': False,
- # 'test_case_data': self.test_case_data
- # }
- # result = get_class.evaluate(**kwargs)
kwargs = {
'metadata': {
'user_answer': user_answer,
@@ -354,12 +292,6 @@ class CppStdioEvaluationTestCases(unittest.TestCase):
while(0==0){
printf("abc");}
}""")
- # get_class = CppStdioEvaluator()
- # kwargs = {'user_answer': user_answer,
- # 'partial_grading': False,
- # 'test_case_data': self.test_case_data
- # }
- # result = get_class.evaluate(**kwargs)
kwargs = {
'metadata': {
'user_answer': user_answer,
@@ -388,12 +320,6 @@ class CppStdioEvaluationTestCases(unittest.TestCase):
int a=5,b=6;
printf("%d",a+b);
}""")
- # get_class = CppStdioEvaluator()
- # kwargs = {'user_answer': user_answer,
- # 'partial_grading': False,
- # 'test_case_data': self.test_case_data
- # }
- # result = get_class.evaluate(**kwargs)
kwargs = {
'metadata': {
'user_answer': user_answer,
@@ -419,12 +345,6 @@ class CppStdioEvaluationTestCases(unittest.TestCase):
cin>>a>>b;
cout<>a;
cout<', mode='exec')
@@ -68,7 +63,7 @@ class PythonStdioEvaluator(BaseEvaluator):
self.output_value = output_buffer.getvalue().rstrip("\n")
return self.output_value
- def check_code(self): # user_answer, file_paths, partial_grading, expected_input, expected_output, weight):
+ def check_code(self):
success = False
test_case_weight = 0.0
--
cgit