Author: Matti Picus <matti.pi...@gmail.com> Branch: py3.6 Changeset: r98651:b0ffc7814382 Date: 2020-02-03 21:47 +0200 http://bitbucket.org/pypy/pypy/changeset/b0ffc7814382/
Log: merge default into py3.6 diff --git a/pypy/interpreter/test/test_error.py b/pypy/interpreter/test/test_error.py --- a/pypy/interpreter/test/test_error.py +++ b/pypy/interpreter/test/test_error.py @@ -146,8 +146,8 @@ [os.strerror(errno.EBADF)], None) # e = wrap_oserror(space, OSError(errno.EBADF, "foobar"), - filename = "test.py", - exception_name = "w_EnvironmentError") + filename="test.py", + w_exception_class=space.w_EnvironmentError) assert isinstance(e, OperationError) assert e.w_type == [EnvironmentError] assert e.get_w_value(space) == ([EnvironmentError], [errno.EBADF], @@ -155,8 +155,8 @@ ["test.py"]) # e = wrap_oserror(space, OSError(errno.EBADF, "foobar"), - filename = "test.py", - w_exception_class = [SystemError]) + filename="test.py", + w_exception_class=[SystemError]) assert isinstance(e, OperationError) assert e.w_type == [SystemError] assert e.get_w_value(space) == ([SystemError], [errno.EBADF], diff --git a/pypy/module/_io/interp_stringio.py b/pypy/module/_io/interp_stringio.py --- a/pypy/module/_io/interp_stringio.py +++ b/pypy/module/_io/interp_stringio.py @@ -9,19 +9,13 @@ from pypy.module._io.interp_iobase import convert_size class UnicodeIO(object): - def __init__(self, data=None, pos=0): + def __init__(self, data=None): if data is None: data = '' self.data = [] self.pos = 0 - # break the data into unicode codepoints - _pos = 0 - while _pos < pos: - _pos = next_codepoint_pos(data, _pos) - if _pos >= len(data): - break - self.write(data[_pos:]) - self.pos = pos + self.write(data) + self.pos = 0 def resize(self, newlength): if len(self.data) > newlength: 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 @@ -237,6 +237,15 @@ if encoding is not None: return space.newtext(encoding) + # Try to shortcut the app-level call if locale.CODESET works + if _WINDOWS: + return space.newtext(rlocale.getdefaultlocale()[1]) + else: + if rlocale.HAVE_LANGINFO: + codeset = rlocale.nl_langinfo(rlocale.CODESET) + if codeset: + return space.newtext(codeset) + # Try os.device_encoding(fileno) which is interp_posix.device_encoding try: w_fileno = space.call_method(w_buffer, 'fileno') diff --git a/pypy/module/_multiprocessing/test/test_interp_semaphore.py b/pypy/module/_multiprocessing/test/test_interp_semaphore.py --- a/pypy/module/_multiprocessing/test/test_interp_semaphore.py +++ b/pypy/module/_multiprocessing/test/test_interp_semaphore.py @@ -6,7 +6,8 @@ from pypy.module.thread.os_lock import _set_sentinel from pypy.module.thread.os_thread import start_new_thread from pypy.module._multiprocessing.interp_semaphore import ( - create_semaphore, sem_unlink, W_SemLock) + create_semaphore, W_SemLock) + @pytest.mark.parametrize('spaceconfig', [ {'usemodules': ['_multiprocessing', 'thread']}]) 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 @@ -26,6 +26,7 @@ mod.path3 = udir.join('unlinktestfile.txt') mod.path3.write("delete me!") pdir = udir.ensure('posixtestdir', dir=True) + pdir = udir.ensure('posixtestdir', dir=True) pdir.join('file1').write("test1") os.chmod(str(pdir.join('file1')), 0o600) pdir.join('file2').write("test2") @@ -444,7 +445,6 @@ assert isinstance(result.children_user, float) assert isinstance(result.children_system, float) assert isinstance(result.elapsed, float) - def test_strerror(self): assert isinstance(self.posix.strerror(0), str) assert isinstance(self.posix.strerror(1), str) @@ -545,7 +545,8 @@ os.execv("/bin/sh", ["sh", "-c", "echo caf\xe9 \u1234 > onefile"]) os.waitpid(pid, 0) - assert open("onefile", "rb").read() == output + with open("onefile", "rb") as fid: + asert fid.read() == output os.unlink("onefile") def test_execve(self): @@ -577,7 +578,8 @@ "echo caf\xe9 \u1234 $t > onefile"], {'ddd': 'xxx', 't': t}) os.waitpid(pid, 0) - assert open("onefile", "rb").read() == output + b'\n' + with open("onefile") as fid: + assert fid.read() == output os.unlink("onefile") pass # <- please, inspect.getsource(), don't crash @@ -606,11 +608,10 @@ def test__getfullpathname(self): # nt specific posix = self.posix - import os - sysdrv = os.getenv("SystemDrive", "C:") + sysdrv = posix.environ.get("SystemDrive", "C:") # just see if it does anything path = sysdrv + 'hubber' - assert os.sep in posix._getfullpathname(path) + assert '\\' in posix._getfullpathname(path) assert type(posix._getfullpathname(b'C:')) is bytes def test_utime(self): @@ -877,17 +878,15 @@ localdir = os.getcwd() os.mkdir(self.path2 + 'fchdir') for func in [os.fchdir, os.chdir]: + fd = os.open(self.path2 + 'fchdir', os.O_RDONLY) try: - fd = os.open(self.path2 + 'fchdir', os.O_RDONLY) - try: - func(fd) - mypath = os.getcwd() - finally: - os.close(fd) - assert mypath.endswith('test_posix2-fchdir') - raises(OSError, func, fd) + func(fd) + mypath = os.getcwd() finally: + os.close(fd) os.chdir(localdir) + assert mypath.endswith('test_posix2-fchdir') + raises(OSError, func, fd) raises(ValueError, os.fchdir, -1) if hasattr(rposix, 'pread'): @@ -1295,7 +1294,7 @@ # working? def test_has_kill(self): - import os + os = self.posix assert hasattr(os, 'kill') def test_pipe_flush(self): @@ -1604,6 +1603,7 @@ def setup_class(cls): cls.w_posix = space.appexec([], GET_POSIX) cls.w_path = space.wrap(str(path)) + cls.w_posix = space.appexec([], GET_POSIX) def test_environ(self): environ = self.posix.environ @@ -1638,7 +1638,7 @@ if hasattr(__import__(os.name), "unsetenv"): def test_unsetenv_nonexisting(self): - import os + os = self.posix os.unsetenv("XYZABC") #does not raise try: os.environ["ABCABC"] diff --git a/pypy/module/select/interp_select.py b/pypy/module/select/interp_select.py --- a/pypy/module/select/interp_select.py +++ b/pypy/module/select/interp_select.py @@ -50,7 +50,7 @@ fd = space.c_filedescriptor_w(w_fd) if fd not in self.fddict: raise wrap_oserror(space, OSError(errno.ENOENT, "poll.modify"), - exception_name='w_IOError') + w_exception_class=space.w_IOError) self.fddict[fd] = events def unregister(self, space, w_fd): _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit