[Erp5-report] r45587 seb - in /erp5/trunk/utils/erp5.recipe.test_suite_runner: ./ src/ src/...

nobody at svn.erp5.org nobody at svn.erp5.org
Wed Apr 20 13:08:29 CEST 2011


Author: seb
Date: Wed Apr 20 13:08:29 2011
New Revision: 45587

URL: http://svn.erp5.org?rev=45587&view=rev
Log:
create recipe that generate runTestSuite commands that is
aware of eggs and path installed by buildout

Added:
    erp5/trunk/utils/erp5.recipe.test_suite_runner/
    erp5/trunk/utils/erp5.recipe.test_suite_runner/CHANGES.txt
    erp5/trunk/utils/erp5.recipe.test_suite_runner/README.txt
    erp5/trunk/utils/erp5.recipe.test_suite_runner/setup.py
    erp5/trunk/utils/erp5.recipe.test_suite_runner/src/
    erp5/trunk/utils/erp5.recipe.test_suite_runner/src/erp5/
    erp5/trunk/utils/erp5.recipe.test_suite_runner/src/erp5/__init__.py
    erp5/trunk/utils/erp5.recipe.test_suite_runner/src/erp5/recipe/
    erp5/trunk/utils/erp5.recipe.test_suite_runner/src/erp5/recipe/__init__.py
    erp5/trunk/utils/erp5.recipe.test_suite_runner/src/erp5/recipe/test_suite_runner/
    erp5/trunk/utils/erp5.recipe.test_suite_runner/src/erp5/recipe/test_suite_runner/__init__.py

Added: erp5/trunk/utils/erp5.recipe.test_suite_runner/CHANGES.txt
URL: http://svn.erp5.org/erp5/trunk/utils/erp5.recipe.test_suite_runner/CHANGES.txt?rev=45587&view=auto
==============================================================================
--- erp5/trunk/utils/erp5.recipe.test_suite_runner/CHANGES.txt (added)
+++ erp5/trunk/utils/erp5.recipe.test_suite_runner/CHANGES.txt [utf8] Wed Apr 20 13:08:29 2011
@@ -0,0 +1,7 @@
+Changelog
+=========
+
+1.0 (2011-04-19)
+----------------
+
+- Initial version that generates a test suite runner

Added: erp5/trunk/utils/erp5.recipe.test_suite_runner/README.txt
URL: http://svn.erp5.org/erp5/trunk/utils/erp5.recipe.test_suite_runner/README.txt?rev=45587&view=auto
==============================================================================
--- erp5/trunk/utils/erp5.recipe.test_suite_runner/README.txt (added)
+++ erp5/trunk/utils/erp5.recipe.test_suite_runner/README.txt [utf8] Wed Apr 20 13:08:29 2011
@@ -0,0 +1,75 @@
+Introduction
+============
+
+This recipe generates a test runner for ERP5
+
+
+Example
+=======
+
+You can use it with a part like this::
+
+  [runUnitTest]
+  recipe = erp5.recipe.testrunner
+  zope2-location = ${zope2:location}
+  products = ${erp5_instance:products}
+             ${zope2:location}/lib/python/Products/
+  eggs = ${erp5_instance:eggs}
+  bt5_path = ${download_bt5:location}
+
+
+Options
+=======
+
+zope2-location
+  Location of a zope2 installation, similar to this option in zope2instance
+  recipe.
+
+products
+  Products to use in the generated scripts
+
+eggs
+  Eggs to use in the generated scripts
+
+bt5_path
+  Paths containing business templates to be installed
+
+mysql_create_database
+  If true creates the database using the options below that come from
+  erp5.recipe.mysqldatabase (Starting with mysql_). Notice that, to use this
+  option, one of two things need to happen:
+
+  * Your python interpreter already has the MySQL-python package installed
+
+  * You set the 'recipe' of your part to:
+    recipe = erp5.recipe.testrunner[standalone]
+    This will use the '[standalone]' variant of erp5.recipe.mysqldatabase and
+    will install the MySQL-python egg automatically
+
+mysql_database_name
+  Mysql Database name.
+
+erp5_sql_connection_string
+  python-mysql connection string to database.
+  (Optional).
+
+mysql_host
+  Hostname which is running your mysql server. By Default uses localhost.
+  (Optional).
+
+mysql_port
+  Port Number which is running your mysql server. By Default uses 3306.
+  (Optional).
+
+mysql_user
+  User of new database, used to grant privilegies on the new database.
+
+mysql_password
+  User's Password of new database, used to grant privilegies on the new
+  database.
+
+mysql_superuser
+  User of mysql used to connect to mysql server to create the database.
+
+mysql_superpassword
+  Password of user defined at mysql_superuser.

Added: erp5/trunk/utils/erp5.recipe.test_suite_runner/setup.py
URL: http://svn.erp5.org/erp5/trunk/utils/erp5.recipe.test_suite_runner/setup.py?rev=45587&view=auto
==============================================================================
--- erp5/trunk/utils/erp5.recipe.test_suite_runner/setup.py (added)
+++ erp5/trunk/utils/erp5.recipe.test_suite_runner/setup.py [utf8] Wed Apr 20 13:08:29 2011
@@ -0,0 +1,37 @@
+from setuptools import setup, find_packages
+
+name = "erp5.recipe.test_suite_runner"
+version = '1.0.0'
+
+def read(name):
+    return open(name).read()
+
+long_description=(
+        read('README.txt')
+        + '\n' +
+        read('CHANGES.txt')
+    )
+
+setup(
+    name = name,
+    version = version,
+    author = "Nexedi",
+    author_email = "info at nexedi.com",
+    description = "ZC Buildout recipe for creating a test suite runner compatible"\
+                  " with ERP5 slapos",
+    long_description=long_description,
+    license = "ZPL 2.1",
+    keywords = "zope2 buildout",
+    url='http://www.erp5.org/HowToUseBuildout',
+    classifiers=[
+      "License :: OSI Approved :: Zope Public License",
+      "Framework :: Buildout",
+      "Framework :: Zope2",
+      ],
+    packages = find_packages('src'),
+    package_dir = {'': 'src'},
+    install_requires = ['zc.recipe.egg', 
+                        ],
+    namespace_packages = ['erp5', 'erp5.recipe'],
+    entry_points = {'zc.buildout': ['default = %s:Recipe' % name]},
+    )

Added: erp5/trunk/utils/erp5.recipe.test_suite_runner/src/erp5/__init__.py
URL: http://svn.erp5.org/erp5/trunk/utils/erp5.recipe.test_suite_runner/src/erp5/__init__.py?rev=45587&view=auto
==============================================================================
--- erp5/trunk/utils/erp5.recipe.test_suite_runner/src/erp5/__init__.py (added)
+++ erp5/trunk/utils/erp5.recipe.test_suite_runner/src/erp5/__init__.py [utf8] Wed Apr 20 13:08:29 2011
@@ -0,0 +1,6 @@
+# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
+try:
+    __import__('pkg_resources').declare_namespace(__name__)
+except ImportError:
+    from pkgutil import extend_path
+    __path__ = extend_path(__path__, __name__)

Added: erp5/trunk/utils/erp5.recipe.test_suite_runner/src/erp5/recipe/__init__.py
URL: http://svn.erp5.org/erp5/trunk/utils/erp5.recipe.test_suite_runner/src/erp5/recipe/__init__.py?rev=45587&view=auto
==============================================================================
--- erp5/trunk/utils/erp5.recipe.test_suite_runner/src/erp5/recipe/__init__.py (added)
+++ erp5/trunk/utils/erp5.recipe.test_suite_runner/src/erp5/recipe/__init__.py [utf8] Wed Apr 20 13:08:29 2011
@@ -0,0 +1,6 @@
+# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
+try:
+    __import__('pkg_resources').declare_namespace(__name__)
+except ImportError:
+    from pkgutil import extend_path
+    __path__ = extend_path(__path__, __name__)

