diff options
-rw-r--r-- | yaksh/evaluator_tests/test_python_evaluation.py | 32 | ||||
-rw-r--r-- | yaksh/grader.py | 5 | ||||
-rw-r--r-- | yaksh/static/yaksh/js/requesthandler.js | 26 |
3 files changed, 48 insertions, 15 deletions
diff --git a/yaksh/evaluator_tests/test_python_evaluation.py b/yaksh/evaluator_tests/test_python_evaluation.py index 2748d8a..1933d17 100644 --- a/yaksh/evaluator_tests/test_python_evaluation.py +++ b/yaksh/evaluator_tests/test_python_evaluation.py @@ -317,12 +317,15 @@ class PythonAssertionEvaluationTestCases(EvaluatorBaseTest): # When grader = Grader(self.in_dir) result = grader.evaluate(kwargs) - err = result.get("error")[0]['traceback'] + errors = result.get("error") # Then self.assertFalse(result.get("success")) for msg in value_error_msg: - self.assert_correct_output(msg, err) + self.assert_correct_output(msg, errors[0]['traceback']) + for index, error in enumerate(errors): + self.assertEqual(error['test_case'], + self.test_case_data[index]['test_case']) def test_file_based_assert(self): # Given @@ -694,6 +697,31 @@ class PythonStdIOEvaluationTestCases(EvaluatorBaseTest): # Then self.assertTrue(result.get("success")) + def test_get_error_lineno(self): + user_answer = dedent("""\ + print(1/0) + """) + test_case_data = [{"test_case_type": "stdiobasedtestcase", + "expected_input": "", + "expected_output": "1", + "weight": 0.0 + }] + kwargs = {'metadata': { + 'user_answer': user_answer, + 'file_paths': self.file_paths, + 'partial_grading': False, + 'language': 'python'}, + 'test_case_data': test_case_data, + } + # When + grader = Grader(self.in_dir) + result = grader.evaluate(kwargs) + # Then + self.assertFalse(result.get("success")) + error = result.get("error")[0] + self.assertEqual(error['line_no'], 1) + self.assertEqual(error['exception'], "ZeroDivisionError") + class PythonHookEvaluationTestCases(EvaluatorBaseTest): diff --git a/yaksh/grader.py b/yaksh/grader.py index 9bc4e5c..2a246b8 100644 --- a/yaksh/grader.py +++ b/yaksh/grader.py @@ -151,7 +151,10 @@ class Grader(object): except Exception as e: exc_type, exc_value, exc_tb = sys.exc_info() tb_list = traceback.format_exception(exc_type, exc_value, exc_tb) - line_no = e.lineno + try: + line_no = e.lineno + except AttributeError: + line_no = traceback.extract_tb(exc_tb)[-1][1] if len(tb_list) > 2: del tb_list[1:3] error.append( diff --git a/yaksh/static/yaksh/js/requesthandler.js b/yaksh/static/yaksh/js/requesthandler.js index f858317..952de3a 100644 --- a/yaksh/static/yaksh/js/requesthandler.js +++ b/yaksh/static/yaksh/js/requesthandler.js @@ -75,21 +75,23 @@ function response_handler(method_type, content_type, data, uid){ var error_output = document.getElementById("error_panel"); error_output.innerHTML = res.error; focus_on_error(error_output); - err_lineno = $("#err_lineno").val(); - if(marker){ - marker.clear(); - } - if(err_lineno){ - var lineno = parseInt(err_lineno) - 1; - var editor = global_editor.editor; - var line_length = editor.getLine(lineno).length; - marker = editor.markText({line: lineno, ch: 0}, {line: lineno, ch: line_length}, - {className: "activeline", clearOnEnter:true}); - } - else{ + if(global_editor.editor){ + err_lineno = $("#err_lineno").val(); if(marker){ marker.clear(); } + if(err_lineno){ + var lineno = parseInt(err_lineno) - 1; + var editor = global_editor.editor; + var line_length = editor.getLine(lineno).length; + marker = editor.markText({line: lineno, ch: 0}, {line: lineno, ch: line_length}, + {className: "activeline", clearOnEnter:true}); + } + else{ + if(marker){ + marker.clear(); + } + } } } } else { |