[Checkins] SVN: five.hashedresource/trunk/src/five/hashedresource/ Re #4709: Remove the static resourceDir for the tests and replace it with a

Sebastian Wehrmann sw at gocept.com
Mon Jul 27 07:11:25 EDT 2009


Log message for revision 102333:
  Re #4709: Remove the static resourceDir for the tests and replace it with a
  temprary one. Fix the tests.
  

Changed:
  U   five.hashedresource/trunk/src/five/hashedresource/ftesting.zcml
  U   five.hashedresource/trunk/src/five/hashedresource/testing.py
  D   five.hashedresource/trunk/src/five/hashedresource/tests/fixture/
  U   five.hashedresource/trunk/src/five/hashedresource/tests/test_browser.py
  U   five.hashedresource/trunk/src/five/hashedresource/tests/test_hash.py
  U   five.hashedresource/trunk/src/five/hashedresource/tests/test_url.py

-=-
Modified: five.hashedresource/trunk/src/five/hashedresource/ftesting.zcml
===================================================================
--- five.hashedresource/trunk/src/five/hashedresource/ftesting.zcml	2009-07-27 11:10:17 UTC (rev 102332)
+++ five.hashedresource/trunk/src/five/hashedresource/ftesting.zcml	2009-07-27 11:11:25 UTC (rev 102333)
@@ -9,15 +9,15 @@
 
   <!-- example resource for testing -->
   <browser:resourceDirectory
-    directory="tests/fixture"
+    directory="fixture"
     name="myresource"
     />
   <browser:resource
-    file="tests/fixture/example.txt"
+    file="fixture/example.txt"
     name="example.txt"
     />
   <browser:resource
-    file="tests/fixture/test.txt"
+    file="fixture/test.txt"
     name="test.txt"
     />
 </configure>

Modified: five.hashedresource/trunk/src/five/hashedresource/testing.py
===================================================================
--- five.hashedresource/trunk/src/five/hashedresource/testing.py	2009-07-27 11:10:17 UTC (rev 102332)
+++ five.hashedresource/trunk/src/five/hashedresource/testing.py	2009-07-27 11:11:25 UTC (rev 102333)
@@ -33,28 +33,9 @@
 import zope.interface
 
 
-fixture = os.path.join(
-    os.path.dirname(five.hashedresource.tests.__file__), 'fixture')
-
-
-class HashedResourcesLayer(Testing.ZopeTestCase.layer.ZopeLiteLayer):
-
-    @classmethod
-    def setUp(cls):
-        open(os.path.join(fixture, 'example.txt'), 'w').write('')
-        Products.Five.zcml.load_config(
-            'configure.zcml', Products.Five)
-        Products.Five.zcml.load_config(
-            'ftesting-devmode.zcml', five.hashedresource)
-
-    @classmethod
-    def tearDown(cls):
-        os.unlink(os.path.join(fixture, 'example.txt'))
-
-
 class FunctionalTestCase(Testing.ZopeTestCase.FunctionalTestCase):
 
