[Checkins] SVN: z3c.testsetup/branches/0.2/ Merge changes for
zope.app.testing-less setups in bugfix version.
Uli Fouquet
uli at gnufix.de
Wed Jun 25 11:20:54 EDT 2008
Log message for revision 87763:
Merge changes for zope.app.testing-less setups in bugfix version.
Changed:
U z3c.testsetup/branches/0.2/CHANGES.txt
U z3c.testsetup/branches/0.2/src/z3c/testsetup/__init__.py
U z3c.testsetup/branches/0.2/src/z3c/testsetup/doctesting.py
D z3c.testsetup/branches/0.2/src/z3c/testsetup/ftesting.zcml
A z3c.testsetup/branches/0.2/src/z3c/testsetup/functional/
D z3c.testsetup/branches/0.2/src/z3c/testsetup/functionaldoctestsetup.txt
A z3c.testsetup/branches/0.2/src/z3c/testsetup/nozopeapptesting.txt
U z3c.testsetup/branches/0.2/src/z3c/testsetup/testgetter.py
U z3c.testsetup/branches/0.2/src/z3c/testsetup/testgetter.txt
U z3c.testsetup/branches/0.2/src/z3c/testsetup/testrunner.txt
U z3c.testsetup/branches/0.2/src/z3c/testsetup/tests/test_testsetup.py
-=-
Modified: z3c.testsetup/branches/0.2/CHANGES.txt
===================================================================
--- z3c.testsetup/branches/0.2/CHANGES.txt 2008-06-25 15:16:51 UTC (rev 87762)
+++ z3c.testsetup/branches/0.2/CHANGES.txt 2008-06-25 15:20:53 UTC (rev 87763)
@@ -4,7 +4,15 @@
0.2.3 (unreleased)
==================
+Bug fixes
+---------
+* ``z3c.testsetup`` really shouldn't require ``zope.app.testing`` any
+ more. If you use it in an environment without this package, then you
+ cannot register functional tests, which is determined when loading
+ ``register_all_tests`` from ``z3c.testsetup``.
+
+
0.2.2 (2008-02-29)
==================
Modified: z3c.testsetup/branches/0.2/src/z3c/testsetup/__init__.py
===================================================================
--- z3c.testsetup/branches/0.2/src/z3c/testsetup/__init__.py 2008-06-25 15:16:51 UTC (rev 87762)
+++ z3c.testsetup/branches/0.2/src/z3c/testsetup/__init__.py 2008-06-25 15:20:53 UTC (rev 87763)
@@ -1,8 +1,16 @@
-from z3c.testsetup.doctesting import UnitDocTestSetup, FunctionalDocTestSetup
+from z3c.testsetup.doctesting import UnitDocTestSetup
from z3c.testsetup.testing import UnitTestSetup
from z3c.testsetup.util import get_package
-from z3c.testsetup.testgetter import (TestCollector, DocTestCollector,
- PythonTestGetter)
+try:
+ import zope.app.testing
+ from z3c.testsetup.functional.doctesting import FunctionalDocTestSetup
+ from z3c.testsetup.functional.testgetter import (
+ TestCollector, DocTestCollector, PythonTestGetter)
+except ImportError:
+ # if zope.app.testing is missing we get a reduced set of getters
+ # and collectors, i.e. a set without functional testing machinery.
+ from z3c.testsetup.testgetter import (TestCollector, DocTestCollector,
+ PythonTestGetter)
def register_all_tests(pkg_or_dotted_name, *args, **kwargs):
return TestCollector(pkg_or_dotted_name, *args, **kwargs)
Modified: z3c.testsetup/branches/0.2/src/z3c/testsetup/doctesting.py
===================================================================
--- z3c.testsetup/branches/0.2/src/z3c/testsetup/doctesting.py 2008-06-25 15:16:51 UTC (rev 87762)
+++ z3c.testsetup/branches/0.2/src/z3c/testsetup/doctesting.py 2008-06-25 15:20:53 UTC (rev 87763)
@@ -16,9 +16,6 @@
import unittest
import os.path
from zope.testing import doctest, cleanup
-from zope.app.testing.functional import (
- HTTPCaller, getRootFolder, sync, ZCMLLayer, FunctionalDocFileSuite,
- FunctionalTestSetup)
from z3c.testsetup.base import BasicTestSetup
from z3c.testsetup.util import get_package
@@ -98,93 +95,3 @@
))
return suite
-
-class FunctionalDocTestSetup(DocTestSetup):
- """A functional test setup for packages.
-
- A collection of methods to search for appropriate doctest files in
- a given package. ``FunctionalTestSetup`` is also able to
- 'register' the tests found and to deliver them as a ready-to-use
- ``unittest.TestSuite`` instance.
-
- While the functionality to search for testfiles is mostly
- inherited from the base class, the focus here is to setup the
- tests correctly.
- """
- ftesting_zcml = os.path.join(os.path.dirname(__file__),
- 'ftesting.zcml')
- layer = ZCMLLayer(ftesting_zcml, __name__,
- 'FunctionalLayer')
-
- globs=dict(http=HTTPCaller(),
- getRootFolder=getRootFolder,
- sync=sync
- )
-
- optionflags = (doctest.ELLIPSIS+
- doctest.NORMALIZE_WHITESPACE+
- doctest.REPORT_NDIFF)
-
- regexp_list = [
- '^\s*:(T|t)est-(L|l)ayer:\s*(functional)\s*',
- ]
-
- checker = None
-
- def __init__(self, package, checker=None, zcml_config = None,
- layer_name='FunctionalLayer', layer=None, **kw):
- DocTestSetup.__init__(self, package, **kw)
- self.checker = checker
- # Setup a new layer if specified in params...
- if zcml_config is not None and layer is None:
- if not os.path.isfile(zcml_config):
- zcml_config = os.path.join(
- os.path.dirname(self.package.__file__),
- zcml_config)
- self.layer = ZCMLLayer(zcml_config, self.package.__name__,
- layer_name)
- elif layer is None:
- # Look for ftesting.zcml in pkg-root...
- pkg_ftesting_zcml = os.path.join(
- os.path.dirname(self.package.__file__), 'ftesting.zcml')
- if os.path.isfile(pkg_ftesting_zcml):
- self.layer = ZCMLLayer(pkg_ftesting_zcml,
- self.package.__name__, layer_name)
- # Passing a ready-for-use layer overrides layer specified by
- # zcml_config...
- if layer is not None:
- self.layer = layer
- return
-
- def setUp(self, test):
- FunctionalTestSetup().setUp()
-
- def tearDown(self, test):
- FunctionalTestSetup().tearDown()
-
- def suiteFromFile(self, name):
- suite = unittest.TestSuite()
- if os.path.isabs(name):
- # We get absolute pathnames, but we need relative ones...
- common_prefix = os.path.commonprefix([self.package.__file__, name])
- name = name[len(common_prefix):]
- test = FunctionalDocFileSuite(
- name, package=self.package,
- setUp=self.setUp, tearDown=self.tearDown,
- globs=self.globs,
- optionflags=self.optionflags,
- encoding=self.encoding,
- checker=self.checker,
- **self.additional_options
- )
- test.layer = self.layer
- suite.addTest(test)
- return suite
-
- def getTestSuite(self):
- docfiles = self.getDocTestFiles(package=self.package)
- suite = unittest.TestSuite()
- for name in docfiles:
- suite.addTest(self.suiteFromFile(name))
- return suite
-
Deleted: z3c.testsetup/branches/0.2/src/z3c/testsetup/ftesting.zcml
===================================================================
--- z3c.testsetup/branches/0.2/src/z3c/testsetup/ftesting.zcml 2008-06-25 15:16:51 UTC (rev 87762)
+++ z3c.testsetup/branches/0.2/src/z3c/testsetup/ftesting.zcml 2008-06-25 15:20:53 UTC (rev 87763)
@@ -1,14 +0,0 @@
-<configure
- xmlns="http://namespaces.zope.org/zope"
- i18n_domain="zope"
- >
-
- <!--
- This is only a dummy layer to enable local tests and avoid
- dependencies from packages we do not need badly.
-
- For tests that include testbrowser tests and similar, write your
- own ftesting.zcml with registration of principals etc.
- -->
-
-</configure>
Copied: z3c.testsetup/branches/0.2/src/z3c/testsetup/functional (from rev 87762, z3c.testsetup/branches/ulif-sepfunctesting/src/z3c/testsetup/functional)
Deleted: z3c.testsetup/branches/0.2/src/z3c/testsetup/functionaldoctestsetup.txt
===================================================================
--- z3c.testsetup/branches/0.2/src/z3c/testsetup/functionaldoctestsetup.txt 2008-06-25 15:16:51 UTC (rev 87762)
+++ z3c.testsetup/branches/0.2/src/z3c/testsetup/functionaldoctestsetup.txt 2008-06-25 15:20:53 UTC (rev 87763)
@@ -1,485 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2008 Zope Corporation 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.
-#
-##############################################################################
-"""
-=========================
-Functional Doc Test Setup
-=========================
-
-``FunctionalDocTestSetup`` helps to find and setup functional doctests
-contained in a package. The most important method therefore might be
-``getTestSuite()``, which searches a given package for doctest files
-and returns all tests found as a suite of functional doctests.
-
-Functional doctest setups find and register only doctests. Those tests
-can also be Python modules but if you defined real `unttest.TestCase`
-classes in your tests, then you most likely have 'normal' Python unit
-tests. Please see 'pythontestsetup.txt' in this case. For simple unit
-doctests, that do not require a more or less complex framework setup
-to be done for each test, the setups described in
-'unitdoctestsetup.txt' might suit your needs better.
-
-There are also real 'oneliners' possible, that wrap around the classes
-described here. See 'README.txt' to learn more about that.
-
-The work is done mainly in two stages:
-
-1) The package is searched for appropriate docfiles, based on the
- settings of instance attributes.
-
-2) The tests contained in the found docfiles are setup as functional
- tests and added to a ``unittest.TestSuite`` instance.
-
-There are plenty of default values active, if you use instances of
-this class without further modifications. Therefore we will first
-discuss the default behaviour and afterwards show, how you can modify
-this behaviour to suit your special expectations on the tests.
-
-
-Setting up a simple test suite
-------------------------------
-
-We want to register the doctests contained in the local ``cave``
-package. This can be simply archieved by doing::
-
- >>> from z3c.testsetup import FunctionalDocTestSetup
- >>> setup = FunctionalDocTestSetup('z3c.testsetup.tests.cave')
- >>> setup
- <z3c.testsetup.doctesting.FunctionalDocTestSetup object at 0x...>
-
-Apparently the package to handle was passed as a string in 'dotted
-name' notation. We could also pass the package itself, if it was
-loaded before::
-
- >>> from z3c.testsetup.tests import cave
- >>> setup = FunctionalDocTestSetup(cave)
- >>> setup
- <z3c.testsetup.doctesting.FunctionalDocTestSetup object at 0x...>
-
-This setup is ready for use::
-
- >>> suite = setup.getTestSuite()
- >>> suite
- <unittest.TestSuite tests=[...]>
-
-To sum it up, writing a test setup for a project now can be that
-short::
-
- import z3c.testsetup
- def test_suite():
- setup = z3c.testsetup.FunctionalDocTestSetup('z3c.testsetup.tests.cave')
- return setup.getTestSuite()
-
-This will find all .rst and .txt files in the package that provide a
-certain signature (see below), register the contained tests as
-functional tests and run them as part of a `unittest.TestSuite`.
-
-Note: in many test setups you will find a code fragment like the
- following at the end of file::
-
- if __name__ == '__main__':
- unittest.main(default='test_suite')
-
- This is not neccessary for usual testrunner setups. A testrunner
- will look for appropriate filenames (modules) and if those
- modules provide a callable ``test_suite`` (usually a function)
- this callable will be called to deliver a test suite.
-
-FunctionalDocTestSetup default values
--------------------------------------
-
-Understanding the defaults is important, because the default values
-are driving the whole process of finding and registering the test.
-
-
-Which files are found by default?
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-Basically, all files are accepted that
-
-1) reside inside the package passed to the constructor. This includes
- subdirectories.
-
-2) have a filename extension `.txt` or `.rst` (uppercase, lowercase
- etc. does not matter).
-
-3) are *not* located inside a 'hidden' directory (i.e. a directory
- starting with a dot ('.'). Also subdirectories of 'hidden'
- directories are skipped.
-
-4) contain a ReStructured Text meta-marker somewhere, that defines the
- file as a functional doctest explicitly::
-
- :Test-Layer: functional
-
- This means: there *must* be a line like the above one in the
- doctest file. The term might be preceeded or followed by whitspace
- characters (spaces, tabs).
-
-Only files, that meet all four conditions are searched for functional
-doctests. You can modify this behaviour of course, which will be
-explained below in detail.
-
-
-What options are set by default?
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-Many options can be set, when registering functional doctests. When
-using the default set of options, the following values are set::
-
-* The setup-instance's ``setUp``-method is set as the ``setUp``
- function.
-
-* The setup-instance's ``tearDown``-method is set as the ``tearDown``
- function.
-
- >>> setup.setUp
- <bound method FunctionalDocTestSetup.setUp of
- <z3c.testsetup.doctesting.FunctionalDocTestSetup object at 0x...>>
-
-* The setup-instance's `globs` attribute is passed as the `globs`
- parameter. By default `globs` is a dictionary of functions, that
- should be'globally' available during testruns and it contains::
-
- >>> setup.globs
- {'http': <zope.app.testing.functional.HTTPCaller object at 0x...>,
- 'sync': <function sync at 0x...>,
- 'getRootFolder': <function getRootFolder at 0x...>}
-
- The functions `sync` and `getRootFolder` are provided by
- `zope.app.testing.functional`.
-
-* The setup-instance's `optionsflags` attribute is passed. It
- includes by default the following doctest constants:
-
- >>> from zope.testing import doctest
- >>> setup.optionflags == (doctest.ELLIPSIS+
- ... doctest.NORMALIZE_WHITESPACE |
- ... doctest.REPORT_NDIFF)
- True
-
-* The setup-instances `encoding` attribute is passed. Setting it in
- the constructor will expect doctest files to provide the appropriate
- encoding. By default it is set to 'utf-8':
-
- >>> setup.encoding
- 'utf-8'
-
- You can set it to a another value for differently encoded doctests.
- If no encoding is set (`encoding` is None), 7-bit ASCII will be
- assumed.
-
-* The `checker` attribute helps to renormalize expected
- output. A typical output checker can be created like this::
-
- >>> import re
- >>> from zope.testing import renormalizing
- >>> mychecker = renormalizing.RENormalizing([
- ... (re.compile('[0-9]*[.][0-9]* seconds'),
- ... '<SOME NUMBER OF> seconds'),
- ... (re.compile('at 0x[0-9a-f]+'), 'at <SOME ADDRESS>'),
- ... ])
-
- By default a `FunctionalDocTest` instance has no checker::
-
- >>> setup.checker is None
- True
-
-Because functional tests require a ZCML layer, that defines a ZCML
-setup for the tests, we provide a layer, that is driven by the file
-`ftesting.zcml`, which comes with `z3c.testsetup`. The layer is
-accessible as the setup instance attribute `layer`::
-
- >>> setup.layer
- <zope.app.testing.functional.ZCMLLayer instance at 0x...>
-
- >>> setup.layer.config_file
- '...ftesting.zcml'
-
-You can define a custom layer. This is described below.
-
-
-No other options/parameters are set by default.
-
-
-Customizing functional test setup:
-----------------------------------
-
-You can modify the behaviour of z3c.testsetup.FunctionalTestSetup such,
-that a different set of files is registered and/or the found tests are
-registered with a different set of parameters/options. We will first
-discuss modifying the set of files to be searched.
-
-
-Customizing the doctest file search:
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-The searching of appropriate doctest files is basically done by the
-base class `BasicTestSetup`. Its purpose is to determine the set of
-files in a package, that contain functional tests. See the testfile
-`basicsetup.txt` to learn more about the procedure.
-
-The functional test setup, however, provides a special
-`isDocTestFile()` method, which does additional checking. Namely it
-checks for the existance of the above mentioned ReStructured Text
-meta-marker::
-
- `:Test-Layer: functional`
-
-This is determined by a list of regular expressions, which is also
-available as an object attribute::
-
- >>> setup.regexp_list
- ['^\\s*:(T|t)est-(L|l)ayer:\\s*(functional)\\s*']
-
-This is the default value of functional doctest setups.
-
-There are two files in the `cave` subpackage, which include that
-marker. We can get the list of test files using
-`getDocTestFiles()``::
-
- >>> testfile_list = setup.getDocTestFiles()
- >>> testfile_list.sort()
- >>> testfile_list
- ['...file1.txt', '...subdirfile.txt']
-
- >>> len(testfile_list)
- 2
-
-The ``isTestFile()`` method of our setup object did the filtering
-here::
-
- >>> setup.isTestFile(testfile_list[0])
- True
-
-The file file1.rst does not contain a functional test marker::
-
- >>> import os.path
- >>> path = os.path.join(os.path.dirname(cave.__file__),
- ... 'test1.rst')
- >>> setup.isTestFile(path)
- False
-
-The `regexp_list` attribute of a ``FunctionalTestSetup`` contains a
-list of regular expressions, of which each one must at least match one
-line of a searched file to be accepted. If you want to include files
-with different marker-strings, just change this attribute. The value
-will influence behaviour of the `isTestFile()``, ``getDocTestFiles()``
-and ``getTestSuite()`` methods.
-
-If you need more complex checks here, you can derive your customized
-test setup class and overwrite ``isTestFile()``.
-
-See `basicsetup.py` for further methods how to modify test file
-search, for example by choosing another set of accepted filename
-extensions.
-
-
-Customizing the functional doctest setup
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-To customize the setup of your tests, you have three options:
-
-- Pass appropriate parameters to the constructor.
-
-- Set attributes of an existing `FunctionalDocTestSetup` instance.
-
-- Create your own class derived from `FunctionalDocTestSetup`.
-
-The first two ways should suit most testing environments. All the
-attributes mentioned above are settable at creation time, namely:
-
-- `setup`::
-
- >>> def myfunc(test):
- ... """A useless function."""
- ... print "Hello!"
- >>> mysetup = FunctionalDocTestSetup(cave, setup=myfunc)
- >>> mysetup.setUp(None)
- Hello!
-
-- `teardown`::
-
- >>> mysetup = FunctionalDocTestSetup(cave, teardown=myfunc)
- >>> mysetup.tearDown(None)
- Hello!
-
-- `globs`:
-
- `globs` is a dictionary of things (objects, functions, vars) that
- are available for every test immediately (without import or
- similar)::
-
- >>> mysetup = FunctionalDocTestSetup(
- ... cave, globs={'myfunc': myfunc})
- >>> mysetup.globs
- {'myfunc': <function myfunc at 0x...>}
-
-- `optionflags`
-
- See the `zope.testing.doctest` module for all optionflags::
-
- >>> from zope.testing import doctest
- >>> mysetup = FunctionalDocTestSetup(
- ... cave, optionflags=(doctest.ELLIPSIS +
- ... doctest.REPORT_UDIFF))
- >>> mysetup.optionflags & doctest.REPORT_NDIFF == 0
- True
-
- >>> mysetup.optionflags & doctest.REPORT_UDIFF == doctest.REPORT_UDIFF
- True
-
-- `checker`
-
- An output checker for functional doctests. `None` by default. A
- typical output checker can be created like this::
-
- >>> import re
- >>> from zope.testing import renormalizing
- >>> mychecker = renormalizing.RENormalizing([
- ... (re.compile('[0-9]*[.][0-9]* seconds'),
- ... '<SOME NUMBER OF> seconds'),
- ... (re.compile('at 0x[0-9a-f]+'), 'at <SOME ADDRESS>') ])
-
- Then, a setup with this checker can be created::
-
- >>> mysetup = FunctionalDocTestSetup(cave, checker = mychecker)
- >>> mysetup.checker
- <zope.testing.renormalizing.RENormalizing instance at 0x...>
-
- Let's see, whether we got the wanted checker, by passing an
- example string, which should match the first of the terms defined
- in the checker::
-
- >>> mysetup.checker.check_output(
- ... '''\
- ... Test took 0.012 seconds
- ... ''', '''\
- ... Test took <SOME NUMBER OF> seconds
- ... ''', 0)
- True
-
- See the `zope.testing.renormalizing` module for more things, you
- can do with checkers.
-
-- `encoding`
-
- If your doctests contain non-ASCII characters, this might lead to
- problems. You can circumvent this by setting an appropriate
- encoding string in the header of your doctest files. Another
- possibility is to pass the encoding keyword. By default
- z3c.testsetup uses 'utf-8' as default encoding::
-
- >>> setup.encoding
- 'utf-8'
-
- But you can set it as you like::
-
- >>> mysetup = FunctionalDocTestSetup(cave, encoding = 'ascii')
- >>> mysetup.encoding
- 'ascii'
-
-To setup layers, there are the following constructor options
-available:
-
-- `zcml_config`
-
- The path to a ZCML file, often named `ftesting.zcml`. If a
- package, provides a file `ftesting.zcml` in its root, then this is
- taken as default. The ``cave_to_let`` package in the tests/
- directory provides such an `ftesting.zcml`::
-
- >>> from z3c.testsetup.tests import cave_to_let
- >>> setup = FunctionalDocTestSetup(cave_to_let)
- >>> pnorm(setup.layer.config_file)
- '.../tests/cave_to_let/ftesting.zcml'
-
- The fallback-solution is to take the layer from the
- `z3c.testsetup` package::
-
- >>> setup = FunctionalDocTestSetup(cave)
- >>> pnorm(setup.layer.config_file)
- '...z3c/testsetup/ftesting.zcml'
-
- Now the fallback `ftesting.zcml` was taken, because the cave got
- no own ftesting.zcml.
-
-- `layer_name`
-
- A string. The default is ``FunctionalLayer``.
-
-- `layer`
-
- A ``zope.app.testing.functional.ZCMLLayer`` object. Setting a
- layer overrides `zcml_config` and `layer_name`.
-
-Their usage is explained in the next section.
-
-
-Cutomizing the ZCML layer
-+++++++++++++++++++++++++
-
-The ZCML layer of a FunctionalDocTestSetup is searched in four steps:
-
-1) If a setup is called with `layer` parameter, take this.
-
-2) If a setup is called with `zcml_config` paramter, take this.
-
-3) If an `ftesting.zcml` can be found in the root of the package to
- search, take this (default).
-
-4) Take the (very poor) ftesting.zcml of the z3c.testsetup package
- (fallback).
-
-The ZCML layer registered as fallback by ``z3c.testsetup`` is very
-poor. In fact it only exists, to satisfy dependencies. In most cases,
-you would like to write your own ZCML configuration to register
-principals etc. during functional doctests.
-
-For this purpose, ``FunctionalDocTestSetup`` supports the constructor
-parameters `zcml_config` and `layer_name`. If the first is set, then
-the ZCML file denoted by the path in this variable will be used
-instead of the dummy ZCML contained in ``z3c.testsetup``.
-
- >>> setup_w_custom_layer = FunctionalDocTestSetup(
- ... cave,
- ... zcml_config = 'sampleftesting.zcml')
- >>> pnorm(setup_w_custom_layer.layer.config_file)
- '.../tests/cave/sampleftesting.zcml'
-
-You can also pass a keyword parameter `layer`, which should provide a
-value with a ready-to-use ZCML layer. If this happens, the
-`zcml_config` and `layer_name` parameter will have no effect.
-
-To show this, we first create a custom layer::
-
- >>> from zope.app.testing.functional import ZCMLLayer
- >>> mylayer = ZCMLLayer(
- ... os.path.join(os.path.dirname(__file__), 'ftesting.zcml'),
- ... __name__,
- ... 'MyFunctionalLayer')
-
-and create a functional doctest setup with it::
-
- >>> setup_w_custom_layer = FunctionalDocTestSetup(
- ... cave,
- ... zcml_config = 'sampleftesting.zcml',
- ... layer = mylayer)
- >>> pnorm(setup_w_custom_layer.layer.config_file)
- '.../testsetup/ftesting.zcml'
-
-As we can see, the `mylayer` config file is registered and the
-`zcml_config` parameter was skipped.
-
-
-"""
Copied: z3c.testsetup/branches/0.2/src/z3c/testsetup/nozopeapptesting.txt (from rev 87762, z3c.testsetup/branches/ulif-sepfunctesting/src/z3c/testsetup/nozopeapptesting.txt)
===================================================================
--- z3c.testsetup/branches/0.2/src/z3c/testsetup/nozopeapptesting.txt (rev 0)
+++ z3c.testsetup/branches/0.2/src/z3c/testsetup/nozopeapptesting.txt 2008-06-25 15:20:53 UTC (rev 87763)
@@ -0,0 +1,80 @@
+===================================
+Testsetups without zope.app.testing
+===================================
+
+In some packages zope.app.testing might not be available or it is not
+wanted. This is important for ``z3c.testsetup`` because functional
+tests require that package for setup, etc. For example when it comes
+to plain Python packages.
+
+The ``z3c.testsetup`` package in this case should provide us reduced
+sets of test collectors automatically and run all but the functional
+tests.
+
+To simulate this, we removed ``zope.app.testing`` from the registered
+modules in ``sys.modules`` before running this testfile and reloaded
+the z3c.testsetup package. The latter is necessary, because
+z3c.testsetup decides on import time, whether zope.app.testing is
+available and then provides different testgetters and -collectors.
+
+We can see this when we do a testsetup, that would normally include
+functional tests. Consider the example given in the
+``samplesetup_short0.py`` setup file, which is located in the ``cave``
+package of the ``tests``::
+
+ >>> import os
+ >>> cavepath = os.path.join(os.path.dirname(__file__), 'tests', 'cave')
+ >>> setupfile = os.path.join(cavepath, 'samplesetup_short0.py')
+ >>> print open(setupfile).read()
+ import z3c.testsetup
+ test_suite = z3c.testsetup.register_all_tests('z3c.testsetup.tests.cave')
+
+It is the same setup file, that we used in testrunner.txt (at the very
+beginning). Using it there (with ``zope.app.testing`` available), this
+setup found four (successful) tests, of which two were functional
+ones.
+
+The only difference now is, that we have no ``zope.app.testing`` and
+therefore no machinery for functional tests. We can check that
+beforehand by looking at the testgetters defined in the general test
+collector::
+
+ >>> import z3c.testsetup
+ >>> from z3c.testsetup import TestCollector
+ >>> tc = z3c.testsetup.TestCollector.handled_getters
+ >>> from pprint import pprint
+ >>> pprint(sorted([str(x) for x in tc]))
+ ["<class 'z3c.testsetup.testgetter.PythonTestGetter'>",
+ "<class 'z3c.testsetup.testgetter.UnitDocTestGetter'>"]
+
+What is missing here, is the FunctionalDocTestGetter that normally
+appears here. As a result there will be less tests found and run by
+the 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.
+ False
+
+As we can see, only unit test were run and no functional ones anymore.
+
+After making zope.app.testing available again, we should get a
+different result::
+
+ >>> sys.path[:] = globals()['saved-sys-info'][0]
+ >>> sys.modules.update(globals()['saved-sys-info'][2])
+ >>> z3c.testsetup = __import__('z3c.testsetup')
+ >>> from z3c.testsetup import TestCollector
+ >>> tc = TestCollector.handled_getters
+ >>> from pprint import pprint
+ >>> pprint(sorted([str(x) for x in tc]))
+ ["<class 'z3c.testsetup.functional.testgetter.FunctionalDocTestGetter'>",
+ "<class 'z3c.testsetup.testgetter.PythonTestGetter'>",
+ "<class 'z3c.testsetup.testgetter.UnitDocTestGetter'>"]
Modified: z3c.testsetup/branches/0.2/src/z3c/testsetup/testgetter.py
===================================================================
--- z3c.testsetup/branches/0.2/src/z3c/testsetup/testgetter.py 2008-06-25 15:16:51 UTC (rev 87762)
+++ z3c.testsetup/branches/0.2/src/z3c/testsetup/testgetter.py 2008-06-25 15:20:53 UTC (rev 87763)
@@ -20,7 +20,7 @@
See testgetter.txt to learn more about this stuff.
"""
import unittest
-from z3c.testsetup.doctesting import UnitDocTestSetup, FunctionalDocTestSetup
+from z3c.testsetup.doctesting import UnitDocTestSetup
from z3c.testsetup.testing import UnitTestSetup
from z3c.testsetup.util import get_package, get_keyword_params
@@ -91,13 +91,6 @@
return self.__call__()
-class FunctionalDocTestGetter(BasicTestGetter):
- """Collect functional doctests.
- """
-
- wrapped_class = FunctionalDocTestSetup
- special_char = 'f'
-
class UnitDocTestGetter(BasicTestGetter):
"""Collect unit doctests.
"""
@@ -136,13 +129,12 @@
return suite
class DocTestCollector(BasicTestCollector):
- """A TestCollector that wraps functional doctests and unit doctests.
+ """A TestCollector that wraps unit doctests.
"""
- handled_getters = [FunctionalDocTestGetter, UnitDocTestGetter]
+ handled_getters = [UnitDocTestGetter,]
class TestCollector(BasicTestCollector):
"""A TestCollector that wraps doctests and PythonTests.
"""
- handled_getters = [FunctionalDocTestGetter, UnitDocTestGetter,
- PythonTestGetter]
+ handled_getters = [UnitDocTestGetter, PythonTestGetter]
Modified: z3c.testsetup/branches/0.2/src/z3c/testsetup/testgetter.txt
===================================================================
--- z3c.testsetup/branches/0.2/src/z3c/testsetup/testgetter.txt 2008-06-25 15:16:51 UTC (rev 87762)
+++ z3c.testsetup/branches/0.2/src/z3c/testsetup/testgetter.txt 2008-06-25 15:20:53 UTC (rev 87763)
@@ -56,7 +56,7 @@
>>> from z3c.testsetup import TestCollector
>>> collector = TestCollector('z3c.testsetup.tests.cave')
>>> collector
- <z3c.testsetup.testgetter.TestCollector object at 0x...>
+ <z3c.testsetup.functional.testgetter.TestCollector object at 0x...>
A main difference of TestGetters and TestCollectors to ordinary
TestSetups is the set of supported/accepted keyword parameters: it
@@ -98,7 +98,7 @@
TestCollector now registers three TestGetters. This is stored in the
``handled_getters`` attribute of TestCollectors::
- >>> from z3c.testsetup.testgetter import TestCollector
+ >>> from z3c.testsetup.functional.testgetter import TestCollector
>>> getter_classes = TestCollector.handled_getters
>>> getter_classes
[<class '....FunctionalDocTestGetter'>,
@@ -210,7 +210,7 @@
distinguish parameters specifically passed for your wrapper from
others. Let's create a TestGetter for functional doctest files::
- >>> from z3c.testsetup.doctesting import FunctionalDocTestSetup
+ >>> from z3c.testsetup.functional.doctesting import FunctionalDocTestSetup
>>> class CustomGetter(BasicTestGetter):
... wrapped_class = FunctionalDocTestSetup
... special_char = 'c'
@@ -427,7 +427,7 @@
>>> from z3c.testsetup import TestCollector
>>> collector = TestCollector('z3c.testsetup.tests.cave')
>>> collector
- <z3c.testsetup.testgetter.TestCollector object at 0x...>
+ <z3c.testsetup.functional.testgetter.TestCollector object at 0x...>
The package can passed as string in 'dotted name' notation or as real
package::
@@ -435,7 +435,7 @@
>>> from z3c.testsetup.tests import cave
>>> collector = TestCollector(cave)
>>> collector
- <z3c.testsetup.testgetter.TestCollector object at 0x...>
+ <z3c.testsetup.functional.testgetter.TestCollector object at 0x...>
If we call that getter, we should get a ``unittest.TestSuite``::
Modified: z3c.testsetup/branches/0.2/src/z3c/testsetup/testrunner.txt
===================================================================
--- z3c.testsetup/branches/0.2/src/z3c/testsetup/testrunner.txt 2008-06-25 15:16:51 UTC (rev 87762)
+++ z3c.testsetup/branches/0.2/src/z3c/testsetup/testrunner.txt 2008-06-25 15:20:53 UTC (rev 87763)
@@ -34,11 +34,11 @@
>>> testrunner.run(defaults)
Running unit tests:
Ran 2 tests with 0 failures and 0 errors in ... seconds.
- Running z3c.testsetup.doctesting.FunctionalLayer tests:
- Set up z3c.testsetup.doctesting.FunctionalLayer 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
+ Tear down z3c.testsetup....doctesting.FunctionalLayer ... not supported
Total: 4 tests, 0 failures, 0 errors in ... seconds.
False
@@ -68,11 +68,11 @@
>>> 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.
+ 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
+ Tear down z3c.testsetup....doctesting.FunctionalLayer ... not supported
Total: 3 tests, 0 failures, 0 errors in ... seconds.
False
@@ -100,11 +100,11 @@
>>> 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.
+ 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
+ Tear down z3c.testsetup....doctesting.FunctionalLayer ... not supported
Total: 3 tests, 0 failures, 0 errors in ... seconds.
False
@@ -231,11 +231,11 @@
... ]
>>> sys.argv = 'test -f '.split()
>>> testrunner.run(defaults)
- Running z3c.testsetup.doctesting.FunctionalLayer tests:
- Set up z3c.testsetup.doctesting.FunctionalLayer 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
+ Tear down z3c.testsetup....doctesting.FunctionalLayer ... not supported
False
The same setup, but without a modified checker will deliver::
@@ -246,8 +246,8 @@
... ]
>>> sys.argv = 'test -f '.split()
>>> testrunner.run(defaults)
- Running z3c.testsetup.doctesting.FunctionalLayer tests:
- Set up z3c.testsetup.doctesting.FunctionalLayer in ... seconds.
+ Running z3c.testsetup....doctesting.FunctionalLayer tests:
+ Set up z3c.testsetup....doctesting.FunctionalLayer in ... seconds.
<BLANKLINE>
<BLANKLINE>
Failure in test ...checkertest.chk
@@ -271,7 +271,7 @@
<BLANKLINE>
Ran 2 tests with 1 failures and 0 errors in ... seconds.
Tearing down left over layers:
- Tear down z3c.testsetup.doctesting.FunctionalLayer ... not supported
+ Tear down z3c.testsetup....doctesting.FunctionalLayer ... not supported
True
Note that checkers are currently only supported for functional
@@ -324,11 +324,11 @@
... ]
>>> sys.argv = 'test -f '.split()
>>> testrunner.run(defaults)
- Running z3c.testsetup.doctesting.FunctionalLayer tests:
- Set up z3c.testsetup.doctesting.FunctionalLayer in ... seconds.
+ 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
+ Tear down z3c.testsetup....doctesting.FunctionalLayer ... not supported
False
The testrunner finished without any error. So the ``basename``
@@ -356,7 +356,7 @@
... ]
>>> sys.argv = 'test -f '.split()
>>> testrunner.run(defaults)
- Running z3c.testsetup.doctesting.FunctionalLayer tests:
+ Running z3c.testsetup....doctesting.FunctionalLayer tests:
...
Ran 1 tests with 0 failures and 0 errors in ... seconds.
...
@@ -434,11 +434,11 @@
>>> 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.
+ 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
+ Tear down z3c.testsetup....doctesting.FunctionalLayer ... not supported
Total: 3 tests, 0 failures, 0 errors in ... seconds.
False
Modified: z3c.testsetup/branches/0.2/src/z3c/testsetup/tests/test_testsetup.py
===================================================================
--- z3c.testsetup/branches/0.2/src/z3c/testsetup/tests/test_testsetup.py 2008-06-25 15:16:51 UTC (rev 87762)
+++ z3c.testsetup/branches/0.2/src/z3c/testsetup/tests/test_testsetup.py 2008-06-25 15:20:53 UTC (rev 87763)
@@ -7,7 +7,8 @@
import zope.component.eventtesting
from z3c.testsetup.util import get_package
-TESTFILES = ['basicsetup.txt', 'functionaldoctestsetup.txt',
+TESTFILES = ['basicsetup.txt',
+ os.path.join('functional', 'functionaldoctestsetup.txt'),
'pythontestsetup.txt', 'unitdoctestsetup.txt', 'util.txt',
'unittestsetup.txt']
@@ -89,7 +90,44 @@
suite = unittest.TestSuite(suites)
return suite
+def zopeapptestingless_suite():
+ def setUp(test):
+ test.globs['saved-sys-info'] = (
+ sys.path[:],
+ sys.argv[:],
+ sys.modules.copy(),
+ gc.get_threshold(),
+ )
+ mlist = [x for x in sys.modules.keys()
+ if 'zope.app' in x or 'z3c.testsetup' in x]
+ for m in mlist:
+ del sys.modules[m]
+ plist = [x for x in sys.path if 'zope.app' in x]
+ for p in plist:
+ del sys.path[sys.path.index(p)]
+ test.globs['this_directory'] = os.path.split(__file__)[0]
+ test.globs['testrunner_script'] = __file__
+ test.globs['get_basenames_from_suite'] = get_basenames_from_suite
+
+ def tearDown(test):
+ sys.path[:], sys.argv[:] = test.globs['saved-sys-info'][:2]
+ gc.set_threshold(*test.globs['saved-sys-info'][3])
+ sys.modules.clear()
+ sys.modules.update(test.globs['saved-sys-info'][2])
+ suites = [
+ doctest.DocFileSuite(
+ 'nozopeapptesting.txt',
+ package='z3c.testsetup',
+ setUp=setUp, tearDown=tearDown,
+ optionflags=doctest.ELLIPSIS+doctest.NORMALIZE_WHITESPACE,
+ checker=checker),
+ ]
+
+ suite = unittest.TestSuite(suites)
+ return suite
+
+
def suiteFromFile(filename):
suite = unittest.TestSuite()
test = doctest.DocFileSuite(filename,
@@ -111,4 +149,5 @@
for name in TESTFILES:
suite.addTest(suiteFromFile(name))
suite.addTest(testrunner_suite())
+ suite.addTest(zopeapptestingless_suite())
return suite
More information about the Checkins
mailing list