[Checkins] SVN: zc.buildout/trunk/ Added testrunner recipe tests.
Jim Fulton
jim at zope.com
Thu Jun 8 18:59:24 EDT 2006
Log message for revision 68532:
Added testrunner recipe tests.
Changed:
U zc.buildout/trunk/buildout.cfg
A zc.buildout/trunk/testrunnerrecipe/src/zc/recipe/testrunner/
A zc.buildout/trunk/testrunnerrecipe/src/zc/recipe/testrunner/README.txt
A zc.buildout/trunk/testrunnerrecipe/src/zc/recipe/testrunner/__init__.py
A zc.buildout/trunk/testrunnerrecipe/src/zc/recipe/testrunner/tests.py
D zc.buildout/trunk/testrunnerrecipe/src/zc/recipe/testrunner.py
-=-
Modified: zc.buildout/trunk/buildout.cfg
===================================================================
--- zc.buildout/trunk/buildout.cfg 2006-06-08 18:13:43 UTC (rev 68531)
+++ zc.buildout/trunk/buildout.cfg 2006-06-08 22:59:23 UTC (rev 68532)
@@ -4,5 +4,5 @@
[test]
recipe = zc.recipe.testrunner
-distributions = zc.buildout zc.recipe.egg
+distributions = zc.buildout zc.recipe.egg zc.recipe.testrunner
Added: zc.buildout/trunk/testrunnerrecipe/src/zc/recipe/testrunner/README.txt
===================================================================
--- zc.buildout/trunk/testrunnerrecipe/src/zc/recipe/testrunner/README.txt 2006-06-08 18:13:43 UTC (rev 68531)
+++ zc.buildout/trunk/testrunnerrecipe/src/zc/recipe/testrunner/README.txt 2006-06-08 22:59:23 UTC (rev 68532)
@@ -0,0 +1,102 @@
+Test-Runner Recipe
+==================
+
+The test-runner recipe, zc.recipe.testrunner, creates a test runner
+for a project.
+
+The rest-runner recipe has 2 options:
+
+- The distributions option takes the names of the distributions to be tested.
+ These are not installed by the recipe. They must be installed by
+ some other recipe. This option is required.
+
+- The script option gives the name of the script to generate, in the
+ buildout bin directory. Of the option isn't used, the part name
+ will be used.
+
+(Note that, at this time, due to limitations in the Zope test runner,
+the distributions cannot be zip files. XXX need to add option to an
+unzip option to the egg recipe.)
+
+To illustrate this, we'll create a project in our sample buildout:
+
+ >>> mkdir(sample_buildout, 'demo')
+ >>> write(sample_buildout, 'demo', 'tests.py',
+ ... '''
+ ... import unittest
+ ...
+ ... class TestSomething(unittest.TestCase):
+ ... def test_something(self):
+ ... pass
+ ...
+ ... def test_suite():
+ ... return unittest.makeSuite(TestSomething)
+ ... ''')
+
+ >>> write(sample_buildout, 'demo', 'setup.py',
+ ... """
+ ... from setuptools import setup
+ ...
+ ... setup(name = "demo")
+ ... """)
+
+ >>> write(sample_buildout, 'demo', 'README.txt', '')
+
+We'll update our buildout to install the demo project as a
+develop egg and to create the test script:
+
+ >>> write(sample_buildout, 'buildout.cfg',
+ ... """
+ ... [buildout]
+ ... develop = demo
+ ... parts = testdemo
+ ...
+ ... [testdemo]
+ ... recipe = zc.recipe.testrunner
+ ... distributions = demo
+ ... script = test
+ ... """)
+
+Now when we run the buildout:
+
+ >>> import os
+ >>> os.chdir(sample_buildout)
+ >>> print system(os.path.join(sample_buildout, 'bin', 'buildout')),
+
+We get a test script installed in our bin directory:
+
+ >>> ls(sample_buildout, 'bin')
+ - buildout
+ - test
+
+We can run the test script to run our demo test:
+
+ >>> print system(os.path.join(sample_buildout, 'bin', 'test')),
+ Running unit tests:
+ Ran 1 tests with 0 failures and 0 errors in 0.000 seconds.
+
+If we leave the script option out of the configuration, then the test
+script will get it's name from the part:
+
+ >>> write(sample_buildout, 'buildout.cfg',
+ ... """
+ ... [buildout]
+ ... develop = demo
+ ... parts = testdemo
+ ...
+ ... [testdemo]
+ ... recipe = zc.recipe.testrunner
+ ... distributions = demo
+ ... """)
+
+ >>> print system(os.path.join(sample_buildout, 'bin', 'buildout')),
+
+ >>> ls(sample_buildout, 'bin')
+ - buildout
+ - testdemo
+
+We can run the test script to run our demo test:
+
+ >>> print system(os.path.join(sample_buildout, 'bin', 'testdemo')),
+ Running unit tests:
+ Ran 1 tests with 0 failures and 0 errors in 0.000 seconds.
Property changes on: zc.buildout/trunk/testrunnerrecipe/src/zc/recipe/testrunner/README.txt
___________________________________________________________________
Name: svn:eol-style
+ native
Copied: zc.buildout/trunk/testrunnerrecipe/src/zc/recipe/testrunner/__init__.py (from rev 68531, zc.buildout/trunk/testrunnerrecipe/src/zc/recipe/testrunner.py)
===================================================================
--- zc.buildout/trunk/testrunnerrecipe/src/zc/recipe/testrunner.py 2006-06-08 18:13:43 UTC (rev 68531)
+++ zc.buildout/trunk/testrunnerrecipe/src/zc/recipe/testrunner/__init__.py 2006-06-08 22:59:23 UTC (rev 68532)
@@ -0,0 +1,69 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+"""A few built-in recipes
+
+$Id$
+"""
+
+import os, sys
+import zc.buildout.egglinker
+
+class TestRunner:
+
+ def __init__(self, buildout, name, options):
+ self.buildout = buildout
+ self.name = name
+ self.options = options
+
+ def install(self):
+ distributions = self.options['distributions'].split()
+ path = zc.buildout.egglinker.path(
+ distributions+['zope.testing'],
+ [self.buildout.eggs],
+ )
+
+ locations = [zc.buildout.egglinker.location(distribution,
+ [self.buildout.eggs])
+ for distribution in distributions]
+ script = self.options.get('script', self.name)
+ script = self.buildout.buildout_path('bin', script)
+ open(script, 'w').write(tests_template % dict(
+ PYTHON=sys.executable,
+ PATH="',\n '".join(path),
+ TESTPATH="',\n '--test-path', '".join(locations),
+ ))
+ try:
+ os.chmod(script, 0755)
+ except (AttributeError, os.error):
+ pass
+
+ return script
+
+
+tests_template = """#!%(PYTHON)s
+
+import sys
+sys.path[0:0] = [
+ '%(PATH)s',
+ ]
+
+from zope.testing import testrunner
+
+defaults = [
+ '--test-path', '%(TESTPATH)s',
+ ]
+
+sys.exit(testrunner.run(defaults))
+"""
+
Added: zc.buildout/trunk/testrunnerrecipe/src/zc/recipe/testrunner/tests.py
===================================================================
--- zc.buildout/trunk/testrunnerrecipe/src/zc/recipe/testrunner/tests.py 2006-06-08 18:13:43 UTC (rev 68531)
+++ zc.buildout/trunk/testrunnerrecipe/src/zc/recipe/testrunner/tests.py 2006-06-08 22:59:23 UTC (rev 68532)
@@ -0,0 +1,48 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+
+import os, re, shutil, sys, tempfile
+import pkg_resources
+import zc.buildout.testing
+
+import unittest
+from zope.testing import doctest, renormalizing
+
+def dirname(d, level=1):
+ if level == 0:
+ return d
+ return dirname(os.path.dirname(d), level-1)
+
+def setUp(test):
+ zc.buildout.testing.buildoutSetUp(test)
+ open(os.path.join(test.globs['sample_buildout'],
+ 'eggs', 'zc.recipe.testrunner.egg-link'),
+ 'w').write(dirname(__file__, 4))
+
+def tearDown(test):
+ zc.buildout.testing.buildoutTearDown(test)
+
+
+def test_suite():
+ return unittest.TestSuite((
+ #doctest.DocTestSuite(),
+ doctest.DocFileSuite(
+ 'README.txt',
+ setUp=setUp, tearDown=tearDown,
+ ),
+
+ ))
+
+if __name__ == '__main__':
+ unittest.main(defaultTest='test_suite')
Property changes on: zc.buildout/trunk/testrunnerrecipe/src/zc/recipe/testrunner/tests.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Deleted: zc.buildout/trunk/testrunnerrecipe/src/zc/recipe/testrunner.py
===================================================================
--- zc.buildout/trunk/testrunnerrecipe/src/zc/recipe/testrunner.py 2006-06-08 18:13:43 UTC (rev 68531)
+++ zc.buildout/trunk/testrunnerrecipe/src/zc/recipe/testrunner.py 2006-06-08 22:59:23 UTC (rev 68532)
@@ -1,65 +0,0 @@
-##############################################################################
-#
-# 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.
-#
-##############################################################################
-"""A few built-in recipes
-
-$Id$
-"""
-
-# XXX need tests
-
-import os, sys
-import zc.buildout.egglinker
-
-class TestRunner:
-
- def __init__(self, buildout, name, options):
- self.buildout = buildout
- self.name = name
- self.options = options
-
- def install(self):
- distributions = self.options['distributions'].split()
- path = self.buildout.distributions_path(distributions+['zope.testing'])
- locations = [zc.buildout.egglinker.location(distribution,
- [self.buildout.eggs])
- for distribution in distributions]
- script = self.options.get('script', self.name)
- script = self.buildout.buildout_path('bin', script)
- open(script, 'w').write(tests_template % dict(
- PYTHON=sys.executable,
- PATH="',\n '".join(path),
- TESTPATH="',\n '--test-path', '".join(locations),
- ))
- try:
- os.chmod(script, 0755)
- except (AttributeError, os.error):
- pass
-
-
-tests_template = """#!%(PYTHON)s
-
-import sys
-sys.path[0:0] = [
- '%(PATH)s',
- ]
-
-from zope.testing import testrunner
-
-defaults = [
- '--test-path', '%(TESTPATH)s',
- ]
-
-sys.exit(testrunner.run(defaults))
-"""
-
More information about the Checkins
mailing list