[Erp5-report] r35591 rafael - in /erp5/trunk/utils/erp5.recipe.testing: ./ src/ src/erp5/ s...
nobody at svn.erp5.org
nobody at svn.erp5.org
Tue May 25 05:58:35 CEST 2010
Author: rafael
Date: Tue May 25 05:58:29 2010
New Revision: 35591
URL: http://svn.erp5.org?rev=35591&view=rev
Log:
Initial Import.
Added:
erp5/trunk/utils/erp5.recipe.testing/CHANGES.txt (with props)
erp5/trunk/utils/erp5.recipe.testing/README.txt (with props)
erp5/trunk/utils/erp5.recipe.testing/setup.py
erp5/trunk/utils/erp5.recipe.testing/src/
erp5/trunk/utils/erp5.recipe.testing/src/erp5/
erp5/trunk/utils/erp5.recipe.testing/src/erp5/__init__.py
erp5/trunk/utils/erp5.recipe.testing/src/erp5/recipe/
erp5/trunk/utils/erp5.recipe.testing/src/erp5/recipe/__init__.py
erp5/trunk/utils/erp5.recipe.testing/src/erp5/recipe/testing/
erp5/trunk/utils/erp5.recipe.testing/src/erp5/recipe/testing/__init__.py
erp5/trunk/utils/erp5.recipe.testing/src/erp5/recipe/testing/run_unit_test.py
Added: erp5/trunk/utils/erp5.recipe.testing/CHANGES.txt
URL: http://svn.erp5.org/erp5/trunk/utils/erp5.recipe.testing/CHANGES.txt?rev=35591&view=auto
==============================================================================
--- erp5/trunk/utils/erp5.recipe.testing/CHANGES.txt (added)
+++ erp5/trunk/utils/erp5.recipe.testing/CHANGES.txt [utf8] Tue May 25 05:58:29 2010
@@ -1,0 +1,8 @@
+Changelog
+=========
+
+1.0 (2010-05-25)
+----------------
+
+- Initial Release
+ [Rafael Monnerat]
Propchange: erp5/trunk/utils/erp5.recipe.testing/CHANGES.txt
------------------------------------------------------------------------------
svn:eol-style = native
Added: erp5/trunk/utils/erp5.recipe.testing/README.txt
URL: http://svn.erp5.org/erp5/trunk/utils/erp5.recipe.testing/README.txt?rev=35591&view=auto
==============================================================================
--- erp5/trunk/utils/erp5.recipe.testing/README.txt (added)
+++ erp5/trunk/utils/erp5.recipe.testing/README.txt [utf8] Tue May 25 05:58:29 2010
@@ -1,0 +1,16 @@
+Introduction
+============
+
+erp5.recipe.testing is used to launch tests based on a environment. It should be
+able to run any kind of test (unit, functional, KVM or what ever), where only
+download the source code is required.
+
+Example
+=======
+
+XXX Example
+
+Options
+=======
+
+XXX Description
Propchange: erp5/trunk/utils/erp5.recipe.testing/README.txt
------------------------------------------------------------------------------
svn:eol-style = native
Added: erp5/trunk/utils/erp5.recipe.testing/setup.py
URL: http://svn.erp5.org/erp5/trunk/utils/erp5.recipe.testing/setup.py?rev=35591&view=auto
==============================================================================
--- erp5/trunk/utils/erp5.recipe.testing/setup.py (added)
+++ erp5/trunk/utils/erp5.recipe.testing/setup.py [utf8] Tue May 25 05:58:29 2010
@@ -1,0 +1,34 @@
+from setuptools import setup, find_packages
+
+name = "erp5.recipe.testing"
+version = '1.0'
+
+def read(name):
+ return open(name).read()
+
+long_description=( read('README.txt')
+ + '\n' +
+ read('CHANGES.txt')
+ )
+setup(
+ name = name,
+ version = version,
+ author = "Rafael Monnerat",
+ author_email = "rafael at nexedi.com",
+ description = "ZC Buildout recipe for setup a test runner based on svn.",
+ long_description=long_description,
+ license = "ZPL 2.1",
+ keywords = "buildout erp5 test",
+ classifiers=[
+ "License :: OSI Approved :: Zope Public License",
+ "Framework :: Buildout",
+ ],
+ packages = find_packages('src'),
+ package_dir = {'': 'src'},
+ install_requires = ['zc.recipe.egg',
+ 'infrae.subversion',
+ 'pysvn',
+ 'setuptools'],
+ namespace_packages = ['erp5', 'erp5.recipe'],
+ entry_points = {'zc.buildout': ['default = %s:Recipe' % name]},
+ )
Added: erp5/trunk/utils/erp5.recipe.testing/src/erp5/__init__.py
URL: http://svn.erp5.org/erp5/trunk/utils/erp5.recipe.testing/src/erp5/__init__.py?rev=35591&view=auto
==============================================================================
--- erp5/trunk/utils/erp5.recipe.testing/src/erp5/__init__.py (added)
+++ erp5/trunk/utils/erp5.recipe.testing/src/erp5/__init__.py [utf8] Tue May 25 05:58:29 2010
@@ -1,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.testing/src/erp5/recipe/__init__.py
URL: http://svn.erp5.org/erp5/trunk/utils/erp5.recipe.testing/src/erp5/recipe/__init__.py?rev=35591&view=auto
==============================================================================
--- erp5/trunk/utils/erp5.recipe.testing/src/erp5/recipe/__init__.py (added)
+++ erp5/trunk/utils/erp5.recipe.testing/src/erp5/recipe/__init__.py [utf8] Tue May 25 05:58:29 2010
@@ -1,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.testing/src/erp5/recipe/testing/__init__.py
URL: http://svn.erp5.org/erp5/trunk/utils/erp5.recipe.testing/src/erp5/recipe/testing/__init__.py?rev=35591&view=auto
==============================================================================
--- erp5/trunk/utils/erp5.recipe.testing/src/erp5/recipe/testing/__init__.py (added)
+++ erp5/trunk/utils/erp5.recipe.testing/src/erp5/recipe/testing/__init__.py [utf8] Tue May 25 05:58:29 2010
@@ -1,0 +1,31 @@
+import infrae.subversion
+import zc.buildout.easy_install
+import zc.recipe.egg
+
+
+class Recipe(infrae.subversion.Recipe):
+ def __init__(self, buildout, name, options):
+ self.egg = zc.recipe.egg.Egg(buildout, options['recipe'], options)
+ options['urls'] = "%s ." % (options.get("url"))
+ options.setdefault("testing_bin_folder", buildout["buildout"]['bin-directory'])
+ options.setdefault("testing_script_name", "run_unit_test")
+ options.setdefault("testing_script_args", "")
+ infrae.subversion.Recipe.__init__(self, buildout, name, options)
+
+
+ def install(self):
+ options = self.options
+ location = self.location
+ requirements, ws = self.egg.working_set(['erp5.recipe.testing'])
+ testing_script_args = options.get("testing_script_args").split()
+ script_name = "%s_run_test" % self.name
+ scripts = zc.buildout.easy_install.scripts(
+ [(script_name,'erp5.recipe.testing.run_unit_test', 'main')],
+ ws, options['executable'], options.get("testing_bin_folder"),
+ arguments = ("\n sys.argv[1:] ,"
+ "\n path='%s', "
+ "\n script_name='%s', "
+ "\n args=%s" % (location,
+ options.get("testing_script_name"),
+ testing_script_args)))
+ return infrae.subversion.Recipe.install(self)
Added: erp5/trunk/utils/erp5.recipe.testing/src/erp5/recipe/testing/run_unit_test.py
URL: http://svn.erp5.org/erp5/trunk/utils/erp5.recipe.testing/src/erp5/recipe/testing/run_unit_test.py?rev=35591&view=auto
==============================================================================
--- erp5/trunk/utils/erp5.recipe.testing/src/erp5/recipe/testing/run_unit_test.py (added)
+++ erp5/trunk/utils/erp5.recipe.testing/src/erp5/recipe/testing/run_unit_test.py [utf8] Tue May 25 05:58:29 2010
@@ -1,0 +1,154 @@
+#!/usr/bin/python
+
+import pysvn
+import os
+import subprocess
+import signal
+
+def usage():
+ return """
+
+Usage:
+
+ start : Start to run the tests.
+
+ stop : Stop to run the tests.
+
+ status : Verify if the test are running or not.
+ """
+
+
+def newHandler():
+ """
+ Returns a pysvn client which does not prompt for
+ SSL certifications.
+ """
+ # Pass user and password
+ client = pysvn.Client()
+ client.set_interactive(False)
+
+ def callback_ssl(info):
+ return True, 0, False
+
+ client.callback_ssl_server_trust_prompt = callback_ssl
+ return client
+
+class TestingHandler:
+
+ def __init__(self, path, script_name, args, revision):
+ """
+ path is the location of repository.
+
+ script_name is the python script which contains TestSuite class.
+
+ args are the extra arguments for the TestSuite Class.
+
+ revision is for be used for svn update, but it is not used for
+ now.
+ """
+ self.path = path
+ self.script_name = script_name
+ self.args = args
+
+ def _writePid(self, pid):
+ """
+ Write pid of test into the pidfile.
+ """
+ open(self.path + "/test.pid", "w+").write(str(pid))
+
+ def _readPid(self):
+ """
+ Load Pid file.
+ """
+ if not os.path.exists(self.path + "/test.pid"):
+ return -1
+
+ pid = open(self.path + "/test.pid", "r").read()
+ return int(pid)
+
+ def _update(self):
+ """
+ Update test repository, for now we only support
+ svn updates.
+ """
+ svn = newHandler()
+ svn.update(self.path)
+
+ def start(self):
+ """
+ Start a test script using subprocess and store the pid.
+ """
+ if self.status():
+ # Last tests didn't finished yet, so do not start it again.
+ return False
+
+ self._update()
+
+ # run test at the folder.
+ os.chdir(self.path)
+ test_script = '%s/%s' % (self.path, self.script_name)
+ if not os.path.exists(test_script):
+ raise ValueError("Script %s does not exists." % test_script)
+ # XXX There is a problem here, which python/bash should we use to
+ # run the script.
+ sp = subprocess.Popen( [test_script] + self.args,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE,
+ close_fds=True)
+ self._writePid(sp.pid)
+ return True
+
+ def stop(self):
+ """
+ Send a kill signal to the pid. Repeat operations 5 times in case pid
+ still running.
+ """
+ if not self.status():
+ # Process is not running, nothing to kill
+ return True
+
+ pid = self._readPid()
+ tries = 5
+ while tries > 0:
+ if not self.status():
+ return True
+ try:
+ os.kill(pid, signal.SIGTERM)
+ except IOError:
+ return True
+ tries -= 1
+
+ return False
+
+ def status(self):
+ """
+ Load pid file and check if the pid are still running.
+ """
+ pid = self._readPid()
+ if pid == -1:
+ # If no pid, means it is not running.
+ return False
+ # XXX Check if the pid is running same script is missing.
+ p = subprocess.Popen("ps -o pid,comm ax",
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE,
+ shell=True)
+ stdout, stderr = p.communicate()
+ if "%s %s" % (str(pid), self.script_name) in stdout.splitlines():
+ return True
+
+def main(command, path, script_name, args=[], revision=None):
+ """
+
+ """
+ if isinstance(command,[].__class__):
+ command = command[0]
+ if command not in ["start", "stop", "status"]:
+ print usage()
+ return
+
+ handler = TestingHandler(path, script_name, args, revision)
+ output = getattr(handler, command)()
+ print output
+ return output
+
More information about the Erp5-report
mailing list