[Zope3-checkins] SVN: zope.testing/trunk/ Renamed wait_until to wait to avoid a module name with an awkward _.

Jim Fulton jim at zope.com
Sun Jan 29 14:22:07 UTC 2012


Log message for revision 124239:
  Renamed wait_until to wait to avoid a module name with an awkward _.
  

Changed:
  U   zope.testing/trunk/CHANGES.txt
  U   zope.testing/trunk/README.txt
  U   zope.testing/trunk/setup.py
  U   zope.testing/trunk/src/zope/testing/tests.py
  A   zope.testing/trunk/src/zope/testing/wait.py
  A   zope.testing/trunk/src/zope/testing/wait.txt
  D   zope.testing/trunk/src/zope/testing/wait_until.py
  D   zope.testing/trunk/src/zope/testing/wait_until.txt

-=-
Modified: zope.testing/trunk/CHANGES.txt
===================================================================
--- zope.testing/trunk/CHANGES.txt	2012-01-29 05:24:17 UTC (rev 124238)
+++ zope.testing/trunk/CHANGES.txt	2012-01-29 14:22:06 UTC (rev 124239)
@@ -1,7 +1,7 @@
 zope.testing Changelog
 **********************
 
-4.1.0 (2012-01-28)
+4.1.0 (2012-01-29)
 ==================
 
 - Added context-manager support to ``zope.testing.setupstack``
@@ -11,7 +11,7 @@
   easier to write test setup code that workes with doctests and other
   kinds of tests.
 
-- Added the ``wait_until`` module, which makes it easier to deal with
+- Added the ``wait`` module, which makes it easier to deal with
   non-deterministic timing issues.
 
 - Renamed ``zope.testing.renormalizing.RENormalizing`` to

Modified: zope.testing/trunk/README.txt
===================================================================
--- zope.testing/trunk/README.txt	2012-01-29 05:24:17 UTC (rev 124238)
+++ zope.testing/trunk/README.txt	2012-01-29 14:22:06 UTC (rev 124239)
@@ -49,9 +49,9 @@
   A simple framework for automating doctest set-up and tear-down.
   See setupstack.txt.
 
-wait_until
+wait
   A small utility for dealing with timing non-determinism
-  See wait_until.txt.
+  See wait.txt.
 
 Getting started
 ***************

Modified: zope.testing/trunk/setup.py
===================================================================
--- zope.testing/trunk/setup.py	2012-01-29 05:24:17 UTC (rev 124238)
+++ zope.testing/trunk/setup.py	2012-01-29 14:22:06 UTC (rev 124239)
@@ -42,7 +42,7 @@
     'loggingsupport.txt',
     'renormalizing.txt',
     'setupstack.txt',
