[Checkins] SVN: zc.recipe.testrunner/trunk/ Added a relative-paths option to use egg, test, and

Jim Fulton jim at zope.com
Thu Mar 19 16:43:02 EDT 2009


Log message for revision 98279:
  Added a relative-paths option to use egg, test, and
  working-directory paths relative to the test script.
  

Changed:
  U   zc.recipe.testrunner/trunk/CHANGES.txt
  U   zc.recipe.testrunner/trunk/setup.py
  U   zc.recipe.testrunner/trunk/src/zc/recipe/testrunner/README.txt
  U   zc.recipe.testrunner/trunk/src/zc/recipe/testrunner/__init__.py
  U   zc.recipe.testrunner/trunk/src/zc/recipe/testrunner/tests.py

-=-
Modified: zc.recipe.testrunner/trunk/CHANGES.txt
===================================================================
--- zc.recipe.testrunner/trunk/CHANGES.txt	2009-03-19 18:46:11 UTC (rev 98278)
+++ zc.recipe.testrunner/trunk/CHANGES.txt	2009-03-19 20:43:01 UTC (rev 98279)
@@ -2,10 +2,11 @@
 Change History
 **************
 
-1.1.1 (unreleased)
+1.2.0 (2009-03-19)
 ==================
 
-- 
+- Added a relative-paths option to use egg, test, and
+  working-directory paths relative to the test script.
 
 
 1.1.0 (2008-08-25)

Modified: zc.recipe.testrunner/trunk/setup.py
===================================================================
--- zc.recipe.testrunner/trunk/setup.py	2009-03-19 18:46:11 UTC (rev 98278)
+++ zc.recipe.testrunner/trunk/setup.py	2009-03-19 20:43:01 UTC (rev 98279)
@@ -29,10 +29,10 @@
     include_package_data = True,
     package_dir = {'':'src'},
     namespace_packages = ['zc', 'zc.recipe'],
-    install_requires = ['zc.buildout >=1.0.0b12',
-                        'zope.testing >=3.6.0', 
+    install_requires = ['zc.buildout >=1.2.0',
+                        'zope.testing >=3.6.0',
                         'setuptools',
-                        'zc.recipe.egg  >=1.0.0a3',
+                        'zc.recipe.egg  >=1.2.0',
                         ],
     test_suite = name+'.tests.test_suite',
     entry_points = {'zc.buildout': ['default = %s:TestRunner' % name]},

Modified: zc.recipe.testrunner/trunk/src/zc/recipe/testrunner/README.txt
===================================================================
--- zc.recipe.testrunner/trunk/src/zc/recipe/testrunner/README.txt	2009-03-19 18:46:11 UTC (rev 98278)
+++ zc.recipe.testrunner/trunk/src/zc/recipe/testrunner/README.txt	2009-03-19 20:43:01 UTC (rev 98279)
@@ -22,7 +22,7 @@
 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. 
+    yielding a list, typically a list literal.
 
 working-directory
     The working-directory option lets to specify a directory where the
@@ -34,6 +34,12 @@
     A set of environment variables that should be exported before
     starting the tests.
 
+initialization
+    Provide initialization code to run before running tests.
+
+relative-paths
+    Use egg, test, and working-directory paths relative to the 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!)
 
@@ -58,7 +64,7 @@
     >>> write(sample_buildout, 'demo', 'setup.py',
     ... """
     ... from setuptools import setup
-    ... 
+    ...
     ... setup(name = "demo")
     ... """)
 
@@ -82,7 +88,7 @@
     >>> write(sample_buildout, 'demo2', 'setup.py',
     ... """
     ... from setuptools import setup
-    ... 
+    ...
     ... setup(name = "demo2", install_requires= ['demoneeded'])
     ... """)
 
@@ -108,7 +114,7 @@
     >>> write(sample_buildout, 'demoneeded', 'setup.py',
     ... """
     ... from setuptools import setup
-    ... 
+    ...
     ... setup(name = "demoneeded")
     ... """)
 
@@ -126,7 +132,7 @@
     ...
     ... [testdemo]
     ... recipe = zc.recipe.testrunner
