diff options
author | ankitjavalkar | 2016-11-16 20:32:21 +0530 |
---|---|---|
committer | ankitjavalkar | 2016-11-16 20:32:21 +0530 |
commit | cb9a541a4653b2ed13db3a6171b50de575b0f05d (patch) | |
tree | 9fcab71c37e49ac1dfe61ba35fb97b50a32aaa25 /yaksh | |
parent | 0b151541d9414572965b597815f98c4b057430e1 (diff) | |
download | online_test-cb9a541a4653b2ed13db3a6171b50de575b0f05d.tar.gz online_test-cb9a541a4653b2ed13db3a6171b50de575b0f05d.tar.bz2 online_test-cb9a541a4653b2ed13db3a6171b50de575b0f05d.zip |
Fix Output display of Code Question
Diffstat (limited to 'yaksh')
-rw-r--r-- | yaksh/code_evaluator.py | 4 | ||||
-rw-r--r-- | yaksh/evaluator_tests/test_python_evaluation.py | 44 | ||||
-rw-r--r-- | yaksh/python_assertion_evaluator.py | 5 | ||||
-rw-r--r-- | yaksh/templates/yaksh/grade_user.html | 2 | ||||
-rw-r--r-- | yaksh/templates/yaksh/question.html | 4 |
5 files changed, 45 insertions, 14 deletions
diff --git a/yaksh/code_evaluator.py b/yaksh/code_evaluator.py index 8cea94e..afe18c3 100644 --- a/yaksh/code_evaluator.py +++ b/yaksh/code_evaluator.py @@ -124,10 +124,8 @@ class CodeEvaluator(object): ) if test_case_success: weight += test_case_weight - error = err - else: - error += err + "\n" + error += err + "\n" test_case_success_status[idx] = test_case_success success = all(test_case_success_status) diff --git a/yaksh/evaluator_tests/test_python_evaluation.py b/yaksh/evaluator_tests/test_python_evaluation.py index a0e3713..a3a0be8 100644 --- a/yaksh/evaluator_tests/test_python_evaluation.py +++ b/yaksh/evaluator_tests/test_python_evaluation.py @@ -45,7 +45,7 @@ class PythonAssertionEvaluationTestCases(unittest.TestCase): # Then self.assertTrue(result.get('success')) - self.assertEqual(result.get('error'), "Correct answer") + self.assertIn("Correct answer", result.get('error')) def test_incorrect_answer(self): # Given @@ -62,12 +62,42 @@ class PythonAssertionEvaluationTestCases(unittest.TestCase): # Then self.assertFalse(result.get('success')) - self.assertEqual(result.get('error'), - ('AssertionError in: assert(add(1,2)==3)\n' - 'AssertionError in: assert(add(-1,2)==1)\n' - 'AssertionError in: assert(add(-1,-2)==-3)\n' - ) - ) + self.assertIn('AssertionError in: assert(add(1,2)==3)', + result.get('error') + ) + self.assertIn('AssertionError in: assert(add(-1,2)==1)', + result.get('error') + ) + self.assertIn('AssertionError in: assert(add(-1,-2)==-3)', + result.get('error') + ) + + def test_partial_incorrect_answer(self): + # Given + user_answer = "def add(a,b):\n\treturn abs(a) + abs(b)" + test_case_data = [{"test_case": 'assert(add(-1,2)==1)', 'weight': 1.0}, + {"test_case": 'assert(add(-1,-2)==-3)', 'weight': 1.0}, + {"test_case": 'assert(add(1,2)==3)', 'weight': 2.0} + ] + kwargs = {'user_answer': user_answer, + 'test_case_data': test_case_data, + 'file_paths': self.file_paths, + 'partial_grading': True + } + + # When + evaluator = PythonAssertionEvaluator() + result = evaluator.evaluate(**kwargs) + + # Then + self.assertFalse(result.get('success')) + self.assertEqual(result.get('weight'), 2.0) + self.assertIn('AssertionError in: assert(add(-1,2)==1)', + result.get('error') + ) + self.assertIn('AssertionError in: assert(add(-1,-2)==-3)', + result.get('error') + ) def test_infinite_loop(self): # Given diff --git a/yaksh/python_assertion_evaluator.py b/yaksh/python_assertion_evaluator.py index 1cc4fa4..275244a 100644 --- a/yaksh/python_assertion_evaluator.py +++ b/yaksh/python_assertion_evaluator.py @@ -68,12 +68,13 @@ class PythonAssertionEvaluator(CodeEvaluator): info = traceback.extract_tb(tb) fname, lineno, func, text = info[-1] text = str(test_case).splitlines()[lineno-1] - err = "{0} {1} in: {2}".format(type.__name__, str(value), text) + err = ("-----\nExpected Test Case:\n{0}\n" + "Error - {1} {2} in: {3}\n-----").format(test_case, type.__name__, str(value), text) except Exception: raise # Exception will be caught in CodeEvaluator. else: success = True - err = 'Correct answer' + err = '-----\nCorrect answer\nTest Case: {0}\n-----'.format(test_case) test_case_weight = float(weight) if partial_grading else 0.0 del tb return success, err, test_case_weight diff --git a/yaksh/templates/yaksh/grade_user.html b/yaksh/templates/yaksh/grade_user.html index ced3ca2..38f31ca 100644 --- a/yaksh/templates/yaksh/grade_user.html +++ b/yaksh/templates/yaksh/grade_user.html @@ -157,7 +157,7 @@ Status : <b style="color: green;"> Passed </b><br/> <h5>Student answer: </h5> {% for answer in answers %} {% if not answer.skipped %} - {% if "Correct answer" in answer.error %} + {% if answer.correct %} <div class="panel panel-success"> {% else %} <div class="panel panel-danger"> diff --git a/yaksh/templates/yaksh/question.html b/yaksh/templates/yaksh/question.html index a8de448..18b6388 100644 --- a/yaksh/templates/yaksh/question.html +++ b/yaksh/templates/yaksh/question.html @@ -163,9 +163,11 @@ function call_skip(url) <div class="panel-footer"> {% if question.type == "code" %} {% if error_message %} - <p> Output Message</p> + <p><h4> Output Message </h4></p> <div class="alert alert-danger" role="alert"> + <textarea class="output" id="output" rows=10 cols=155> {{ error_message }} + </textarea> </div> {% endif %} {% endif %} |