[pypy-svn] r74375 - in pypy/trunk/pypy/module/cpyext: . test
afa at codespeak.net
afa at codespeak.net
Wed May 5 11:10:00 CEST 2010
Author: afa
Date: Wed May 5 11:09:58 2010
New Revision: 74375
Modified:
pypy/trunk/pypy/module/cpyext/pyerrors.py
pypy/trunk/pypy/module/cpyext/test/test_api.py
pypy/trunk/pypy/module/cpyext/test/test_import.py
pypy/trunk/pypy/module/cpyext/test/test_pyerrors.py
Log:
PyErr_WarnEx now uses the real warnings module
Modified: pypy/trunk/pypy/module/cpyext/pyerrors.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/pyerrors.py (original)
+++ pypy/trunk/pypy/module/cpyext/pyerrors.py Wed May 5 11:09:58 2010
@@ -7,6 +7,7 @@
from pypy.module.cpyext.pyobject import (
PyObject, PyObjectP, make_ref, Py_DecRef, register_container)
from pypy.module.cpyext.state import State
+from pypy.module.cpyext.import_ import PyImport_Import
from pypy.rlib.rposix import get_errno
@cpython_api([PyObject, PyObject], lltype.Void)
@@ -188,10 +189,14 @@
For information about warning control, see the documentation for the
warnings module and the -W option in the command line
documentation. There is no C API for warning control."""
- message = rffi.charp2str(message_ptr)
if w_category is None:
- w_category = space.gettypeobject(W_RuntimeWarning.typedef)
- os.write(2, "WARNING: " + message + "\n")
+ w_category = space.w_None
+ w_message = space.wrap(rffi.charp2str(message_ptr))
+ w_stacklevel = space.wrap(stacklevel)
+
+ w_module = PyImport_Import(space, space.wrap("warnings"))
+ w_warn = space.getattr(w_module, space.wrap("warn"))
+ space.call_function(w_warn, w_message, w_category, w_stacklevel)
return 0
@cpython_api([PyObject, CONST_STRING], rffi.INT_real, error=-1)
Modified: pypy/trunk/pypy/module/cpyext/test/test_api.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/test/test_api.py (original)
+++ pypy/trunk/pypy/module/cpyext/test/test_api.py Wed May 5 11:09:58 2010
@@ -7,6 +7,7 @@
PyObject = api.PyObject
from pypy.interpreter.error import OperationError
from pypy.module.cpyext.state import State
+import os
@api.cpython_api([PyObject], lltype.Void)
def PyPy_GetWrapped(space, w_arg):
@@ -17,8 +18,17 @@
class BaseApiTest(LeakCheckingTest):
def setup_class(cls):
- cls.space = gettestobjspace(usemodules=['cpyext', 'thread'])
- cls.space.getbuiltinmodule("cpyext")
+ cls.space = space = gettestobjspace(usemodules=['cpyext', 'thread'])
+
+ # warm up reference counts:
+ # - the posix module allocates a HCRYPTPROV on Windows
+ # - writing to stderr allocates a file lock
+ space.getbuiltinmodule("cpyext")
+ space.getbuiltinmodule(os.name)
+ space.call_function(space.getattr(space.sys.get("stderr"),
+ space.wrap("write")),
+ space.wrap(""))
+
class CAPI:
def __getattr__(self, name):
return getattr(cls.space, name)
Modified: pypy/trunk/pypy/module/cpyext/test/test_import.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/test/test_import.py (original)
+++ pypy/trunk/pypy/module/cpyext/test/test_import.py Wed May 5 11:09:58 2010
@@ -2,11 +2,6 @@
from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
class TestImport(BaseApiTest):
- def setup_method(self, func):
- from pypy.module.imp.importing import importhook
- importhook(self.space, "os") # warm up reference counts
- BaseApiTest.setup_method(self, func)
-
def test_import(self, space, api):
pdb = api.PyImport_Import(space.wrap("pdb"))
assert pdb
Modified: pypy/trunk/pypy/module/cpyext/test/test_pyerrors.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/test/test_pyerrors.py (original)
+++ pypy/trunk/pypy/module/cpyext/test/test_pyerrors.py Wed May 5 11:09:58 2010
@@ -72,6 +72,13 @@
assert space.eq_w(state.operror.w_type, space.w_TypeError)
api.PyErr_Clear()
+ def test_Warning(self, space, api, capfd):
+ message = rffi.str2charp("this is a warning")
+ api.PyErr_WarnEx(None, message, 1)
+ out, err = capfd.readouterr()
+ assert ": UserWarning: this is a warning" in err
+ rffi.free_charp(message)
+
class AppTestFetch(AppTestCpythonExtensionBase):
def setup_class(cls):
AppTestCpythonExtensionBase.setup_class.im_func(cls)
@@ -129,5 +136,3 @@
except OSError, e:
assert e.errno == errno.EBADF
assert e.strerror == os.strerror(errno.EBADF)
-
-
More information about the Pypy-commit
mailing list