-    ... eggs = 
+    ... eggs =
     ...    demo
     ...    demo2
     ... script = test
@@ -154,6 +160,7 @@
     >>> ls(sample_buildout, 'parts')
     d  testdemo
 
+
 And updating leaves its contents intact:
 
     >>> _ = system(os.path.join(sample_buildout, 'bin', 'test') +
@@ -228,7 +235,7 @@
 
     >>> print system(os.path.join(sample_buildout, 'bin', 'buildout') + ' -q'),
 
-    >>> cat(sample_buildout, 'bin', 'testdemo') # doctest: +REPORT_NDIFF
+    >>> cat(sample_buildout, 'bin', 'testdemo')
     #!/usr/local/bin/python2.4
     <BLANKLINE>
     import sys
@@ -249,8 +256,8 @@
     <BLANKLINE>
     if __name__ == '__main__':
         zope.testing.testrunner.run([
-      '--test-path', '/sample-buildout/demo',
-      ])
+            '--test-path', '/sample-buildout/demo',
+            ])
 
 We can use the working-directory option to specify a working
 directory:
@@ -271,7 +278,7 @@
 
     >>> print system(os.path.join(sample_buildout, 'bin', 'buildout') + ' -q'),
 
-    >>> cat(sample_buildout, 'bin', 'testdemo') # doctest: +REPORT_NDIFF
+    >>> cat(sample_buildout, 'bin', 'testdemo')
     #!/usr/local/bin/python2.4
     <BLANKLINE>
     import sys
@@ -292,8 +299,8 @@
     <BLANKLINE>
     if __name__ == '__main__':
         zope.testing.testrunner.run([
-      '--test-path', '/sample-buildout/demo',
-      ])
+            '--test-path', '/sample-buildout/demo',
+            ])
 
 Now that out tests use a specified working directory, their designated
 part directory is gone:
@@ -319,14 +326,14 @@
     ... recipe = zc.recipe.testrunner
     ... eggs = demo
     ... extra-paths = /usr/local/zope/lib/python
