diff options
author | Berker Peksag <berker.peksag@gmail.com> | 2019-05-19 18:56:15 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-19 18:56:15 +0300 |
commit | 7c59362a15dfce538512ff1fce4e07d33a925cfb (patch) | |
tree | ab4a3d9933d81c3e5b227419fa1c39afae6c6d37 /Lib/test | |
parent | f4e1babf44792bdeb0c01da96821ba0800a51fd8 (diff) | |
download | cpython-git-7c59362a15dfce538512ff1fce4e07d33a925cfb.tar.gz |
bpo-29183: Fix double exceptions in wsgiref.handlers.BaseHandler (GH-12914)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_wsgiref.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/Lib/test/test_wsgiref.py b/Lib/test/test_wsgiref.py index 46f88a9443..42432bfbd2 100644 --- a/Lib/test/test_wsgiref.py +++ b/Lib/test/test_wsgiref.py @@ -806,6 +806,31 @@ class HandlerTests(TestCase): self.assertFalse(stderr.getvalue()) + def testDontResetInternalStateOnException(self): + class CustomException(ValueError): + pass + + # We are raising CustomException here to trigger an exception + # during the execution of SimpleHandler.finish_response(), so + # we can easily test that the internal state of the handler is + # preserved in case of an exception. + class AbortingWriter: + def write(self, b): + raise CustomException + + stderr = StringIO() + environ = {"SERVER_PROTOCOL": "HTTP/1.0"} + h = SimpleHandler(BytesIO(), AbortingWriter(), stderr, environ) + h.run(hello_app) + + self.assertIn("CustomException", stderr.getvalue()) + + # Test that the internal state of the handler is preserved. + self.assertIsNotNone(h.result) + self.assertIsNotNone(h.headers) + self.assertIsNotNone(h.status) + self.assertIsNotNone(h.environ) + if __name__ == "__main__": unittest.main() |