[Checkins] SVN: zc.buildout/trunk/zc.recipe.testrunner/src/zc/recipe/testrunner/ Added defaults option.

Jim Fulton jim at zope.com
Sun Oct 1 11:15:14 EDT 2006


Log message for revision 70455:
  Added defaults option.
  

Changed:
  U   zc.buildout/trunk/zc.recipe.testrunner/src/zc/recipe/testrunner/README.txt
  U   zc.buildout/trunk/zc.recipe.testrunner/src/zc/recipe/testrunner/__init__.py

-=-
Modified: zc.buildout/trunk/zc.recipe.testrunner/src/zc/recipe/testrunner/README.txt
===================================================================
--- zc.buildout/trunk/zc.recipe.testrunner/src/zc/recipe/testrunner/README.txt	2006-10-01 15:15:11 UTC (rev 70454)
+++ zc.buildout/trunk/zc.recipe.testrunner/src/zc/recipe/testrunner/README.txt	2006-10-01 15:15:13 UTC (rev 70455)
@@ -19,7 +19,12 @@
 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. 
+
 (Note that, at this time, due to limitations in the Zope test runner,
  the distributions cannot be zip files. TODO: Fix the test runner!)
 
@@ -209,3 +214,56 @@
         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
+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.
+
+  

Modified: zc.buildout/trunk/zc.recipe.testrunner/src/zc/recipe/testrunner/__init__.py
===================================================================
--- zc.buildout/trunk/zc.recipe.testrunner/src/zc/recipe/testrunner/__init__.py	2006-10-01 15:15:11 UTC (rev 70454)
+++ zc.buildout/trunk/zc.recipe.testrunner/src/zc/recipe/testrunner/__init__.py	2006-10-01 15:15:13 UTC (rev 70455)
@@ -38,16 +38,20 @@
 
         test_paths = [ws.find(pkg_resources.Requirement.parse(spec)).location
                       for spec in eggs]
+
+        defaults = options.get('defaults', '').strip()
+        if defaults:
+            defaults = '(%s) + ' % defaults
         
         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(
+            arguments = defaults + (arg_template % dict(
                 TESTPATH=repr(test_paths)[1:-1].replace(
                                ', ', ",\n  '--test-path', "),
-                ),
+                )),
             )
 
 arg_template = """[



More information about the Checkins mailing list