summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--yaksh/python_assertion_evaluator.py22
-rw-r--r--yaksh/templates/exam.html28
2 files changed, 32 insertions, 18 deletions
diff --git a/yaksh/python_assertion_evaluator.py b/yaksh/python_assertion_evaluator.py
index 35a08ec..af89fc3 100644
--- a/yaksh/python_assertion_evaluator.py
+++ b/yaksh/python_assertion_evaluator.py
@@ -75,23 +75,23 @@ class PythonAssertionEvaluator(BaseEvaluator):
except TimeoutException:
raise
except AssertionError:
- type, _, tb = sys.exc_info()
- tb_info = traceback.extract_tb(tb)
- filename, line, func, text = tb_info[-1]
+ exc_type, exc_value, exc_tb = sys.exc_info()
value = "Expected answer from the test case didnt match the output"
err = {"type": "assertion",
"test_case": self.test_case,
- "exception": type.__name__,
- "message": value
+ "exception": exc_type.__name__,
+ "message": value,
}
except Exception:
- type, value, tb = sys.exc_info()
- tb_info = traceback.extract_tb(tb)
- filename, line, func, text = tb_info[-1]
+ 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]
+
err = {"type": "assertion",
- "test_case": self.test_case,
- "exception": type.__name__,
- "message": str(value)
+ "traceback": "".join(tb_list),
+ "exception": exc_type.__name__,
+ "message": str(exc_value)
}
else:
diff --git a/yaksh/templates/exam.html b/yaksh/templates/exam.html
index 7b6d54e..8b573d4 100644
--- a/yaksh/templates/exam.html
+++ b/yaksh/templates/exam.html
@@ -91,17 +91,31 @@
{% if not error.type %}
<pre><code> {{error|safe}} </code></pre>
{% elif error.type == 'assertion' %}
- We tried the calling your function with the following test case:<br/>
- <pre><code><strong>{{error.test_case}}</strong></code></pre>
- <table>
- <tr> But the following error took place: </tr>
- <tr>
- <td>Exception Name</td>
+ {% if error.test_case %}
+ <table class="table table-bordered">
+ <col width="30%">
+ <tr class = "active">
+ <td> We tried calling your function with the following test case:</td>
+ <td><code><strong>{{error.test_case}}</strong></code></td>
+ </tr>
+ </table>
+ {% endif %}
+ <p> <b>The following error took place: </b></p>
+ <table class="table table-bordered" width="100%">
+ <col width="30%">
+ <tr class = "active">
+ <td><b>Exception Name: </b></td>
<td><mark style="background-color:#ff9999;">{{error.exception}}</mark>
</td>
</tr>
<tr>
- <td>Exception Message</td><td>{{error.message}}</td>
+ <td><b>Exception Message: </b></td><td>{{error.message}}</td>
+ </tr>
+ <tr>
+ {% if error.traceback %}
+ <td><b>Full exception: </b></td>
+ <td><pre>{{error.traceback}}</pre></td>
+ {% endif %}
</tr>
</table>
{% elif error.type == 'stdio' %}