Mailing List Archive

CVS: Products/Basket/tests - testBasket.py:1.45
Update of /cvs-repository/Products/Basket/tests
In directory cvs.zope.org:/tmp/cvs-serv10113/tests

Modified Files:
testBasket.py
Log Message:
Fix tests to do a pseudo-PlacelessSetup style z3 environment setup.


=== Products/Basket/tests/testBasket.py 1.44 => 1.45 ===
--- Products/Basket/tests/testBasket.py:1.44 Mon Dec 12 10:48:46 2005
+++ Products/Basket/tests/testBasket.py Mon Dec 12 16:28:15 2005
@@ -17,7 +17,8 @@
import tempfile
from Products.Five.traversable import FakeRequest

-from zope.app.tests.placelesssetup import PlacelessSetup
+from zope.component.tests.placelesssetup import PlacelessSetup as \
+ CAPlacelessSetup
from zope.component import getView

here = os.path.dirname(__file__)
@@ -107,9 +108,17 @@
def legacymethod(self):
pass

-class TestBasket(unittest.TestCase, PlacelessSetup, LogInterceptor):
+class TestBasket(unittest.TestCase, LogInterceptor):

def setUp(self):
+ # we don't derive from PlacelessSetup because we want to be able
+ # to directly execute zcml as opposed to emulating an environment
+ # with provideAdapter and friends. The below just does what that
+ # might have done (and has mirror code in tearDown)
+ from zope.app.schema.vocabulary import ZopeVocabularyRegistry
+ import zope.app.schema.vocabulary
+ zope.app.schema.vocabulary.vocabularyService = ZopeVocabularyRegistry()
+
self.working_set = pkg_resources.working_set
self.oldsyspath = sys.path[:]
self.oldsysmodules = copy.copy(sys.modules)
@@ -134,6 +143,12 @@
Products.__path__[:] = self.oldproductpath
App.config.getConfiguration().debug_mode = self.old_debug_mode

+ from zope.app.schema.vocabulary import ZopeVocabularyRegistry
+ import zope.app.schema.vocabulary
+ zope.app.schema.vocabulary.vocabularyService = ZopeVocabularyRegistry()
+ from zope.component.service import serviceManager
+ serviceManager._clear()
+
def _getTargetClass(self):
from Products.Basket.basket import Basket
return Basket
@@ -445,13 +460,14 @@
timestampFile = os.path.join(distDir, 'timestamp-%s' % eggName)

self.failUnless(os.path.isdir(distDir))
- timestamp = (os.path.getatime(timestampFile), os.path.getmtime(timestampFile))
+ timestamp = (os.path.getatime(timestampFile),
+ os.path.getmtime(timestampFile))

self.failUnless(os.path.getatime(testEgg) == timestamp[0])
self.failUnless(os.path.getmtime(testEgg) == timestamp[1])

basket.cleanup()
- shutil.rmtree(testDir, ignore_errors=True)
+ shutil.rmtree(testDir, ignore_errors=True)

def test_product_distributions_by_dwim(self):
basket = self._makeOne()
@@ -599,47 +615,44 @@
products = findProducts()
self.assert_(Products.fiveproduct in products)

- try:
- # do what Five.loadProduct does
- sitezcml = """\
- <configure xmlns="http://namespaces.zope.org/zope"
- xmlns:five="http://namespaces.zope.org/five">
- <include package="Products.Five" />
- <include package="Products.fiveproduct"/>
- </configure>"""
+ # do what Five.loadProduct does
+ sitezcml = """\
+ <configure xmlns="http://namespaces.zope.org/zope"
+ xmlns:five="http://namespaces.zope.org/five">
+ <include package="Products.Five" />
+ <include package="Products.fiveproduct"/>
+ </configure>"""

- xmlconfig.string(sitezcml)
+ xmlconfig.string(sitezcml)

- # verify that the zcml had the correct effect
+ # verify that the zcml had the correct effect

- from Products.fiveproduct.module import SampleAdapter
- from Products.fiveproduct.module import ISampleAdapter
- from Products.fiveproduct.module import ExtraSampleAdapter
- from Products.fiveproduct.module import IExtraSampleAdapter
+ from Products.fiveproduct.module import SampleAdapter
+ from Products.fiveproduct.module import ISampleAdapter
+ from Products.fiveproduct.module import ExtraSampleAdapter
+ from Products.fiveproduct.module import IExtraSampleAdapter

- context = None
+ context = None

- adapter = ISampleAdapter(context)
- self.assertEqual(adapter.__class__, SampleAdapter)
- self.assertEqual(adapter.context, context)
+ adapter = ISampleAdapter(context)
+ self.assertEqual(adapter.__class__, SampleAdapter)
+ self.assertEqual(adapter.context, context)

- adapter = IExtraSampleAdapter(context)
- self.assertEqual(adapter.__class__, ExtraSampleAdapter)
- self.assertEqual(adapter.context, context)
+ adapter = IExtraSampleAdapter(context)
+ self.assertEqual(adapter.__class__, ExtraSampleAdapter)
+ self.assertEqual(adapter.context, context)

- view = getView(object(), 'example_view', FakeRequest())
+ view = getView(object(), 'example_view', FakeRequest())

- self.failUnless(view is not None)
- finally:
- # clean up
- PlacelessSetup.tearDown(self)
+ self.failUnless(view is not None)

def test_five_product_with_no_Products_namespace(self):
basket = self._makeOne()
from Products.Basket import monkeypatches
monkeypatches.patch_findProducts(basket)

- basket.pdist_fname = os.path.join(self.fixtures,'pdist-fiveproduct2.txt')
+ basket.pdist_fname = os.path.join(self.fixtures,
+ 'pdist-fiveproduct2.txt')

sys.path.append(self.fixtures)
self.working_set.add_entry(self.fixtures)
@@ -662,29 +675,23 @@
products = findProducts()
self.assert_(fiveproduct2 in products)

- try:
- # do what Five.loadProduct does
- sitezcml = """\
- <configure xmlns="http://namespaces.zope.org/zope"
- xmlns:five="http://namespaces.zope.org/five">
- <include package="Products.Five" />
- <include package="fiveproduct2"/>
- </configure>"""
-
- xmlconfig.string(sitezcml)
+ # do what Five.loadProduct does
+ sitezcml = """\
+ <configure xmlns="http://namespaces.zope.org/zope"
+ xmlns:five="http://namespaces.zope.org/five">
+ <include package="Products.Five" />
+ <include package="fiveproduct2"/>
+ </configure>"""

- # verify that the zcml had the correct effect
+ xmlconfig.string(sitezcml)

- context = None
+ # verify that the zcml had the correct effect

- view = getView(object(), 'example_view', FakeRequest())
-
- self.failUnless(view is not None)
- finally:
- # clean up
- PlacelessSetup.tearDown(self)
+ context = None

+ view = getView(object(), 'example_view', FakeRequest())

+ self.failUnless(view is not None)

def test_remove_product_distribution_from_working_set_fixes_ns_pkgs(self):
basket = self._makeOne()

_______________________________________________
Zope-CVS maillist - Zope-CVS@zope.org
http://mail.zope.org/mailman/listinfo/zope-cvs

Zope CVS instructions: http://dev.zope.org/CVS