[pypy-svn] r75160 - in pypy/trunk/pypy/module/cpyext: . test
dan at codespeak.net
dan at codespeak.net
Mon Jun 7 02:59:44 CEST 2010
Author: dan
Date: Mon Jun 7 02:59:43 2010
New Revision: 75160
Modified:
pypy/trunk/pypy/module/cpyext/datetime.py
pypy/trunk/pypy/module/cpyext/stubs.py
pypy/trunk/pypy/module/cpyext/test/test_datetime.py
Log:
Added PyDelta_Check() and test.
Modified: pypy/trunk/pypy/module/cpyext/datetime.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/datetime.py (original)
+++ pypy/trunk/pypy/module/cpyext/datetime.py Mon Jun 7 02:59:43 2010
@@ -1,6 +1,6 @@
from pypy.rpython.lltypesystem import rffi, lltype
from pypy.module.cpyext.pyobject import PyObject
-from pypy.module.cpyext.api import cpython_api
+from pypy.module.cpyext.api import cpython_api, CANNOT_FAIL
from pypy.module.cpyext.import_ import PyImport_Import
@cpython_api([], lltype.Void)
@@ -14,3 +14,14 @@
w_datetime, "time",
space.wrap(hour), space.wrap(minute), space.wrap(second),
space.wrap(usecond))
+
+ at cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
+def PyDelta_Check(space, w_obj):
+ """Return true if ob is of type PyDateTime_DeltaType or a subtype of
+ PyDateTime_DeltaType. ob must not be NULL.
+ """
+ return space.is_true(
+ space.appexec([w_obj], """(obj):
+ from datetime import timedelta
+ return isinstance(obj, timedelta)
+ """))
Modified: pypy/trunk/pypy/module/cpyext/stubs.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/stubs.py (original)
+++ pypy/trunk/pypy/module/cpyext/stubs.py Mon Jun 7 02:59:43 2010
@@ -23,7 +23,7 @@
_inittab = lltype.Void
PyThreadState = lltype.Void
PyInterpreterState = lltype.Void
-PyOS_sighandler_t = lltype.Void
+#PyOS_sighandler_t = lltype.Void
Py_UNICODE = lltype.Void
PyCompilerFlags = lltype.Void
_node = lltype.Void
@@ -616,13 +616,6 @@
raise NotImplementedError
@cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
-def PyDelta_Check(space, ob):
- """Return true if ob is of type PyDateTime_DeltaType or a subtype of
- PyDateTime_DeltaType. ob must not be NULL.
- """
- raise NotImplementedError
-
- at cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
def PyDelta_CheckExact(space, ob):
"""Return true if ob is of type PyDateTime_DeltaType. ob must not be
NULL.
Modified: pypy/trunk/pypy/module/cpyext/test/test_datetime.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/test/test_datetime.py (original)
+++ pypy/trunk/pypy/module/cpyext/test/test_datetime.py Mon Jun 7 02:59:43 2010
@@ -5,3 +5,15 @@
def test_time(self, space, api):
w_time = api.PyTime_FromTime(23, 15, 40, 123456)
assert space.unwrap(space.str(w_time)) == '23:15:40.123456'
+ def test_deltacheck(self, space, api):
+ w_delta = space.appexec([space.wrap(3), space.wrap(15)], """(days, seconds):
+ from datetime import timedelta
+ return timedelta(days, seconds)
+ """)
+ assert api.PyDelta_Check(w_delta)
+
+ w_delta = space.appexec([space.wrap(1), space.wrap(1), space.wrap(1999)], """(day, month, year):
+ from datetime import datetime
+ return datetime.now() - datetime(year, month, day)
+ """)
+ assert api.PyDelta_Check(w_delta)
More information about the Pypy-commit
mailing list