[Checkins] SVN: zope.file/trunk/ Make a good package out of this package.

Stephan Richter srichter at cosmos.phy.tufts.edu
Thu Nov 1 23:19:50 EDT 2007


Log message for revision 81401:
  Make a good package out of this package.
  

Changed:
  A   zope.file/trunk/CHANGES.txt
  A   zope.file/trunk/README.txt
  U   zope.file/trunk/buildout.cfg
  U   zope.file/trunk/setup.py
  _U  zope.file/trunk/src/
  U   zope.file/trunk/src/zope/file/README.txt
  U   zope.file/trunk/src/zope/file/browser.txt
  U   zope.file/trunk/src/zope/file/contenttype.txt
  U   zope.file/trunk/src/zope/file/download.txt
  U   zope.file/trunk/src/zope/file/ftesting.zcml
  D   zope.file/trunk/src/zope/file/ftests.py
  A   zope.file/trunk/src/zope/file/testing.py
  U   zope.file/trunk/src/zope/file/tests.py
  U   zope.file/trunk/src/zope/file/upload.txt

-=-
Added: zope.file/trunk/CHANGES.txt
===================================================================
--- zope.file/trunk/CHANGES.txt	                        (rev 0)
+++ zope.file/trunk/CHANGES.txt	2007-11-02 03:19:48 UTC (rev 81401)
@@ -0,0 +1,18 @@
+=======
+CHANGES
+=======
+
+0.3.0 (2007-11-01)
+------------------
+
+- Package data update.
+
+0.2.0 (2007-04-18)
+------------------
+
+- Fix code for Publisher version 3.4.
+
+0.1.0 (2007-04-18)
+------------------
+
+- Initial release.


Property changes on: zope.file/trunk/CHANGES.txt
___________________________________________________________________
Name: svn:eol-style
   + native

Added: zope.file/trunk/README.txt
===================================================================
--- zope.file/trunk/README.txt	                        (rev 0)
+++ zope.file/trunk/README.txt	2007-11-02 03:19:48 UTC (rev 81401)
@@ -0,0 +1,2 @@
+The `zope.file` package provides a content object used to store a
+file. The interface supports efficient upload and download.


Property changes on: zope.file/trunk/README.txt
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: zope.file/trunk/buildout.cfg
===================================================================
--- zope.file/trunk/buildout.cfg	2007-11-02 03:11:10 UTC (rev 81400)
+++ zope.file/trunk/buildout.cfg	2007-11-02 03:19:48 UTC (rev 81401)
@@ -2,10 +2,8 @@
 develop = .
 parts = test
 
-find-links = http://download.zope.org/distribution/
-
 [test]
 recipe = zc.recipe.testrunner
-eggs = zope.file
+eggs = zope.file [test]
 extra-paths = parts/zope3/src
-defaults = "--tests-pattern [fn]?tests --exit-with-status".split()
+defaults = ["--exit-with-status"]

Modified: zope.file/trunk/setup.py
===================================================================
--- zope.file/trunk/setup.py	2007-11-02 03:11:10 UTC (rev 81400)
+++ zope.file/trunk/setup.py	2007-11-02 03:19:48 UTC (rev 81401)
@@ -1,29 +1,83 @@
+##############################################################################
+#
+# Copyright (c) 2006 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.
+#
+##############################################################################
+"""Setup for zope.file package
+
+$Id: setup.py 80818 2007-10-11 04:06:12Z srichter $
+"""
+import os
 from setuptools import setup, find_packages
 
