[Checkins] SVN: Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/ Add tests for globs.

Uli Fouquet uli at gnufix.de
Thu Feb 14 08:49:15 EST 2008


Log message for revision 83832:
  Add tests for globs.

Changed:
  U   Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/README.txt
  U   Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/testrunner.txt
  A   Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/tests/cave/globstest.chk
  A   Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/tests/cave/samplesetup_short7.py

-=-
Modified: Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/README.txt
===================================================================
--- Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/README.txt	2008-02-14 13:33:04 UTC (rev 83831)
+++ Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/README.txt	2008-02-14 13:49:15 UTC (rev 83832)
@@ -335,6 +335,8 @@
 
       <SOME NUBMER OF> seconds
 
+    Please see ``testrunner.txt`` for examples of usage.
+
     Checkers are applied to functional doctests only!
 
 - `globs`:
@@ -351,8 +353,11 @@
 
     If you want to register special globals for functional doctest or
     unit doctests only, then you can use the `fglobs` and/or `uglobs`
-    keyword respectively. These keywords replace any `globs` value.
+    keyword respectively. These keywords replace any `globs` value for
+    the respective kind of tests.
 
+    For more extensive examples see ``testrunner.txt``.
+
 - `setup`:
 
     A function that takes a `test` argument and is executed before

Modified: Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/testrunner.txt
===================================================================
--- Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/testrunner.txt	2008-02-14 13:33:04 UTC (rev 83831)
+++ Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/testrunner.txt	2008-02-14 13:49:15 UTC (rev 83832)
@@ -278,7 +278,60 @@
 doctests.
 
 
+Setting globals for doctests
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
+For a testsuite you can define a set of globals, which are applied to
+each test before it runs. Normally one uses such globals, to have
+certain functions or objects available, which are complex to setup
+during tests but useful.
+
+The objects and functions registered this way can then be used by
+their names in tests out-of-the-box.
+
+You can pass the globals for a testsetup by passing the ``globs``
+keyword parameter or ``fglobs``/``uglobs``, if you only want them to
+be applied to either functional or unit doctests.
+
+An example of the ``globs`` usage can be found in
+``samplesetup_short7`` of the ``cave`` package::
+
+    >>> setupfile = os.path.join(cavepath, 'samplesetup_short7.py')
+    >>> print open(setupfile).read()
+    import os
+    from zope.testing import renormalizing
+    import z3c.testsetup
+    test_suite = z3c.testsetup.register_all_tests(
+        'z3c.testsetup.tests.cave',
+        extensions = ['.chk',],
+        fregexp_list = [':Test-Layer:.*globs.*',],
+        globs = {
+            'basename' : os.path.basename
+        }
+        )
+
+Here the ``os.path.basename`` function is registered under the name
+'basename' and should be usable in the doctest file
+``globstest.chk``::
+
+    >>> defaults = [
+    ...     '--path', cavepath,
+    ...     '--tests-pattern', '^samplesetup_short7$',
+    ...     ]
+    >>> sys.argv = 'test -f '.split()
+    >>> testrunner.run(defaults)
+    Running z3c.testsetup.doctesting.FunctionalLayer tests:
+      Set up z3c.testsetup.doctesting.FunctionalLayer in ... seconds.
+      Ran 1 tests with 0 failures and 0 errors in ... seconds.
+    Tearing down left over layers:
+      Tear down z3c.testsetup.doctesting.FunctionalLayer ... not supported
+    False
+
+The testrunner finished without any error. So the ``basename``
+function was indeed known to the doctest and could be used.
+
+
+
 Extended setups
 ---------------
 

Added: Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/tests/cave/globstest.chk
===================================================================
--- Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/tests/cave/globstest.chk	                        (rev 0)
+++ Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/tests/cave/globstest.chk	2008-02-14 13:49:15 UTC (rev 83832)
@@ -0,0 +1,12 @@
+============
+Test Globals
+============
+
+:Test-Layer: globs
+
+This test tests the functionality of ``globs``. The framework should
+provide us a ``basename`` function, which we do not have to define nor
+import here::
+
+  >>> basename(__file__)
+  'globstest.chk'

Added: Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/tests/cave/samplesetup_short7.py
===================================================================
--- Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/tests/cave/samplesetup_short7.py	                        (rev 0)
+++ Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/tests/cave/samplesetup_short7.py	2008-02-14 13:49:15 UTC (rev 83832)
@@ -0,0 +1,11 @@
+import os
+from zope.testing import renormalizing
+import z3c.testsetup
+test_suite = z3c.testsetup.register_all_tests(
+    'z3c.testsetup.tests.cave',
+    extensions = ['.chk',],
+    fregexp_list = [':Test-Layer:.*globs.*',],
+    globs = {
+        'basename' : os.path.basename
+    }
+    )



More information about the Checkins mailing list