Permalink
Browse files

added a test environment

svn path=/buildout/plone.recipe.zope2zeoserver/trunk/; revision=58711
  • Loading branch information...
1 parent c83302b commit 706202a0476b4f3cc90b37feaacc150ad486efd8 Tarek Ziade committed Feb 14, 2008
View
@@ -4,7 +4,9 @@ Change History
0.11 (unreleased)
-----------------
-
+- added a test environement and a basic doctest to validate
+ the recipe.
+ [tarek]
0.10
----
View
@@ -0,0 +1,52 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+"""Bootstrap a buildout-based project
+
+Simply run this script in a directory containing a buildout.cfg.
+The script accepts buildout command-line options, so you can
+use the -c option to specify an alternate configuration file.
+
+$Id$
+"""
+
+import os, shutil, sys, tempfile, urllib2
+
+tmpeggs = tempfile.mkdtemp()
+
+ez = {}
+exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
+ ).read() in ez
+ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)
+
+import pkg_resources
+
+cmd = 'from setuptools.command.easy_install import main; main()'
+if sys.platform == 'win32':
+ cmd = '"%s"' % cmd # work around spawn lamosity on windows
+
+ws = pkg_resources.working_set
+assert os.spawnle(
+ os.P_WAIT, sys.executable, sys.executable,
+ '-c', cmd, '-mqNxd', tmpeggs, 'zc.buildout',
+ dict(os.environ,
+ PYTHONPATH=
+ ws.find(pkg_resources.Requirement.parse('setuptools')).location
+ ),
+ ) == 0
+
+ws.add_entry(tmpeggs)
+ws.require('zc.buildout')
+import zc.buildout.buildout
+zc.buildout.buildout.main(sys.argv[1:] + ['bootstrap'])
+shutil.rmtree(tmpeggs)
View
@@ -0,0 +1,8 @@
+[buildout]
+develop = .
+parts = test
+
+[test]
+recipe = zc.recipe.testrunner
+eggs = plone.recipe.zope2zeoserver
+
View
@@ -34,6 +34,7 @@ def read(*rnames):
package_dir = {'':'src'},
namespace_packages = ['plone', 'plone.recipe'],
install_requires = ['zc.buildout', 'setuptools', 'zc.recipe.egg'],
+ tests_require=['zope.testing'],
zip_safe=False,
entry_points = {'zc.buildout': ['default = %s:Recipe' % name]},
)
@@ -0,0 +1 @@
+# package
@@ -0,0 +1,62 @@
+# -*- coding: utf-8 -*-
+"""
+Grabs the doctests in /tests
+"""
+__docformat__ = 'restructuredtext'
+
+import unittest
+import doctest
+import sys
+import re
+import os
+import shutil
+import popen2
+import StringIO
+
+from zope.testing import doctest, renormalizing
+import zc.buildout.testing, zc.buildout.easy_install
+
+current_dir = os.path.abspath(os.path.dirname(__file__))
+recipe_location = current_dir
+
+for i in range(5):
+ recipe_location = os.path.split(recipe_location)[0]
+
+def doc_suite(test_dir, globs=None):
+ """Returns a test suite, based on doctests found in /doctest."""
+ suite = []
+ if globs is None:
+ globs = globals()
+
+ flags = (doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE |
+ doctest.REPORT_ONLY_FIRST_FAILURE)
+
+ doctest_dir = test_dir
+
+ # filtering files on extension
+ docs = [os.path.join(doctest_dir, doc) for doc in
+ os.listdir(doctest_dir) if doc.endswith('.txt')]
+
+ for test in docs:
+ suite.append(doctest.DocFileSuite(test, optionflags=flags,
+ globs=globs,
+ setUp=zc.buildout.testing.buildoutSetUp,
+ tearDown=zc.buildout.testing.buildoutTearDown,
+ checker=renormalizing.RENormalizing([
+ zc.buildout.testing.normalize_path,
+ (re.compile(r'\S+buildout.py'), 'buildout.py'),
+ (re.compile(r'line \d+'), 'line NNN'),
+ (re.compile(r'py\(\d+\)'), 'py(NNN)'),
+ ])
+ ,
+ module_relative=False))
+
+ return unittest.TestSuite(suite)
+
+def test_suite():
+ """returns the test suite"""
+ return doc_suite(current_dir)
+
+if __name__ == '__main__':
+ unittest.main(defaultTest='test_suite')
+
@@ -0,0 +1,79 @@
+===========================
+plone.recipe.zope2zeoserver
+===========================
+
+
+This is the doctest for plone.recipe.zope2instance. It ensures the template
+works fine. It is based on zc.buildout testing module::
+
+ >>> from zc.buildout.testing import *
+ >>> from os.path import join
+ >>> import sys, os
+
+Let's create a minimum buildout that uses the current
+plone.recipe.zope2instance::
+
+ >>> write('buildout.cfg',
+ ... '''
+ ... [buildout]
+ ... parts = zeo
+ ... develop =
+ ... %(recipe_location)s
+ ...
+ ... [zeo]
+ ... recipe = plone.recipe.zope2zeoserver
+ ...
+ ... ''' % globals())
+
+Let's run it::
+
+ >>> print system(join('bin', 'buildout')),
+ Develop: '...'
+ ...
+ Generated script '.../bin/zeo'.
+ Generated script '.../bin/zeopack'.
+
+We should have a zope instance, with a basic zeo.conf::
+
+ >>> zeo = os.path.join(sample_buildout, 'parts', 'zeo')
+ >>> print open(os.path.join(zeo, 'etc', 'zeo.conf')).read()
+ %define INSTANCE /sample-buildout/parts/zeo
+ <BLANKLINE>
+ <zeo>
+ address 8100
+ read-only false
+ invalidation-queue-size 100
+ pid-filename /sample-buildout/var/zeo.pid
+ </zeo>
+ <BLANKLINE>
+ <filestorage 1>
+ path /sample-buildout/var/filestorage/Data.fs
+ </filestorage>
+ <BLANKLINE>
+ <eventlog>
+ level info
+ <logfile>
+ path /sample-buildout/var/log/zeo.log
+ format %(message)s
+ </logfile>
+ </eventlog>
+ <BLANKLINE>
+ <runner>
+ program $INSTANCE/bin/runzeo
+ socket-name /sample-buildout/var/zeo.zdsock
+ daemon true
+ forever false
+ backoff-limit 10
+ exit-codes 0, 2
+ directory $INSTANCE
+ default-to-interactive true
+ <BLANKLINE>
+ <BLANKLINE>
+ # This logfile should match the one in the zeo.conf file.
+ # It is used by zdctl's logtail command, zdrun/zdctl doesn't write it.
+ logfile /sample-buildout/var/log/zeo.log
+ </runner>
+ <BLANKLINE>
+ <BLANKLINE>
+ <BLANKLINE>
+

0 comments on commit 706202a

Please sign in to comment.