Author: Manuel Jacob <m...@manueljacob.de>
Branch: 
Changeset: r82578:de33a380d179
Date: 2016-02-27 00:18 +0100
http://bitbucket.org/pypy/pypy/changeset/de33a380d179/

Log:    Rewrite _vmprof test slightly to make it work on py3k.

        The problem with the previous way it was written is that in the py3k
        branch the test is executed in a separate process, where the file
        descriptor opened in the setup method is not available anymore.

diff --git a/pypy/module/_vmprof/test/test__vmprof.py 
b/pypy/module/_vmprof/test/test__vmprof.py
--- a/pypy/module/_vmprof/test/test__vmprof.py
+++ b/pypy/module/_vmprof/test/test__vmprof.py
@@ -5,14 +5,15 @@
 class AppTestVMProf(object):
     def setup_class(cls):
         cls.space = gettestobjspace(usemodules=['_vmprof', 'struct'])
-        cls.tmpfile = udir.join('test__vmprof.1').open('wb')
-        cls.w_tmpfileno = cls.space.wrap(cls.tmpfile.fileno())
-        cls.w_tmpfilename = cls.space.wrap(cls.tmpfile.name)
-        cls.tmpfile2 = udir.join('test__vmprof.2').open('wb')
-        cls.w_tmpfileno2 = cls.space.wrap(cls.tmpfile2.fileno())
-        cls.w_tmpfilename2 = cls.space.wrap(cls.tmpfile2.name)
+        cls.w_tmpfilename = cls.space.wrap(str(udir.join('test__vmprof.1')))
+        cls.w_tmpfilename2 = cls.space.wrap(str(udir.join('test__vmprof.2')))
 
     def test_import_vmprof(self):
+        tmpfile = open(self.tmpfilename, 'wb')
+        tmpfileno = tmpfile.fileno()
+        tmpfile2 = open(self.tmpfilename2, 'wb')
+        tmpfileno2 = tmpfile2.fileno()
+
         import struct, sys
 
         WORD = struct.calcsize('l')
@@ -45,7 +46,7 @@
             return count
         
         import _vmprof
-        _vmprof.enable(self.tmpfileno, 0.01)
+        _vmprof.enable(tmpfileno, 0.01)
         _vmprof.disable()
         s = open(self.tmpfilename, 'rb').read()
         no_of_codes = count(s)
@@ -56,7 +57,7 @@
             pass
         """ in d
 
-        _vmprof.enable(self.tmpfileno2, 0.01)
+        _vmprof.enable(tmpfileno2, 0.01)
 
         exec """def foo2():
             pass
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to