Added: erp5/trunk/utils/erp5.recipe.test_suite_runner/src/erp5/recipe/test_suite_runner/__init__.py
URL: http://svn.erp5.org/erp5/trunk/utils/erp5.recipe.test_suite_runner/src/erp5/recipe/test_suite_runner/__init__.py?rev=45587&view=auto
==============================================================================
--- erp5/trunk/utils/erp5.recipe.test_suite_runner/src/erp5/recipe/test_suite_runner/__init__.py (added)
+++ erp5/trunk/utils/erp5.recipe.test_suite_runner/src/erp5/recipe/test_suite_runner/__init__.py [utf8] Wed Apr 20 13:08:29 2011
@@ -0,0 +1,147 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# Copyright (c) 2010 Nexedi SA and Contributors. All Rights Reserved.
+# Copyright (c) 2006-2008 Zope Corporation and Contributors.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+
+import os, re, shutil, sys, glob
+import zc.buildout
+import zc.recipe.egg
+
+class Recipe:
+    '''Creates a runTestSuite aware of eggs and custom paths used in this
+    buildout.
+    '''
+    name = 'runTestSuite'
+
+    def __init__(self, buildout, name, options):
+        self.buildout, self.options, self.name = buildout, options, name
+        
+        self.location = options['location'] = os.path.join(
+            buildout['buildout']['parts-directory'],
+            self.name,
+            )
+        try:
+            self.instance_home = (options.get('instance-home') or
+                                  # backward compatibility...
+                                  self.buildout['erp5_instance']['location'])
+        except KeyError:
+            raise RuntimeError('please specify location of ERP5 instance '
+                               '(e.g.: "instance-home = '
+                               '${erp5_instance:location}")')
+        # force the generation of a single script...
+        scriptName = options.get('control-script', name).strip()
+        options['scripts'] = 'runTestSuite=' + scriptName
+        # ...manually defined by our entry point
+        options['entry-points'] = '''
+          runTestSuite=Products.ERP5Type.tests.runTestSuite:main
+        '''
+        # initialize the recipe that will actually generate the script
+        self.egg = zc.recipe.egg.Egg(buildout, '', options)
+
+    def install(self):
+        options = self.options
+        location = self.location
+
+        extra_paths = self.egg.extra_paths
+        # insert software-home into extra_paths, calculating from
+        # zope2-location if necessary
+        software_home = options.get('software-home')
+        zope2_location = options.get('zope2-location')
+        if zope2_location and not software_home:
+            software_home = os.path.join(zope2_location, 'lib', 'python')
+        if software_home:
+            extra_paths.insert(0, software_home)
+            zope_scripts = None
+        else:
+            # if no software_home can be found, assume software_home is already
+            # reachable by eggs or extra-paths (the generated script will check
+            # if that is the case), but then the skeletons on
+            # ERP5Type/tests/skel2.12 will need to find the Zope startup
+            # scripts (zopectl, runzope), which will likely be in this buildout
+            # bin directory.
+            zope_scripts = options.get('zope2-scripts', 
+                                       options['bin-directory'])
+
+        init = init_template % dict(name=self.name,
+                                    zope_scripts=zope_scripts)
+
+        # runUnitTest works in our parts directory, which will contain
+        # custom_zodb.py
+        if not os.path.exists(location):
+          os.mkdir(location)
+        init += set_env_and_chdir_template % dict(location=location)
+
+        # framework.py requires a Products directory, so create it here
+        # This is temporary, as we're getting rid of "framework.py"
+        products_dir = os.path.join(location, 'Products')
+        if not os.path.exists(products_dir):
+           os.mkdir(products_dir)
+
+        self.options['initialization'] = '\n'.join([init,
+            self.options.get('initialization','')])
+        # reassign just to be on the safe side...
+        self.egg.extra_paths = extra_paths
+
+        # generate the script according to our configuration
+        self.egg.install()
+
+        return [location]
+
+    update = install
+
+init_template = '''
+import os
+from os.path import dirname, abspath
+
+# derive SOFTWARE_HOME from import location of Zope2
+try:
+  import Zope2
+except ImportError:
+  print >> sys.stderr, ("Zope2 could not be found. In the %(name)r part of the "
+                        "buildout configuration, please specify either "
+                        "software-home or zope2-location, or add Zope2 to the "
+                        "list of eggs.")
+  raise
+else:
+  os.environ['SOFTWARE_HOME'] = abspath(dirname(dirname(Zope2.__file__)))
+
+# if under Zope 2.12, we need the location of the Zope2 startup scripts for the
+# substitutions in the skel2.12 directory
+ZOPE_SCRIPTS = %(zope_scripts)r
+if ZOPE_SCRIPTS is not None:
+  os.environ['ZOPE_SCRIPTS'] = ZOPE_SCRIPTS 
+
+import Products
+
+# Testing needs to be imported, otherwise framework.py will guess it from
+# sys.path, which can be a zipped egg
+import Testing
+'''
+
+add_product_path_template = '''
+Products.__path__.append(%(product_path)r)'''
+
+add_sys_path_template = '''
+sys.path.append(%(sys_path)r)'''
+
+add_bt5_path_template = '''
+sys.argv.insert(1, %(bt5_path)r)
+sys.argv.insert(1, '--bt5_path')'''
+
+set_env_and_chdir_template = '''
+
+# execute framework.py, like in zope testcase
+os.environ['INSTANCE_HOME'] = %(location)r
+os.environ['REAL_INSTANCE_HOME'] = %(location)r
+os.chdir(%(location)r)
+'''



More information about the Erp5-report mailing list