[Checkins] SVN: z3c.versionedresource/trunk/ - Feature: List script can now also create directory with all resources in

Stephan Richter srichter at cosmos.phy.tufts.edu
Sun Aug 10 02:08:34 EDT 2008


Log message for revision 89586:
  - Feature: List script can now also create directory with all resources in
    it. There is also an option to store the resources in gzip format.
  
  - Bug: Fixed test coverage to 100%.
  

Changed:
  U   z3c.versionedresource/trunk/CHANGES.txt
  U   z3c.versionedresource/trunk/setup.py
  U   z3c.versionedresource/trunk/src/z3c/versionedresource/README.txt
  U   z3c.versionedresource/trunk/src/z3c/versionedresource/list.py
  U   z3c.versionedresource/trunk/src/z3c/versionedresource/resource.py
  U   z3c.versionedresource/trunk/src/z3c/versionedresource/tests/simple.zcml
  U   z3c.versionedresource/trunk/src/z3c/versionedresource/tests/test_doc.py
  A   z3c.versionedresource/trunk/src/z3c/versionedresource/tests/testfiles/test.pt

-=-
Modified: z3c.versionedresource/trunk/CHANGES.txt
===================================================================
--- z3c.versionedresource/trunk/CHANGES.txt	2008-08-10 02:27:08 UTC (rev 89585)
+++ z3c.versionedresource/trunk/CHANGES.txt	2008-08-10 06:08:33 UTC (rev 89586)
@@ -2,6 +2,14 @@
 CHANGES
 =======
 
+Version 0.2.0 (2008-08-09)
+--------------------------
+
+- Feature: List script can now also create directory with all resources in
+  it. There is also an option to store the resources in gzip format.
+
+- Bug: Fixed test coverage to 100%.
+
 Version 0.1.0 (2008-08-04)
 --------------------------
 

Modified: z3c.versionedresource/trunk/setup.py
===================================================================
--- z3c.versionedresource/trunk/setup.py	2008-08-10 02:27:08 UTC (rev 89585)
+++ z3c.versionedresource/trunk/setup.py	2008-08-10 06:08:33 UTC (rev 89586)
@@ -23,7 +23,7 @@
 
 setup (
     name='z3c.versionedresource',
-    version='0.2.0dev',
+    version='0.2.0',
     author = "Stephan Richter and the Zope Community",
     author_email = "zope3-dev at zope.org",
     description = "Versioned Resources",

Modified: z3c.versionedresource/trunk/src/z3c/versionedresource/README.txt
===================================================================
--- z3c.versionedresource/trunk/src/z3c/versionedresource/README.txt	2008-08-10 02:27:08 UTC (rev 89585)
+++ z3c.versionedresource/trunk/src/z3c/versionedresource/README.txt	2008-08-10 06:08:33 UTC (rev 89586)
@@ -144,11 +144,19 @@
 The versioned file resource is identical to the default file resource, except
 that it has a versioned URL and a 10 year cache timeout.
 
+  >>> import os.path
+  >>> import z3c.versionedresource.tests
+  >>> filesdir = os.path.join(
+  ...     os.path.dirname(z3c.versionedresource.tests.__file__),
+  ...     'testfiles')
+
+  >>> from zope.app.publisher.fileresource import File
+  >>> file = File(os.path.join(filesdir, 'test.txt'), 'test.txt')
   >>> request = TestRequest()
-  >>> res = resource.FileResource(None, request)
+  >>> res = resource.FileResource(file, request)
   >>> res.__name__ = 'ajax.js'
   >>> res
-  <z3c.versionedresource.resource.FileResource object at ...>
+  <FileResource '.../z3c/versionedresource/tests/testfiles/test.txt'>
   >>> res.cacheTimeout
   315360000
   >>> res()
@@ -156,25 +164,19 @@
 
 Two factories, one for files and one for images is used:
 
-  >>> import os.path
-  >>> import z3c.versionedresource.tests
-  >>> filesdir = os.path.join(
-  ...     os.path.dirname(z3c.versionedresource.tests.__file__),
-  ...     'testfiles')
-
   >>> factory = resource.FileResourceFactory(
   ...     os.path.join(filesdir, 'test.txt'), None, 'test.txt')
   >>> factory
   <z3c.versionedresource.resource.FileResourceFactory object at ...>
   >>> factory(request)
-  <z3c.versionedresource.resource.FileResource object at ...>
+  <FileResource '.../z3c/versionedresource/tests/testfiles/test.txt'>
 
   >>> factory = resource.ImageResourceFactory(
   ...     os.path.join(filesdir, 'test.gif'), None, 'test.gif')
   >>> factory
   <z3c.versionedresource.resource.ImageResourceFactory object at ...>
   >>> factory(request)
-  <z3c.versionedresource.resource.FileResource object at ...>
+  <FileResource '.../z3c/versionedresource/tests/testfiles/test.gif'>
 
 
 Directory Resource
@@ -190,14 +192,14 @@
   ...     Directory(os.path.join(filesdir, 'subdir'), None, 'subdir'), request)
   >>> res.__name__ = 'subdir'
   >>> res
