[Checkins] SVN: zc.recipe.testrunner/branches/ctheune-envvariables/ - ignoring the eggs directory

Christian Theune ct at gocept.com
Mon Apr 16 07:56:35 EDT 2007


Log message for revision 74172:
   - ignoring the eggs directory
   - added feature to insert environment variables into the test runner
  

Changed:
  _U  zc.recipe.testrunner/branches/ctheune-envvariables/
  U   zc.recipe.testrunner/branches/ctheune-envvariables/src/zc/recipe/testrunner/README.txt
  U   zc.recipe.testrunner/branches/ctheune-envvariables/src/zc/recipe/testrunner/__init__.py

-=-

Property changes on: zc.recipe.testrunner/branches/ctheune-envvariables
___________________________________________________________________
Name: svn:ignore
   - build
dist
develop-eggs
bin
parts
.installed.cfg

   + build
eggs
dist
develop-eggs
bin
parts
.installed.cfg


Modified: zc.recipe.testrunner/branches/ctheune-envvariables/src/zc/recipe/testrunner/README.txt
===================================================================
--- zc.recipe.testrunner/branches/ctheune-envvariables/src/zc/recipe/testrunner/README.txt	2007-04-16 11:22:12 UTC (rev 74171)
+++ zc.recipe.testrunner/branches/ctheune-envvariables/src/zc/recipe/testrunner/README.txt	2007-04-16 11:56:34 UTC (rev 74172)
@@ -30,6 +30,10 @@
     run. If the working directory is the empty string or not specified
     at all, the recipe will create a working directory among the parts.
 
+environment
+    A set of environment variables that should be exported before
+    starting the tests.
+
 (Note that, at this time, due to limitations in the Zope test runner,
  the distributions cannot be zip files. TODO: Fix the test runner!)
 
@@ -218,7 +222,7 @@
 
     >>> print system(os.path.join(sample_buildout, 'bin', 'buildout') + ' -q'),
 
-    >>> cat(sample_buildout, 'bin', 'testdemo')
+    >>> cat(sample_buildout, 'bin', 'testdemo') # doctest: +REPORT_NDIFF
     #!/usr/local/bin/python2.4
     <BLANKLINE>
     import sys
@@ -233,6 +237,7 @@
     sys.argv[0] = os.path.abspath(sys.argv[0])
     os.chdir('/sample-buildout/parts/testdemo')
     <BLANKLINE>
+    <BLANKLINE>
     import zope.testing.testrunner
     <BLANKLINE>
     if __name__ == '__main__':
@@ -259,7 +264,7 @@
 
     >>> print system(os.path.join(sample_buildout, 'bin', 'buildout') + ' -q'),
 
-    >>> cat(sample_buildout, 'bin', 'testdemo')
+    >>> cat(sample_buildout, 'bin', 'testdemo') # doctest: +REPORT_NDIFF
     #!/usr/local/bin/python2.4
     <BLANKLINE>
     import sys
@@ -274,6 +279,7 @@
     sys.argv[0] = os.path.abspath(sys.argv[0])
     os.chdir('/foo/bar')
     <BLANKLINE>
+    <BLANKLINE>
     import zope.testing.testrunner
     <BLANKLINE>
     if __name__ == '__main__':
@@ -313,7 +319,7 @@
 
     >>> 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
@@ -328,6 +334,7 @@
     sys.argv[0] = os.path.abspath(sys.argv[0])
     os.chdir('/sample-buildout/parts/testdemo')
     <BLANKLINE>
+    <BLANKLINE>
     import zope.testing.testrunner
     <BLANKLINE>
     if __name__ == '__main__':
@@ -344,3 +351,46 @@
 - Leading whitespace is removed.
 
   
+We can specify  ``environment`` option to setup environment variables that
+tests might want to read::
+
+    >>> write(sample_buildout, 'buildout.cfg',
+    ... """
+    ... [buildout]
+    ... develop = demo
+    ... parts = testdemo
+    ... offline = true
+    ...
+    ... [testdemo]
+    ... recipe = zc.recipe.testrunner
+    ... eggs = demo
+    ... environment = testenv
+    ...
+    ... [testenv]
+    ... foo = bar
+    ... """)
+
+    >>> print system(os.path.join(sample_buildout, 'bin', 'buildout') + ' -q'),
+
+    >>> cat(sample_buildout, 'bin', 'testdemo') # doctest: +REPORT_NDIFF
+    #!/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',
+      ]
+    <BLANKLINE>
+    import os
+    sys.argv[0] = os.path.abspath(sys.argv[0])
+    os.chdir('/sample-buildout/parts/testdemo')
+    os.env['foo'] = 'bar'
+    <BLANKLINE>
+    <BLANKLINE>
+    import zope.testing.testrunner
+    <BLANKLINE>
+    if __name__ == '__main__':
+        zope.testing.testrunner.run([
+      '--test-path', '/sample-buildout/demo',
+      ])

Modified: zc.recipe.testrunner/branches/ctheune-envvariables/src/zc/recipe/testrunner/__init__.py
===================================================================
--- zc.recipe.testrunner/branches/ctheune-envvariables/src/zc/recipe/testrunner/__init__.py	2007-04-16 11:22:12 UTC (rev 74171)
+++ zc.recipe.testrunner/branches/ctheune-envvariables/src/zc/recipe/testrunner/__init__.py	2007-04-16 11:56:34 UTC (rev 74172)
@@ -56,7 +56,13 @@
                 os.mkdir(wd)
             dest.append(wd)
         initialization = initialization_template % wd
-        
+
+        env_section = options.get('environment', '').strip()
+        if env_section:
+            env = self.buildout[env_section]
+            for key, value in env.items():
+                initialization += env_template % (key, value)
+
         dest.extend(zc.buildout.easy_install.scripts(
             [(options['script'], 'zope.testing.testrunner', 'run')],
             ws, options['executable'],
@@ -76,7 +82,11 @@
 arg_template = """[
   '--test-path', %(TESTPATH)s,
   ]"""
-                                 
+
 initialization_template = """import os
 sys.argv[0] = os.path.abspath(sys.argv[0])
-os.chdir(%r)"""
+os.chdir(%r)
+"""
+
+env_template = """os.env['%s'] = %r
+"""



More information about the Checkins mailing list