-    ... defaults = ['--tests-pattern', '^f?tests$', 
+    ... defaults = ['--tests-pattern', '^f?tests$',
     ...             '-v'
     ...            ]
     ... """)
 
     >>> print system(os.path.join(sample_buildout, 'bin', 'buildout') + ' -q'),
 
-    >>> cat(sample_buildout, 'bin', 'testdemo') 
+    >>> cat(sample_buildout, 'bin', 'testdemo')
     #!/usr/local/bin/python2.4
     <BLANKLINE>
     import sys
@@ -349,8 +356,8 @@
         zope.testing.testrunner.run((['--tests-pattern', '^f?tests$',
     '-v'
     ]) + [
-      '--test-path', '/sample-buildout/demo',
-      ])
+            '--test-path', '/sample-buildout/demo',
+            ])
 
 Some things to note from this example:
 
@@ -424,7 +431,7 @@
 
     >>> print system(os.path.join(sample_buildout, 'bin', 'buildout') + ' -q'),
 
-    >>> cat(sample_buildout, 'bin', 'testdemo') # doctest: +REPORT_NDIFF
+    >>> cat(sample_buildout, 'bin', 'testdemo')
     #!/usr/local/bin/python2.4
     <BLANKLINE>
     import sys
@@ -445,8 +452,8 @@
     <BLANKLINE>
     if __name__ == '__main__':
         zope.testing.testrunner.run([
-      '--test-path', '/sample-buildout/demo',
-      ])
+            '--test-path', '/sample-buildout/demo',
+            ])
 
     >>> print system(os.path.join(sample_buildout, 'bin', 'testdemo') + ' -vv'),
     Running tests at level 1
@@ -472,7 +479,7 @@
     ... recipe = zc.recipe.testrunner
     ... eggs = demo
     ... extra-paths = /usr/local/zope/lib/python
-    ... defaults = ['--tests-pattern', '^f?tests$', 
+    ... defaults = ['--tests-pattern', '^f?tests$',
     ...             '-v'
     ...            ]
     ... initialization = print 'Hello all you egg-laying pythons!'
@@ -480,7 +487,7 @@
 
     >>> print system(os.path.join(sample_buildout, 'bin', 'buildout') + ' -q'),
 
-    >>> cat(sample_buildout, 'bin', 'testdemo') # doctest: +REPORT_NDIFF
+    >>> cat(sample_buildout, 'bin', 'testdemo')
     #!/usr/local/bin/python2.4
     <BLANKLINE>
     import sys
@@ -503,8 +510,8 @@
         zope.testing.testrunner.run((['--tests-pattern', '^f?tests$',
     '-v'
     ]) + [
-      '--test-path', '/sample-buildout/demo',
-      ])
+            '--test-path', '/sample-buildout/demo',
+            ])
 
 This will also work with a multi-line initialization section:
 
@@ -519,7 +526,7 @@
     ... recipe = zc.recipe.testrunner
     ... eggs = demo
     ... extra-paths = /usr/local/zope/lib/python
-    ... defaults = ['--tests-pattern', '^f?tests$', 
+    ... defaults = ['--tests-pattern', '^f?tests$',
     ...             '-v'
     ...            ]
     ... initialization = print 'Hello all you egg-laying pythons!'
@@ -528,7 +535,7 @@
 
     >>> print system(os.path.join(sample_buildout, 'bin', 'buildout') + ' -q'),
 
-    >>> cat(sample_buildout, 'bin', 'testdemo') # doctest: +REPORT_NDIFF
+    >>> cat(sample_buildout, 'bin', 'testdemo')
     #!/usr/local/bin/python2.4
     <BLANKLINE>
     import sys
@@ -552,5 +559,107 @@
         zope.testing.testrunner.run((['--tests-pattern', '^f?tests$',
     '-v'
     ]) + [
-      '--test-path', '/sample-buildout/demo',
-      ])
\ No newline at end of file
+            '--test-path', '/sample-buildout/demo',
+            ])
+
+If the relative-paths option is used, egg (and extra) paths are
+generated relative to the test script.
+
+    >>> 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
+    ...               ${buildout:directory}/sources
+    ... relative-paths = true
+    ... """)
+
+    >>> print system(os.path.join(sample_buildout, 'bin', 'buildout') + ' -q'),
+
+    >>> cat(sample_buildout, 'bin', 'testdemo')
+    #!/usr/local/bin/python2.4
+    <BLANKLINE>
+    import os
+    <BLANKLINE>
+    join = os.path.join
+    base = os.path.dirname(__file__)
+    base = os.path.dirname(base)
+    <BLANKLINE>
+    import sys
+    sys.path[0:0] = [
+      join(base, 'demo'),
+      join(base, 'eggs/zope.testing-3.7.1-py2.4.egg'),
+      join(base, 'eggs/zope.interface-3.5.1-py2.4-linux-i686.egg'),
+      join(base, 'eggs/setuptools-0.6c9-py2.4.egg'),
+      '/usr/local/zope/lib/python',
+      join(base, 'sources'),
+      ]
+    <BLANKLINE>
+    import os
+    sys.argv[0] = os.path.abspath(sys.argv[0])
+    os.chdir(join(base, 'parts/testdemo'))
+    <BLANKLINE>
+    <BLANKLINE>
+    import zope.testing.testrunner
+    <BLANKLINE>
+    if __name__ == '__main__':
+        zope.testing.testrunner.run([
+            '--test-path', join(base, 'demo'),
+            ])
+
+The relative-paths option can be specified at the buildout level:
+
+    >>> write(sample_buildout, 'buildout.cfg',
+    ... """
+    ... [buildout]
+    ... develop = demo
+    ... parts = testdemo
+    ... offline = true
+    ... relative-paths = true
+    ...
+    ... [testdemo]
+    ... recipe = zc.recipe.testrunner
+    ... eggs = demo
+    ... extra-paths = /usr/local/zope/lib/python
+    ...               ${buildout:directory}/sources
+    ... """)
+
+    >>> print system(os.path.join(sample_buildout, 'bin', 'buildout') + ' -q'),
+
+    >>> cat(sample_buildout, 'bin', 'testdemo')
+    #!/usr/local/bin/python2.4
+    <BLANKLINE>
+    import os
+    <BLANKLINE>
+    join = os.path.join
+    base = os.path.dirname(__file__)
+    base = os.path.dirname(base)
+    <BLANKLINE>
+    import sys
+    sys.path[0:0] = [
+      join(base, 'demo'),
+      join(base, 'eggs/zope.testing-3.7.1-py2.4.egg'),
+      join(base, 'eggs/zope.interface-3.5.1-py2.4-linux-i686.egg'),
+      join(base, 'eggs/setuptools-0.6c9-py2.4.egg'),
+      '/usr/local/zope/lib/python',
+      join(base, 'sources'),
+      ]
+    <BLANKLINE>
+    import os
+    sys.argv[0] = os.path.abspath(sys.argv[0])
+    os.chdir(join(base, 'parts/testdemo'))
+    <BLANKLINE>
+    <BLANKLINE>
+    import zope.testing.testrunner
+    <BLANKLINE>
+    if __name__ == '__main__':
+        zope.testing.testrunner.run([
+            '--test-path', join(base, 'demo'),
+            ])
+

Modified: zc.recipe.testrunner/trunk/src/zc/recipe/testrunner/__init__.py
===================================================================
--- zc.recipe.testrunner/trunk/src/zc/recipe/testrunner/__init__.py	2009-03-19 18:46:11 UTC (rev 98278)
+++ zc.recipe.testrunner/trunk/src/zc/recipe/testrunner/__init__.py	2009-03-19 20:43:01 UTC (rev 98279)
@@ -58,6 +58,15 @@
                 os.mkdir(wd)
             dest.append(wd)
         wd = os.path.abspath(wd)
+
+        if self.egg._relative_paths:
+            wd = _relativize(self.egg._relative_paths, wd)
+            test_paths = [_relativize(self.egg._relative_paths, p)
+                          for p in test_paths]
+        else:
+            wd = repr(wd)
+            test_paths = map(repr, test_paths)
+
         initialization = initialization_template % wd
 
         env_section = options.get('environment', '').strip()
@@ -75,11 +84,13 @@
             ws, options['executable'],
             self.buildout['buildout']['bin-directory'],
             extra_paths=self.egg.extra_paths,
-            arguments = defaults + (arg_template % dict(
-                TESTPATH=repr(test_paths)[1:-1].replace(
-                               ', ', ",\n  '--test-path', "),
-                )),
+            arguments = defaults + (
+                    '[\n'+
+                    ''.join(("        '--test-path', %s,\n" % p)
+                            for p in test_paths)
+                    +'        ]'),
             initialization = initialization,
+            relative_paths = self.egg._relative_paths,
             ))
 
         return dest
@@ -92,8 +103,16 @@
 
 initialization_template = """import os
 sys.argv[0] = os.path.abspath(sys.argv[0])
-os.chdir(%r)
+os.chdir(%s)
 """
 
 env_template = """os.environ['%s'] = %r
 """
+
+def _relativize(base, path):
+    base += os.path.sep
+    if path.startswith(base):
+        path = 'join(base, %r)' % path[len(base):]
+    else:
+        path = repr(path)
+    return path

Modified: zc.recipe.testrunner/trunk/src/zc/recipe/testrunner/tests.py
===================================================================
--- zc.recipe.testrunner/trunk/src/zc/recipe/testrunner/tests.py	2009-03-19 18:46:11 UTC (rev 98278)
+++ zc.recipe.testrunner/trunk/src/zc/recipe/testrunner/tests.py	2009-03-19 20:43:01 UTC (rev 98279)
@@ -31,7 +31,7 @@
 def test_suite():
     return unittest.TestSuite((
         zope.testing.doctest.DocFileSuite(
-            'README.txt', 
+            'README.txt',
             'bugfixes.txt',
             setUp=setUp, tearDown=zc.buildout.testing.buildoutTearDown,
             checker=zope.testing.renormalizing.RENormalizing(
@@ -44,7 +44,6 @@
                      (re.compile('setuptools-[^-]+-'), 'setuptools-X-'),
                      (re.compile('zope.interface-[^-]+-'), 'zope.interface-X-'),
                      ]),
-            optionflags=doctest.REPORT_NDIFF,
             ),
         ))
 



More information about the Checkins mailing list