Author: Matti Picus <[email protected]>
Branch:
Changeset: r98585:cad029326210
Date: 2020-01-26 08:36 +0200
http://bitbucket.org/pypy/pypy/changeset/cad029326210/
Log: fix curses tests and make sure ffi.string returns str for python3
diff --git a/lib-python/2.7/test/test_curses.py
b/lib-python/2.7/test/test_curses.py
--- a/lib-python/2.7/test/test_curses.py
+++ b/lib-python/2.7/test/test_curses.py
@@ -15,7 +15,8 @@
import tempfile
import unittest
-from test.test_support import requires, import_module, verbose, run_unittest
+from test.test_support import (requires, import_module, verbose, run_unittest,
+ cpython_only)
# Optionally test curses module. This currently requires that the
# 'curses' resource be given on the regrtest command line using the -u
@@ -276,6 +277,7 @@
msg='userptr should fail since not set'):
p.userptr()
+ @cpython_only
def test_userptr_memory_leak(self):
w = curses.newwin(10, 10)
p = curses.panel.new_panel(w)
@@ -288,6 +290,7 @@
self.assertEqual(sys.getrefcount(obj), nrefs,
"set_userptr leaked references")
+ @cpython_only
def test_userptr_segfault(self):
panel = curses.panel.new_panel(self.stdscr)
class A:
diff --git a/lib_pypy/_curses.py b/lib_pypy/_curses.py
--- a/lib_pypy/_curses.py
+++ b/lib_pypy/_curses.py
@@ -57,7 +57,7 @@
if key_n == b"UNKNOWN KEY":
continue
if not isinstance(key_n, str): # python 3
- key_n = key_n.decode()
+ key_n = key_n.decode('utf-8')
key_n = key_n.replace('(', '').replace(')', '')
globals()[key_n] = key
@@ -83,7 +83,9 @@
def _ensure_initialised_color():
- if not _initialised and _initialised_color:
+ if not _initialised:
+ raise error("must call initscr() first")
+ if not _initialised_color:
raise error("must call start_color() first")
@@ -420,11 +422,16 @@
val = lib.keyname(val)
if val == ffi.NULL:
return ""
- return ffi.string(val)
+ key_n = ffi.string(val)
+ if not isinstance(key_n, str):
+ key_n = key_n.decode('utf-8')
+ return key_n
@_argspec(0, 1, 2)
def getstr(self, y, x, n=1023):
n = min(n, 1023)
+ if n < 0:
+ raise ValueError("'n' must be nonnegative")
buf = ffi.new("char[1024]") # /* This should be big enough.. I hope */
if y is None:
@@ -467,6 +474,8 @@
@_argspec(0, 1, 2)
def instr(self, y, x, n=1023):
n = min(n, 1023)
+ if n < 0:
+ raise ValueError("'n' must be nonnegative")
buf = ffi.new("char[1024]") # /* This should be big enough.. I hope */
if y is None:
code = lib.winnstr(self._win, buf, n)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit