[pypy-commit] pypy stdlib-2.7.4: test and fix for TextIO flush error on close

bdkearns noreply at buildbot.pypy.org
Sat Apr 13 01:02:14 CEST 2013


Author: Brian Kearns <bdkearns at gmail.com>
Branch: stdlib-2.7.4
Changeset: r63300:ccbca586192b
Date: 2013-04-12 19:00 -0400
http://bitbucket.org/pypy/pypy/changeset/ccbca586192b/

Log:	test and fix for TextIO flush error on close

diff --git a/pypy/module/_io/interp_textio.py b/pypy/module/_io/interp_textio.py
--- a/pypy/module/_io/interp_textio.py
+++ b/pypy/module/_io/interp_textio.py
@@ -497,7 +497,8 @@
             try:
                 space.call_method(self, "flush")
             finally:
-                return space.call_method(self.w_buffer, "close")
+                ret = space.call_method(self.w_buffer, "close")
+            return ret
 
     # _____________________________________________________________
     # read methods
diff --git a/pypy/module/_io/test/test_textio.py b/pypy/module/_io/test/test_textio.py
--- a/pypy/module/_io/test/test_textio.py
+++ b/pypy/module/_io/test/test_textio.py
@@ -199,6 +199,15 @@
         b.name = "dummy"
         assert repr(t) == "<_io.TextIOWrapper name='dummy' encoding='utf-8'>"
 
+    def test_flush_error_on_close(self):
+        import _io
+        txt = _io.TextIOWrapper(_io.BytesIO(""), encoding="ascii")
+        def bad_flush():
+            raise IOError()
+        txt.flush = bad_flush
+        raises(IOError, txt.close)  # exception not swallowed
+        assert txt.closed
+
 
 class AppTestIncrementalNewlineDecoder:
     def test_newline_decoder(self):


More information about the pypy-commit mailing list