[pypy-commit] pypy py3k: Updated posix module for py3k.

prestontimmons noreply at buildbot.pypy.org
Wed Mar 14 19:34:42 CET 2012


Author: Preston Timmons <prestontimmons at gmail.com>
Branch: py3k
Changeset: r53570:90afa8ce9ff5
Date: 2012-03-13 19:20 +0000
http://bitbucket.org/pypy/pypy/changeset/90afa8ce9ff5/

Log:	Updated posix module for py3k.

	Removed tmpnam(), tempnam(), and tmpfile() which were replaced by
	the tempfile module. Removed popen and fdopen tests which were
	removed from posix in py3k.

diff --git a/pypy/module/posix/__init__.py b/pypy/module/posix/__init__.py
--- a/pypy/module/posix/__init__.py
+++ b/pypy/module/posix/__init__.py
@@ -73,7 +73,6 @@
     'unlink'    : 'interp_posix.unlink',
     'remove'    : 'interp_posix.remove',
     'getcwd'    : 'interp_posix.getcwd',
-    'getcwdu'   : 'interp_posix.getcwdu',
     'chdir'     : 'interp_posix.chdir',
     'mkdir'     : 'interp_posix.mkdir',
     'rmdir'     : 'interp_posix.rmdir',
diff --git a/pypy/module/posix/interp_posix.py b/pypy/module/posix/interp_posix.py
--- a/pypy/module/posix/interp_posix.py
+++ b/pypy/module/posix/interp_posix.py
@@ -418,22 +418,6 @@
     else:
         return space.wrap(cur)
 
-if sys.platform == 'win32':
-    def getcwdu(space):
-        """Return the current working directory as a unicode string."""
-        try:
-            cur = os.getcwdu()
-        except OSError, e:
-            raise wrap_oserror(space, e)
-        else:
-            return space.wrap(cur)
-else:
-    def getcwdu(space):
-        """Return the current working directory as a unicode string."""
-        filesystemencoding = space.sys.filesystemencoding
-        return space.call_method(getcwd(space), 'decode',
-                                 space.wrap(filesystemencoding))
-
 def chdir(space, w_path):
     """Change the current working directory to the specified path."""
     try:
diff --git a/pypy/module/posix/test/test_posix2.py b/pypy/module/posix/test/test_posix2.py
--- a/pypy/module/posix/test/test_posix2.py
+++ b/pypy/module/posix/test/test_posix2.py
@@ -265,8 +265,6 @@
 
     def test_getcwd(self):
         assert isinstance(self.posix.getcwd(), str)
-        assert isinstance(self.posix.getcwdu(), unicode)
-        assert self.posix.getcwd() == self.posix.getcwdu()
 
     def test_listdir(self):
         pdir = self.pdir
@@ -461,14 +459,6 @@
                              {'FOOBAR': '42'})
             assert ret == 42
 
-    def test_popen(self):
-        os = self.posix
-        for i in range(5):
-            stream = os.popen('echo 1')
-            res = stream.read()
-            assert res == '1\n'
-            assert stream.close() is None
-
     if hasattr(__import__(os.name), '_getfullpathname'):
         def test__getfullpathname(self):
             # nt specific
@@ -846,68 +836,6 @@
             # How else could we test that getlogin is properly
             # working?
 