-setup(
-    name="zope.file",
-    version="0.3dev",
-    packages=find_packages('src'),
-    package_dir={'':'src'},
-    namespace_packages=['zope'],
-    include_package_data=True,
-    zip_safe = False,
-    install_requires=['setuptools',
-                      'ZODB3>=3.8.0b1',
-                      'zope.app.appsetup',
-                      'zope.app.publication',
-                      'zope.app.wsgi',
-                      'zope.event',
-                      'zope.interface',
-                      'zope.publisher',
-                      'zope.security',
-                      'zope.mimetype',
-                      # "extras"
-                      'zope.app.testing',
-                      'zope.app.securitypolicy',
-                      'zope.app.zcmlfiles',
-                      'zope.testbrowser',
-                      'zope.formlib',
-                      'zope.app.server',
-                      ],
-    )
+def read(*rnames):
+    return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
+
+setup(name='zope.file',
+      version = '0.3.0',
+      author='Zope Corporation and Contributors',
+      author_email='zope3-dev at zope.org',
+      description='Efficient File Implementation for Zope Applications',
+      long_description=(
+          read('README.txt')
+          + '\n\n' +
+          'Detailed Documentation\n' +
+          '======================\n\n'
+          + '\n\n' +
+          read('src', 'zope', 'file', 'README.txt')
+          + '\n\n' +
+          read('src', 'zope', 'file', 'download.txt')
+          + '\n\n' +
+          read('src', 'zope', 'file', 'upload.txt')
+          + '\n\n' +
+          read('src', 'zope', 'file', 'contenttype.txt')
+          + '\n\n' +
+          read('src', 'zope', 'file', 'browser.txt')
+          + '\n\n' +
+          read('CHANGES.txt')
+          ),
+      keywords = "zope3 web html ui file pattern",
+      classifiers = [
+          'Development Status :: 5 - Production/Stable',
+          'Environment :: Web Environment',
+          'Intended Audience :: Developers',
+          'License :: OSI Approved :: Zope Public License',
+          'Programming Language :: Python',
+          'Natural Language :: English',
+          'Operating System :: OS Independent',
+          'Topic :: Internet :: WWW/HTTP',
+          'Framework :: Zope3'],
+      url='http://cheeseshop.python.org/pypi/zope.file',
+      license='ZPL 2.1',
+      packages=find_packages('src'),
+      package_dir = {'': 'src'},
+      namespace_packages=['zope'],
+      extras_require = dict(
+          test=['zope.app.testing',
+                'zope.app.securitypolicy',
+                'zope.app.zcmlfiles',
+                'zope.testbrowser',
+                'zope.formlib',
+                'zope.app.server']),
+     install_requires=['setuptools',
+                       'ZODB3',
+                       'zope.app.appsetup',
+                       'zope.app.publication',
+                       'zope.app.wsgi',
+                       'zope.event',
+                       'zope.interface',
+                       'zope.publisher',
+                       'zope.security',
+                       'zope.mimetype',
+                       ],
+      include_package_data = True,
+      zip_safe = False,
+      )


Property changes on: zope.file/trunk/src
___________________________________________________________________
Name: svn:ignore
   + zope.file.egg-info


Modified: zope.file/trunk/src/zope/file/README.txt
===================================================================
--- zope.file/trunk/src/zope/file/README.txt	2007-11-02 03:11:10 UTC (rev 81400)
+++ zope.file/trunk/src/zope/file/README.txt	2007-11-02 03:19:48 UTC (rev 81401)
@@ -4,14 +4,14 @@
 
 The `zope.file` package provides a content object used to store a
 file.  The interface supports efficient upload and download.  Let's
-create an instance::
+create an instance:
 
   >>> from zope.file.file import File
   >>> f = File()
 
 The object provides a limited number of data attributes.  The
 `mimeType` attribute is used to store the preferred MIME
-content-type value for the data::
+content-type value for the data:
 
   >>> f.mimeType
 
@@ -25,7 +25,7 @@
 
 The `parameters` attribute is a mapping used to store the content-type
 parameters.  This is where encoding information can be found when
-applicable (and available)::
+applicable (and available):
 
   >>> f.parameters
   {}
@@ -34,7 +34,7 @@
   'us-ascii'
 
 File objects also sport a `size` attribute that provides the number of
-bytes in the file::
+bytes in the file:
 
   >>> f.size
   0
@@ -45,7 +45,7 @@
 
 A file that hasn't been written to is empty.  We can get a reader by calling
 `open()`. Note that all blobs are binary, thus the mode always contains a
-'b'::
+'b':
 
   >>> r = f.open("r")
   >>> r.mode
@@ -53,7 +53,7 @@
 
 The `read()` method can be called with a non-negative integer argument
 to specify how many bytes to read, or with a negative or omitted
-argument to read to the end of the file::
+argument to read to the end of the file:
 
   >>> r.read(10)
   ''
