[Checkins] SVN: zope.app.testing/trunk/src/zope/app/testing/ add support for product configuration in the functional test layer
Fred L. Drake, Jr.
fdrake at gmail.com
Wed Aug 20 13:07:35 EDT 2008
Log message for revision 90031:
add support for product configuration in the functional test layer
Changed:
U zope.app.testing/trunk/src/zope/app/testing/functional.py
U zope.app.testing/trunk/src/zope/app/testing/tests.py
-=-
Modified: zope.app.testing/trunk/src/zope/app/testing/functional.py
===================================================================
--- zope.app.testing/trunk/src/zope/app/testing/functional.py 2008-08-20 17:05:58 UTC (rev 90030)
+++ zope.app.testing/trunk/src/zope/app/testing/functional.py 2008-08-20 17:07:35 UTC (rev 90031)
@@ -328,7 +328,7 @@
"""
globals = sys._getframe(1).f_globals
globals[name] = ZCMLLayer(
- os.path.join(os.path.split(globals['__file__'])[0], zcml),
+ os.path.join(os.path.dirname(globals['__file__']), zcml),
globals['__name__'],
name,
allow_teardown=allow_teardown,
Modified: zope.app.testing/trunk/src/zope/app/testing/tests.py
===================================================================
--- zope.app.testing/trunk/src/zope/app/testing/tests.py 2008-08-20 17:05:58 UTC (rev 90030)
+++ zope.app.testing/trunk/src/zope/app/testing/tests.py 2008-08-20 17:07:35 UTC (rev 90031)
@@ -495,6 +495,74 @@
"""
+def doctest_ZCMLLayer_carries_product_configuration():
+ """Show that ``ZCMLLayer`` carries along product configuration.
+
+ ZCML layers can carry be defined to work with specific product
+ configuration; this is useful when application code (early subscribers,
+ including generations) need configuration data.
+
+ Let's define a couple of separate ZCML layers, and show that the
+ configuration data is properly associated with each, and applied at
+ appropriate times.
+
+ We'll need two distinct product configurations:
+
+ >>> product_config_one = '''
+ ... <product-config abc>
+ ... key1 a1
+ ... key2 a2
+ ... </product-config>
+ ... '''
+
+ >>> product_config_two = '''
+ ... <product-config abc>
+ ... key1 b1
+ ... key2 b2
+ ... </product-config>
+ ... '''
+
+ We can create two distinct layers that use these configurations:
+
+ >>> LayerOne = functional.ZCMLLayer(
+ ... empty_zcml, 'zope.app.testing.tests', 'LayerOne',
+ ... product_config=product_config_one)
+
+ >>> LayerTwo = functional.ZCMLLayer(
+ ... empty_zcml, 'zope.app.testing.tests', 'LayerTwo',
+ ... product_config=product_config_two)
+
+ For each layer, we can see that the correct product configuration is
+ installed, and subsequent layer usages won't have problems because of the
+ previously installed layer. This checks that initialization and
+ deconstruction of the functional test setup is handled properly to allow
+ layers to be used in sequence.
+
+ Let's use a helper function to show the configuration:
+
+ >>> import pprint
+
+ >>> def show_config():
+ ... c = zope.app.appsetup.product.getProductConfiguration('abc')
+ ... pprint.pprint(c, width=1)
+
+ >>> LayerOne.setUp()
+ >>> show_config()
+ {'key1': 'a1',
+ 'key2': 'a2'}
+
+ >>> LayerOne.tearDown()
+
+ >>> LayerTwo.setUp()
+ >>> show_config()
+ {'key1': 'b1',
+ 'key2': 'b2'}
+
+ >>> LayerTwo.tearDown()
+
+ """
+
+
def test_suite():
checker = RENormalizing([
(re.compile(r'^HTTP/1.1 (\d{3}) .*?\n'), 'HTTP/1.1 \\1\n')
More information about the Checkins
mailing list