Author: Matti Picus <[email protected]>
Branch: py3.6
Changeset: r96496:df2790e6e32f
Date: 2019-04-15 20:13 +0300
http://bitbucket.org/pypy/pypy/changeset/df2790e6e32f/

Log:    test, fix fscode and also win32, fixes issue 2985

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
@@ -69,10 +69,10 @@
         self.w_obj = w_obj
 
     def as_bytes(self):
-        return self.space.bytesbuf0_w(self.w_obj)
+        return self.space.fsencode_w(self.w_obj)
 
     def as_unicode(self):
-        ret = self.space.fsdecode_w(self.w_obj)
+        ret = self.space.fsdecode_w(self.w_obj).decode('utf-8')
         if u'\x00' in ret:
             raise oefmt(self.space.w_ValueError, "embedded null character")
         return ret
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
@@ -96,10 +96,19 @@
             cls.w_confstr_result = space.wrap(os.confstr(confstr_name))
         cls.w_SIGABRT = space.wrap(signal.SIGABRT)
         cls.w_python = space.wrap(sys.executable)
+        cls.w_platform = space.wrap(sys.platform)
         if hasattr(os, 'major'):
             cls.w_expected_major_12345 = space.wrap(os.major(12345))
             cls.w_expected_minor_12345 = space.wrap(os.minor(12345))
         cls.w_udir = space.wrap(str(udir))
+        cls.w_Path = space.appexec([], """():
+            class Path:
+                def __init__(self, _path):
+                    self._path =_path
+                def __fspath__(self):
+                    return self._path
+            return Path
+            """) 
 
     def setup_method(self, meth):
         if getattr(meth, 'need_sparse_files', False):
@@ -401,10 +410,7 @@
         path = self.path3
         with open(path, 'wb'):
             pass
-        class Path:
-            def __fspath__(self):
-                return path
-        os.unlink(Path())
+        os.unlink(self.Path())
 
     def test_times(self):
         """
@@ -1076,7 +1082,7 @@
         os.closerange(start, stop)
         for fd in fds:
             os.close(fd)     # should not have been closed
-        if sys.platform == 'win32' and not we_are_translated():
+        if self.platform == 'win32' and not we_are_translated():
             # XXX kills the host interpreter untranslated
             for fd in range(start, stop):
                 raises(OSError, os.fstat, fd)   # should have been closed
@@ -1224,17 +1230,12 @@
                 posix.unlink(bytes_dir + '/somelink'.encode())
 
         def test_symlink_fspath(self):
-            class Path:
-                def __init__(self, b):
-                    self.path = b
-                def __fspath__(self):
-                    return self.path
             posix = self.posix
             bytes_dir = self.bytes_dir
             if bytes_dir is None:
                 skip("encoding not good enough")
-            dest = Path(bytes_dir + b"/file.txt")
-            posix.symlink(Path(bytes_dir + b"/somefile"), dest)
+            dest = self.Path(bytes_dir + b"/file.txt")
+            posix.symlink(self.Path(bytes_dir + b"/somefile"), dest)
             try:
                 with open(dest) as f:
                     data = f.read()
@@ -1548,6 +1549,7 @@
                 return 4
 
         raises(TypeError, self.posix.fspath, WrongSample())
+        raises(OSError, self.posix.replace, self.Path('nonexistentfile1'), 
'bok')
 
     if hasattr(rposix, 'getxattr'):
         def test_xattr_simple(self):
diff --git a/rpython/rlib/rposix.py b/rpython/rlib/rposix.py
--- a/rpython/rlib/rposix.py
+++ b/rpython/rlib/rposix.py
@@ -1262,18 +1262,16 @@
 @replace_os_function('rename')
 @specialize.argtype(0, 1)
 def rename(path1, path2):
-    if not _WIN32:
-        handle_posix_error('rename',
-                           c_rename(_as_bytes0(path1), _as_bytes0(path2)))
-    else:
+    if _WIN32:
         traits = _preferred_traits2(path1, path2)
         win32traits = make_win32_traits(traits)
         path1 = traits.as_str0(path1)
         path2 = traits.as_str0(path2)
-        assert isinstance(path1, unicode)
-        assert isinstance(path2, unicode)
         if not win32traits.MoveFileEx(path1, path2, 0):
             raise rwin32.lastSavedWindowsError()
+    else:
+        handle_posix_error('rename',
+                           c_rename(_as_bytes0(path1), _as_bytes0(path2)))
 
 @specialize.argtype(0, 1)
 def replace(path1, path2):
@@ -1282,8 +1280,6 @@
         win32traits = make_win32_traits(traits)
         path1 = traits.as_str0(path1)
         path2 = traits.as_str0(path2)
-        assert isinstance(path1, unicode)
-        assert isinstance(path2, unicode)
         ret = win32traits.MoveFileEx(path1, path2,
                      win32traits.MOVEFILE_REPLACE_EXISTING)
         if not ret:
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to