[pypy-commit] pypy default: The test can't write to the 'lib' object (it is now read-only). Tweak monkey-patching.

arigo noreply at buildbot.pypy.org
Wed May 20 11:09:15 CEST 2015


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r77424:6b9fb9ee807a
Date: 2015-05-20 11:08 +0200
http://bitbucket.org/pypy/pypy/changeset/6b9fb9ee807a/

Log:	The test can't write to the 'lib' object (it is now read-only).
	Tweak monkey-patching.

diff --git a/pypy/module/test_lib_pypy/test_curses.py b/pypy/module/test_lib_pypy/test_curses.py
--- a/pypy/module/test_lib_pypy/test_curses.py
+++ b/pypy/module/test_lib_pypy/test_curses.py
@@ -19,41 +19,44 @@
 
 
 def test_color_content(monkeypatch):
-    def lib_color_content(color, r, g, b):
-        r[0], g[0], b[0] = 42, 43, 44
-        return lib.OK
-
+    class patched:
+        OK = lib.OK
+        ERR = lib.ERR
+        def color_content(self, color, r, g, b):
+            r[0], g[0], b[0] = 42, 43, 44
+            return lib.OK
     monkeypatch.setattr(_curses, '_ensure_initialised_color', lambda: None)
-    monkeypatch.setattr(lib, 'color_content', lib_color_content)
+    monkeypatch.setattr(_curses, 'lib', patched())
 
     assert _curses.color_content(None) == (42, 43, 44)
 
 
 def test_setupterm(monkeypatch):
-    def make_setupterm(err_no):
-        def lib_setupterm(term, fd, err):
-            err[0] = err_no
-
+    class make_setupterm:
+        OK = lib.OK
+        ERR = lib.ERR
+        def __init__(self, err_no):
+            self.err_no = err_no
+        def setupterm(self, term, fd, err):
+            err[0] = self.err_no
             return lib.ERR
 
-        return lib_setupterm
-
     monkeypatch.setattr(_curses, '_initialised_setupterm', False)
-    monkeypatch.setattr(lib, 'setupterm', make_setupterm(0))
+    monkeypatch.setattr(_curses, 'lib', make_setupterm(0))
 
     with pytest.raises(Exception) as exc_info:
         _curses.setupterm()
 
     assert "could not find terminal" in exc_info.value.args[0]
 
-    monkeypatch.setattr(lib, 'setupterm', make_setupterm(-1))
+    monkeypatch.setattr(_curses, 'lib', make_setupterm(-1))
 
     with pytest.raises(Exception) as exc_info:
         _curses.setupterm()
 
     assert "could not find terminfo database" in exc_info.value.args[0]
 
-    monkeypatch.setattr(lib, 'setupterm', make_setupterm(42))
+    monkeypatch.setattr(_curses, 'lib', make_setupterm(42))
 
     with pytest.raises(Exception) as exc_info:
         _curses.setupterm()


More information about the pypy-commit mailing list