Commit df27e3e4 authored by jim's avatar jim

Added testrunner recipe tests.


git-svn-id: http://svn.zope.org/repos/main/zc.buildout/trunk@68532 62d5b8a3-27da-0310-9561-8e5933582275
parent 4c1ca35d
...@@ -4,5 +4,5 @@ parts = test ...@@ -4,5 +4,5 @@ parts = test
[test] [test]
recipe = zc.recipe.testrunner recipe = zc.recipe.testrunner
distributions = zc.buildout zc.recipe.egg distributions = zc.buildout zc.recipe.egg zc.recipe.testrunner
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.
...@@ -16,8 +16,6 @@ ...@@ -16,8 +16,6 @@
$Id$ $Id$
""" """
# XXX need tests
import os, sys import os, sys
import zc.buildout.egglinker import zc.buildout.egglinker
...@@ -30,7 +28,11 @@ class TestRunner: ...@@ -30,7 +28,11 @@ class TestRunner:
def install(self): def install(self):
distributions = self.options['distributions'].split() distributions = self.options['distributions'].split()
path = self.buildout.distributions_path(distributions+['zope.testing']) path = zc.buildout.egglinker.path(
distributions+['zope.testing'],
[self.buildout.eggs],
)
locations = [zc.buildout.egglinker.location(distribution, locations = [zc.buildout.egglinker.location(distribution,
[self.buildout.eggs]) [self.buildout.eggs])
for distribution in distributions] for distribution in distributions]
...@@ -46,6 +48,8 @@ class TestRunner: ...@@ -46,6 +48,8 @@ class TestRunner:
except (AttributeError, os.error): except (AttributeError, os.error):
pass pass
return script
tests_template = """#!%(PYTHON)s tests_template = """#!%(PYTHON)s
......
##############################################################################
#
# 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')
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment