Author: Antonio Cuni <[email protected]>
Branch: resource_warning
Changeset: r83569:3649155837b6
Date: 2016-04-07 16:09 +0200
http://bitbucket.org/pypy/pypy/changeset/3649155837b6/

Log:    improve the test and check that we don't get the warning if we
        explicitly close the file

diff --git a/pypy/module/_file/test/test_file.py 
b/pypy/module/_file/test/test_file.py
--- a/pypy/module/_file/test/test_file.py
+++ b/pypy/module/_file/test/test_file.py
@@ -270,24 +270,29 @@
         import os, gc, sys, cStringIO
         if '__pypy__' not in sys.builtin_module_names:
             skip("pypy specific test")
-        def fn(flag1, flag2):
+        def fn(flag1, flag2, do_close=False):
             sys.pypy_set_track_resources(flag1)
             f = self.file(self.temppath, 'w')
             sys.pypy_set_track_resources(flag2)
-            g = cStringIO.StringIO()
+            buf = cStringIO.StringIO()
             preverr = sys.stderr
             try:
-                sys.stderr = g
+                sys.stderr = buf
+                if do_close:
+                    f.close()
                 del f
                 gc.collect() # force __del__ to be called
             finally:
                 sys.stderr = preverr
                 sys.pypy_set_track_resources(False)
-            return g.getvalue()
+            return buf.getvalue()
 
         # check with track_resources disabled
         assert fn(False, False) == ""
         #
+        # check that we don't get the warning if we actually close the file
+        assert fn(False, False, do_close=True) == ""
+        #
         # check with track_resources enabled
         msg = fn(True, True)
         assert self.regex_search(r"""
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to