[pypy-svn] r28280 - in pypy/dist/pypy/module/time2: . test
hpk at codespeak.net
hpk at codespeak.net
Sun Jun 4 17:46:06 CEST 2006
Author: hpk
Date: Sun Jun 4 17:46:06 2006
New Revision: 28280
Added:
pypy/dist/pypy/module/time2/
pypy/dist/pypy/module/time2/README
pypy/dist/pypy/module/time2/__init__.py (contents, props changed)
pypy/dist/pypy/module/time2/interp_time.py (contents, props changed)
pypy/dist/pypy/module/time2/test/
pypy/dist/pypy/module/time2/test/__init__.py (contents, props changed)
pypy/dist/pypy/module/time2/test/test_time.py (contents, props changed)
Log:
add my try at a rctypes based time module
Added: pypy/dist/pypy/module/time2/README
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/module/time2/README Sun Jun 4 17:46:06 2006
@@ -0,0 +1,5 @@
+
+This is just some experimental code, likely
+we cannot implement a time module on top of rctypes
+as a mixed module because it would make life too hard
+for ootype backends.
Added: pypy/dist/pypy/module/time2/__init__.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/module/time2/__init__.py Sun Jun 4 17:46:06 2006
@@ -0,0 +1,11 @@
+from pypy.interpreter.mixedmodule import MixedModule
+
+class Module(MixedModule):
+ """A demo built-in module based on ctypes."""
+
+ interpleveldefs = {
+ 'clock' : 'interp_time.clock',
+ }
+
+ appleveldefs = {
+ }
Added: pypy/dist/pypy/module/time2/interp_time.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/module/time2/interp_time.py Sun Jun 4 17:46:06 2006
@@ -0,0 +1,26 @@
+from pypy.interpreter.error import OperationError
+from pypy.interpreter.baseobjspace import ObjSpace, W_Root
+from pypy.rpython.rctypes.tool import ctypes_platform
+from pypy.rpython.rctypes.tool.clib import clib
+
+import sys
+from ctypes import *
+
+class CConfig:
+ _header_ = """#include <time.h>
+"""
+ time_t = ctypes_platform.SimpleType('time_t', c_int)
+ clock_t = ctypes_platform.SimpleType('clock_t', c_int)
+ CLOCKS_PER_SEC = ctypes_platform.DefinedConstantInteger('CLOCKS_PER_SEC')
+
+cconfig = ctypes_platform.configure(CConfig)
+
+clock_t = cconfig['clock_t']
+CLOCKS_PER_SEC = cconfig['CLOCKS_PER_SEC']
+
+c_clock = clib.clock
+c_clock.restype = clock_t
+
+def clock(space):
+ return space.wrap(float(c_clock()) / CLOCKS_PER_SEC)
+clock.unwrap_spec = [ObjSpace, ]
Added: pypy/dist/pypy/module/time2/test/__init__.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/module/time2/test/__init__.py Sun Jun 4 17:46:06 2006
@@ -0,0 +1 @@
+#
Added: pypy/dist/pypy/module/time2/test/test_time.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/module/time2/test/test_time.py Sun Jun 4 17:46:06 2006
@@ -0,0 +1,25 @@
+from pypy.objspace.std import StdObjSpace
+import time
+
+def setup_module(mod):
+ mod.space = StdObjSpace(usemodules=['time2'])
+
+class TestTime:
+ def test_clock(self):
+ t0 = time.clock()
+ w_t1 = space.appexec([], """(): import time2; return time2.clock()""")
+ t2 = time.clock()
+ assert t0 <= space.unwrap(w_t1) <= t2
+
+ def XXXtest_time(self):
+ t0 = time.time()
+ w_t1 = space.appexec([], """(): import time; return time.time()""")
+ t2 = time.time()
+ assert t0 <= space.unwrap(w_t1) <= t2
+
+ def XXXtest_sleep(self):
+ w_sleep = space.appexec([], """(): import time; return time.sleep""")
+ t0 = time.time()
+ space.call_function(w_sleep, space.wrap(0.3))
+ t1 = time.time()
+ assert t1-t0 > 0.25
More information about the Pypy-commit
mailing list