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
buildout bin directory. Of the option isn't used, the part name
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,
the distributions cannot be zip files. TODO: Fix the test runner!)
......@@ -123,13 +127,12 @@ Now when we run the buildout:
>>> import os
>>> 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:
>>> ls(sample_buildout, 'bin')
- buildout
- py-zc.buildout
- 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:
... 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')
- buildout
- py-zc.buildout
- testdemo
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:
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:
def install(self):
options = self.options
requirements, ws = self.egg.working_set(('zope.testing', ))
path = [dist.location for dist in ws]
project_names = [
pkg_resources.Requirement.parse(r).project_name
for r in requirements
]
locations = [dist.location for dist in ws
if dist.project_name in project_names]
result = []
script = options['script']
if sys.platform == 'win32':
# generate exe file and give the script a magic name:
open(script+'.exe', 'wb').write(
pkg_resources.resource_string('setuptools', 'cli.exe')
)
result.append(script+'.exe')
script += '-script.py'
open(script, 'w').write(tests_template % dict(
PYTHON=options['executable'],
PATH=repr(path)[1:-1].replace(', ', ',\n '),
TESTPATH=repr(locations)[1:-1].replace(
eggs, ws = self.egg.working_set(('zope.testing', ))
test_paths = [ws.find(pkg_resources.Requirement.parse(spec)).location
for spec in eggs]
return zc.buildout.easy_install.scripts(
[(options['script'], 'zope.testing.testrunner', 'run')],
ws, options['executable'],
self.buildout['buildout']['bin-directory'],
extra_paths=self.egg.extra_paths,
arguments = arg_template % dict(
TESTPATH=repr(test_paths)[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 = [
arg_template = """[
'--test-path', %(TESTPATH)s,
]
sys.exit(testrunner.run(defaults))
"""
]"""
......@@ -28,17 +28,18 @@ def 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'),
eggs = os.path.join(test.globs['sample_buildout'], 'eggs')
open(os.path.join(eggs, 'zc.recipe.testrunner.egg-link'),
'w').write(dirname(__file__, 4))
open(os.path.join(test.globs['sample_buildout'],
'eggs', 'zc.recipe.egg.egg-link'),
open(os.path.join(eggs, 'zc.recipe.egg.egg-link'),
'w').write(dirname(zc.recipe.egg.__file__, 4))
# XXX assumes that zope.testing egg is a directory
open(os.path.join(test.globs['sample_buildout'],
'eggs', 'zope.testing.egg-link'),
'w').write(dirname(zope.testing.__file__, 3))
testing = dirname(zope.testing.__file__, 3)
assert testing.endswith('.egg')
if os.path.isfile(testing):
shutil.copy(testing, eggs)
else:
shutil.copytree(testing, os.path.join(eggs, os.path.basename(testing)))
def tearDown(test):
zc.buildout.testing.buildoutTearDown(test)
......@@ -53,6 +54,9 @@ def test_suite():
checker=renormalizing.RENormalizing([
(re.compile('(\n?)- ([a-zA-Z_.-]+)-script.py\n- \\2.exe\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