summaryrefslogtreecommitdiff
path: root/tests/view_tests
diff options
context:
space:
mode:
authorGiebisch <rafael@giebisch-mail.de>2022-11-03 11:49:10 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-11-29 08:40:11 +0100
commit85b52d22fd2841c34e95b3a80d6f2b668ce2f160 (patch)
tree957e84409a0ca2135e79ae202005732dfbf3fdd8 /tests/view_tests
parent9d726c7902979d4ad53945ed8f1037266a88010d (diff)
downloaddjango-85b52d22fd2841c34e95b3a80d6f2b668ce2f160.tar.gz
Fixed #33701 -- Added fine-grained error locations to the technical 500 debug page.
Diffstat (limited to 'tests/view_tests')
-rw-r--r--tests/view_tests/tests/test_debug.py73
1 files changed, 73 insertions, 0 deletions
diff --git a/tests/view_tests/tests/test_debug.py b/tests/view_tests/tests/test_debug.py
index a9b7625617..020ac7193e 100644
--- a/tests/view_tests/tests/test_debug.py
+++ b/tests/view_tests/tests/test_debug.py
@@ -766,6 +766,79 @@ class ExceptionReporterTests(SimpleTestCase):
self.assertIn(implicit_exc.format("<p>Second exception</p>"), text)
self.assertEqual(3, text.count("<p>Final exception</p>"))
+ @skipIf(
+ sys._xoptions.get("no_debug_ranges", False)
+ or os.environ.get("PYTHONNODEBUGRANGES", False),
+ "Fine-grained error locations are disabled.",
+ )
+ @skipUnless(PY311, "Fine-grained error locations were added in Python 3.11.")
+ def test_highlight_error_position(self):
+ request = self.rf.get("/test_view/")
+ try:
+ try:
+ raise AttributeError("Top level")
+ except AttributeError as explicit:
+ try:
+ raise ValueError(mark_safe("<p>2nd exception</p>")) from explicit
+ except ValueError:
+ raise IndexError("Final exception")
+ except Exception:
+ exc_type, exc_value, tb = sys.exc_info()
+
+ reporter = ExceptionReporter(request, exc_type, exc_value, tb)
+ html = reporter.get_traceback_html()
+ self.assertIn(
+ "<pre> raise AttributeError(&quot;Top level&quot;)\n"
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^</pre>",
+ html,
+ )
+ self.assertIn(
+ "<pre> raise ValueError(mark_safe("
+ "&quot;&lt;p&gt;2nd exception&lt;/p&gt;&quot;)) from explicit\n"
+ " "
+ "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^</pre>",
+ html,
+ )
+ self.assertIn(
+ "<pre> raise IndexError(&quot;Final exception&quot;)\n"
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^</pre>",
+ html,
+ )
+ # Pastebin.
+ self.assertIn(
+ " raise AttributeError(&quot;Top level&quot;)\n"
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
+ html,
+ )
+ self.assertIn(
+ " raise ValueError(mark_safe("
+ "&quot;&lt;p&gt;2nd exception&lt;/p&gt;&quot;)) from explicit\n"
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
+ html,
+ )
+ self.assertIn(
+ " raise IndexError(&quot;Final exception&quot;)\n"
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
+ html,
+ )
+ # Text traceback.
+ text = reporter.get_traceback_text()
+ self.assertIn(
+ ' raise AttributeError("Top level")\n'
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
+ text,
+ )
+ self.assertIn(
+ ' raise ValueError(mark_safe("<p>2nd exception</p>")) from explicit\n'
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
+ text,
+ )
+ self.assertIn(
+ ' raise IndexError("Final exception")\n'
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
+ text,
+ )
+
def test_reporting_frames_without_source(self):
try:
source = "def funcName():\n raise Error('Whoops')\nfuncName()"