summaryrefslogtreecommitdiff
path: root/yaksh
diff options
context:
space:
mode:
Diffstat (limited to 'yaksh')
-rw-r--r--yaksh/bash_code_evaluator.py101
-rwxr-xr-xyaksh/code_server.py9
-rw-r--r--yaksh/cpp_code_evaluator.py127
-rw-r--r--yaksh/forms.py9
-rw-r--r--yaksh/java_code_evaluator.py152
-rw-r--r--yaksh/language_registry.py10
-rw-r--r--yaksh/models.py64
-rw-r--r--yaksh/python_assertion_evaluator.py5
-rw-r--r--yaksh/python_stdout_evaluator.py6
-rw-r--r--yaksh/scilab_code_evaluator.py68
-rw-r--r--yaksh/templates/yaksh/add_question.html4
-rw-r--r--yaksh/tests.py23
-rw-r--r--yaksh/views.py222
13 files changed, 2 insertions, 798 deletions
diff --git a/yaksh/bash_code_evaluator.py b/yaksh/bash_code_evaluator.py
index b649af7..12177f9 100644
--- a/yaksh/bash_code_evaluator.py
+++ b/yaksh/bash_code_evaluator.py
@@ -12,25 +12,11 @@ from code_evaluator import CodeEvaluator
class BashCodeEvaluator(CodeEvaluator):
- # """Tests the Bash code obtained from Code Server"""
- # def __init__(self, test_case_data, test, language, user_answer,
- # ref_code_path=None, in_dir=None):
- # super(BashCodeEvaluator, self).__init__(test_case_data, test, language, user_answer,
- # ref_code_path, in_dir)
- # self.test_case_args = self._setup()
-
# Private Protocol ##########
def setup(self):
super(BashCodeEvaluator, self).setup()
self.submit_code_path = self.create_submit_code_file('submit.sh')
self._set_file_as_executable(self.submit_code_path)
- # get_ref_path, get_test_case_path = self.ref_code_path.strip().split(',')
- # get_ref_path = get_ref_path.strip()
- # get_test_case_path = get_test_case_path.strip()
- # ref_path, test_case_path = self._set_test_code_file_path(get_ref_path,
- # get_test_case_path)
-
- # return ref_path, self.submit_code_path, test_case_path
def teardown(self):
# Delete the created file.
@@ -60,7 +46,6 @@ class BashCodeEvaluator(CodeEvaluator):
the required permissions are not given to the file(s).
"""
- # ref_code_path = test_case_data[0]
ref_code_path = test_case
get_ref_path, get_test_case_path = ref_code_path.strip().split(',')
get_ref_path = get_ref_path.strip()
@@ -127,89 +112,3 @@ class BashCodeEvaluator(CodeEvaluator):
err = "Error:expected %s, got %s" % (inst_stdout+inst_stderr,
stdnt_stdout+stdnt_stderr)
return False, err
-
-
-
- # def _check_code(self, ref_path, submit_path,
- # test_case_path=None):
- # """ Function validates student script using instructor script as
- # reference. Test cases can optionally be provided. The first argument
- # ref_path, is the path to instructor script, it is assumed to
- # have executable permission. The second argument submit_path, is
- # the path to the student script, it is assumed to have executable
- # permission. The Third optional argument is the path to test the
- # scripts. Each line in this file is a test case and each test case is
- # passed to the script as standard arguments.
-
- # Returns
- # --------
-
- # returns (True, "Correct answer") : If the student script passes all
- # test cases/have same output, when compared to the instructor script
-
- # returns (False, error_msg): If the student script fails a single
- # test/have dissimilar output, when compared to the instructor script.
-
- # Returns (False, error_msg): If mandatory arguments are not files or if
- # the required permissions are not given to the file(s).
-
- # """
- # if not isfile(ref_path):
- # return False, "No file at %s or Incorrect path" % ref_path
- # if not isfile(submit_path):
- # return False, "No file at %s or Incorrect path" % submit_path
- # if not os.access(ref_path, os.X_OK):
- # return False, "Script %s is not executable" % ref_path
- # if not os.access(submit_path, os.X_OK):
- # return False, "Script %s is not executable" % submit_path
-
- # success = False
-
- # if test_case_path is None or "":
- # ret = self._run_command(ref_path, stdin=None,
- # stdout=subprocess.PIPE,
- # stderr=subprocess.PIPE)
- # proc, inst_stdout, inst_stderr = ret
- # ret = self._run_command(submit_path, stdin=None,
- # stdout=subprocess.PIPE,
- # stderr=subprocess.PIPE)
- # proc, stdnt_stdout, stdnt_stderr = ret
- # if inst_stdout == stdnt_stdout:
- # return True, "Correct answer"
- # else:
- # err = "Error: expected %s, got %s" % (inst_stderr,
- # stdnt_stderr)
- # return False, err
- # else:
- # if not isfile(test_case_path):
- # return False, "No test case at %s" % test_case_path
- # if not os.access(ref_path, os.R_OK):
- # return False, "Test script %s, not readable" % test_case_path
- # # valid_answer is True, so that we can stop once a test case fails
- # valid_answer = True
- # # loop_count has to be greater than or equal to one.
- # # Useful for caching things like empty test files,etc.
- # loop_count = 0
- # test_cases = open(test_case_path).readlines()
- # num_lines = len(test_cases)
- # for test_case in test_cases:
- # loop_count += 1
- # if valid_answer:
- # args = [ref_path] + [x for x in test_case.split()]
- # ret = self._run_command(args, stdin=None,
- # stdout=subprocess.PIPE,
- # stderr=subprocess.PIPE)
- # proc, inst_stdout, inst_stderr = ret
- # args = [submit_path]+[x for x in test_case.split()]
- # ret = self._run_command(args, stdin=None,
- # stdout=subprocess.PIPE,
- # stderr=subprocess.PIPE)
- # proc, stdnt_stdout, stdnt_stderr = ret
- # valid_answer = inst_stdout == stdnt_stdout
- # if valid_answer and (num_lines == loop_count):
- # return True, "Correct answer"
- # else:
- # err = "Error:expected %s, got %s" % (inst_stdout+inst_stderr,
- # stdnt_stdout+stdnt_stderr)
- # return False, err
-
diff --git a/yaksh/code_server.py b/yaksh/code_server.py
index 48b97a7..2397582 100755
--- a/yaksh/code_server.py
+++ b/yaksh/code_server.py
@@ -80,15 +80,6 @@ class CodeServer(object):
self.queue.put(self.port)
server.serve_forever()
- # # Private Protocol ##########
- # def _create_evaluator_instance(self, language, json_data, in_dir):
- # """Create instance of relevant EvaluateCode class based on language"""
- # # set_registry()
- # registry = get_registry()
- # cls = registry.get_class(language)
- # instance = cls.from_json(language, json_data, in_dir)
- # return instance
-
###############################################################################
# `ServerPool` class.
diff --git a/yaksh/cpp_code_evaluator.py b/yaksh/cpp_code_evaluator.py
index 312467d..becf371 100644
--- a/yaksh/cpp_code_evaluator.py
+++ b/yaksh/cpp_code_evaluator.py
@@ -53,7 +53,6 @@ class CppCodeEvaluator(CodeEvaluator):
self.write_to_submit_code_file(self.submit_code_path, user_answer)
self.user_output_path, self.ref_output_path = self.set_file_paths()
self.compile_command, self.compile_main = self.get_commands(clean_ref_code_path, self.user_output_path, self.ref_output_path)
- # self.compiled_output = self._compile_command(self.compile_command)
self.compiled_user_answer = self._run_command(self.compile_command,
shell=True,
stdout=subprocess.PIPE,
@@ -87,21 +86,6 @@ class CppCodeEvaluator(CodeEvaluator):
if the required permissions are not given to the file(s).
"""
- # ref_code_path = test_case
- # clean_ref_code_path, clean_test_case_path = self._set_test_code_file_path(ref_code_path)
-
- # if not isfile(clean_ref_code_path):
- # return False, "No file at %s or Incorrect path" % clean_ref_code_path
- # if not isfile(self.submit_code_path):
- # return False, 'No file at %s or Incorrect path' % self.submit_code_path
-
- # success = False
- # self.write_to_submit_code_file(self.submit_code_path, user_answer)
- # user_output_path, ref_output_path = self.set_file_paths()
- # compile_command, compile_main = self.get_commands(clean_ref_code_path, user_output_path, ref_output_path)
- # ret = self._compile_command(compile_command)
- # proc, stdnt_stderr = ret
- # stdnt_stderr = self._remove_null_substitute_char(stdnt_stderr)
success = False
proc, stdnt_out, stdnt_stderr = self.compiled_user_answer
stdnt_stderr = self._remove_null_substitute_char(stdnt_stderr)
@@ -109,11 +93,6 @@ class CppCodeEvaluator(CodeEvaluator):
# Only if compilation is successful, the program is executed
# And tested with testcases
if stdnt_stderr == '':
- # ret = self._compile_command(self.compile_main)
- # ret = self._run_command(self.compile_main,
- # shell=True,
- # stdout=subprocess.PIPE,
- # stderr=subprocess.PIPE)
proc, main_out, main_err = self.compiled_test_code
main_err = self._remove_null_substitute_char(main_err)
@@ -152,109 +131,3 @@ class CppCodeEvaluator(CodeEvaluator):
err = err + "\n" + stdnt_stderr
return success, err
-
- # def __init__(self, test_case_data, test, language, user_answer,
- # ref_code_path=None, in_dir=None):
- # super(CppCodeEvaluator, self).__init__(test_case_data, test, language,
- # user_answer, ref_code_path,
- # in_dir)
- # self.test_case_args = self.setup()
-
- # def setup(self):
- # super(CppCodeEvaluator, self).setup()
-
- # get_ref_path = self.ref_code_path
- # ref_path, test_case_path = self._set_test_code_file_path(get_ref_path)
- # self.submit_path = self.create_submit_code_file('submit.c')
-
- # # Set file paths #@@@ in different func get_output_file_paths
- # c_user_output_path = os.getcwd() + '/output'
- # c_ref_output_path = os.getcwd() + '/executable'
-
- # # Set command variables #@@@ This section in different func get_commands
- # compile_command = 'g++ {0} -c -o {1}'.format(self.submit_path,
- # c_user_output_path)
- # compile_main = 'g++ {0} {1} -o {2}'.format(ref_path,
- # c_user_output_path,
- # c_ref_output_path)
- # run_command_args = [c_ref_output_path]
- # remove_user_output = c_user_output_path #@@@ not required
- # remove_ref_output = c_ref_output_path #@@@ not required
-
- # return (ref_path, self.submit_path, compile_command, compile_main,
- # run_command_args, remove_user_output, remove_ref_output)
-
- # def check_code(self, ref_code_path, submit_code_path, compile_command,
- # compile_main, run_command_args, remove_user_output,
- # remove_ref_output):
- # """ Function validates student code using instructor code as
- # reference.The first argument ref_code_path, is the path to
- # instructor code, it is assumed to have executable permission.
- # The second argument submit_code_path, is the path to the student
- # code, it is assumed to have executable permission.
-
- # Returns
- # --------
-
- # returns (True, "Correct answer") : If the student function returns
- # expected output when called by reference code.
-
- # returns (False, error_msg): If the student function fails to return
- # expected output when called by reference code.
-
- # Returns (False, error_msg): If mandatory arguments are not files or
- # if the required permissions are not given to the file(s).
-
- # """
- # if not isfile(ref_code_path):
- # return False, "No file at %s or Incorrect path" % ref_code_path
- # if not isfile(submit_code_path):
- # return False, 'No file at %s or Incorrect path' % submit_code_path
-
- # success = False
- # ret = self._compile_command(compile_command)
- # proc, stdnt_stderr = ret
- # stdnt_stderr = self._remove_null_substitute_char(stdnt_stderr)
-
- # # Only if compilation is successful, the program is executed
- # # And tested with testcases
- # if stdnt_stderr == '':
- # ret = self._compile_command(compile_main)
- # proc, main_err = ret
- # main_err = self._remove_null_substitute_char(main_err)
-
- # if main_err == '':
- # ret = self._run_command(run_command_args, stdin=None,
- # stdout=subprocess.PIPE,
- # stderr=subprocess.PIPE)
- # proc, stdout, stderr = ret
- # if proc.returncode == 0:
- # success, err = True, "Correct answer"
- # else:
- # err = stdout + "\n" + stderr
- # os.remove(remove_ref_output)
- # else:
- # err = "Error:"
- # try:
- # error_lines = main_err.splitlines()
- # for e in error_lines:
- # if ':' in e:
- # err = err + "\n" + e.split(":", 1)[1]
- # else:
- # err = err + "\n" + e
- # except:
- # err = err + "\n" + main_err
- # os.remove(remove_user_output)
- # 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]
- # else:
- # err = err + "\n" + e
- # except:
- # err = err + "\n" + stdnt_stderr
-
- # return success, err
diff --git a/yaksh/forms.py b/yaksh/forms.py
index ddb1819..2ce2cba 100644
--- a/yaksh/forms.py
+++ b/yaksh/forms.py
@@ -44,17 +44,8 @@ attempts.append((-1, 'Infinite'))
days_between_attempts = ((j, j) for j in range(401))
def get_object_form(model, exclude_fields=None):
- # ctype = ContentType.objects.get(app_label="yaksh", model=model)
- # ctype = ContentType.objects.get(pk=type_id)
- # model_class = ctype.model_class()
model_class = get_model_class(model)
class _ObjectForm(forms.ModelForm):
- # def __init__(self, *args, **kwargs):
- # if "question" in kwargs:
- # question = kwargs.pop("question")
- # else:
- # question = None
- # self.fields["question"] = question
class Meta:
model = model_class
exclude = exclude_fields
diff --git a/yaksh/java_code_evaluator.py b/yaksh/java_code_evaluator.py
index 9ec4209..ac2c487 100644
--- a/yaksh/java_code_evaluator.py
+++ b/yaksh/java_code_evaluator.py
@@ -50,18 +50,12 @@ class JavaCodeEvaluator(CodeEvaluator):
user_code_directory = os.getcwd() + '/'
self.write_to_submit_code_file(self.submit_code_path, user_answer)
ref_file_name = (clean_ref_code_path.split('/')[-1]).split('.')[0]
- # user_output_path = "{0}{1}.class".format(user_code_directory,
- # 'Test')
- # ref_output_path = "{0}{1}.class".format(user_code_directory,
- # ref_file_name)
- # user_output_path, ref_output_path = self.set_file_paths(user_code_directory, clean_ref_code_path)
self.user_output_path = self.set_file_paths(user_code_directory, 'Test')
self.ref_output_path = self.set_file_paths(user_code_directory, ref_file_name)
compile_command, self.compile_main = self.get_commands(clean_ref_code_path, user_code_directory)
self.run_command_args = "java -cp {0} {1}".format(user_code_directory,
ref_file_name)
- # self.compiled_output = self._compile_command(compile_command)
self.compiled_user_answer = self._run_command(compile_command,
shell=True,
stdout=subprocess.PIPE,
@@ -94,31 +88,6 @@ class JavaCodeEvaluator(CodeEvaluator):
if the required permissions are not given to the file(s).
"""
- # ref_code_path = test_case
- # clean_ref_code_path, clean_test_case_path = self._set_test_code_file_path(ref_code_path)
-
- # if not isfile(clean_ref_code_path):
- # return False, "No file at %s or Incorrect path" % clean_ref_code_path
- # if not isfile(self.submit_code_path):
- # return False, 'No file at %s or Incorrect path' % self.submit_code_path
-
- # success = False
- # user_code_directory = os.getcwd() + '/'
- # self.write_to_submit_code_file(self.submit_code_path, user_answer)
- # ref_file_name = (clean_ref_code_path.split('/')[-1]).split('.')[0]
- # # user_output_path = "{0}{1}.class".format(user_code_directory,
- # # 'Test')
- # # ref_output_path = "{0}{1}.class".format(user_code_directory,
- # # ref_file_name)
- # # user_output_path, ref_output_path = self.set_file_paths(user_code_directory, clean_ref_code_path)
- # user_output_path = self.set_file_paths(user_code_directory, 'Test')
- # ref_output_path = self.set_file_paths(user_code_directory, ref_file_name)
-
- # compile_command, compile_main = self.get_commands(clean_ref_code_path, user_code_directory)
- # run_command_args = "java -cp {0} {1}".format(user_code_directory,
- # ref_file_name)
- # ret = self._compile_command(compile_command)
- # proc, stdnt_stderr = ret
success = False
proc, stdnt_out, stdnt_stderr = self.compiled_user_answer
stdnt_stderr = self._remove_null_substitute_char(stdnt_stderr)
@@ -126,12 +95,6 @@ class JavaCodeEvaluator(CodeEvaluator):
# Only if compilation is successful, the program is executed
# And tested with testcases
if stdnt_stderr == '':
- # ret = self._compile_command(self.compile_main)
- # ret = self._run_command(self.compile_main,
- # shell=True,
- # stdout=subprocess.PIPE,
- # stderr=subprocess.PIPE)
-
proc, main_out, main_err = self.compiled_test_code
main_err = self._remove_null_substitute_char(main_err)
@@ -171,118 +134,3 @@ class JavaCodeEvaluator(CodeEvaluator):
err = err + "\n" + stdnt_stderr
return success, err
-
-
- # def __init__(self, test_case_data, test, language, user_answer,
- # ref_code_path=None, in_dir=None):
- # super(JavaCodeEvaluator, self).__init__(test_case_data, test,
- # language, user_answer,
- # ref_code_path, in_dir)
- # self.test_case_args = self.setup()
-
- # def setup(self):
- # super(JavaCodeEvaluator, self).setup()
-
- # ref_path, test_case_path = self._set_test_code_file_path(self.ref_code_path)
- # self.submit_path = self.create_submit_code_file('Test.java')
-
- # # Set file paths
- # java_student_directory = os.getcwd() + '/'
- # java_ref_file_name = (ref_path.split('/')[-1]).split('.')[0]
-
- # # Set command variables
- # compile_command = 'javac {0}'.format(self.submit_path),
- # compile_main = ('javac {0} -classpath '
- # '{1} -d {2}').format(ref_path,
- # java_student_directory,
- # java_student_directory)
- # run_command_args = "java -cp {0} {1}".format(java_student_directory,
- # java_ref_file_name)
- # remove_user_output = "{0}{1}.class".format(java_student_directory,
- # 'Test')
- # remove_ref_output = "{0}{1}.class".format(java_student_directory,
- # java_ref_file_name)
-
- # return (ref_path, self.submit_path, compile_command, compile_main,
- # run_command_args, remove_user_output, remove_ref_output)
-
- # def teardown(self):
- # # Delete the created file.
- # super(JavaCodeEvaluator, self).teardown()
- # os.remove(self.submit_path)
-
- # def check_code(self, ref_code_path, submit_code_path, compile_command,
- # compile_main, run_command_args, remove_user_output,
- # remove_ref_output):
- # """ Function validates student code using instructor code as
- # reference.The first argument ref_code_path, is the path to
- # instructor code, it is assumed to have executable permission.
- # The second argument submit_code_path, is the path to the student
- # code, it is assumed to have executable permission.
-
- # Returns
- # --------
-
- # returns (True, "Correct answer") : If the student function returns
- # expected output when called by reference code.
-
- # returns (False, error_msg): If the student function fails to return
- # expected output when called by reference code.
-
- # Returns (False, error_msg): If mandatory arguments are not files or
- # if the required permissions are not given to the file(s).
-
- # """
- # if not isfile(ref_code_path):
- # return False, "No file at %s or Incorrect path" % ref_code_path
- # if not isfile(submit_code_path):
- # return False, 'No file at %s or Incorrect path' % submit_code_path
-
- # success = False
- # ret = self._compile_command(compile_command)
- # proc, stdnt_stderr = ret
- # stdnt_stderr = self._remove_null_substitute_char(stdnt_stderr)
-
- # # Only if compilation is successful, the program is executed
- # # And tested with testcases
- # if stdnt_stderr == '':
- # ret = self._compile_command(compile_main)
- # proc, main_err = ret
- # main_err = self._remove_null_substitute_char(main_err)
-
- # if main_err == '':
- # ret = self._run_command(run_command_args, shell=True,
- # stdin=None,
- # stdout=subprocess.PIPE,
- # stderr=subprocess.PIPE)
- # proc, stdout, stderr = ret
- # if proc.returncode == 0:
- # success, err = True, "Correct answer"
- # else:
- # err = stdout + "\n" + stderr
- # os.remove(remove_ref_output)
- # else:
- # err = "Error:"
- # try:
- # error_lines = main_err.splitlines()
- # for e in error_lines:
- # if ':' in e:
- # err = err + "\n" + e.split(":", 1)[1]
- # else:
- # err = err + "\n" + e
- # except:
- # err = err + "\n" + main_err
- # os.remove(remove_user_output)
- # 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]
- # else:
- # err = err + "\n" + e
- # except:
- # err = err + "\n" + stdnt_stderr
-
- # return success, err
diff --git a/yaksh/language_registry.py b/yaksh/language_registry.py
index 3205279..398e1aa 100644
--- a/yaksh/language_registry.py
+++ b/yaksh/language_registry.py
@@ -3,12 +3,8 @@ import importlib
import json
registry = None
-
-# def set_registry():
-# global registry
-# registry = _LanguageRegistry()
-def get_registry(): #@@@get_evaluator_registry
+def get_registry():
global registry
if registry is None:
registry = _LanguageRegistry()
@@ -20,11 +16,9 @@ def unpack_json(json_data):
def create_evaluator_instance(language, test_case_type, json_data, in_dir):
"""Create instance of relevant EvaluateCode class based on language"""
- # set_registry()
registry = get_registry()
- cls = registry.get_class(language, test_case_type) #@@@get_evaluator_for_language
+ cls = registry.get_class(language, test_case_type)
instance = cls(in_dir)
- # instance = cls.from_json(language, json_data, in_dir)
return instance
class _LanguageRegistry(object):
diff --git a/yaksh/models.py b/yaksh/models.py
index fa4121d..a200ae1 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -159,16 +159,6 @@ class Question(models.Model):
# Number of points for the question.
points = models.FloatField(default=1.0)
- # Answer for MCQs.
- # test = models.TextField(blank=True)
-
- # Test cases file paths (comma seperated for reference code path and test case code path)
- # Applicable for CPP, C, Java and Scilab
- # ref_code_path = models.TextField(blank=True)
-
- # # Any multiple choice options. Place one option per line.
- # options = models.TextField(blank=True)
-
# The language for question.
language = models.CharField(max_length=24,
choices=languages)
@@ -183,52 +173,12 @@ class Question(models.Model):
# when creating a QuestionPaper.
active = models.BooleanField(default=True)
- # Snippet of code provided to the user.
- # snippet = models.CharField(max_length=256)
-
# Tags for the Question.
tags = TaggableManager(blank=True)
# user for particular question
user = models.ForeignKey(User, related_name="user")
- # def consolidate_answer_data(self, test_cases, user_answer):
- # def consolidate_answer_data(self, user_answer):
- # test_case_data_dict = []
- # question_info_dict = {}
-
- # for test_case in test_cases:
- # kw_args_dict = {}
- # pos_args_list = []
-
- # test_case_data = {}
- # test_case_data['test_id'] = test_case.id
- # test_case_data['func_name'] = test_case.func_name
- # test_case_data['expected_answer'] = test_case.expected_answer
-
- # if test_case.kw_args:
- # for args in test_case.kw_args.split(","):
- # arg_name, arg_value = args.split("=")
- # kw_args_dict[arg_name.strip()] = arg_value.strip()
-
- # if test_case.pos_args:
- # for args in test_case.pos_args.split(","):
- # pos_args_list.append(args.strip())
-
- # test_case_data['kw_args'] = kw_args_dict
- # test_case_data['pos_args'] = pos_args_list
- # test_case_data_dict.append(test_case_data)
-
- # question_info_dict['language'] = self.language
- # question_info_dict['id'] = self.id
- # question_info_dict['user_answer'] = user_answer
- # question_info_dict['test_parameter'] = test_case_data_dict
- # question_info_dict['ref_code_path'] = self.ref_code_path
- # question_info_dict['test'] = self.test
- # question_info_dict['test_case_type'] = self.test_case_type
-
- # return json.dumps(question_info_dict)
-
def consolidate_answer_data(self, user_answer):
question_data = {}
test_case_data = []
@@ -239,18 +189,11 @@ class Question(models.Model):
test_case_as_dict = test.get_field_value()
test_case_data.append(test_case_as_dict)
- # test_cases = self.testcase_set.all()
- # for test in test_cases:
- # test_case_child_instance = test.get_child_instance(self.test_case_type)
- # test_case_instance_dict = test_case_child_instance.get_instance_as_dict()
- # test_case_data.append(test_case_field_value)
-
question_data['test_case_data'] = test_case_data
question_data['user_answer'] = user_answer
return json.dumps(question_data)
-<<<<<<< HEAD
def dump_into_json(self, question_ids, user):
questions = Question.objects.filter(id__in = question_ids, user_id = user.id)
questions_dict = []
@@ -277,9 +220,6 @@ class Question(models.Model):
return test_cases
- # def get_test_case(self, test_case_id):
- # test_case_ctype = ContentType.objects.get(app_label="yaksh", model=self.test_case_type)
- # test_case = test_case_ctype.get_object_for_this_type(question=self, id=test_case_id)
def get_test_case(self, **kwargs):
test_case_ctype = ContentType.objects.get(app_label="yaksh", model=self.test_case_type)
test_case = test_case_ctype.get_object_for_this_type(question=self, **kwargs)
@@ -801,10 +741,6 @@ class AssignmentUpload(models.Model):
class TestCase(models.Model):
question = models.ForeignKey(Question, blank=True, null = True)
- # def get_child_instance(self, type):
- # return getattr(self, type)
-
-
class StandardTestCase(TestCase):
test_case = models.TextField(blank=True)
diff --git a/yaksh/python_assertion_evaluator.py b/yaksh/python_assertion_evaluator.py
index 82b5912..ff56421 100644
--- a/yaksh/python_assertion_evaluator.py
+++ b/yaksh/python_assertion_evaluator.py
@@ -25,15 +25,10 @@ class PythonAssertionEvaluator(CodeEvaluator):
exec submitted in self.exec_scope
return self.exec_scope
- # def check_code(self, test, user_answer, ref_code_path):
- # def check_code(self, user_answer, test_case_data): #@@@v2
def check_code(self, user_answer, test_case):
success = False
try:
tb = None
- # submitted = compile(user_answer, '<string>', mode='exec')
- # g = {}
- # exec submitted in g
_tests = compile(test_case, '<string>', mode='exec')
exec _tests in self.exec_scope
except AssertionError:
diff --git a/yaksh/python_stdout_evaluator.py b/yaksh/python_stdout_evaluator.py
index 4d89e16..b967024 100644
--- a/yaksh/python_stdout_evaluator.py
+++ b/yaksh/python_stdout_evaluator.py
@@ -40,12 +40,6 @@ class PythonStdoutEvaluator(CodeEvaluator):
success = False
tb = None
- # submitted = compile(user_answer, '<string>', mode='exec')
- # with redirect_stdout() as output_buffer:
- # g = {}
- # exec submitted in g
- # raw_output_value = output_buffer.getvalue()
- # output_value = raw_output_value.strip()
if expected_output in user_answer:
success = False
err = "Incorrect Answer: Please avoid printing the expected output directly"
diff --git a/yaksh/scilab_code_evaluator.py b/yaksh/scilab_code_evaluator.py
index fedfab3..3af9782 100644
--- a/yaksh/scilab_code_evaluator.py
+++ b/yaksh/scilab_code_evaluator.py
@@ -12,16 +12,6 @@ from code_evaluator import CodeEvaluator
class ScilabCodeEvaluator(CodeEvaluator):
"""Tests the Scilab code obtained from Code Server"""
- # def __init__(self, test_case_data, test, language, user_answer,
- # ref_code_path=None, in_dir=None):
- # super(ScilabCodeEvaluator, self).__init__(test_case_data, test,
- # language, user_answer,
- # ref_code_path, in_dir)
-
- # # Removes all the commands that terminates scilab
- # self.user_answer, self.terminate_commands = self._remove_scilab_exit(user_answer.lstrip())
- # self.test_case_args = self.setup()
-
def setup(self):
super(ScilabCodeEvaluator, self).setup()
# ref_path, test_case_path = self._set_test_code_file_path(self.ref_code_path)
@@ -33,30 +23,6 @@ class ScilabCodeEvaluator(CodeEvaluator):
# Delete the created file.
os.remove(self.submit_code_path)
- # def compile_code(self, user_answer, test_case):
- # if hasattr(self, 'compiled_output'):
- # return None
- # else:
- # ref_code_path = test_case
- # clean_ref_path, clean_test_case_path = self._set_test_code_file_path(ref_code_path)
- # user_answer, terminate_commands = self._remove_scilab_exit(user_answer.lstrip())
-
- # self.write_to_submit_code_file(self.submit_code_path, user_answer)
- # # Throw message if there are commmands that terminates scilab
- # self.add_err = ""
- # if terminate_commands:
- # self.add_err = "Please do not use exit, quit and abort commands in your\
- # code.\n Otherwise your code will not be evaluated\
- # correctly.\n"
-
- # cmd = 'printf "lines(0)\nexec(\'{0}\',2);\nquit();"'.format(clean_ref_path)
- # cmd += ' | timeout 8 scilab-cli -nb'
- # self.compiled_output = self._run_command(cmd,
- # shell=True,
- # stdout=subprocess.PIPE,
- # stderr=subprocess.PIPE)
- # return self.compiled_output
-
def check_code(self, user_answer, test_case):
ref_code_path = test_case
clean_ref_path, clean_test_case_path = self._set_test_code_file_path(ref_code_path)
@@ -89,46 +55,12 @@ class ScilabCodeEvaluator(CodeEvaluator):
if proc.returncode == 5:
success, err = True, "Correct answer"
else:
- # err = self.add_err + stdout
err = add_err + stdout
else:
- # err = self.add_err + stderr
err = add_err + stderr
return success, err
- # def check_code(self, ref_path):
- # success = False
-
- # # Throw message if there are commmands that terminates scilab
- # add_err=""
- # if self.terminate_commands:
- # add_err = "Please do not use exit, quit and abort commands in your\
- # code.\n Otherwise your code will not be evaluated\
- # correctly.\n"
-
- # cmd = 'printf "lines(0)\nexec(\'{0}\',2);\nquit();"'.format(ref_path)
- # cmd += ' | timeout 8 scilab-cli -nb'
- # ret = self._run_command(cmd,
- # shell=True,
- # stdout=subprocess.PIPE,
- # stderr=subprocess.PIPE)
- # proc, stdout, stderr = ret
-
- # # Get only the error.
- # stderr = self._get_error(stdout)
- # if stderr is None:
- # # Clean output
- # stdout = self._strip_output(stdout)
- # if proc.returncode == 5:
- # success, err = True, "Correct answer"
- # else:
- # err = add_err + stdout
- # else:
- # err = add_err + stderr
-
- # return success, err
-
def _remove_scilab_exit(self, string):
"""
Removes exit, quit and abort from the scilab code
diff --git a/yaksh/templates/yaksh/add_question.html b/yaksh/templates/yaksh/add_question.html
index bc700d1..eb9419c 100644
--- a/yaksh/templates/yaksh/add_question.html
+++ b/yaksh/templates/yaksh/add_question.html
@@ -24,11 +24,7 @@
<tr><td>Points:<td><button class="btn-mini" type="button" onClick="increase(frm);">+</button>{{ form.points }}<button class="btn-mini" type="button" onClick="decrease(frm);">-</button>{{ form.points.errors }}
<tr><td><strong>Rendered: </strong><td><p id='my'></p>
<tr><td>Description: <td>{{ form.description}} {{form.description.errors}}
- <!-- <tr><td>Snippet: <td>{{ form.snippet }}{{ form.snippet.errors }}</td></tD></td></tr> -->
<tr><td>Tags: <td>{{ form.tags }}
- <!-- <tr><td id='label_option'>Options: <td>{{ form.options }} {{form.options.errors}} -->
- <!-- <tr><td id='label_solution'>Test: <td>{{ form.test }} {{form.test.errors}} -->
- <!-- <tr><td id='label_ref_code_path'>Reference Code Path: <td>{{ form.ref_code_path }} {{form.ref_code_path.errors}} -->
<tr><td> Test Case Type: <td> {{ form.test_case_type }}{{ form.test_case_type.errors }}
<div class="form-group">
diff --git a/yaksh/tests.py b/yaksh/tests.py
index 900a261..6e50fc5 100644
--- a/yaksh/tests.py
+++ b/yaksh/tests.py
@@ -107,11 +107,9 @@ class QuestionTestCases(unittest.TestCase):
self.assertEqual(self.question1.summary, 'Demo question')
self.assertEqual(self.question1.language, 'Python')
self.assertEqual(self.question1.type, 'Code')
- # self.assertFalse(self.question.options)
self.assertEqual(self.question1.description, 'Write a function')
self.assertEqual(self.question1.points, 1.0)
self.assertTrue(self.question1.active)
- # self.assertEqual(self.question.snippet, 'def myfunc()')
tag_list = []
for tag in self.question1.tags.all():
tag_list.append(tag.name)
@@ -150,27 +148,6 @@ class QuestionTestCases(unittest.TestCase):
self.assertEqual(question_data.snippet, 'def fact()')
###############################################################################
-# class TestCaseTestCases(unittest.TestCase):
-# def setUp(self):
-# self.question = Question(summary='Demo question', language='Python',
-# type='Code', active=True,
-# description='Write a function', points=1.0,
-# snippet='def myfunc()')
-# self.question.save()
-# self.testcase = TestCase(question=self.question,
-# func_name='def myfunc', kw_args='a=10,b=11',
-# pos_args='12,13', expected_answer='15')
-
-# def test_testcase(self):
-# """ Test question """
-# self.assertEqual(self.testcase.question, self.question)
-# self.assertEqual(self.testcase.func_name, 'def myfunc')
-# self.assertEqual(self.testcase.kw_args, 'a=10,b=11')
-# self.assertEqual(self.testcase.pos_args, '12,13')
-# self.assertEqual(self.testcase.expected_answer, '15')
-
-
-###############################################################################
class QuizTestCases(unittest.TestCase):
def setUp(self):
self.quiz1 = Quiz.objects.get(pk=1)
diff --git a/yaksh/views.py b/yaksh/views.py
index 59a51aa..ffb08d8 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -154,11 +154,6 @@ def add_question(request):
question_form = QuestionForm(request.POST)
if question_form.is_valid():
new_question = question_form.save()
- # tags = question_form['tags'].data.split(',')
- # for i in range(0, len(tags)):
- # tag = tags[i].strip()
- # new_question.tags.add(tag)
- # new_question.save()
return my_redirect("/exam/manage/addquestion/{0}".format(new_question.id))
else:
return my_render_to_response('yaksh/add_question.html',
@@ -185,11 +180,6 @@ def edit_question(request, question_id=None):
question_form = QuestionForm(request.POST, instance=question_instance)
if question_form.is_valid():
new_question = question_form.save(commit=False)
- # tags = question_form['tags'].data.split(',')
- # for i in range(0, len(tags)):
- # tag = tags[i].strip()
- # new_question.tags.add(tag)
- # new_question.save()
test_case_type = question_form.cleaned_data.get('test_case_type')
test_case_form_class = get_object_form(model=test_case_type, exclude_fields=['question'])
test_case_model_class = get_model_class(test_case_type)
@@ -198,7 +188,6 @@ def edit_question(request, question_id=None):
if test_case_formset.is_valid():
new_question.save()
test_case_formset.save()
- # return my_redirect("/exam/manage/questions")
return my_redirect("/exam/manage/addquestion/{0}".format(new_question.id))
else:
return my_render_to_response('yaksh/add_question.html',
@@ -220,186 +209,6 @@ def edit_question(request, question_id=None):
'question_id': question_id},
context_instance=ci)
-# def add_question(request, question_id=None):
-# def add_question(request, question_id=None):
-# """To add a new question in the database.
-# Create a new question and store it."""
-# user = request.user
-# ci = RequestContext(request)
-# if not user.is_authenticated() or not is_moderator(user):
-# raise Http404('You are not allowed to view this page!')
-# if request.method == "POST":
-# form = QuestionForm(request.POST)
-# if form.is_valid():
-# if question_id is None:
-# if 'save_question' in request.POST:
-# form.save()
-# question = Question.objects.order_by("-id")[0]
-# tags = form['tags'].data.split(',')
-# for i in range(0, len(tags)-1):
-# tag = tags[i].strip()
-# question.tags.add(tag)
-
-# return my_redirect("/exam/manage/questions")
-
-# return my_render_to_response('yaksh/add_question.html',
-# # {'form': form},
-# {'form': form,
-# 'question_id': question_id},
-# context_instance=ci)
-
-# else:
-# d = Question.objects.get(id=question_id)
-# if 'save_question' in request.POST:
-# d.summary = form['summary'].data
-# d.description = form['description'].data
-# d.points = form['points'].data
-# # d.options = form['options'].data
-# d.type = form['type'].data
-# d.active = form['active'].data
-# d.language = form['language'].data
-# # d.snippet = form['snippet'].data
-# # d.ref_code_path = form['ref_code_path'].data
-# # d.test = form['test'].data
-# d.save()
-# question = Question.objects.get(id=question_id)
-# for tag in question.tags.all():
-# question.tags.remove(tag)
-# tags = form['tags'].data.split(',')
-# for i in range(0, len(tags)-1):
-# tag = tags[i].strip()
-# question.tags.add(tag)
-
-# return my_redirect("/exam/manage/questions")
-
-# return my_render_to_response('yaksh/add_question.html',
-# # {'form': form},
-# {'form': form,
-# 'question_id': question_id},
-# context_instance=ci)
-
-# else:
-# return my_render_to_response('yaksh/add_question.html',
-# # {'form': form},
-# {'form': form,
-# 'question_id': question_id},
-# context_instance=ci)
-# else:
-# form = QuestionForm()
-# if question_id is None:
-# form = QuestionForm()
-# return my_render_to_response('yaksh/add_question.html',
-# # {'form': form},
-# {'form': form,
-# 'question_id': question_id},
-# context_instance=ci)
-# else:
-# d = Question.objects.get(id=question_id)
-# form = QuestionForm()
-# form.initial['summary'] = d.summary
-# form.initial['description'] = d.description
-# form.initial['points'] = d.points
-# # form.initial['options'] = d.options
-# form.initial['type'] = d.type
-# form.initial['active'] = d.active
-# form.initial['language'] = d.language
-# # form.initial['snippet'] = d.snippet
-# # form.initial['ref_code_path'] = d.ref_code_path
-# # form.initial['test'] = d.test
-# form_tags = d.tags.all()
-# form_tags_split = form_tags.values('name')
-# initial_tags = ""
-# for tag in form_tags_split:
-# initial_tags = initial_tags + str(tag['name']).strip() + ","
-# if (initial_tags == ","):
-# initial_tags = ""
-# form.initial['tags'] = initial_tags
-
-# return my_render_to_response('yaksh/add_question.html',
-# # {'form': form},
-# {'form': form,
-# 'question_id': question_id},
-# context_instance=ci)
-
-# @login_required
-# def show_testcase(request, question_id=None):
-# """Show all test cases related to Questions"""
-
-# user = request.user
-# ci = RequestContext(request)
-# if not user.is_authenticated() or not is_moderator(user):
-# raise Http404('You are not allowed to view this page!')
-# if not question_id:
-# raise Http404('No Question Found')
-
-# question = Question.objects.get(id=question_id)
-# test_cases = question.get_test_cases()
-
-# if request.POST.get('delete') == 'delete':
-# data = request.POST.getlist('test_case')
-# for i in data:
-# for t in test_cases:
-# if int(i) == t.id:
-# test_case_deleted = t.delete()
-# test_cases = question.get_test_cases()
-
-# return my_render_to_response('yaksh/show_testcase.html',
-# {'test_cases': test_cases,
-# 'question_id': question_id},
-# context_instance=ci)
-
-
-# @login_required
-# def add_testcase(request, question_id=None, test_case_id=None):
-# """To add new test case for a question"""
-
-# user = request.user
-# ci = RequestContext(request)
-# if not user.is_authenticated() or not is_moderator(user):
-# raise Http404('You are not allowed to view this page!')
-# if not question_id:
-# raise Http404('No Question Found')
-
-# question = Question.objects.get(id=question_id)
-# test_case_type = question.test_case_type
-
-# if test_case_id:
-# instance = question.get_test_case(test_case_id)
-# else:
-# instance = None
-
-# # test_cases = self.testcase_set.all()
-# # for test in test_cases:
-# # test_case_child_instance = test.get_child_instance(test_case_type)
-
-# test_case_form_object = get_object_form(model=test_case_type, exclude_fields=['question'])
-
-# # if test_case_type == "standardtestcase":
-# # from yaksh.forms import StandardTestCaseForm
-# # if request.method == "POST":
-# # form = StandardTestCaseForm(request.POST)
-# # form = StandardTestCaseForm(initial)
-
-# if request.method == "POST":
-# form = test_case_form_object(request.POST, instance=instance)
-# if form.is_valid():
-# form_data = form.save(commit=False)
-# form_data.question = question
-# form_data.save()
-# return my_redirect("/exam/manage/showtestcase/{0}".format(question_id))
-# else:
-# return my_render_to_response('yaksh/add_testcase.html',
-# {'form': form,
-# 'question_id': question_id},
-# context_instance=ci)
-
-# else:
-# form = test_case_form_object(initial={"question": question}, instance=instance)
-# return my_render_to_response('yaksh/add_testcase.html',
-# {'form': form,
-# 'question_id': question_id},
-# context_instance=ci)
-
@login_required
def add_quiz(request, quiz_id=None):
"""To add a new quiz in the database.
@@ -669,36 +478,6 @@ def check(request, q_id, attempt_num=None, questionpaper_id=None):
return show_question(request, question, paper)
-# def validate_answer(user, user_answer, question, json_data=None):
-# """
-# Checks whether the answer submitted by the user is right or wrong.
-# If right then returns correct = True, success and
-# message = Correct answer.
-# success is True for MCQ's and multiple correct choices because
-# only one attempt are allowed for them.
-# For code questions success is True only if the answer is correct.
-# """
-
-# result = {'success': True, 'error': 'Incorrect answer'}
-# correct = False
-
-# if user_answer is not None:
-# if question.type == 'mcq':
-# if user_answer.strip() == question.test.strip():
-# correct = True
-# elif question.type == 'mcc':
-# answers = set(question.test.splitlines())
-# if set(user_answer) == answers:
-# correct = True
-# elif question.type == 'code':
-# user_dir = get_user_dir(user)
-# json_result = code_server.run_code(question.language, question.test_case_type, json_data, user_dir)
-# result = json.loads(json_result)
-# if result.get('success'):
-# correct = True
-
-# return correct, result
-
def validate_answer(user, user_answer, question, json_data=None):
"""
Checks whether the answer submitted by the user is right or wrong.
@@ -721,7 +500,6 @@ def validate_answer(user, user_answer, question, json_data=None):
expected_answers = []
for opt in question.get_test_cases(correct=True):
expected_answers.append(opt.options)
- # answers = set(question.test.splitlines())
if set(user_answer) == set(expected_answers):
correct = True
elif question.type == 'code':