Commit 2e3a9eec authored by jim's avatar jim

Added defaults option.


git-svn-id: http://svn.zope.org/repos/main/zc.buildout/trunk@70455 62d5b8a3-27da-0310-9561-8e5933582275
parent ec310a92
...@@ -19,6 +19,11 @@ script ...@@ -19,6 +19,11 @@ script
extra-paths extra-paths
One or more extra paths to include in the generated test script. One or more extra paths to include in the generated test script.
defaults
The defaults option lets you specify testrunner default
options. These are specified as Python source for an expression
yielding a list, typically a list literal.
(Note that, at this time, due to limitations in the Zope test runner, (Note that, at this time, due to limitations in the Zope test runner,
the distributions cannot be zip files. TODO: Fix the test runner!) the distributions cannot be zip files. TODO: Fix the test runner!)
...@@ -209,3 +214,56 @@ extra-paths option to specify them: ...@@ -209,3 +214,56 @@ extra-paths option to specify them:
zope.testing.testrunner.run([ zope.testing.testrunner.run([
'--test-path', '/sample-buildout/demo', '--test-path', '/sample-buildout/demo',
]) ])
If we need to specify default options, we can use the defaults
option. For example, Zope 3 applications typically define test suites
in modules named ftests or tests. The default test runner behaviour
is to look in modules named tests. To specify that we want to look in
tests and ftests module, we'd supply a default for the --tests-pattern
option. If we like dots, we could also request more verbose output
using the -v option.
>>> write(sample_buildout, 'buildout.cfg',
... """
... [buildout]
... develop = demo
... parts = testdemo
... offline = true
...
... [testdemo]
... recipe = zc.recipe.testrunner
... eggs = demo
... extra-paths = /usr/local/zope/lib/python
... defaults = ['--tests-pattern', '^f?tests$',
... '-v'
... ]
... """)
>>> print system(os.path.join(sample_buildout, 'bin', 'buildout') + ' -q'),
>>> cat(sample_buildout, 'bin', 'testdemo')
#!/usr/local/bin/python2.4
<BLANKLINE>
import sys
sys.path[0:0] = [
'/sample-buildout/demo',
'/sample-buildout/eggs/zope.testing-3.0-py2.4.egg',
'/usr/local/zope/lib/python',
]
<BLANKLINE>
import zope.testing.testrunner
<BLANKLINE>
if __name__ == '__main__':
zope.testing.testrunner.run((['--tests-pattern', '^f?tests$',
'-v'
]) + [
'--test-path', '/tmp/tmpef05fA/_TEST_/sample-buildout/demo',
])
Some things to note from this example:
- Parentheses are placed around the given expression.
- Leading whitespace is removed.
...@@ -38,16 +38,20 @@ class TestRunner: ...@@ -38,16 +38,20 @@ class TestRunner:
test_paths = [ws.find(pkg_resources.Requirement.parse(spec)).location test_paths = [ws.find(pkg_resources.Requirement.parse(spec)).location
for spec in eggs] for spec in eggs]
defaults = options.get('defaults', '').strip()
if defaults:
defaults = '(%s) + ' % defaults
return zc.buildout.easy_install.scripts( return zc.buildout.easy_install.scripts(
[(options['script'], 'zope.testing.testrunner', 'run')], [(options['script'], 'zope.testing.testrunner', 'run')],
ws, options['executable'], ws, options['executable'],
self.buildout['buildout']['bin-directory'], self.buildout['buildout']['bin-directory'],
extra_paths=self.egg.extra_paths, extra_paths=self.egg.extra_paths,
arguments = arg_template % dict( arguments = defaults + (arg_template % dict(
TESTPATH=repr(test_paths)[1:-1].replace( TESTPATH=repr(test_paths)[1:-1].replace(
', ', ",\n '--test-path', "), ', ', ",\n '--test-path', "),
), )),
) )
arg_template = """[ arg_template = """[
......
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