[Zope-Checkins] SVN: Zope/trunk/doc/WHATSNEW.rst Updated the what's new in AQ section with philiKON's feedback
Log message for revision 97621: Updated the what's new in AQ section with philiKON's feedback Changed: U Zope/trunk/doc/WHATSNEW.rst -=- Modified: Zope/trunk/doc/WHATSNEW.rst === --- Zope/trunk/doc/WHATSNEW.rst 2009-03-07 11:39:13 UTC (rev 97620) +++ Zope/trunk/doc/WHATSNEW.rst 2009-03-07 12:33:39 UTC (rev 97621) @@ -134,26 +134,31 @@ inherit from the Acquisition base classes. As a result almost no external package could directly work inside Zope2 but required an integration layer. -With this version of Zope2 classes do have a second option of providing -location awareness to Zope API's in a transparent way. The second option is the -`zope.location http://pypi.python.org/pypi/zope.location`_ API as described -by the ILocation interface. +With this version of Zope2, objects have a new option of providing location +awareness to Zope APIs. This new option is to provide an explicit parent +pointer in the ``__parent__`` attribute, much like specified by the ILocation +API from `zope.location http://pypi.python.org/pypi/zope.location`_. Browser +views and other location-dependent components implement ILocation already. -Classes implementing this interface get `__parent__` pointers set to their -container object, when being put into the container. Code that operates on such -objects can then walk up the containment hierarchy by following the pointers. -In Acquisition based classes no information would be stored on the objects, but -Acquisition wrappers are constructed around the objects instead. Only those -wrappers would hold the container references. The Acquisition wrapping relies -on the objects to provide an `__of__` method as done by the Acquisition base -classes. +Classes adhering to this convention need to get `__parent__` pointers set to +their container object, when being put into the container. Code that operates +on such objects can then walk up the containment hierarchy by following the +pointers. In Acquisition based classes no information would be stored on the +objects, but Acquisition wrappers are constructed around the objects instead. +Only those wrappers would hold the container references. The Acquisition +wrapping relies on the objects to provide an `__of__` method as done by the +Acquisition base classes. -The standard way of getting the container of an instance is to call:: +The most common way of getting the container of an instance is to call:: from Acquisition import aq_parent container = aq_parent(instance) +For instances providing the ILocation interface the common way is:: + + container = instance.__parent__ + There are various `aq_*` methods available for various other tasks related to locating objects in the containment hierarchy. So far virtually all objects in Zope2 would participate in Acquisition. As a side-effect many people relied on @@ -174,53 +179,58 @@ In addition to this check you should no longer rely on the `aq_*` methods to be available as attributes. While all code inside Zope2 itself still supports -this, it does no longer rely on thosem but makes proper use of the functions +this, it does no longer rely on those but makes proper use of the functions provided by the Acquisition package. To understand the interaction between the new and old approach here is a little example:: - class O(object): + class Location(object): ... def __init__(self, name): - ... self.__name__ = str(name) + ... self.__name__ = name ... def __repr__(self): - ... return self.__class__.__name__ + self.__name__ + ... return self.__name__ # Create an Acquisition variant of the class: - from Acquisition import Implicit - class I(O, Implicit): + import Acquisition + class Implicit(Location, Acquisition.Implicit): ... pass - i1 = I(1) - i2 = I(2) - o1 = O(1) - o2 = O(2) + # Create two implicit instances: + root = Implicit('root') + folder = Implicit('folder') + + # And two new Acquisition-free instances: + + container = Location('container') + item = Location('item') + # Provide the containment hints: - i2 = i2.__of__(i1) - o1.__parent__ = i2 - o2.__parent__ = o1 + folder = folder.__of__(root) + container.__parent__ = folder + item.__parent__ = container # Test the containtment chain: from Acquisition import aq_parent - aq_parent(o1) - I2 + aq_parent(container) + folder from Acquisition import aq_chain - aq_chain(o2) - [O2, O1, I2, I1] + aq_chain(item) + [item, container, folder, root] # Explicit pointers take precedence over Acquisition wrappers: - i3 = I(3) - i3 = i3.__of__(i2) - i3.__parent__ = o1 + item2 = Implicit('item2') + item2 = item2.__of__(folder) + item2.__parent__ = container - aq_chain(i3) - [I3, O1, I2, I1] + aq_chain(item2) + [item2, container, folder, root] For a less abstract example, you so far had
[Zope-Checkins] SVN: Zope/trunk/src/OFS/ObjectManager.py cfg.zopehome is no longer part of the default configuration.
Log message for revision 97638: cfg.zopehome is no longer part of the default configuration. Changed: U Zope/trunk/src/OFS/ObjectManager.py -=- Modified: Zope/trunk/src/OFS/ObjectManager.py === --- Zope/trunk/src/OFS/ObjectManager.py 2009-03-07 20:08:53 UTC (rev 97637) +++ Zope/trunk/src/OFS/ObjectManager.py 2009-03-07 20:50:40 UTC (rev 97638) @@ -618,7 +618,7 @@ raise BadRequest, 'Invalid file name %s' % escape(file) cfg = getConfiguration() -for impath in (cfg.instancehome, cfg.zopehome): +for impath in (cfg.instancehome, getattr(cfg, 'zopehome', '')): filepath = os.path.join(impath, 'import', file) if os.path.exists(filepath): break ___ Zope-Checkins maillist - Zope-Checkins@zope.org http://mail.zope.org/mailman/listinfo/zope-checkins
[Zope-Checkins] SVN: Zope/trunk/src/OFS/ObjectManager.py Extract _getImportPaths method.
Log message for revision 97639: Extract _getImportPaths method. Changed: U Zope/trunk/src/OFS/ObjectManager.py -=- Modified: Zope/trunk/src/OFS/ObjectManager.py === --- Zope/trunk/src/OFS/ObjectManager.py 2009-03-07 20:50:40 UTC (rev 97638) +++ Zope/trunk/src/OFS/ObjectManager.py 2009-03-07 21:16:37 UTC (rev 97639) @@ -618,7 +618,7 @@ raise BadRequest, 'Invalid file name %s' % escape(file) cfg = getConfiguration() -for impath in (cfg.instancehome, getattr(cfg, 'zopehome', '')): +for impath in self._getImportPaths(): filepath = os.path.join(impath, 'import', file) if os.path.exists(filepath): break @@ -655,8 +655,7 @@ ob=self._getOb(id) ob.manage_changeOwnershipType(explicit=0) -def list_imports(self): -listing = [] +def _getImportPaths(self): cfg = getConfiguration() paths = [] zopehome = getattr(cfg, 'zopehome', None) @@ -664,7 +663,11 @@ paths.append(zopehome) if not cfg.instancehome in paths: paths.append(cfg.instancehome) -for impath in paths: +return paths + +def list_imports(self): +listing = [] +for impath in self._getImportPaths(): directory = os.path.join(impath, 'import') if not os.path.isdir(directory): continue ___ Zope-Checkins maillist - Zope-Checkins@zope.org http://mail.zope.org/mailman/listinfo/zope-checkins
[Zope-Checkins] SVN: Zope/trunk/src/Testing/ZopeTestCase/ Remove testrunner boilerplate.
Log message for revision 97640: Remove testrunner boilerplate. Changed: U Zope/trunk/src/Testing/ZopeTestCase/testBaseTestCase.py U Zope/trunk/src/Testing/ZopeTestCase/testFunctional.py U Zope/trunk/src/Testing/ZopeTestCase/testInterfaces.py U Zope/trunk/src/Testing/ZopeTestCase/testPlaceless.py U Zope/trunk/src/Testing/ZopeTestCase/testPortalTestCase.py U Zope/trunk/src/Testing/ZopeTestCase/testPythonScript.py U Zope/trunk/src/Testing/ZopeTestCase/testSkeleton.py U Zope/trunk/src/Testing/ZopeTestCase/testWebserver.py U Zope/trunk/src/Testing/ZopeTestCase/testZODBCompat.py U Zope/trunk/src/Testing/ZopeTestCase/testZopeTestCase.py U Zope/trunk/src/Testing/ZopeTestCase/zopedoctest/testAuthHeaderTest.py U Zope/trunk/src/Testing/ZopeTestCase/zopedoctest/testFunctionalDocTest.py U Zope/trunk/src/Testing/ZopeTestCase/zopedoctest/testPackageAsProduct.py U Zope/trunk/src/Testing/ZopeTestCase/zopedoctest/testWarningsTest.py U Zope/trunk/src/Testing/ZopeTestCase/zopedoctest/testZopeDocTest.py -=- Modified: Zope/trunk/src/Testing/ZopeTestCase/testBaseTestCase.py === --- Zope/trunk/src/Testing/ZopeTestCase/testBaseTestCase.py 2009-03-07 21:16:37 UTC (rev 97639) +++ Zope/trunk/src/Testing/ZopeTestCase/testBaseTestCase.py 2009-03-07 21:48:23 UTC (rev 97640) @@ -21,10 +21,6 @@ $Id$ -import os, sys -if __name__ == '__main__': -execfile(os.path.join(sys.path[0], 'framework.py')) - import transaction from Testing.ZopeTestCase import base @@ -463,6 +459,3 @@ suite.addTest(makeSuite(TestRequestGarbage3)) return suite -if __name__ == '__main__': -framework() - Modified: Zope/trunk/src/Testing/ZopeTestCase/testFunctional.py === --- Zope/trunk/src/Testing/ZopeTestCase/testFunctional.py 2009-03-07 21:16:37 UTC (rev 97639) +++ Zope/trunk/src/Testing/ZopeTestCase/testFunctional.py 2009-03-07 21:48:23 UTC (rev 97640) @@ -18,10 +18,6 @@ $Id$ -import os, sys -if __name__ == '__main__': -execfile(os.path.join(sys.path[0], 'framework.py')) - from Testing import ZopeTestCase ZopeTestCase.installProduct('PythonScripts') @@ -206,6 +202,3 @@ suite.addTest(makeSuite(TestFunctional)) return suite -if __name__ == '__main__': -framework() - Modified: Zope/trunk/src/Testing/ZopeTestCase/testInterfaces.py === --- Zope/trunk/src/Testing/ZopeTestCase/testInterfaces.py 2009-03-07 21:16:37 UTC (rev 97639) +++ Zope/trunk/src/Testing/ZopeTestCase/testInterfaces.py 2009-03-07 21:48:23 UTC (rev 97640) @@ -15,10 +15,6 @@ $Id$ -import os, sys -if __name__ == '__main__': -execfile(os.path.join(sys.path[0], 'framework.py')) - from Testing.ZopeTestCase import * from Testing.ZopeTestCase.interfaces import * @@ -99,6 +95,3 @@ suite.addTest(makeSuite(TestPortalTestCase)) return suite -if __name__ == '__main__': -framework() - Modified: Zope/trunk/src/Testing/ZopeTestCase/testPlaceless.py === --- Zope/trunk/src/Testing/ZopeTestCase/testPlaceless.py2009-03-07 21:16:37 UTC (rev 97639) +++ Zope/trunk/src/Testing/ZopeTestCase/testPlaceless.py2009-03-07 21:48:23 UTC (rev 97640) @@ -15,10 +15,6 @@ $Id$ -import os, sys -if __name__ == '__main__': -execfile(os.path.join(sys.path[0], 'framework.py')) - from Testing import ZopeTestCase from Testing.ZopeTestCase.placeless import setUp, tearDown @@ -92,6 +88,3 @@ suite.addTest(makeSuite(TestPlacelessSetUp)) return suite -if __name__ == '__main__': -framework() - Modified: Zope/trunk/src/Testing/ZopeTestCase/testPortalTestCase.py === --- Zope/trunk/src/Testing/ZopeTestCase/testPortalTestCase.py 2009-03-07 21:16:37 UTC (rev 97639) +++ Zope/trunk/src/Testing/ZopeTestCase/testPortalTestCase.py 2009-03-07 21:48:23 UTC (rev 97640) @@ -21,10 +21,6 @@ $Id$ -import os, sys -if __name__ == '__main__': -execfile(os.path.join(sys.path[0], 'framework.py')) - from Testing import ZopeTestCase from Acquisition import aq_base @@ -523,6 +519,3 @@ suite.addTest(makeSuite(TestSetUpRaises)) return suite -if __name__ == '__main__': -framework() - Modified: Zope/trunk/src/Testing/ZopeTestCase/testPythonScript.py === --- Zope/trunk/src/Testing/ZopeTestCase/testPythonScript.py 2009-03-07 21:16:37 UTC (rev 97639) +++ Zope/trunk/src/Testing/ZopeTestCase/testPythonScript.py 2009-03-07 21:48:23 UTC (rev 97640) @@ -25,10 +25,6 @@ $Id$ -import os, sys -if __name__ == '__main__': -execfile(os.path.join(sys.path[0], 'framework.py')) - from Testing import ZopeTestCase
[Zope-Checkins] SVN: Zope/trunk/src/Testing/ZopeTestCase/ Remove ancient testrunner.
Log message for revision 97641: Remove ancient testrunner. Changed: D Zope/trunk/src/Testing/ZopeTestCase/runalltests.py D Zope/trunk/src/Testing/ZopeTestCase/zopedoctest/runalltests.py D Zope/trunk/src/Testing/ZopeTestCase/ztc_common.py -=- Deleted: Zope/trunk/src/Testing/ZopeTestCase/runalltests.py === --- Zope/trunk/src/Testing/ZopeTestCase/runalltests.py 2009-03-07 21:48:23 UTC (rev 97640) +++ Zope/trunk/src/Testing/ZopeTestCase/runalltests.py 2009-03-07 21:57:53 UTC (rev 97641) @@ -1,52 +0,0 @@ -## -# -# Copyright (c) 2005 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. -# -## -Runs all tests in the current directory [and below] - -Execute like: - python runalltests.py [-R] - -$Id$ - - -__version__ = '0.3.1' - -import os, sys -if __name__ == '__main__': -execfile(os.path.join(sys.path[0], 'framework.py')) - -import unittest -TestRunner = unittest.TextTestRunner -suite = unittest.TestSuite() -cwd = os.getcwd() - -def test_finder(recurse, dir, names): -if dir == os.curdir or '__init__.py' in names: -parts = [x for x in dir[len(os.curdir):].split(os.sep) if x] -tests = [x for x in names if x.startswith('test') and x.endswith('.py')] -for test in tests: -if test == 'tests.py' and 'ZopeTestCase' in cwd: -# Skip tests.py when running ZTC tests -continue -modpath = parts + [test[:-3]] -m = __import__('.'.join(modpath)) -for part in modpath[1:]: -m = getattr(m, part) -if hasattr(m, 'test_suite'): -suite.addTest(m.test_suite()) -if not recurse: -names[:] = [] - -if __name__ == '__main__': -os.path.walk(os.curdir, test_finder, '-R' in sys.argv) -TestRunner().run(suite) - Deleted: Zope/trunk/src/Testing/ZopeTestCase/zopedoctest/runalltests.py === --- Zope/trunk/src/Testing/ZopeTestCase/zopedoctest/runalltests.py 2009-03-07 21:48:23 UTC (rev 97640) +++ Zope/trunk/src/Testing/ZopeTestCase/zopedoctest/runalltests.py 2009-03-07 21:57:53 UTC (rev 97641) @@ -1,52 +0,0 @@ -## -# -# Copyright (c) 2005 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. -# -## -Runs all tests in the current directory [and below] - -Execute like: - python runalltests.py [-R] - -$Id$ - - -__version__ = '0.3.1' - -import os, sys -if __name__ == '__main__': -execfile(os.path.join(sys.path[0], 'framework.py')) - -import unittest -TestRunner = unittest.TextTestRunner -suite = unittest.TestSuite() -cwd = os.getcwd() - -def test_finder(recurse, dir, names): -if dir == os.curdir or '__init__.py' in names: -parts = [x for x in dir[len(os.curdir):].split(os.sep) if x] -tests = [x for x in names if x.startswith('test') and x.endswith('.py')] -for test in tests: -if test == 'tests.py' and 'ZopeTestCase' in cwd: -# Skip tests.py when running ZTC tests -continue -modpath = parts + [test[:-3]] -m = __import__('.'.join(modpath)) -for part in modpath[1:]: -m = getattr(m, part) -if hasattr(m, 'test_suite'): -suite.addTest(m.test_suite()) -if not recurse: -names[:] = [] - -if __name__ == '__main__': -os.path.walk(os.curdir, test_finder, '-R' in sys.argv) -TestRunner().run(suite) - Deleted: Zope/trunk/src/Testing/ZopeTestCase/ztc_common.py === --- Zope/trunk/src/Testing/ZopeTestCase/ztc_common.py 2009-03-07 21:48:23 UTC (rev 97640) +++ Zope/trunk/src/Testing/ZopeTestCase/ztc_common.py 2009-03-07 21:57:53 UTC (rev 97641) @@ -1,171 +0,0 @@
[Zope-Checkins] SVN: Zope/trunk/src/Testing/ZopeTestCase/ Reverted r90443 and r90454. We keep the shopping cart tests working by including a copy of Examples.zexp.
Log message for revision 97643: Reverted r90443 and r90454. We keep the shopping cart tests working by including a copy of Examples.zexp. Changed: U Zope/trunk/src/Testing/ZopeTestCase/doc/ENVIRONMENT.txt U Zope/trunk/src/Testing/ZopeTestCase/doc/HOWTO.stx U Zope/trunk/src/Testing/ZopeTestCase/doc/README.stx U Zope/trunk/src/Testing/ZopeTestCase/doc/TIMELINES.txt U Zope/trunk/src/Testing/ZopeTestCase/testBaseTestCase.py U Zope/trunk/src/Testing/ZopeTestCase/testPortalTestCase.py A Zope/trunk/src/Testing/ZopeTestCase/testShoppingCart.py U Zope/trunk/src/Testing/ZopeTestCase/testZopeTestCase.py A Zope/trunk/src/Testing/ZopeTestCase/testimport/ A Zope/trunk/src/Testing/ZopeTestCase/testimport/Examples.zexp -=- Modified: Zope/trunk/src/Testing/ZopeTestCase/doc/ENVIRONMENT.txt === --- Zope/trunk/src/Testing/ZopeTestCase/doc/ENVIRONMENT.txt 2009-03-07 22:04:50 UTC (rev 97642) +++ Zope/trunk/src/Testing/ZopeTestCase/doc/ENVIRONMENT.txt 2009-03-07 22:26:44 UTC (rev 97643) @@ -2,9 +2,14 @@ ZTC makes the following assumptions about its environment: a) The 'ZopeTestCase' package is installed in the Zope trunk inside the - 'Testing' module. + 'Testing' module, which means: SOFTWARE_HOME/Testing/ZopeTestCase. -b) The somewhat weak assumption is that ZTC can walk up the directory tree from +b) A 'Products' directory exists inside SOFTWARE_HOME and INSTANCE_HOME. + +c) The tests (the 'tests' subdirectories) are located either below a + SOFTWARE_HOME or INSTANCE_HOME, typically in Products/MyCoolProduct/tests. + +d) The somewhat weak assumption is that ZTC can walk up the directory tree from 'tests', and find a 'Products' directory. This is how INSTANCE_HOME detection works. It regrettably fails on some filesystems when symbolic links are involved (a solution is detailed below, so hang on). @@ -19,7 +24,8 @@ ZTC attempts to resolve this by detecting an INSTANCE_HOME for 1) but leaving -the actual environment variable untouched. +the actual environment variable untouched so 2) works by still pointing into +SOFTWARE_HOME/Testing. As soon as I allow you to set INSTANCE_HOME yourself, I lose the ability to distinguish whether you mean 1) or 2) or both. Modified: Zope/trunk/src/Testing/ZopeTestCase/doc/HOWTO.stx === --- Zope/trunk/src/Testing/ZopeTestCase/doc/HOWTO.stx 2009-03-07 22:04:50 UTC (rev 97642) +++ Zope/trunk/src/Testing/ZopeTestCase/doc/HOWTO.stx 2009-03-07 22:26:44 UTC (rev 97643) @@ -176,6 +176,9 @@ It demonstrates how to manipulate the test user's roles and permissions and how security is validated. +- **'testShoppingCart.py'** tests the ShoppingCart example. This test + uses Sessions and shows how to test a TTW Zope application. + - **'testFunctional.py'** demonstrates the new functional testing features. Tests may call 'self.publish()' to simulate URL calls to the ZPublisher. Modified: Zope/trunk/src/Testing/ZopeTestCase/doc/README.stx === --- Zope/trunk/src/Testing/ZopeTestCase/doc/README.stx 2009-03-07 22:04:50 UTC (rev 97642) +++ Zope/trunk/src/Testing/ZopeTestCase/doc/README.stx 2009-03-07 22:26:44 UTC (rev 97643) @@ -43,9 +43,27 @@ Note that there is a skeleton test suite named 'testSkeleton.py' that you may copy into your 'tests' directory and take it from there. +Note also that when the tests are run in an INSTANCE_HOME installation of +Zope, you must set the SOFTWARE_HOME environment variable for the 'Testing' +and 'ZopeTestCase' packages to be found. + See the sample tests in the 'ZopeTestCase' directory for details on writing your own tests. +framework.py + +1. Uses SOFTWARE_HOME (if set) to locate the Testing package. + +2. Detects and handles INSTANCE_HOME installations of Zope. Please + see ENVIRONMENT.txt for the assumptions ZTC makes about its + environment. + +3. Supports setting up a ZODB from a 'custom_zodb.py' file in + the 'tests' directory. + +4. Allows to connect to a running ZEO server by setting the + ZEO_INSTANCE_HOME environment variable. + testrunner.py Alternatively, you may use Zope's testrunner utility to run your tests @@ -53,7 +71,8 @@ installation). If you do so, you will have to define a 'test_suite' method in your modules (see examples). -You may have to provide the -i flag when testing in an INSTANCE_HOME setup. +There is no need to set SOFTWARE_HOME when using the testrunner but you may +have to provide the -i flag when testing in an INSTANCE_HOME setup. Example: 'python /path/to/Zope/utilities/testrunner.py -q -i -a' Modified: Zope/trunk/src/Testing/ZopeTestCase/doc/TIMELINES.txt