-    layer = HashedResourcesLayer
+    zcml = 'ftesting-devmode.zcml'
 
     def assertMatches(self, regex, text):
         self.assert_(re.match(regex, text), "/%s/ did not match '%s'" % (
@@ -64,9 +45,20 @@
         super(FunctionalTestCase, self).setUp()
 
         self.tmpdir = tempfile.mkdtemp()
-        open(os.path.join(self.tmpdir, 'example.txt'), 'w').write('')
-        self.dirname = os.path.basename(self.tmpdir)
+        self.fixture = os.path.join(self.tmpdir, 'fixture')
+        os.mkdir(self.fixture)
+        open(os.path.join(self.fixture, 'example.txt'), 'w').write('')
+        open(os.path.join(self.fixture, 'test.txt'), 'w').write('test\ndata\n')
 
+        for file_ in ['ftesting.zcml', 'ftesting-devmode.zcml']:
+            shutil.copy(os.path.join(os.path.dirname(__file__), file_),
+                os.path.join(self.tmpdir, file_))
+
+        Products.Five.zcml.load_config(
+            'configure.zcml', Products.Five)
+        Products.Five.zcml.load_config(
+            os.path.join(self.tmpdir, self.zcml))
+
         self.app = self._app()
         self.request = Testing.ZopeTestCase.utils.makerequest(
             self.app).REQUEST
@@ -77,6 +69,8 @@
             '++resource++myresource')
 
     def tearDown(self):
+        super(FunctionalTestCase, self).tearDown()
+        Products.Five.zcml.cleanUp()
         shutil.rmtree(self.tmpdir)
 
     def _hash(self, text):

Modified: five.hashedresource/trunk/src/five/hashedresource/tests/test_browser.py
===================================================================
--- five.hashedresource/trunk/src/five/hashedresource/tests/test_browser.py	2009-07-27 11:10:17 UTC (rev 102332)
+++ five.hashedresource/trunk/src/five/hashedresource/tests/test_browser.py	2009-07-27 11:11:25 UTC (rev 102333)
@@ -24,10 +24,8 @@
 import zope.publisher.browser
 
 
-class BrowserTest(Testing.ZopeTestCase.FunctionalTestCase):
+class BrowserTest(testing.FunctionalTestCase):
 
-    layer = testing.HashedResourcesLayer
-
     def setUp(self):
         super(BrowserTest, self).setUp()
         self.browser = Products.Five.testbrowser.Browser()

Modified: five.hashedresource/trunk/src/five/hashedresource/tests/test_hash.py
===================================================================
--- five.hashedresource/trunk/src/five/hashedresource/tests/test_hash.py	2009-07-27 11:10:17 UTC (rev 102332)
+++ five.hashedresource/trunk/src/five/hashedresource/tests/test_hash.py	2009-07-27 11:11:25 UTC (rev 102333)
@@ -21,22 +21,15 @@
 import Products.Five.zcml
 import Testing.ZopeTestCase.layer
 import five.hashedresource
+import five.hashedresource.testing
 import os
 import unittest
 import zope.component
 
 
-class ProductionModeLayer(Testing.ZopeTestCase.layer.ZopeLiteLayer):
-
-    @classmethod
-    def setUp(cls):
-        Products.Five.zcml.load_config(
-            'ftesting.zcml', five.hashedresource)
-
-
 class CachingContentsHashTest(testing.FunctionalTestCase):
 
-    layer = ProductionModeLayer
+    zcml = 'ftesting.zcml'
 
     def test_production_mode_hash_should_not_change(self):
         zope.component.provideAdapter(

Modified: five.hashedresource/trunk/src/five/hashedresource/tests/test_url.py
===================================================================
--- five.hashedresource/trunk/src/five/hashedresource/tests/test_url.py	2009-07-27 11:10:17 UTC (rev 102332)
+++ five.hashedresource/trunk/src/five/hashedresource/tests/test_url.py	2009-07-27 11:11:25 UTC (rev 102333)
@@ -30,7 +30,7 @@
                 zope.traversing.browser.interfaces.IAbsoluteURL))
         self.assertMatches(
             r'http://nohost/\+\+noop\+\+[^/]*/\+\+resource\+\+%s' %
-            self.dirname, directory_url)
+            'myresource', directory_url)
 
     def test_file_url_should_contain_hash(self):
         file = self.app.aq_inner.restrictedTraverse('++resource++test.txt')
@@ -41,12 +41,12 @@
             file_url)
 
     def test_different_files_hashes_should_differ(self):
-        open(os.path.join(testing.fixture, 'example.txt'), 'w').write('foo')
-        file = self.app.aq_inner.restrictedTraverse('++resource++example.txt')
-        file1_url = str(zope.component.getMultiAdapter((file, self.request),
+        open(os.path.join(self.fixture, 'example.txt'), 'w').write('foo')
+        file_ = self.app.aq_inner.restrictedTraverse('++resource++example.txt')
+        file1_url = str(zope.component.getMultiAdapter((file_, self.request),
                 zope.traversing.browser.interfaces.IAbsoluteURL))
-        open(os.path.join(testing.fixture, 'example.txt'), 'w').write('bar')
-        file2_url = str(zope.component.getMultiAdapter((file, self.request),
+        open(os.path.join(self.fixture, 'example.txt'), 'w').write('bar')
+        file2_url = str(zope.component.getMultiAdapter((file_, self.request),
                 zope.traversing.browser.interfaces.IAbsoluteURL))
         self.assertNotEqual(self._hash(file1_url), self._hash(file2_url))
 
@@ -54,7 +54,7 @@
         before = str(zope.component.getMultiAdapter(
                 (self.directory, self.request),
                 zope.traversing.browser.interfaces.IAbsoluteURL))
-        f = open(os.path.join(self.tmpdir, 'example.txt'), 'w')
+        f = open(os.path.join(self.fixture, 'example.txt'), 'w')
         f.write('foo')
         f.close()
         after = str(zope.component.getMultiAdapter(



More information about the Checkins mailing list