diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2014-10-08 18:00:09 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2014-10-08 18:00:09 (GMT) |
commit | 0ddbf4795f40d2d3386dc56ffa264b50a015f6c9 (patch) | |
tree | ad87573215721b20a0160dacbe8dc0f423e56c1c /Lib | |
parent | b2fdafe3d2ac643b635d3b89429818e6036e8925 (diff) | |
download | cpython-0ddbf4795f40d2d3386dc56ffa264b50a015f6c9.zip cpython-0ddbf4795f40d2d3386dc56ffa264b50a015f6c9.tar.gz cpython-0ddbf4795f40d2d3386dc56ffa264b50a015f6c9.tar.bz2 |
Issue #22462: Fix pyexpat's creation of a dummy frame to make it appear in exception tracebacks.
Initial patch by Mark Shannon.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_pyexpat.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/Lib/test/test_pyexpat.py b/Lib/test/test_pyexpat.py index 95a614b..26f1961 100644 --- a/Lib/test/test_pyexpat.py +++ b/Lib/test/test_pyexpat.py @@ -2,7 +2,9 @@ # handler, are obscure and unhelpful. from io import BytesIO +import os import unittest +import traceback from xml.parsers import expat from xml.parsers.expat import errors @@ -419,7 +421,11 @@ class HandlerExceptionTest(unittest.TestCase): def StartElementHandler(self, name, attrs): raise RuntimeError(name) - def test(self): + def check_traceback_entry(self, entry, filename, funcname): + self.assertEqual(os.path.basename(entry[0]), filename) + self.assertEqual(entry[2], funcname) + + def test_exception(self): parser = expat.ParserCreate() parser.StartElementHandler = self.StartElementHandler try: @@ -429,6 +435,16 @@ class HandlerExceptionTest(unittest.TestCase): self.assertEqual(e.args[0], 'a', "Expected RuntimeError for element 'a', but" + \ " found %r" % e.args[0]) + # Check that the traceback contains the relevant line in pyexpat.c + entries = traceback.extract_tb(e.__traceback__) + self.assertEqual(len(entries), 3) + self.check_traceback_entry(entries[0], + "test_pyexpat.py", "test_exception") + self.check_traceback_entry(entries[1], + "pyexpat.c", "StartElement") + self.check_traceback_entry(entries[2], + "test_pyexpat.py", "StartElementHandler") + self.assertIn('call_with_frame("StartElement"', entries[1][3]) # Test Current* members: |