From ac011cb91d23015dbdca14815f228601e223822f Mon Sep 17 00:00:00 2001 From: jim <jim@62d5b8a3-27da-0310-9561-8e5933582275> Date: Tue, 24 Oct 2006 23:30:28 +0000 Subject: [PATCH] Added a working-directory option. git-svn-id: http://svn.zope.org/repos/main/zc.buildout/trunk@70904 62d5b8a3-27da-0310-9561-8e5933582275 --- zc.recipe.testrunner/CHANGES.txt | 10 ++++ zc.recipe.testrunner/setup.py | 5 +- .../src/zc/recipe/testrunner/README.txt | 49 ++++++++++++++++++- .../src/zc/recipe/testrunner/__init__.py | 7 +++ 4 files changed, 67 insertions(+), 4 deletions(-) diff --git a/zc.recipe.testrunner/CHANGES.txt b/zc.recipe.testrunner/CHANGES.txt index b7527f25..adfcc507 100644 --- a/zc.recipe.testrunner/CHANGES.txt +++ b/zc.recipe.testrunner/CHANGES.txt @@ -2,6 +2,16 @@ Change History ************** +1.0.0b4 (2006-10-24) +==================== + +Feature Changes +--------------- + +- Added a working-directoy option to specify a working directory for + the generated script. + + 1.0.0b3 (2006-10-16) ==================== diff --git a/zc.recipe.testrunner/setup.py b/zc.recipe.testrunner/setup.py index c08a1502..9ddae755 100644 --- a/zc.recipe.testrunner/setup.py +++ b/zc.recipe.testrunner/setup.py @@ -7,7 +7,7 @@ def read(*rnames): name = "zc.recipe.testrunner" setup( name = name, - version = "1.0.0b3", + version = "1.0.0b4", author = "Jim Fulton", author_email = "jim@zope.com", description = "ZC Buildout recipe for creating test runners", @@ -32,7 +32,8 @@ setup( include_package_data = True, package_dir = {'':'src'}, namespace_packages = ['zc', 'zc.recipe'], - install_requires = ['zc.buildout >=1.0.0b7', 'zope.testing', 'setuptools', + install_requires = ['zc.buildout >=1.0.0b12', + 'zope.testing', 'setuptools', 'zc.recipe.egg >=1.0.0a3', ], test_suite = name+'.tests.test_suite', diff --git a/zc.recipe.testrunner/src/zc/recipe/testrunner/README.txt b/zc.recipe.testrunner/src/zc/recipe/testrunner/README.txt index 09e11ea4..f17d2cc1 100644 --- a/zc.recipe.testrunner/src/zc/recipe/testrunner/README.txt +++ b/zc.recipe.testrunner/src/zc/recipe/testrunner/README.txt @@ -4,7 +4,7 @@ Test-Runner Recipe The test-runner recipe, zc.recipe.testrunner, creates a test runner for a project. -The test-runner recipe has 3 options: +The test-runner recipe has several options: eggs The eggs option specified a list of eggs to test given as one ore @@ -20,11 +20,15 @@ extra-paths 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. +working-directory + The working-directory option lets to specify a directory where the + tests will run. The testrunner will change to this directory whe + run. + (Note that, at this time, due to limitations in the Zope test runner, the distributions cannot be zip files. TODO: Fix the test runner!) @@ -216,6 +220,47 @@ extra-paths option to specify them: '--test-path', '/sample-buildout/demo', ]) +We can use the working-directory option to specify an working +directory: + + >>> 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 + ... working-directory = /foo/bar + ... """) + + >>> 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', + '/sample-buildout/eggs/setuptools-0.6-py1.3.egg', + '/usr/local/zope/lib/python', + ] + <BLANKLINE> + import os + os.chdir('/foo/bar') + <BLANKLINE> + import zope.testing.testrunner + <BLANKLINE> + if __name__ == '__main__': + zope.testing.testrunner.run([ + '--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 diff --git a/zc.recipe.testrunner/src/zc/recipe/testrunner/__init__.py b/zc.recipe.testrunner/src/zc/recipe/testrunner/__init__.py index 1e10b7dd..2c3e0898 100644 --- a/zc.recipe.testrunner/src/zc/recipe/testrunner/__init__.py +++ b/zc.recipe.testrunner/src/zc/recipe/testrunner/__init__.py @@ -42,6 +42,12 @@ class TestRunner: defaults = options.get('defaults', '').strip() if defaults: defaults = '(%s) + ' % defaults + + wd = options.get('working-directory', '') + if wd: + initialization = "import os\nos.chdir(%r)" % wd + else: + initialization = '' return zc.buildout.easy_install.scripts( [(options['script'], 'zope.testing.testrunner', 'run')], @@ -52,6 +58,7 @@ class TestRunner: TESTPATH=repr(test_paths)[1:-1].replace( ', ', ",\n '--test-path', "), )), + initialization = initialization, ) update = install -- 2.30.9