@@ -62,7 +62,7 @@
   >>> r.read(-1)
   ''
 
-Once the accessor has been closed, we can no longer read from it::
+Once the accessor has been closed, we can no longer read from it:
 
   >>> r.close()
   >>> r.read()
@@ -73,20 +73,20 @@
 file object.
 
 Data is added by using a writer, which is also created using the
-`open()` method on the file, but requesting a write file mode::
+`open()` method on the file, but requesting a write file mode:
 
   >>> w = f.open("w")
   >>> w.mode
   'wb'
 
 The `write()` method is used to add data to the file, but note that
-the data may be buffered in the writer::
+the data may be buffered in the writer:
 
   >>> w.write("some text ")
   >>> w.write("more text")
 
 The `flush()` method ensure that the data written so far is written to
-the file object::
+the file object:
 
   >>> w.flush()
 
@@ -97,7 +97,7 @@
   19
 
 We can now use a reader to see that the data has been written to the
-file::
+file:
 
   >>> w = f.open("w")
   >>> w.write('some text more text')
@@ -114,20 +114,20 @@
 The reader also has a `seek()` method that can be used to back up or
 skip forward in the data stream.  Simply passing an offset argument,
 we see that the current position is moved to that offset from the
-start of the file::
+start of the file:
 
   >>> r.seek(20)
   >>> r.read()
   'still more'
 
-That's equivalent to passing 0 as the `whence` argument::
+That's equivalent to passing 0 as the `whence` argument:
 
   >>> r.seek(20, 0)
   >>> r.read()
   'still more'
 
 We can skip backward and forward relative to the current position by
-passing 1 for `whence`::
+passing 1 for `whence`:
 
   >>> r.seek(-10, 1)
   >>> r.read(5)
@@ -137,7 +137,7 @@
   'ore'
 
 We can skip to some position backward from the end of the file using
-the value 2 for `whence`::
+the value 2 for `whence`:
 
   >>> r.seek(-10, 2)
   >>> r.read()
@@ -151,18 +151,18 @@
   >>> r.close()
 
 
-Attempting to write to a closed writer raises an exception::
+Attempting to write to a closed writer raises an exception:
 
 
   >>> w = f.open('w')
-  >>> w.close()  
+  >>> w.close()
 
   >>> w.write('foobar')
   Traceback (most recent call last):
   ValueError: I/O operation on closed file
 
 Similarly, using `seek()` or `tell()` on a closed reader raises an
-exception::
+exception:
 
   >>> r.close()
   >>> r.seek(0)

Modified: zope.file/trunk/src/zope/file/browser.txt
===================================================================
--- zope.file/trunk/src/zope/file/browser.txt	2007-11-02 03:11:10 UTC (rev 81400)
+++ zope.file/trunk/src/zope/file/browser.txt	2007-11-02 03:19:48 UTC (rev 81401)
@@ -10,7 +10,7 @@
 `zope.app.size.interfaces.ISized` interface.  Such an adapter is
 available for the file object.
 
-Let's do some imports and create a new file object::
+Let's do some imports and create a new file object:
 
   >>> from zope.file.file import File
   >>> from zope.file.browser import Sized
@@ -25,20 +25,20 @@
   >>> s.sizeForDisplay()
   u'0 KB'
 
-Let's add some content to the file::
+Let's add some content to the file:
 
   >>> w = f.open('w')
   >>> w.write("some text")
   >>> w.close()
 
-The sized adapter now reflects the updated size::
+The sized adapter now reflects the updated size:
 
   >>> s.sizeForSorting()
   ('byte', 9)
   >>> s.sizeForDisplay()
   u'1 KB'
 
-Let's try again with a larger file size::
+Let's try again with a larger file size:
 
   >>> w = f.open('w')
   >>> w.write("x" * (1024*1024+10))
@@ -52,7 +52,7 @@
   >>> m.mapping
   {'size': '1.00'}
 
-And still a bigger size::
+And still a bigger size:
 
   >>> w = f.open('w')
   >>> w.write("x" * 3*512*1024)

Modified: zope.file/trunk/src/zope/file/contenttype.txt
===================================================================
--- zope.file/trunk/src/zope/file/contenttype.txt	2007-11-02 03:11:10 UTC (rev 81400)
+++ zope.file/trunk/src/zope/file/contenttype.txt	2007-11-02 03:19:48 UTC (rev 81401)
@@ -7,7 +7,7 @@
 applicable based on the specific content type of the file.
 
 Let's demonstrate the behavior of the form with a simple bit of
-content.  We'll upload a bit of HTML as a sample document::
+content.  We'll upload a bit of HTML as a sample document:
 
   >>> import StringIO
   >>> sio = StringIO.StringIO("A <sub>little</sub> HTML."
@@ -24,7 +24,7 @@
   ...     sio, "text/html", "sample.html")
   >>> browser.getControl("Add").click()
 
-We can see that the MIME handlers have marked this as HTML content::
+We can see that the MIME handlers have marked this as HTML content:
 
   >>> import zope.mimetype.interfaces
   >>> import zope.mimetype.types
@@ -34,13 +34,13 @@
   True
 
 It's important to note that this also means the content is encoded
-text::
+text:
 
   >>> zope.mimetype.interfaces.IContentTypeEncoded.providedBy(file)
   True
 
 The "Content Type" page will show us the MIME type and encoding that
-have been selected::
+have been selected:
 
   >>> browser.getLink("sample.html").click()
   >>> browser.getLink("Content Type").click()
@@ -49,20 +49,20 @@
   ['zope.mimetype.types.IContentTypeTextHtml']
 
 The empty string value indicates that we have no encoding
-information::
+information:
 
   >>> ctrl = browser.getControl(name="form.encoding")
   >>> print ctrl.value
   ['']
 
-Let's now set the encoding value to an old favorite, Latin-1::
+Let's now set the encoding value to an old favorite, Latin-1:
 
   >>> ctrl.value = ["iso-8859-1"]
   >>> browser.handleErrors = False
   >>> browser.getControl("Save").click()
 
 We now see the updated value in the form, and can check the value in
-the MIME content-type parameters on the object::
+the MIME content-type parameters on the object:
 
   >>> ctrl = browser.getControl(name="form.encoding")
   >>> print ctrl.value
@@ -73,7 +73,7 @@
   {'charset': 'iso-8859-1'}
 
 Something more interesting is that we can now use a non-encoded
-content type, and the encoding field will be removed from the form::
+content type, and the encoding field will be removed from the form:
 
   >>> ctrl = browser.getControl(name="form.mimeType")
   >>> ctrl.value = ["zope.mimetype.types.IContentTypeImageTiff"]
@@ -85,7 +85,7 @@
   LookupError: name 'form.encoding'
 
 If we switch back to an encoded type, we see that our encoding wasn't
-lost::
+lost:
 
   >>> ctrl = browser.getControl(name="form.mimeType")
   >>> ctrl.value = ["zope.mimetype.types.IContentTypeTextHtml"]
@@ -96,7 +96,7 @@
 
 On the other hand, if we try setting the encoding to something which
 simply cannot decode the input data, we get an error message saying
-that's not going to work, and no changes are saved::
+that's not going to work, and no changes are saved:
 
   >>> ctrl = browser.getControl(name="form.encoding")
   >>> ctrl.value = ["utf-8"]

Modified: zope.file/trunk/src/zope/file/download.txt
===================================================================
--- zope.file/trunk/src/zope/file/download.txt	2007-11-02 03:11:10 UTC (rev 81400)
+++ zope.file/trunk/src/zope/file/download.txt	2007-11-02 03:19:48 UTC (rev 81401)
@@ -17,7 +17,7 @@
 discarded.
 
 Let's start by creating a file object we can use to demonstrate the
-download support::
+download support:
 
   >>> import transaction
   >>> from zope.file.file import File
@@ -29,7 +29,7 @@
 -------
 
 Now, let's get the headers for this file.  We use a utility function called
-``getHeaders``::
+``getHeaders``:
 
   >>> from zope.file.download import getHeaders
   >>> headers = getHeaders(f, contentDisposition='attachment')
@@ -37,7 +37,7 @@
 Since there's no suggested download filename on the file, the
 Content-Disposition header doesn't specify one, but does indicate that
 the response body be treated as a file to save rather than to apply