-    def test_tmpfile(self):
-        os = self.posix
-        f = os.tmpfile()
-        f.write(b"xxx")
-        f.flush()
-        f.seek(0, 0)
-        assert isinstance(f, file)
-        assert f.read() == b'xxx'
-
-    def test_tmpnam(self):
-        import stat, os
-        s1 = os.tmpnam()
-        s2 = os.tmpnam()
-        assert s1 != s2
-        def isdir(s):
-            try:
-                return stat.S_ISDIR(os.stat(s).st_mode)
-            except OSError:
-                return -1
-        assert isdir(s1) == -1
-        assert isdir(s2) == -1
-        assert isdir(os.path.dirname(s1)) == 1
-        assert isdir(os.path.dirname(s2)) == 1
-
-    def test_tempnam(self):
-        import stat, os
-        for dir in [None, self.udir]:
-            for prefix in [None, 'foobar']:
-                s1 = os.tempnam(dir, prefix)
-                s2 = os.tempnam(dir, prefix)
-                assert s1 != s2
-                def isdir(s):
-                    try:
-                        return stat.S_ISDIR(os.stat(s).st_mode)
-                    except OSError:
-                        return -1
-                assert isdir(s1) == -1
-                assert isdir(s2) == -1
-                assert isdir(os.path.dirname(s1)) == 1
-                assert isdir(os.path.dirname(s2)) == 1
-                if dir:
-                    assert os.path.dirname(s1) == dir
-                    assert os.path.dirname(s2) == dir
-                assert os.path.basename(s1).startswith(prefix or 'tmp')
-                assert os.path.basename(s2).startswith(prefix or 'tmp')
-
-    def test_tmpnam_warning(self):
-        import warnings, os
-        #
-        def f_tmpnam_warning(): os.tmpnam()    # a single line
-        #
-        with warnings.catch_warnings(record=True) as w:
-            warnings.simplefilter("always")
-            f_tmpnam_warning()
-            assert len(w) == 1
-            assert issubclass(w[-1].category, RuntimeWarning)
-            assert "potential security risk" in str(w[-1].message)
-            # check that the warning points to the call to os.tmpnam(),
-            # not to some code inside app_posix.py
-            assert w[-1].lineno == f_tmpnam_warning.func_code.co_firstlineno
-
-
 class AppTestEnvironment(object):
     def setup_class(cls):
         cls.space = space
diff --git a/pypy/module/posix/test/test_posix_libfile.py b/pypy/module/posix/test/test_posix_libfile.py
deleted file mode 100644
--- a/pypy/module/posix/test/test_posix_libfile.py
+++ /dev/null
@@ -1,67 +0,0 @@
-from pypy.conftest import gettestobjspace
-from pypy.tool.udir import udir
-import os
-
-def setup_module(mod):
-    mod.space = gettestobjspace(usemodules=['posix'])
-    mod.path = udir.join('posixtestfile.txt')
-    mod.path.write("this is a test")
-
-class AppTestPosix: 
-    def setup_class(cls): 
-        cls.space = space 
-        cls.w_posix = space.appexec([], "(): import %s as m ; return m" % os.name)
-        cls.w_path = space.wrap(str(path))
-    
-    def test_posix_is_pypy_s(self): 
-        assert self.posix.__file__ 
-
-    def test_fdopen(self):
-        path = self.path 
-        posix = self.posix 
-        fd = posix.open(path, posix.O_RDONLY, 0o777)
-        f = posix.fdopen(fd, "r")
-        result = f.read()
-        assert result == "this is a test"
-
-    def test_popen(self):
-        import sys
-        if sys.platform.startswith('win'):
-            skip("unix specific")
-        path2 = self.path + '2'
-        posix = self.posix
-
-        f = posix.popen("echo hello")
-        data = f.read()
-        f.close()
-        assert data == 'hello\n'
-
-        f = posix.popen("cat > '%s'" % (path2,), 'w')
-        f.write('123\n')
-        f.close()
-        f = open(path2, 'r')
-        data = f.read()
-        f.close()
-        assert data == '123\n'
-
-        import time
-        start_time = time.time()
-        f = posix.popen("sleep 2")
-        f.close()   # should wait here
-        end_time = time.time()
-        assert end_time - start_time >= 1.9
-
-    def test_popen_and_rebind_file_in___builtin__(self):
-        import sys
-        if sys.platform.startswith('win'):
-            skip("unix specific")
-        #
-        import builtins
-        posix = self.posix
-        orig_file = file
-        try:
-            f = posix.popen('true')
-            builtins.file = lambda x : explode
-            f.close()
-        finally:
-            builtins.file = orig_file


More information about the pypy-commit mailing list