-  <z3c.versionedresource.resource.DirectoryResource object at ...>
+  <DirectoryResource '.../z3c/versionedresource/tests/testfiles/subdir'>
   >>> res()
   'http://127.0.0.1/@@/1.0.0/subdir'
 
 Let's try to traverse to some files in the directory:
 
   >>> res.publishTraverse(request, 'test.gif')
-  <z3c.versionedresource.resource.FileResource object at ...>
+  <FileResource '.../z3c/versionedresource/tests/testfiles/subdir/test.gif'>
 
 We also have a factory for it:
 
@@ -206,7 +208,7 @@
   >>> factory
   <z3c.versionedresource.resource.DirectoryResourceFactory object at ...>
   >>> factory(request)
-  <z3c.versionedresource.resource.DirectoryResource object at ...>
+  <DirectoryResource '.../z3c/versionedresource/tests/testfiles/subdir'>
 
 
 Custom ZCML Directives
@@ -237,6 +239,70 @@
   ...          .publishTraverse(request, 'zcml-test.gif')()
   'http://127.0.0.1/@@/1.0.0/zcml-test.gif'
 
+You can also specify a simple file resource,
+
+  >>> context = xmlconfig.string("""
+  ... <configure
+  ...     xmlns:browser="http://namespaces.zope.org/browser">
+  ...   <browser:versionedResource
+  ...       name="zcml-test.txt"
+  ...       file="%s"
+  ...       />
+  ... </configure>
+  ... """ %os.path.join(filesdir, 'test.txt') , context=context)
+
+  >>> resources.publishTraverse(request, '1.0.0')\
+  ...          .publishTraverse(request, 'zcml-test.txt').context
+  <zope.app.publisher.fileresource.File object at ...>
+
+  >>> unregister('zcml-test.txt')
+
+as well as a page template.
+
+  >>> context = xmlconfig.string("""
+  ... <configure
+  ...     xmlns:browser="http://namespaces.zope.org/browser">
+  ...   <browser:versionedResource
+  ...       name="zcml-test.html"
+  ...       template="%s"
+  ...       />
+  ... </configure>
+  ... """ %os.path.join(filesdir, 'test.pt') , context=context)
+
+  >>> resources.publishTraverse(request, '1.0.0')\
+  ...          .publishTraverse(request, 'zcml-test.html').context
+  <zope.app.publisher.pagetemplateresource.PageTemplate object at ...>
+
+Note that the page template resource cannot be a versioned resource, since it
+has dynamic components:
+
+  >>> resources.publishTraverse(request, '1.0.0')\
+  ...          .publishTraverse(request, 'zcml-test.html')()
+  u'<h1>Test</h1>\n'
+
+Note: Eeek, `zope.app.publisher.browser` is broken here. We should have
+gotten a URL back.
+
+  >>> unregister('zcml-test.html')
+
+Finally, a factory can also be passed in:
+
+  >>> context = xmlconfig.string("""
+  ... <configure
+  ...     xmlns:browser="http://namespaces.zope.org/browser">
+  ...   <browser:versionedResource
+  ...       name="zcml-dyn.html"
+  ...       factory="z3c.versionedresource.tests.test_doc.ResourceFactory"
+  ...       />
+  ... </configure>
+  ... """, context=context)
+
+  >>> resources.publishTraverse(request, '1.0.0')\
+  ...          .publishTraverse(request, 'zcml-dyn.html')
+  <ResourceFactory>
+
+  >>> unregister('zcml-dyn.html')
+
 Let's now create a directory resource:
 
   >>> context = xmlconfig.string("""
@@ -255,21 +321,184 @@
   ...          .publishTraverse(request, 'zcml-subdir')()
   'http://127.0.0.1/@@/1.0.0/zcml-subdir'
 
+The directives also have some error handling built-in. So let's have a
+look. In the ``browser:versionedResource`` directive, you can only specify
+either a template, file, image or factory:
 
-Lsiting All Resources
+  >>> context = xmlconfig.string("""
+  ... <configure
+  ...     xmlns:browser="http://namespaces.zope.org/browser">
+  ...   <browser:versionedResource
+  ...       name="zcml-test.gif"
+  ...       file="test.gif"
+  ...       image="test.gif"
+  ...       />
+  ... </configure>
+  ... """, context=context)
+  Traceback (most recent call last):
+  ...
+  ZopeXMLConfigurationError: File "<string>", line 4.2-8.8
+      ConfigurationError: Must use exactly one of factory or file or
+                          image or template attributes for resource directives
+
+The resource directive on the other hand, ensures that the specified path is a
+directory:
+
+  >>> context = xmlconfig.string("""
+  ... <configure
+  ...     xmlns:browser="http://namespaces.zope.org/browser">
+  ...   <browser:versionedResourceDirectory
+  ...       name="zcml-subdir"
+  ...       directory="/foo"
+  ...       />
+  ... </configure>
+  ... """, context=context)
+  Traceback (most recent call last):
+  ...
+  ZopeXMLConfigurationError: File "<string>", line 4.2-7.8
+        ConfigurationError: Directory /foo does not exist
+
+
+Listing All Resources
 ---------------------
 
 Finally, there exists a script that will list all resources registered as
 versioned resources with the system.
 
   >>> from z3c.versionedresource import list
-  >>> list.main(
+
+  >>> list.produceResources(list.get_options(
   ...   ['-u', 'http://zope.org',
   ...    '-l', 'z3c.versionedresource.tests.test_doc.ITestLayer',
-  ...    os.path.join(os.path.dirname(list.__file__), 'tests', 'simple.zcml')])
-  http://zope.org/@@/1.0.0/real-subdir/test.gif
-  http://zope.org/@@/1.0.0/real-subdir/subsubdir/subtest.gif
+  ...    '--list-only',
+  ...    os.path.join(os.path.dirname(list.__file__), 'tests', 'simple.zcml')]
+  ...   ))
   http://zope.org/@@/1.0.0/zcml-subdir/test.gif
   http://zope.org/@@/1.0.0/zcml-subdir/subsubdir/subtest.gif
-  http://zope.org/@@/1.0.0/real-test.gif
   http://zope.org/@@/1.0.0/zcml-test.gif
+
+You can also produce the resources in a directory:
+
+  >>> import tempfile
+  >>> outdir = tempfile.mkdtemp()
+
+  >>> list.produceResources(list.get_options(
+  ...   ['-u', 'http://zope.org',
+  ...    '-l', 'z3c.versionedresource.tests.test_doc.ITestLayer',
+  ...    '-d', outdir,
+  ...    os.path.join(os.path.dirname(list.__file__), 'tests', 'simple.zcml')]
+  ...   ))
+  /.../1.0.0
+
+  >>> ls(outdir)
+  d 1.0.0             4096
+  >>> ls(os.path.join(outdir, '1.0.0'))
+  d zcml-subdir       4096
+  f zcml-test.gif     909
+  >>> ls(os.path.join(outdir, '1.0.0', 'zcml-subdir'))
+  d subsubdir         4096
+  f test.gif          909
+  >>> ls(os.path.join(outdir, '1.0.0', 'zcml-subdir', 'subsubdir'))
+  f subtest.gif       909
+
+The module consists of several small helper functions, so let's look at them
+to verify their correct behavior.
+
+
+`getResources(layerPath, url='http://localhost/')` Function
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+This function retrieves all versioned resources from the system for a given
+layer. Optionally a URL can be passed in to alter the resource URLs.
+
+  >>> resources = list.getResources(
+  ...     'z3c.versionedresource.tests.test_doc.ITestLayer')
+  >>> sorted(resources)
+  [(u'zcml-subdir', <DirectoryResource u'.../testfiles/subdir'>),
+   (u'zcml-test.gif', <FileResource u'.../testfiles/test.gif'>)]
+
+As you can see, this list only provides the first layer. It is the
+responsibility of the consuming code to digg deeper into the directory
+resources.
+
+
+`getResourceUrls(resources)` Function
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Once we have the list of resources, we can produce a full list of all
+available paths.
+
+  >>> sorted(list.getResourceUrls(resources))
+  [u'http://localhost/@@/1.0.0/zcml-subdir/subsubdir/subtest.gif',
+   u'http://localhost/@@/1.0.0/zcml-subdir/test.gif',
+   u'http://localhost/@@/1.0.0/zcml-test.gif']
+
+
+`storeResource(dir, name, resource, zip=False)` Function
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The more interesting use case, however, is this function, which stores the
+resources in a directory. First we need to create an output directory:
+
+  >>> outdir = tempfile.mkdtemp()
+
+We can now store a resource to it:
+
+  >>> list.storeResource(outdir, resources[1][0], resources[1][1])
+  >>> ls(outdir)
+  f zcml-test.gif     909
+
+Let's now zip it:
+
+  >>> list.storeResource(outdir, resources[1][0], resources[1][1], True)
+  >>> ls(outdir)
+  f zcml-test.gif     252
+
+When storing a directory resource, all sub-items are stored as well:
+
+  >>> list.storeResource(outdir, resources[0][0], resources[0][1], True)
+  >>> ls(outdir)
+  d zcml-subdir       4096
+  f zcml-test.gif     252
+
+  >>> ls(os.path.join(outdir, 'zcml-subdir'))
+  d subsubdir 4096
+  f test.gif  259
+
+  >>> ls(os.path.join(outdir, 'zcml-subdir', 'subsubdir'))
+  f subtest.gif       272
+
+
+Some odds and ends
+~~~~~~~~~~~~~~~~~~
+
+Let's use the `main()` function too. It is the one used by the script, but
+always raises a system exist:
+
+  >>> list.main()
+  Traceback (most recent call last):
+  ...
+  SystemExit: 2
+
+  >>> list.main(['foo'])
+  Traceback (most recent call last):
+  ...
+  SystemExit: 1
+
+  >>> list.main(
+  ...   ['-l', 'z3c.versionedresource.tests.test_doc.ITestLayer',
+  ...    '--list-only',
+  ...    os.path.join(os.path.dirname(list.__file__), 'tests', 'simple.zcml')]
+  ...   )
+  Traceback (most recent call last):
+  ...
+  SystemExit: 0
+
+If the positional argument is missing, then we get a parser error:
+
+  >>> list.main(
+  ...   ['-l', 'z3c.versionedresource.tests.test_doc.ITestLayer',
+  ...    '--list-only'])
+  Traceback (most recent call last):
+  ...
+  SystemExit: 2

Modified: z3c.versionedresource/trunk/src/z3c/versionedresource/list.py
===================================================================
--- z3c.versionedresource/trunk/src/z3c/versionedresource/list.py	2008-08-10 02:27:08 UTC (rev 89585)
+++ z3c.versionedresource/trunk/src/z3c/versionedresource/list.py	2008-08-10 06:08:33 UTC (rev 89586)
@@ -16,6 +16,7 @@
 $Id$
 """
 __docformat__ = 'restructuredtext'
+import gzip
 import optparse
 import os
 import sys
@@ -24,37 +25,87 @@
 from zope.configuration import xmlconfig
 from zope.publisher.browser import TestRequest
 from z3c.versionedresource import interfaces, resource
+from z3c.versionedresource.resource import DirectoryResource
 
+EXCLUDED_NAMES = ('.svn',)
 
-def getAllResources(options):
-    # Run the configuration
-    context = xmlconfig.file(options.zcml)
+def removeExcludedNames(list):
+    for name in EXCLUDED_NAMES:
+        if name in list:
+            list.remove(name)
+
+def getResources(layerPath, url='http://localhost/'):
     # Get the layer interface
-    moduleName, layerName = options.layer.rsplit('.', 1)
+    moduleName, layerName = layerPath.rsplit('.', 1)
     module = __import__(moduleName, {}, {}, [1])
     layer = getattr(module, layerName)
     # Now we create a test request with that layer and our custom base URL.
-    request = TestRequest(environ={'SERVER_URL': options.url})
+    request = TestRequest(environ={'SERVER_URL': url})
     zope.interface.alsoProvides(request, layer)
     # Next we look up all the resources
-    resources = zope.component.getAdapters(
-        (request,), interfaces.IVersionedResource)
+    return tuple(
+        zope.component.getAdapters((request,), interfaces.IVersionedResource))
+
+def getResourceUrls(resources):
     paths = []
     for name, res in resources:
         # For file-based resources, just report their URL.
-        if not isinstance(res, resource.DirectoryResource):
+        if not isinstance(res, DirectoryResource):
             paths.append(res())
         # For directory resources, we want to walk the tree.
         baseURL = res()
         path = res.context.path
         for root, dirs, files in os.walk(path):
-            if '.svn' in dirs:
-                dirs.remove('.svn')
+            # Ignore unwanted names.
+            removeExcludedNames(dirs)
+            removeExcludedNames(files)
+            # Produce a path for the resource
             relativePath = root.replace(path, '')
             for file in files:
                 paths.append(baseURL + relativePath + '/' + file)
     return paths
 
+def storeResource(dir, name, resource, zip=False):
+    outputPath = os.path.join(dir, name)
+    # For directory resources, we create the directory and walk through the
+    # children.
+    if isinstance(resource, DirectoryResource):
+        os.mkdir(outputPath)
+        for name in [name for name in os.listdir(resource.context.path)
+                     if name not in EXCLUDED_NAMES]:
+            subResource = resource.get(name, None)
+            if subResource is not None:
+                storeResource(outputPath, name, subResource, zip)
+    # For file-based resources, get the path, load it and store it at the new
+    # location.
+    else:
+        inFile = open(resource.context.path, 'r')
+        openFile = open
+        if zip:
+            openFile = gzip.open
+        outFile = openFile(outputPath, 'w')
+        outFile.write(inFile.read())
+        inFile.close()
+        outFile.close()
+
+def produceResources(options):
+    # Run the configuration
+    context = xmlconfig.file(options.zcml)
+    # Get resource list
+    resources = getResources(options.layer, options.url)
+    # If we only want to list the paths
+    if options.listOnly:
+        paths = getResourceUrls(resources)
+        print '\n'.join(paths)
+        return
+    # Now we can produce the version directory with all resources in it
+    version = zope.component.getUtility(interfaces.IVersionManager).version
+    outputdir = os.path.join(options.dir, version)
+    os.mkdir(outputdir)
+    for name, resource in resources:
+        storeResource(outputdir, name, resource, options.zip)
+    print outputdir
+
 ###############################################################################
 # Command-line UI
 
@@ -64,41 +115,40 @@
     parser, "Configuration", "Configuration of lookup and reporting parameters.")
 
 config.add_option(
-    '--url', '-u', action="store", dest='url',
-    help="""The base URL that is used to produce the resource URLs.""")
-
-config.add_option(
     '--layer', '-l', action="store", dest='layer',
     default='zope.interface.Interface',
     help="""The layer for which to lookup the resources.""")
 
+config.add_option(
+    '--zip', '-z', action="store_true", dest='zip', default=False,
+    help="""When set, resources are stored in GZIP format.""")
+
+config.add_option(
+    '--output-dir', '-d', action="store", dest='dir',
+    default=os.path.abspath(os.curdir),
+    help="""The directory in which the resources will be stored.""")
+
 parser.add_option_group(config)
 
-# Default setup
-default_setup_args = []
+list = optparse.OptionGroup(
+    parser, "List", "Options for list only result.")
 
-def merge_options(options, defaults):
-    odict = options.__dict__
-    for name, value in defaults.__dict__.items():
-        if (value is not None) and (odict[name] is None):
-            odict[name] = value
+list.add_option(
+    '--list-only', action="store_true", dest='listOnly', default=False,
+    help="When specified causes no directory with the resources "
+         "to be created.")
 
-def get_options(args=None, defaults=None):
+list.add_option(
+    '--url', '-u', action="store", dest='url', default='http://localhost/',
+    help="""The base URL that is used to produce the resource URLs.""")
 
-    default_setup, _ = parser.parse_args(default_setup_args)
-    assert not _
-    if defaults:
-        defaults, _ = parser.parse_args(defaults)
-        assert not _
-        merge_options(defaults, default_setup)
-    else:
-        defaults = default_setup
+parser.add_option_group(list)
 
+def get_options(args=None):
     if args is None:
         args = sys.argv
     original_args = args
     options, positional = parser.parse_args(args)
-    merge_options(options, defaults)
     options.original_args = original_args
 
     if not positional or len(positional) < 1:
@@ -111,11 +161,9 @@
 ###############################################################################
 
 def main(args=None):
-    if args is None:
-        args = sys.argv[1:]
-
     options = get_options(args)
-    options.action = 'Add'
-    resources = getAllResources(options)
-    print '\n'.join(resources)
+    try:
+        produceResources(options)
+    except Exception:
+        sys.exit(1)
     sys.exit(0)

Modified: z3c.versionedresource/trunk/src/z3c/versionedresource/resource.py
===================================================================
--- z3c.versionedresource/trunk/src/z3c/versionedresource/resource.py	2008-08-10 02:27:08 UTC (rev 89585)
+++ z3c.versionedresource/trunk/src/z3c/versionedresource/resource.py	2008-08-10 06:08:33 UTC (rev 89586)
@@ -42,27 +42,31 @@
         return res
 
 
-class VersionResourceBase(object):
+class VersionedResourceBase(object):
 
     def _createUrl(self, baseUrl, name):
         vm = zope.component.queryUtility(interfaces.IVersionManager)
         return '%s/@@/%s/%s' %(baseUrl, vm.version, name)
 