-the default handler for the content type::
+the default handler for the content type:
 
   >>> sorted(headers)
   [('Content-Disposition', 'attachment; filename="file"'),
@@ -49,7 +49,7 @@
 used.
 
 If the file object specifies a content type, that's used in the headers
-by default::
+by default:
 
   >>> f.mimeType = "text/plain"
   >>> headers = getHeaders(f, contentDisposition='attachment')
@@ -58,7 +58,7 @@
    ('Content-Length', '0'),
    ('Content-Type', 'text/plain')]
 
-Alternatively, a content type can be specified to ``getHeaders``::
+Alternatively, a content type can be specified to ``getHeaders``:
 
   >>> headers = getHeaders(f, contentType="text/xml",
   ...                      contentDisposition='attachment')
@@ -68,7 +68,7 @@
    ('Content-Type', 'text/xml')]
 
 The filename provided to the browser can be controlled similarly.  If
-the content object provides one, it will be used by default::
+the content object provides one, it will be used by default:
 
   >>> headers = getHeaders(f, contentDisposition='attachment')
   >>> sorted(headers)
@@ -77,7 +77,7 @@
    ('Content-Type', 'text/plain')]
 
 Providing an alternate name to ``getHeaders`` overrides the download
-name from the file::
+name from the file:
 
   >>> headers = getHeaders(f, downloadName="foo.txt",
   ...                      contentDisposition='attachment')
@@ -87,7 +87,7 @@
    ('Content-Type', 'text/plain')]
 
 The default Content-Disposition header can be overridden by providing
-an argument to ``getHeaders``::
+an argument to ``getHeaders``:
 
   >>> headers = getHeaders(f, contentDisposition="inline")
   >>> sorted(headers)
@@ -96,7 +96,7 @@
    ('Content-Type', 'text/plain')]
 
 If the `contentDisposition` argument is not provided, none will be
-included in the headers::
+included in the headers:
 
   >>> headers = getHeaders(f)
   >>> sorted(headers)
@@ -108,7 +108,7 @@
 ----
 
 We use DownloadResult to deliver the content to the browser.  Since
-there's no data in this file, there are no body chunks::
+there's no data in this file, there are no body chunks:
     
   >>> transaction.commit()
   >>> from zope.file.download import DownloadResult
@@ -117,7 +117,7 @@
   []
 
 We still need to see how non-empty files are handled.  Let's write
-some data to our file object::
+some data to our file object:
 
   >>> w = f.open("w")
   >>> w.write("some text")
@@ -126,7 +126,7 @@
   >>> transaction.commit()
 
 Now we can create a result object and see if we get the data we
-expect::
+expect:
 
   >>> result = DownloadResult(f)
   >>> L = list(result)
@@ -134,7 +134,7 @@
   'some text'
 
 If the body content is really large, the iterator may provide more
-than one chunk of data::
+than one chunk of data:
 
   >>> w = f.open("w")
   >>> w.write("*" * 1024 * 1024)
@@ -148,7 +148,7 @@
   True
 
 Once iteration over the body has completed, further iteration will not
-yield additional data::
+yield additional data:
 
   >>> list(result)
   []
@@ -159,7 +159,7 @@
 
 Now that we've seen the ``getHeaders`` function and the result object,
 let's take a look at the basic download view that uses them.  We'll need
-to add a file object where we can get to it using a browser::
+to add a file object where we can get to it using a browser:
 
   >>> f = File()
   >>> f.mimeType = "text/plain"
@@ -173,7 +173,7 @@
   >>> transaction.commit()
 
 Now, let's request the download view of the file object and check the
-result::
+result:
 
   >>> print http("""
   ... GET /abcdefg/@@download HTTP/1.1
@@ -195,7 +195,7 @@
 Note that browsers may decide not to display the image when this view
 is used and there is not page that it's being loaded into: if this
 view is being referenced directly via the URL, the browser may show
-nothing::
+nothing:
 
   >>> print http("""
   ... GET /abcdefg/@@inline HTTP/1.1
@@ -214,7 +214,7 @@
 
 This view is similar to the download and inline views, but no content
 disposition is specified at all.  This lets the browser's default
-handling of the data in the current context to be applied::
+handling of the data in the current context to be applied:
 
   >>> print http("""
   ... GET /abcdefg/@@display HTTP/1.1

Modified: zope.file/trunk/src/zope/file/ftesting.zcml
===================================================================
--- zope.file/trunk/src/zope/file/ftesting.zcml	2007-11-02 03:11:10 UTC (rev 81400)
+++ zope.file/trunk/src/zope/file/ftesting.zcml	2007-11-02 03:19:48 UTC (rev 81401)
@@ -27,8 +27,7 @@
   <include package="zope.app.securitypolicy" />
 
   <securityPolicy
-      component="zope.app.securitypolicy.zopepolicy.ZopeSecurityPolicy"
-      />
+      component="zope.securitypolicy.zopepolicy.ZopeSecurityPolicy" />
 
   <role
       id="zope.Anonymous"

Deleted: zope.file/trunk/src/zope/file/ftests.py
===================================================================
--- zope.file/trunk/src/zope/file/ftests.py	2007-11-02 03:11:10 UTC (rev 81400)
+++ zope.file/trunk/src/zope/file/ftests.py	2007-11-02 03:19:48 UTC (rev 81401)
@@ -1,117 +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.
-#
-##############################################################################
-"""Functional tests for zope.file.
-
-"""
-__docformat__ = "reStructuredText"
-
-import os.path
-import unittest
-
-import shutil
-import tempfile
-
-import transaction
-from ZODB.DB import DB
-from ZODB.DemoStorage import DemoStorage
-from ZODB.blob import BlobStorage
-from zope.testing import doctest
-import zope.app.testing.functional
-from zope.app.component.hooks import setSite
-
-here = os.path.dirname(os.path.realpath(__file__))
-
-class FunctionalBlobTestSetup(zope.app.testing.functional.FunctionalTestSetup):
-
-    temp_dir_name = None
-
-    def setUp(self):
-        """Prepares for a functional test case."""
-        # Tear down the old demo storage (if any) and create a fresh one
-        transaction.abort()
-        self.db.close()
-        storage = DemoStorage("Demo Storage", self.base_storage)
-        # make a dir
-        temp_dir_name = self.temp_dir_name = tempfile.mkdtemp()
-        # wrap storage with BlobStorage
-        storage = BlobStorage(temp_dir_name, storage)
-        self.db = self.app.db = DB(storage)
-        self.connection = None
-
-    def tearDown(self):
-        """Cleans up after a functional test case."""
-        transaction.abort()
-        if self.connection:
-            self.connection.close()
-            self.connection = None
-        self.db.close()
-        # del dir named '__blob_test__%s' % self.name
-        if self.temp_dir_name is not None:
-            shutil.rmtree(self.temp_dir_name, True)
-            self.temp_dir_name = None
-        setSite(None)
-
-class ZCMLLayer(zope.app.testing.functional.ZCMLLayer):
-
-    def setUp(self):
-        self.setup = FunctionalBlobTestSetup(self.config_file)
-
-def FunctionalBlobDocFileSuite(*paths, **kw):
-    globs = kw.setdefault('globs', {})
-    globs['http'] = zope.app.testing.functional.HTTPCaller()
-    globs['getRootFolder'] = zope.app.testing.functional.getRootFolder
-    globs['sync'] = zope.app.testing.functional.sync
-
-    kw['package'] = doctest._normalize_module(kw.get('package'))
-
-    kwsetUp = kw.get('setUp')
-    def setUp(test):
-        FunctionalBlobTestSetup().setUp()
-
-        if kwsetUp is not None:
-            kwsetUp(test)
-    kw['setUp'] = setUp
-
-    kwtearDown = kw.get('tearDown')
-    def tearDown(test):
-        if kwtearDown is not None:
-            kwtearDown(test)
-        FunctionalBlobTestSetup().tearDown()
-    kw['tearDown'] = tearDown
-
-    if 'optionflags' not in kw:
-        old = doctest.set_unittest_reportflags(0)
-        doctest.set_unittest_reportflags(old)
-        kw['optionflags'] = (old
-                             | doctest.ELLIPSIS
-                             | doctest.REPORT_NDIFF
-                             | doctest.NORMALIZE_WHITESPACE)
-
-    suite = doctest.DocFileSuite(*paths, **kw)
-    suite.layer = zope.app.testing.functional.Functional
-    return suite
-
-ZopeFileLayer = ZCMLLayer(
-    os.path.join(here, "ftesting.zcml"), __name__, "ZopeFileLayer")
-
-def fromDocFile(path):
-    suite = FunctionalBlobDocFileSuite(path)
-    suite.layer = ZopeFileLayer
-    return suite
-
-def test_suite():
-    return unittest.TestSuite([
-        fromDocFile("contenttype.txt"),
-        fromDocFile("download.txt"),
-        fromDocFile("upload.txt"),
-        ])

Added: zope.file/trunk/src/zope/file/testing.py
===================================================================
--- zope.file/trunk/src/zope/file/testing.py	                        (rev 0)
+++ zope.file/trunk/src/zope/file/testing.py	2007-11-02 03:19:48 UTC (rev 81401)
@@ -0,0 +1,103 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+"""Functional tests for zope.file.
+
+"""
+__docformat__ = "reStructuredText"
+
+import os.path
+import shutil
+import tempfile
+
+import transaction
+from ZODB.DB import DB
+from ZODB.DemoStorage import DemoStorage
+from ZODB.blob import BlobStorage
+from zope.testing import doctest
+import zope.app.testing.functional
+from zope.app.component.hooks import setSite
+
+here = os.path.dirname(os.path.realpath(__file__))
+
+class FunctionalBlobTestSetup(zope.app.testing.functional.FunctionalTestSetup):
+
+    temp_dir_name = None
+
+    def setUp(self):
+        """Prepares for a functional test case."""
+        # Tear down the old demo storage (if any) and create a fresh one
+        transaction.abort()
+        self.db.close()
+        storage = DemoStorage("Demo Storage", self.base_storage)
+        # make a dir
+        temp_dir_name = self.temp_dir_name = tempfile.mkdtemp()
+        # wrap storage with BlobStorage
+        storage = BlobStorage(temp_dir_name, storage)
+        self.db = self.app.db = DB(storage)
+        self.connection = None
+
+    def tearDown(self):
+        """Cleans up after a functional test case."""
+        transaction.abort()
+        if self.connection:
+            self.connection.close()
+            self.connection = None
+        self.db.close()
+        # del dir named '__blob_test__%s' % self.name
+        if self.temp_dir_name is not None:
+            shutil.rmtree(self.temp_dir_name, True)
+            self.temp_dir_name = None
+        setSite(None)
+
+class ZCMLLayer(zope.app.testing.functional.ZCMLLayer):
+
+    def setUp(self):
+        self.setup = FunctionalBlobTestSetup(self.config_file)
+
+def FunctionalBlobDocFileSuite(*paths, **kw):
+    globs = kw.setdefault('globs', {})
+    globs['http'] = zope.app.testing.functional.HTTPCaller()
+    globs['getRootFolder'] = zope.app.testing.functional.getRootFolder
+    globs['sync'] = zope.app.testing.functional.sync
+
+    kw['package'] = doctest._normalize_module(kw.get('package'))
+
+    kwsetUp = kw.get('setUp')
+    def setUp(test):
+        FunctionalBlobTestSetup().setUp()
+
+        if kwsetUp is not None:
+            kwsetUp(test)
+    kw['setUp'] = setUp
+
+    kwtearDown = kw.get('tearDown')
+    def tearDown(test):
+        if kwtearDown is not None:
+            kwtearDown(test)
+        FunctionalBlobTestSetup().tearDown()
+    kw['tearDown'] = tearDown
+
+    if 'optionflags' not in kw:
+        old = doctest.set_unittest_reportflags(0)
+        doctest.set_unittest_reportflags(old)
+        kw['optionflags'] = (old
+                             | doctest.ELLIPSIS
+                             | doctest.REPORT_NDIFF
+                             | doctest.NORMALIZE_WHITESPACE)
+
+    suite = doctest.DocFileSuite(*paths, **kw)
+    suite.layer = zope.app.testing.functional.Functional
+    return suite
+
+ZopeFileLayer = ZCMLLayer(
+    os.path.join(here, "ftesting.zcml"), __name__, "ZopeFileLayer")


Property changes on: zope.file/trunk/src/zope/file/testing.py
___________________________________________________________________
Name: svn:keywords
   + Id

Modified: zope.file/trunk/src/zope/file/tests.py
===================================================================
--- zope.file/trunk/src/zope/file/tests.py	2007-11-02 03:11:10 UTC (rev 81400)
+++ zope.file/trunk/src/zope/file/tests.py	2007-11-02 03:19:48 UTC (rev 81401)
@@ -14,14 +14,21 @@
 
 """
 __docformat__ = "reStructuredText"
-
 import unittest
-
 from zope.testing import doctest
 
+from zope.file import testing
 
+def fromDocFile(path):
+    suite = testing.FunctionalBlobDocFileSuite(path)
+    suite.layer = testing.ZopeFileLayer
+    return suite
+
 def test_suite():
-    suite = unittest.TestSuite()
-    suite.addTest(doctest.DocFileSuite("README.txt"))
-    suite.addTest(doctest.DocFileSuite("browser.txt"))
-    return suite
+    return unittest.TestSuite((
+        doctest.DocFileSuite("README.txt"),
+        doctest.DocFileSuite("browser.txt"),
+        fromDocFile("contenttype.txt"),
+        fromDocFile("download.txt"),
+        fromDocFile("upload.txt"),
+        ))

Modified: zope.file/trunk/src/zope/file/upload.txt
===================================================================
--- zope.file/trunk/src/zope/file/upload.txt	2007-11-02 03:11:10 UTC (rev 81400)
+++ zope.file/trunk/src/zope/file/upload.txt	2007-11-02 03:19:48 UTC (rev 81401)
@@ -2,7 +2,7 @@
 Uploading a new file
 ====================
 
-There's a simple view for uploading a new file.  Let's try it::
+There's a simple view for uploading a new file.  Let's try it:
 
   >>> from StringIO import StringIO
 
@@ -19,7 +19,7 @@
   HTTP/1.1 303 ...
 
 Now, let's request the download view of the file object and check the
-result::
+result:
 
   >>> print http("""
   ... GET /plain.txt/@@download HTTP/1.1
@@ -33,14 +33,14 @@
   some text
 
 We'll peek into the database to make sure the object implements the
-expected MIME type interface::
+expected MIME type interface:
 
   >>> from zope.mimetype import types
   >>> ob = getRootFolder()["plain.txt"]
   >>> types.IContentTypeTextPlain.providedBy(ob)
   True
 
-We can upload new data into our file object as well::
+We can upload new data into our file object as well:
 
   >>> sio = StringIO("new text")
   >>> sio.filename = "stuff.txt"
@@ -55,7 +55,7 @@
   HTTP/1.1 200 ...
 
 Now, let's request the download view of the file object and check the
-result::
+result:
 
   >>> print http("""
   ... GET /plain.txt/@@download HTTP/1.1
@@ -71,7 +71,7 @@
 If we upload a file that has imprecise content type information (as we
 expect from browsers generally, and MSIE most significantly), we can
 see that the MIME type machinery will improve the information where
-possible::
+possible:
 
   >>> sio = StringIO("<?xml version='1.0' encoding='utf-8'?>\n"
   ...                "<html>...</html>\n")
@@ -89,7 +89,7 @@
   HTTP/1.1 303 ...
 
 Again, we'll request the download view of the file object and check
-the result::
+the result:
 
   >>> print http("""
   ... GET /simple.html/@@download HTTP/1.1
@@ -121,10 +121,10 @@
   ... Authorization: Basic mgr:mgrpw
   ... """, form={"form.data": sio,
   ...            "form.actions.add": "Add"}, handle_errors=False)
-  HTTP/1.1 303 ... 
+  HTTP/1.1 303 ...
 
 Again, we'll request the download view of the file object and check
-the result::
+the result:
 
   >>> print http("""
   ... GET /naughty%20name.html/@@download HTTP/1.1
@@ -137,5 +137,5 @@
   <BLANKLINE>
   <?xml version='1.0' encoding='utf-8'?>
   <html>...</html>
-  <BLANKLINE> 
+  <BLANKLINE>
 



More information about the Checkins mailing list