[Checkins] SVN: zc.buildout/trunk/zc.recipe.testrunner/src/zc/recipe/testrunner/ Added an extra-paths option to specify paths other than eggs.

Jim Fulton jim at zope.com
Tue Sep 5 18:55:58 EDT 2006


Log message for revision 69992:
  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.
  

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
  U   zc.buildout/trunk/zc.recipe.testrunner/src/zc/recipe/testrunner/tests.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-09-05 22:55:55 UTC (rev 69991)
+++ zc.buildout/trunk/zc.recipe.testrunner/src/zc/recipe/testrunner/README.txt	2006-09-05 22:55:58 UTC (rev 69992)
@@ -16,6 +16,10 @@
     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 @@
 
     >>> 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 @@
     ... 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',
+      ])

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-09-05 22:55:55 UTC (rev 69991)
+++ zc.buildout/trunk/zc.recipe.testrunner/src/zc/recipe/testrunner/__init__.py	2006-09-05 22:55:58 UTC (rev 69992)
@@ -34,56 +34,23 @@
 
     def install(self):
         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]
-        project_names = [
-            pkg_resources.Requirement.parse(r).project_name
-            for r in requirements
-            ]
+        test_paths = [ws.find(pkg_resources.Requirement.parse(spec)).location
+                      for spec in eggs]
         
-        locations = [dist.location for dist in ws
-                     if dist.project_name in project_names]
+        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', "),
+                ),
+            )
 
-        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(
-                ', ', ",\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))
-"""
+  ]"""
                                  

Modified: zc.buildout/trunk/zc.recipe.testrunner/src/zc/recipe/testrunner/tests.py
===================================================================
--- zc.buildout/trunk/zc.recipe.testrunner/src/zc/recipe/testrunner/tests.py	2006-09-05 22:55:55 UTC (rev 69991)
+++ zc.buildout/trunk/zc.recipe.testrunner/src/zc/recipe/testrunner/tests.py	2006-09-05 22:55:58 UTC (rev 69992)
@@ -28,17 +28,18 @@
 
 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)
@@ -52,7 +53,10 @@
             setUp=setUp, tearDown=tearDown,
             checker=renormalizing.RENormalizing([
                (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'),
                ])
             ),
         



More information about the Checkins mailing list