[Checkins] SVN: z3c.testsetup/trunk/src/z3c/testsetup/ Merge changes from new_markers branch: update doctests to reflect new zope.testing behaviour.
Uli Fouquet
uli at gnufix.de
Mon Sep 1 09:53:14 EDT 2008
Log message for revision 90645:
Merge changes from new_markers branch: update doctests to reflect new zope.testing behaviour.
Changed:
D z3c.testsetup/trunk/src/z3c/testsetup/layerrunner.txt
U z3c.testsetup/trunk/src/z3c/testsetup/nozopeapptesting.txt
U z3c.testsetup/trunk/src/z3c/testsetup/testrunner.txt
U z3c.testsetup/trunk/src/z3c/testsetup/tests/setupininit.txt
U z3c.testsetup/trunk/src/z3c/testsetup/tests/test_testsetup.py
-=-
Deleted: z3c.testsetup/trunk/src/z3c/testsetup/layerrunner.txt
===================================================================
--- z3c.testsetup/trunk/src/z3c/testsetup/layerrunner.txt 2008-09-01 13:34:39 UTC (rev 90644)
+++ z3c.testsetup/trunk/src/z3c/testsetup/layerrunner.txt 2008-09-01 13:53:14 UTC (rev 90645)
@@ -1,81 +0,0 @@
-========================
-z3c.testsetup and layers
-========================
-
-Here we discuss complete testsetups that involve test layers. Test
-layers are a method to group several tests or test suites in groups.
-
-Layers are a method to do time-consuming setups like initializing
-databases or whatever only once for a whole bunch of tests. Such you
-can save time and make your testing setup less error-prone.
-
-See `layered_cave/layer.py` for examples of working layers. We will
-use the layers defined there in the following examples.
-
-Simple unit doctests with layers
---------------------------------
-
-Using z3c.testsetup, we can define quite complex testsetups with only
-two lines of code::
-
- >>> import os
- >>> cavepath = os.path.join(os.path.dirname(__file__), 'tests',
- ... 'layered_cave')
- >>> setupfile = os.path.join(cavepath, 'layeredsetup01.py')
- >>> print open(setupfile).read()
- from z3c.testsetup import register_all_tests
- test_suite = register_all_tests('z3c.testsetup.tests.layered_cave')
-
-This means, that we want to register all tests (doctests and 'normal'
-python tests) from the ``layered_cave`` package, whose name we passed in
-dotted name notation as a string. This is enough information for a
-testrunner.
-
-In one of the test files we declared, that a layer should be used::
-
- >>> testfile = os.path.join(cavepath, 'adoctest.txt')
- >>> print open(testfile, 'r').read()
- This is a doctest
- =================
- <BLANKLINE>
- This doctest will be applied to a layer.
- <BLANKLINE>
- :Test-Layer: unit
- :Test-Layerdef: z3c.testsetup.tests.layered_cave.layer.UnitLayer1
- ...
-
-The line saying `:Test-Layerdef:` tells, that we want the layer
-denoted by the trailing dotted name should be applied to the tests of
-the file. It is vital that the denoted object really exist. The format
-of the layer declaration is::
-
- :Test-Layerdef: <dotted.name.of.layer.definition>
-
-where the marker string can be written in upper or lower or mixed
-case. Doing so, the testrunner will apply the declared layer to our
-tests::
-
- >>> import sys
- >>> defaults = [
- ... '--path', cavepath,
- ... '--tests-pattern', '^layeredsetup01$',
- ... ]
- >>> sys.argv = 'test -f'.split()
- >>> from zope.testing import testrunner
- >>> testrunner.run(defaults)
- Running z3c.testsetup.tests.layered_cave.layer.FunctionalLayer1 tests:
- Set up z3c.testsetup...yered_cave.layer.FunctionalLayer1 in ... seconds.
- Ran 1 tests with 0 failures and 0 errors in ... seconds.
- Running z3c.testsetup.tests.layered_cave.layer.UnitLayer1 tests:
- Tear down z3c.testsetup...red_cave.layer.FunctionalLayer1 in ... seconds.
- Set up z3c.testsetup...layered_cave.layer.UnitLayer1 in ... seconds.
- Running testSetUp of UnitLayer1
- Running testTearDown of UnitLayer1
- Ran 1 tests with 0 failures and 0 errors in ... seconds.
- Tearing down left over layers:
- Tear down z3c.testsetup...layered_cave.layer.UnitLayer1 in ... seconds.
- Total: 2 tests, 0 failures, 0 errors in ... seconds.
- False
-
-As we can see, the layer `UnitLayer1` was executed here.
-
Modified: z3c.testsetup/trunk/src/z3c/testsetup/nozopeapptesting.txt
===================================================================
--- z3c.testsetup/trunk/src/z3c/testsetup/nozopeapptesting.txt 2008-09-01 13:34:39 UTC (rev 90644)
+++ z3c.testsetup/trunk/src/z3c/testsetup/nozopeapptesting.txt 2008-09-01 13:53:14 UTC (rev 90645)
@@ -59,8 +59,11 @@
>>> sys.argv = 'test '.split()
>>> from zope.testing import testrunner
>>> testrunner.run(defaults)
- Running unit tests:
+ Running zope.testing.testrunner.layer.UnitTests tests:
+ Set up zope.testing.testrunner.layer.UnitTests in ... seconds.
Ran 2 tests with 0 failures and 0 errors in ... seconds.
+ Tearing down left over layers:
+ Tear down zope.testing.testrunner.layer.UnitTests in ... seconds.
False
As we can see, only unit test were run and no functional ones anymore.
Modified: z3c.testsetup/trunk/src/z3c/testsetup/testrunner.txt
===================================================================
--- z3c.testsetup/trunk/src/z3c/testsetup/testrunner.txt 2008-09-01 13:34:39 UTC (rev 90644)
+++ z3c.testsetup/trunk/src/z3c/testsetup/testrunner.txt 2008-09-01 13:53:14 UTC (rev 90645)
@@ -19,27 +19,33 @@
import z3c.testsetup
test_suite = z3c.testsetup.register_all_tests('z3c.testsetup.tests.cave')
+We clear the commandline, because all parameters passed to the
+commandline would otherwise be applied to the examples herein::
+
+ >>> import sys
+ >>> sys.argv = [sys.argv[0],]
+
This means, that we want to register all tests (doctests and 'normal'
python tests) from the ``cave`` package, whose name we passed in
dotted name notation as a string. This is enough information for a
testrunner::
- >>> import sys
>>> defaults = [
... '--path', cavepath,
... '--tests-pattern', '^samplesetup_short0$',
... ]
- >>> sys.argv = 'test '.split()
>>> from zope.testing import testrunner
>>> testrunner.run(defaults)
- Running unit tests:
- Ran 2 tests with 0 failures and 0 errors in ... seconds.
Running z3c.testsetup.functional.doctesting.FunctionalLayer tests:
- Set up z3c.testsetup....doctesting.FunctionalLayer in ... seconds.
- Ran 2 tests with 0 failures and 0 errors in ... seconds.
- Tearing down left over layers:
- Tear down z3c.testsetup....doctesting.FunctionalLayer ... not supported
- Total: 4 tests, 0 failures, 0 errors in ... seconds.
+ Set up z3c...functional.doctesting.FunctionalLayer in N.NNN seconds.
+ Ran 2 tests with 0 failures and 0 errors in N.NNN seconds.
+ Running zope.testing.testrunner.layer.UnitTests tests:
+ Tear down z3c...functional.doctesting.FunctionalLayer ... not supported
+ Running in a subprocess.
+ Set up zope.testing.testrunner.layer.UnitTests in N.NNN seconds.
+ Ran 2 tests with 0 failures and 0 errors in N.NNN seconds.
+ Tear down zope.testing.testrunner.layer.UnitTests in N.NNN seconds.
+ Total: 4 tests, 0 failures, 0 errors in N.NNN seconds.
False
Of the four tests apparently run, there is one 'normal' python test
@@ -63,17 +69,17 @@
... '--path', cavepath,
... '--tests-pattern', '^samplesetup_short1$',
... ]
- >>> sys.argv = 'test '.split()
- >>> from zope.testing import testrunner
>>> testrunner.run(defaults)
- Running unit tests:
- Ran 1 tests with 0 failures and 0 errors in ... seconds.
- Running z3c.testsetup....doctesting.FunctionalLayer tests:
- Set up z3c.testsetup....doctesting.FunctionalLayer in ... seconds.
- Ran 2 tests with 0 failures and 0 errors in ... seconds.
- Tearing down left over layers:
- Tear down z3c.testsetup....doctesting.FunctionalLayer ... not supported
- Total: 3 tests, 0 failures, 0 errors in ... seconds.
+ Running z3c.testsetup.functional.doctesting.FunctionalLayer tests:
+ Set up z3c.testsetup...doctesting.FunctionalLayer in N.NNN seconds.
+ Ran 2 tests with 0 failures and 0 errors in N.NNN seconds.
+ Running zope.testing.testrunner.layer.UnitTests tests:
+ Tear down z3c.testsetup...doctesting.FunctionalLayer ... not supported
+ Running in a subprocess.
+ Set up zope.testing.testrunner.layer.UnitTests in N.NNN seconds.
+ Ran 1 tests with 0 failures and 0 errors in N.NNN seconds.
+ Tear down zope.testing.testrunner.layer.UnitTests in N.NNN seconds.
+ Total: 3 tests, 0 failures, 0 errors in N.NNN seconds.
False
In the above setup the handled package was given as a string with
@@ -95,17 +101,17 @@
... '--path', cavepath,
... '--tests-pattern', '^samplesetup_short2$',
... ]
- >>> sys.argv = 'test '.split()
- >>> from zope.testing import testrunner
>>> testrunner.run(defaults)
- Running unit tests:
- Ran 1 tests with 0 failures and 0 errors in ... seconds.
- Running z3c.testsetup....doctesting.FunctionalLayer tests:
- Set up z3c.testsetup....doctesting.FunctionalLayer in ... seconds.
- Ran 2 tests with 0 failures and 0 errors in ... seconds.
- Tearing down left over layers:
- Tear down z3c.testsetup....doctesting.FunctionalLayer ... not supported
- Total: 3 tests, 0 failures, 0 errors in ... seconds.
+ Running z3c.testsetup.functional.doctesting.FunctionalLayer tests:
+ Set up z3c.testsetup...doctesting.FunctionalLayer in N.NNN seconds.
+ Ran 2 tests with 0 failures and 0 errors in N.NNN seconds.
+ Running zope.testing.testrunner.layer.UnitTests tests:
+ Tear down z3c.testsetup...doctesting.FunctionalLayer ... not supported
+ Running in a subprocess.
+ Set up zope.testing.testrunner.layer.UnitTests in N.NNN seconds.
+ Ran 1 tests with 0 failures and 0 errors in N.NNN seconds.
+ Tear down zope.testing.testrunner.layer.UnitTests in N.NNN seconds.
+ Total: 3 tests, 0 failures, 0 errors in N.NNN seconds.
False
Now let's run a suite of 'normal' python unit tests, i.e. tests, that
@@ -118,7 +124,6 @@
<BLANKLINE>
test_suite = z3c.testsetup.register_pytests(cave)
-
The only difference to the example before is, that we use
`register_pytests` instead of `register_doctests`. If we run this
setup with the testrunner, one test should be found and executed. This
@@ -126,17 +131,18 @@
information from the run::
>>> defaults = [
- ... '--path', cavepath,
+ ... '--path', cavepath, '-vv',
... '--tests-pattern', '^samplesetup_short3$',
... ]
- >>> sys.argv = 'test -vv'.split()
- >>> from zope.testing import testrunner
>>> testrunner.run(defaults)
Running tests at level 1
- Running unit tests:
+ Running zope.testing.testrunner.layer.UnitTests tests:
+ Set up zope.testing.testrunner.layer.UnitTests in N.NNN seconds.
Running:
testFoo (z3c.testsetup.tests.cave.file1.TestTest)
- Ran 1 tests with 0 failures and 0 errors in ... seconds.
+ Ran 1 tests with 0 failures and 0 errors in N.NNN seconds.
+ Tearing down left over layers:
+ Tear down zope.testing.testrunner.layer.UnitTests in N.NNN seconds.
False
@@ -176,17 +182,17 @@
... '--path', cavepath,
... '--tests-pattern', '^samplesetup_short4$',
... ]
- >>> sys.argv = 'test '.split()
- >>> from zope.testing import testrunner
>>> testrunner.run(defaults)
- Running unit tests:
- Ran 2 tests with 0 failures and 0 errors in ... seconds.
Running z3c.testsetup.tests.cave.SampleLayer tests:
- Set up z3c.testsetup.tests.cave.SampleLayer in ... seconds.
- Ran 2 tests with 0 failures and 0 errors in ... seconds.
- Tearing down left over layers:
+ Set up z3c.testsetup.tests.cave.SampleLayer in N.NNN seconds.
+ Ran 2 tests with 0 failures and 0 errors in N.NNN seconds.
+ Running zope.testing.testrunner.layer.UnitTests tests:
Tear down z3c.testsetup.tests.cave.SampleLayer ... not supported
- Total: 4 tests, 0 failures, 0 errors in ... seconds.
+ Running in a subprocess.
+ Set up zope.testing.testrunner.layer.UnitTests in N.NNN seconds.
+ Ran 2 tests with 0 failures and 0 errors in N.NNN seconds.
+ Tear down zope.testing.testrunner.layer.UnitTests in N.NNN seconds.
+ Total: 4 tests, 0 failures, 0 errors in N.NNN seconds.
False
Apparently now the custom ZCML file in the ``cave`` package was used.
@@ -226,14 +232,13 @@
Running the testrunner with this setup will result in::
>>> defaults = [
- ... '--path', cavepath,
+ ... '--path', cavepath, '-f',
... '--tests-pattern', '^samplesetup_short5$',
... ]
- >>> sys.argv = 'test -f '.split()
>>> testrunner.run(defaults)
Running z3c.testsetup....doctesting.FunctionalLayer tests:
- Set up z3c.testsetup....doctesting.FunctionalLayer in ... seconds.
- Ran 2 tests with 0 failures and 0 errors in ... seconds.
+ Set up z3c.testsetup....doctesting.FunctionalLayer in N.NNN seconds.
+ Ran 2 tests with 0 failures and 0 errors in N.NNN seconds.
Tearing down left over layers:
Tear down z3c.testsetup....doctesting.FunctionalLayer ... not supported
False
@@ -241,10 +246,9 @@
The same setup, but without a modified checker will deliver::
>>> defaults = [
- ... '--path', cavepath,
+ ... '--path', cavepath, '-f',
... '--tests-pattern', '^samplesetup_short6$',
... ]
- >>> sys.argv = 'test -f '.split()
>>> testrunner.run(defaults)
Running z3c.testsetup....doctesting.FunctionalLayer tests:
Set up z3c.testsetup....doctesting.FunctionalLayer in ... seconds.
@@ -319,10 +323,9 @@
``globstest.chk``::
>>> defaults = [
- ... '--path', cavepath,
+ ... '--path', cavepath, '-f',
... '--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.
@@ -351,10 +354,9 @@
)
>>> defaults = [
- ... '--path', cavepath,
+ ... '--path', cavepath, '-f',
... '--tests-pattern', '^samplesetup_short8$',
... ]
- >>> sys.argv = 'test -f '.split()
>>> testrunner.run(defaults)
Running z3c.testsetup....doctesting.FunctionalLayer tests:
...
@@ -380,21 +382,20 @@
)
>>> defaults = [
- ... '--path', cavepath,
+ ... '--path', cavepath, '-u',
... '--tests-pattern', '^samplesetup_short9$',
... ]
- >>> sys.argv = 'test -u '.split()
>>> testrunner.run(defaults)
- Running unit tests:
- Ran 2 tests with 0 failures and 0 errors in ... seconds.
+ Running zope.testing.testrunner.layer.UnitTests tests:
+ Set up zope.testing.testrunner.layer.UnitTests in N.NNN seconds.
+ Ran 2 tests with 0 failures and 0 errors in N.NNN seconds.
+ Tearing down left over layers:
+ Tear down zope.testing.testrunner.layer.UnitTests in N.NNN seconds.
False
-
-
-
Extended setups
---------------
@@ -429,17 +430,97 @@
... '--path', cavepath,
... '--tests-pattern', '^samplesetup1$',
... ]
- >>> sys.argv = 'test '.split()
>>> from zope.testing import testrunner
>>> testrunner.run(defaults)
- Running unit tests:
+ Running z3c.testsetup.functional.doctesting.FunctionalLayer tests:
+ Set up z3c.testsetup...doctesting.FunctionalLayer in N.NNN seconds.
+ Ran 2 tests with 0 failures and 0 errors in N.NNN seconds.
+ Running zope.testing.testrunner.layer.UnitTests tests:
+ Tear down z3c.testsetup...doctesting.FunctionalLayer ... not supported
+ Running in a subprocess.
+ Set up zope.testing.testrunner.layer.UnitTests in N.NNN seconds.
+ Ran 1 tests with 0 failures and 0 errors in N.NNN seconds.
+ Tear down zope.testing.testrunner.layer.UnitTests in N.NNN seconds.
+ Total: 3 tests, 0 failures, 0 errors in N.NNN seconds.
+ False
+
+We ran one unittest and two functional tests.
+
+
+z3c.testsetup and layers
+========================
+
+Here we discuss complete testsetups that involve test layers. Test
+layers are a method to group several tests or test suites in groups.
+
+Layers are a method to do time-consuming setups like initializing
+databases or whatever only once for a whole bunch of tests. Such you
+can save time and make your testing setup less error-prone.
+
+See `layered_cave/layer.py` for examples of working layers. We will
+use the layers defined there in the following examples.
+
+Simple unit doctests with layers
+--------------------------------
+
+Using z3c.testsetup, we can define quite complex testsetups with only
+two lines of code::
+
+ >>> import os
+ >>> cavepath = os.path.join(os.path.dirname(__file__), 'tests',
+ ... 'layered_cave')
+ >>> setupfile = os.path.join(cavepath, 'layeredsetup01.py')
+ >>> print open(setupfile).read()
+ from z3c.testsetup import register_all_tests
+ test_suite = register_all_tests('z3c.testsetup.tests.layered_cave')
+
+This means, that we want to register all tests (doctests and 'normal'
+python tests) from the ``layered_cave`` package, whose name we passed in
+dotted name notation as a string. This is enough information for a
+testrunner.
+
+In one of the test files we declared, that a layer should be used::
+
+ >>> testfile = os.path.join(cavepath, 'adoctest.txt')
+ >>> print open(testfile, 'r').read()
+ This is a doctest
+ =================
+ <BLANKLINE>
+ This doctest will be applied to a layer.
+ <BLANKLINE>
+ :Test-Layer: unit
+ :Test-Layerdef: z3c.testsetup.tests.layered_cave.layer.UnitLayer1
+ ...
+
+The line saying `:Test-Layerdef:` tells, that we want the layer
+denoted by the trailing dotted name should be applied to the tests of
+the file. It is vital that the denoted object really exist. The format
+of the layer declaration is::
+
+ :Test-Layerdef: <dotted.name.of.layer.definition>
+
+where the marker string can be written in upper or lower or mixed
+case. Doing so, the testrunner will apply the declared layer to our
+tests::
+
+ >>> defaults = [
+ ... '--path', cavepath, '-f',
+ ... '--tests-pattern', '^layeredsetup01$',
+ ... ]
+ >>> testrunner.run(defaults)
+ Running z3c.testsetup.tests.layered_cave.layer.FunctionalLayer1 tests:
+ Set up z3c.testsetup...yered_cave.layer.FunctionalLayer1 in ... seconds.
Ran 1 tests with 0 failures and 0 errors in ... seconds.
- Running z3c.testsetup....doctesting.FunctionalLayer tests:
- Set up z3c.testsetup....doctesting.FunctionalLayer in ... seconds.
- Ran 2 tests with 0 failures and 0 errors in ... seconds.
+ Running z3c.testsetup.tests.layered_cave.layer.UnitLayer1 tests:
+ Tear down z3c.testsetup...red_cave.layer.FunctionalLayer1 in ... seconds.
+ Set up z3c.testsetup...layered_cave.layer.UnitLayer1 in ... seconds.
+ Running testSetUp of UnitLayer1
+ Running testTearDown of UnitLayer1
+ Ran 1 tests with 0 failures and 0 errors in ... seconds.
Tearing down left over layers:
- Tear down z3c.testsetup....doctesting.FunctionalLayer ... not supported
- Total: 3 tests, 0 failures, 0 errors in ... seconds.
+ Tear down z3c.testsetup...layered_cave.layer.UnitLayer1 in ... seconds.
+ Total: 2 tests, 0 failures, 0 errors in ... seconds.
False
-We ran one unittest and two functional tests.
+As we can see, the layer `UnitLayer1` was executed here.
+
Modified: z3c.testsetup/trunk/src/z3c/testsetup/tests/setupininit.txt
===================================================================
--- z3c.testsetup/trunk/src/z3c/testsetup/tests/setupininit.txt 2008-09-01 13:34:39 UTC (rev 90644)
+++ z3c.testsetup/trunk/src/z3c/testsetup/tests/setupininit.txt 2008-09-01 13:53:14 UTC (rev 90645)
@@ -27,10 +27,18 @@
... '--tests-pattern', '^tests$',
... '--test-file-pattern', '__init__',
... ]
- >>> sys.argv = 'test '.split()
+ >>> sys.argv = [sys.argv[0]]
>>> from zope.testing import testrunner
>>> testrunner.run(defaults)
- Running unit tests:
+ Running z3c.testsetup.functional.doctesting.FunctionalLayer tests:
+ Set up z3c.testsetup...doctesting.FunctionalLayer in ... seconds.
Ran 2 tests with 0 failures and 0 errors in ... seconds.
+ Running zope.testing.testrunner.layer.UnitTests tests:
+ Tear down z3c.testsetup...doctesting.FunctionalLayer ... not supported
+ Running in a subprocess.
+ Set up zope.testing.testrunner.layer.UnitTests in ... seconds.
+ Ran 2 tests with 0 failures and 0 errors in ... seconds.
+ Tear down zope.testing.testrunner.layer.UnitTests in ... seconds.
+ Total: 4 tests, 0 failures, 0 errors in ... seconds.
False
Modified: z3c.testsetup/trunk/src/z3c/testsetup/tests/test_testsetup.py
===================================================================
--- z3c.testsetup/trunk/src/z3c/testsetup/tests/test_testsetup.py 2008-09-01 13:34:39 UTC (rev 90644)
+++ z3c.testsetup/trunk/src/z3c/testsetup/tests/test_testsetup.py 2008-09-01 13:53:14 UTC (rev 90645)
@@ -4,6 +4,7 @@
import re
import unittest
from zope.testing import doctest, cleanup, renormalizing
+from zope.testing.testrunner.tests import checker
import zope.component.eventtesting
from z3c.testsetup.util import get_package
@@ -55,14 +56,8 @@
def cleanUpZope(test):
cleanup.cleanUp()
-checker = renormalizing.RENormalizing([
- # str(Exception) has changed from Python 2.4 to 2.5 (due to
- # Exception now being a new-style class). This changes the way
- # exceptions appear in traceback printouts.
- (re.compile(r"ConfigurationExecutionError: <class '([\w.]+)'>:"),
- r'ConfigurationExecutionError: \1:'),
- ])
+
def testrunner_suite():
def setUp(test):
test.globs['saved-sys-info'] = (
@@ -82,7 +77,7 @@
sys.modules.update(test.globs['saved-sys-info'][2])
suites = [
doctest.DocFileSuite(
- 'testrunner.txt', 'README.txt', 'testgetter.txt', 'layerrunner.txt',
+ 'README.txt', 'testgetter.txt', 'testrunner.txt',
package='z3c.testsetup',
setUp=setUp, tearDown=tearDown,
optionflags=doctest.ELLIPSIS+doctest.NORMALIZE_WHITESPACE,
More information about the Checkins
mailing list