-    'wait_until.txt',
+    'wait.txt',
     )])
 
 long_description=(

Modified: zope.testing/trunk/src/zope/testing/tests.py
===================================================================
--- zope.testing/trunk/src/zope/testing/tests.py	2012-01-29 05:24:17 UTC (rev 124238)
+++ zope.testing/trunk/src/zope/testing/tests.py	2012-01-29 14:22:06 UTC (rev 124239)
@@ -47,9 +47,9 @@
         doctest.DocFileSuite('renormalizing.txt', setUp=setUp),
         doctest.DocFileSuite('setupstack.txt', setUp=setUp),
         doctest.DocFileSuite(
-            'wait_until.txt', setUp=setUp,
+            'wait.txt', setUp=setUp,
             checker=renormalizing.RENormalizing([
-                (re.compile('zope.testing.wait_until.TimeOutWaitingFor: '),
+                (re.compile('zope.testing.wait.TimeOutWaitingFor: '),
                  'TimeOutWaitingFor: '),
                 ])
             ),

Copied: zope.testing/trunk/src/zope/testing/wait.py (from rev 124225, zope.testing/trunk/src/zope/testing/wait_until.py)
===================================================================
--- zope.testing/trunk/src/zope/testing/wait.py	                        (rev 0)
+++ zope.testing/trunk/src/zope/testing/wait.py	2012-01-29 14:22:06 UTC (rev 124239)
@@ -0,0 +1,68 @@
+##############################################################################
+#
+# Copyright Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+
+import time
+
+class Wait:
+
+    class TimeOutWaitingFor(Exception):
+        "A test condition timed out"
+
+    timeout = 9
+    wait = .01
+
+    def __init__(self,
+                 timeout=None, wait=None, exception=None,
+                 getnow=(lambda : time.time), getsleep=(lambda : time.sleep)):
+
+        if timeout is not None:
+            self.timeout = timeout
+
+        if wait is not None:
+            self.wait = wait
+
+        if exception is not None:
+            self.TimeOutWaitingFor = exception
+
+        self.getnow = getnow
+        self.getsleep = getsleep
+
+    def __call__(self, func=None, timeout=None, wait=None, message=None):
+        if func is None:
+            return lambda func: self(func, timeout, wait, message)
+
+        if func():
+            return
+
+        now = self.getnow()
+        sleep = self.getsleep()
+        if timeout is None:
+            timeout = self.timeout
+        if wait is None:
+            wait = self.wait
+        wait = float(wait)
+
+        deadline = now() + timeout
+        while 1:
+            sleep(wait)
+            if func():
+                return
+            if now() > deadline:
+                raise self.TimeOutWaitingFor(
+                    message or
+                    getattr(func, '__doc__') or
+                    getattr(func, '__name__')
+                    )
+
+wait = Wait()

Copied: zope.testing/trunk/src/zope/testing/wait.txt (from rev 124225, zope.testing/trunk/src/zope/testing/wait_until.txt)
===================================================================
--- zope.testing/trunk/src/zope/testing/wait.txt	                        (rev 0)
+++ zope.testing/trunk/src/zope/testing/wait.txt	2012-01-29 14:22:06 UTC (rev 124239)
@@ -0,0 +1,169 @@
+Wait until a condition holds (or until a time out)
+==================================================
+
+Often, in tests, you need to wait until some condition holds.  This
+may be because you're testing interaction with an external system or
+testing threaded (threads, processes, greenlet's, etc.) interactions.
+
+You can add sleeps to your tests, but it's often hard to know how
+long to sleep.
+
+``zope.testing.wait`` provides a convenient way to wait until
+some condition holds.  It will test a condition and, when true,
+return.  It will sleep a short time between tests.
+
+Here's a silly example, that illustrates it's use:
+
+    >>> from zope.testing.wait import wait
+    >>> wait(lambda : True)
+
+Since the condition we passed is always True, it returned
+immediately.  If the condition doesn't hold, then we'll get a timeout:
+
+    >>> wait((lambda : False), timeout=.01)
+    Traceback (most recent call last):
+    ...
+    TimeOutWaitingFor: <lambda>
+
+``wait`` has some keyword options:
+
+timeout
+   How long, in seconds, to wait for the condition to hold
+
+   Defaults to 9 seconds.
+
+wait
+   How long to wait between calls.
+
+   Defaults to .01 seconds.
+
+message
+   A message (or other data) to pass to the timeout exception.
+
+   This defaults to ``None``.  If this is false, then the callable's
+   doc string or ``__name__`` is used.
+
+``wait`` can be used as a decorator:
+
+    >>> @wait
+    ... def ok():
+    ...     return True
+
+    >>> @wait(timeout=.01)
+    ... def no_way():
+    ...     pass
+    Traceback (most recent call last):
+    ...
+    TimeOutWaitingFor: no_way
+
+    >>> @wait(timeout=.01)
+    ... def no_way():
+    ...     "never true"
+    Traceback (most recent call last):
+    ...
+    TimeOutWaitingFor: never true
+
+.. more tests
+
+    >>> import time
+    >>> now = time.time()
+    >>> @wait(timeout=.01, message='dang')
+    ... def no_way():
+    ...     "never true"
+    Traceback (most recent call last):
+    ...
+    TimeOutWaitingFor: dang
+
+    >>> .01 < (time.time() - now) < .03
+    True
+
+
+Customization
+-------------
+
+``wait`` is an instance of ``Wait``.  With ``Wait``,
+you can create you're own custom ``wait`` utilities.  For
+example, if you're testing something that uses getevent, you'd want to
+use gevent's sleep function:
+
+    >>> import zope.testing.wait
+    >>> wait = zope.testing.wait.Wait(getsleep=lambda : gevent.sleep)
+
+Wait takes a number of customization parameters:
+
+exception
+  Timeout exception class
+
+getnow
+  Function used to get a function for getting the current time.
+
+  Default: lambda : time.time
+
+getsleep
+  Function used to get a sleep function.
+
+  Default: lambda : time.sleep
+
+timeout
+  Default timeout
+
+  Default: 9
+
+wait
+  Default time to wait between attempts
+
+  Default: .01
+
+
+.. more tests
+
+    >>> def mysleep(t):
+    ...     print_('mysleep', t)
+    ...     time.sleep(t)
+
+    >>> def mynow():
+    ...     print_('mynow')
+    ...     return time.time()
+
+    >>> wait = zope.testing.wait.Wait(
+    ...    getnow=(lambda : mynow), getsleep=(lambda : mysleep),
+    ...    exception=ValueError, timeout=.02, wait=.0001)
+
+    >>> @wait
+    ... def _(state=[]):
+    ...     if len(state) > 1:
+    ...        return True
+    ...     state.append(0)
+    mynow
+    mysleep 0.0001
+    mynow
+    mysleep 0.0001
+
+    >>> @wait(wait=.002)
+    ... def _(state=[]):
+    ...     if len(state) > 1:
+    ...        return True
+    ...     state.append(0)
+    mynow
+    mysleep 0.002
+    mynow
+    mysleep 0.002
+
+    >>> @wait(timeout=0)
+    ... def _(state=[]):
+    ...     if len(state) > 1:
+    ...        return True
+    ...     state.append(0)
+    Traceback (most recent call last):
+    ...
+    ValueError: _
+
+    >>> wait = zope.testing.wait.Wait(timeout=0)
+    >>> @wait(timeout=0)
+    ... def _(state=[]):
+    ...     if len(state) > 1:
+    ...        return True
+    ...     state.append(0)
+    Traceback (most recent call last):
+    ...
+    TimeOutWaitingFor: _

Deleted: zope.testing/trunk/src/zope/testing/wait_until.py
===================================================================
--- zope.testing/trunk/src/zope/testing/wait_until.py	2012-01-29 05:24:17 UTC (rev 124238)
+++ zope.testing/trunk/src/zope/testing/wait_until.py	2012-01-29 14:22:06 UTC (rev 124239)
@@ -1,68 +0,0 @@
-##############################################################################
-#
-# Copyright Zope Foundation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-
-import time
-
-class WaitUntil:
-
-    class TimeOutWaitingFor(Exception):
-        "A test condition timed out"
-
-    timeout = 9
-    wait = .01
-
-    def __init__(self,
-                 timeout=None, wait=None, exception=None,
-                 getnow=(lambda : time.time), getsleep=(lambda : time.sleep)):
-
-        if timeout is not None:
-            self.timeout = timeout
-
-        if wait is not None:
-            self.wait = wait
-
-        if exception is not None:
-            self.TimeOutWaitingFor = exception
-
-        self.getnow = getnow
-        self.getsleep = getsleep
-
-    def __call__(self, func=None, timeout=None, wait=None, message=None):
-        if func is None:
-            return lambda func: self(func, timeout, wait, message)
-
-        if func():
-            return
-
-        now = self.getnow()
-        sleep = self.getsleep()
-        if timeout is None:
-            timeout = self.timeout
-        if wait is None:
-            wait = self.wait
-        wait = float(wait)
-
-        deadline = now() + timeout
-        while 1:
-            sleep(wait)
-            if func():
-                return
-            if now() > deadline:
-                raise self.TimeOutWaitingFor(
-                    message or
-                    getattr(func, '__doc__') or
-                    getattr(func, '__name__')
-                    )
-
-wait_until = WaitUntil()

Deleted: zope.testing/trunk/src/zope/testing/wait_until.txt
===================================================================
--- zope.testing/trunk/src/zope/testing/wait_until.txt	2012-01-29 05:24:17 UTC (rev 124238)
+++ zope.testing/trunk/src/zope/testing/wait_until.txt	2012-01-29 14:22:06 UTC (rev 124239)
@@ -1,170 +0,0 @@
-Wait until a condition holds (or until a time out)
-==================================================
-
-Often, in tests, you need to wait until some condition holds.  This
-may be because you're testing interaction with an external system or
-testing threaded (threads, processes, greenlet's, etc.) interactions.
-
-You can add sleeps to your tests, but it's often hard to know how
-long to sleep.
-
-``zope.testing.wait_until`` provides a convenient way to wait until
-some condition holds.  It will test a condition and, when true,
-return.  It will sleep a short time between tests.
-
-Here's a silly example, that illustrates it's use:
-
-    >>> from zope.testing.wait_until import wait_until
-    >>> wait_until(lambda : True)
-
-Since the condition we passed is always True, it returned
-immediately.  If the condition doesn't hold, then we'll get a timeout:
-
-    >>> wait_until((lambda : False), timeout=.01)
-    Traceback (most recent call last):
-    ...
-    TimeOutWaitingFor: <lambda>
-
-``wait_until`` has some keyword options:
-
-timeout
-   How long, in seconds, to wait for the condition to hold
-
-   Defaults to 9 seconds.
-
-wait
-   How long to wait between calls.
-
-   Defaults to .01 seconds.
-
-message
-   A message (or other data) to pass to the timeout exception.
-
-   This defaults to ``None``.  If this is false, then the callable's
-   doc string or ``__name__`` is used.
-
-``wait_until`` can be used as a decorator:
-
-    >>> @wait_until
-    ... def ok():
-    ...     return True
-
-    >>> @wait_until(timeout=.01)
-    ... def no_way():
-    ...     pass
-    Traceback (most recent call last):
-    ...
-    TimeOutWaitingFor: no_way
-
-    >>> @wait_until(timeout=.01)
-    ... def no_way():
-    ...     "never true"
-    Traceback (most recent call last):
-    ...
-    TimeOutWaitingFor: never true
-
-.. more tests
-
-    >>> import time
-    >>> now = time.time()
-    >>> @wait_until(timeout=.01, message='dang')
-    ... def no_way():
-    ...     "never true"
-    Traceback (most recent call last):
-    ...
-    TimeOutWaitingFor: dang
-
-    >>> .01 < (time.time() - now) < .03
-    True
-
-
-Customization
--------------
-
-``wait_until`` is an instance of ``WaitUntil``.  With ``WaitUntil``,
-you can create you're own custom ``wait_until`` utilities.  For
-example, if you're testing something that uses getevent, you'd want to
-use gevent's sleep function:
-
-    >>> import zope.testing.wait_until
-    >>> wait_until = zope.testing.wait_until.WaitUntil(
-    ...    getsleep=lambda : gevent.sleep)
-
-WaitUntil takes a number of customization parameters:
-
-exception
-  Timeout exception class
-
-getnow
-  Function used to get a function for getting the current time.
-
-  Default: lambda : time.time
-
-getsleep
-  Function used to get a sleep function.
-
-  Default: lambda : time.sleep
-
-timeout
-  Default timeout
-
-  Default: 9
-
-wait
-  Default time to wait between attempts
-
-  Default: .01
-
-
-.. more tests
-
-    >>> def mysleep(t):
-    ...     print_('mysleep', t)
-    ...     time.sleep(t)
-
-    >>> def mynow():
-    ...     print_('mynow')
-    ...     return time.time()
-
-    >>> wait_until = zope.testing.wait_until.WaitUntil(
-    ...    getnow=(lambda : mynow), getsleep=(lambda : mysleep),
-    ...    exception=ValueError, timeout=.02, wait=.0001)
-
-    >>> @wait_until
-    ... def _(state=[]):
-    ...     if len(state) > 1:
-    ...        return True
-    ...     state.append(0)
-    mynow
-    mysleep 0.0001
-    mynow
-    mysleep 0.0001
-
-    >>> @wait_until(wait=.002)
-    ... def _(state=[]):
-    ...     if len(state) > 1:
-    ...        return True
-    ...     state.append(0)
-    mynow
-    mysleep 0.002
-    mynow
-    mysleep 0.002
-
-    >>> @wait_until(timeout=0)
-    ... def _(state=[]):
-    ...     if len(state) > 1:
-    ...        return True
-    ...     state.append(0)
-    Traceback (most recent call last):
-    ...
-    ValueError: _
-
-    >>> wait_until = zope.testing.wait_until.WaitUntil(timeout=0)
-    >>> @wait_until(timeout=0)
-    ... def _(state=[]):
-    ...     if len(state) > 1:
-    ...        return True
-    ...     state.append(0)
-    Traceback (most recent call last):
-    ...
-    TimeOutWaitingFor: _



More information about the Zope3-Checkins mailing list