Commit 34b163be authored by jim's avatar jim

Added an extra-paths option to specify paths other than eggs.

Cleaned up the implementation to make greater use of and duplicate
less code from zc.buildout.easy_install.


git-svn-id: http://svn.zope.org/repos/main/zc.buildout/trunk@69992 62d5b8a3-27da-0310-9561-8e5933582275
parent c85a590f
...@@ -16,6 +16,10 @@ script ...@@ -16,6 +16,10 @@ script
buildout bin directory. Of the option isn't used, the part name buildout bin directory. Of the option isn't used, the part name
will be used. will be used.
extra-paths
One or more extra paths to include in the generated test script.
(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!)
...@@ -123,13 +127,12 @@ Now when we run the buildout: ...@@ -123,13 +127,12 @@ Now when we run the buildout:
>>> import os >>> import os
>>> os.chdir(sample_buildout) >>> os.chdir(sample_buildout)
>>> print system(os.path.join(sample_buildout, 'bin', 'buildout')), >>> print system(os.path.join(sample_buildout, 'bin', 'buildout') + ' -q'),
We get a test script installed in our bin directory: We get a test script installed in our bin directory:
>>> ls(sample_buildout, 'bin') >>> ls(sample_buildout, 'bin')
- buildout - buildout
- py-zc.buildout
- test - test
We can run the test script to run our demo test: We can run the test script to run our demo test:
...@@ -160,15 +163,49 @@ script will get it's name from the part: ...@@ -160,15 +163,49 @@ script will get it's name from the part:
... eggs = demo ... eggs = demo
... """) ... """)
>>> print system(os.path.join(sample_buildout, 'bin', 'buildout')), >>> print system(os.path.join(sample_buildout, 'bin', 'buildout') + ' -q'),
>>> ls(sample_buildout, 'bin') >>> ls(sample_buildout, 'bin')
- buildout - buildout
- py-zc.buildout
- testdemo - testdemo
We can run the test script to run our demo test: We can run the test script to run our demo test:
>>> print system(os.path.join(sample_buildout, 'bin', 'testdemo')), >>> print system(os.path.join(sample_buildout, 'bin', 'testdemo') + ' -q'),
Running unit tests: Running unit tests:
Ran 1 tests with 0 failures and 0 errors in 0.000 seconds. Ran 1 tests with 0 failures and 0 errors in 0.000 seconds.
If we need to include other paths in our test script, we can use the
extra-paths option to specify them:
>>> 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
... """)
>>> 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.3.egg',
'/usr/local/zope/lib/python',
]
<BLANKLINE>
import zope.testing.testrunner
<BLANKLINE>
if __name__ == '__main__':
zope.testing.testrunner.run([
'--test-path', '/private/tmp/tmppoToJzsample-buildout/demo',
])
...@@ -34,56 +34,23 @@ class TestRunner: ...@@ -34,56 +34,23 @@ class TestRunner:
def install(self): def install(self):
options = self.options options = self.options
requirements, ws = self.egg.working_set(('zope.testing', )) eggs, ws = self.egg.working_set(('zope.testing', ))
path = [dist.location for dist in ws] test_paths = [ws.find(pkg_resources.Requirement.parse(spec)).location
project_names = [ for spec in eggs]
pkg_resources.Requirement.parse(r).project_name
for r in requirements
]
locations = [dist.location for dist in ws return zc.buildout.easy_install.scripts(
if dist.project_name in project_names] [(options['script'], 'zope.testing.testrunner', 'run')],
ws, options['executable'],
result = [] self.buildout['buildout']['bin-directory'],
script = options['script'] extra_paths=self.egg.extra_paths,
if sys.platform == 'win32': arguments = arg_template % dict(
# generate exe file and give the script a magic name: TESTPATH=repr(test_paths)[1:-1].replace(
open(script+'.exe', 'wb').write( ', ', ",\n '--test-path', "),
pkg_resources.resource_string('setuptools', 'cli.exe') ),
) )
result.append(script+'.exe')
script += '-script.py' arg_template = """[
open(script, 'w').write(tests_template % dict(
PYTHON=options['executable'],
PATH=repr(path)[1:-1].replace(', ', ',\n '),
TESTPATH=repr(locations)[1:-1].replace(
', ', ",\n '--test-path', "),
))
try:
os.chmod(script, 0755)
except (AttributeError, os.error):
pass
result.append(script)
return result
tests_template = """#!%(PYTHON)s
import sys
sys.path[0:0] = [
%(PATH)s,
]
from zope.testing import testrunner
defaults = [
'--test-path', %(TESTPATH)s, '--test-path', %(TESTPATH)s,
] ]"""
sys.exit(testrunner.run(defaults))
"""
...@@ -28,17 +28,18 @@ def dirname(d, level=1): ...@@ -28,17 +28,18 @@ def dirname(d, level=1):
def setUp(test): def setUp(test):
zc.buildout.testing.buildoutSetUp(test) zc.buildout.testing.buildoutSetUp(test)
open(os.path.join(test.globs['sample_buildout'], eggs = os.path.join(test.globs['sample_buildout'], 'eggs')
'eggs', 'zc.recipe.testrunner.egg-link'), open(os.path.join(eggs, 'zc.recipe.testrunner.egg-link'),
'w').write(dirname(__file__, 4)) 'w').write(dirname(__file__, 4))
open(os.path.join(test.globs['sample_buildout'], open(os.path.join(eggs, 'zc.recipe.egg.egg-link'),
'eggs', 'zc.recipe.egg.egg-link'),
'w').write(dirname(zc.recipe.egg.__file__, 4)) 'w').write(dirname(zc.recipe.egg.__file__, 4))
# XXX assumes that zope.testing egg is a directory testing = dirname(zope.testing.__file__, 3)
open(os.path.join(test.globs['sample_buildout'], assert testing.endswith('.egg')
'eggs', 'zope.testing.egg-link'), if os.path.isfile(testing):
'w').write(dirname(zope.testing.__file__, 3)) shutil.copy(testing, eggs)
else:
shutil.copytree(testing, os.path.join(eggs, os.path.basename(testing)))
def tearDown(test): def tearDown(test):
zc.buildout.testing.buildoutTearDown(test) zc.buildout.testing.buildoutTearDown(test)
...@@ -52,7 +53,10 @@ def test_suite(): ...@@ -52,7 +53,10 @@ def test_suite():
setUp=setUp, tearDown=tearDown, setUp=setUp, tearDown=tearDown,
checker=renormalizing.RENormalizing([ checker=renormalizing.RENormalizing([
(re.compile('(\n?)- ([a-zA-Z_.-]+)-script.py\n- \\2.exe\n'), (re.compile('(\n?)- ([a-zA-Z_.-]+)-script.py\n- \\2.exe\n'),
'\\1- \\2\n'), '\\1- \\2\n'),
(re.compile('#!\S+python\S*'), '#!python'),
(re.compile('\S+sample-(\w+)'), r'/sample-\1'),
(re.compile('-([^-]+)-py\d[.]\d.egg'), r'-py2.3.egg'),
]) ])
), ),
......
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