-
-class Resource(VersionResourceBase, resource.Resource):
+class Resource(VersionedResourceBase, resource.Resource):
     pass
 
-class FileResource(VersionResourceBase, fileresource.FileResource):
+
+class FileResource(VersionedResourceBase, fileresource.FileResource):
     # 10 years expiration date
     cacheTimeout = 10 * 365 * 24 * 3600
 
+    def __repr__(self):
+        return '<%s %r>' %(self.__class__.__name__, self.context.path)
+
 class FileResourceFactory(fileresource.FileResourceFactory):
     resourceClass = FileResource
 
 class ImageResourceFactory(fileresource.ImageResourceFactory):
     resourceClass = FileResource
 
-class DirectoryResource(VersionResourceBase,
+
+class DirectoryResource(VersionedResourceBase,
                         directoryresource.DirectoryResource):
 
     resource_factories = {
@@ -77,6 +81,9 @@
     default_factory = FileResourceFactory
     directory_factory = None
 
+    def __repr__(self):
+        return '<%s %r>' %(self.__class__.__name__, self.context.path)
+
 class DirectoryResourceFactory(directoryresource.DirectoryResourceFactory):
     factoryClass = DirectoryResource
 

Modified: z3c.versionedresource/trunk/src/z3c/versionedresource/tests/simple.zcml
===================================================================
--- z3c.versionedresource/trunk/src/z3c/versionedresource/tests/simple.zcml	2008-08-10 02:27:08 UTC (rev 89585)
+++ z3c.versionedresource/trunk/src/z3c/versionedresource/tests/simple.zcml	2008-08-10 06:08:33 UTC (rev 89586)
@@ -5,13 +5,13 @@
   <include file="meta.zcml" />
 
   <browser:versionedResource
-      name="real-test.gif"
+      name="zcml-test.gif"
       image="tests/testfiles/test.gif"
       layer=".tests.test_doc.ITestLayer"
       />
 
   <browser:versionedResourceDirectory
-      name="real-subdir"
+      name="zcml-subdir"
       directory="tests/testfiles/subdir"
       layer=".tests.test_doc.ITestLayer"
       />

Modified: z3c.versionedresource/trunk/src/z3c/versionedresource/tests/test_doc.py
===================================================================
--- z3c.versionedresource/trunk/src/z3c/versionedresource/tests/test_doc.py	2008-08-10 02:27:08 UTC (rev 89585)
+++ z3c.versionedresource/trunk/src/z3c/versionedresource/tests/test_doc.py	2008-08-10 06:08:33 UTC (rev 89586)
@@ -16,18 +16,43 @@
 $Id$
 """
 __docformat__ = "reStructuredText"
+import os
 import unittest
+import zope.interface
+from zope.component import globalregistry
 from zope.testing import doctest
 from zope.app.testing import placelesssetup
 from zope.publisher.interfaces.browser import IDefaultBrowserLayer
+from z3c.versionedresource import interfaces, resource
 
 class ITestLayer(IDefaultBrowserLayer):
     pass
 
+class ResourceFactory(object):
+
+    def __init__(self, request):
+        self.request = request
+
+    def __repr__(self):
+        return '<%s>' %self.__class__.__name__
+
+def unregister(name):
+    reg = globalregistry.globalSiteManager.adapters
+    reg.unregister((IDefaultBrowserLayer,), interfaces.IVersionedResource, name)
+
+def ls(dir):
+    for name in sorted(os.listdir(dir)):
+        path = os.path.join(dir, name)
+        print '%s %s\t%i' %(
+            'd' if os.path.isdir(path) else 'f',
+            name,
+            os.stat(path).st_size)
+
 def test_suite():
     return unittest.TestSuite((
         doctest.DocFileSuite(
             '../README.txt',
             setUp=placelesssetup.setUp, tearDown=placelesssetup.tearDown,
+            globs = {'ls': ls, 'unregister': unregister},
             optionflags=doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS),
         ))

Added: z3c.versionedresource/trunk/src/z3c/versionedresource/tests/testfiles/test.pt
===================================================================
--- z3c.versionedresource/trunk/src/z3c/versionedresource/tests/testfiles/test.pt	                        (rev 0)
+++ z3c.versionedresource/trunk/src/z3c/versionedresource/tests/testfiles/test.pt	2008-08-10 06:08:33 UTC (rev 89586)
@@ -0,0 +1 @@
+<h1>Test</h1>


Property changes on: z3c.versionedresource/trunk/src/z3c/versionedresource/tests/testfiles/test.pt
___________________________________________________________________
Name: svn:eol-style
   + native



More information about the Checkins mailing list