buildtools: Add a helper for running Python tests
authorPetr Viktorin <pviktori@redhat.com>
Tue, 10 Mar 2015 17:19:14 +0000 (18:19 +0100)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 19 May 2015 17:28:19 +0000 (19:28 +0200)
Add the function samba_utils.RUN_PYTHON_TESTS for running a Python
test. When building for multiple Python versions, all are tested.

Also, add the list of configured Python interpreters to build config.

Signed-off-by: Petr Viktorin <pviktori@redhat.com>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Jelmer Vernooij <jelmer@samba.org>
buildtools/wafsamba/samba_python.py
buildtools/wafsamba/samba_utils.py

index a0e0ffa9f6b749f5267bca35b2af71d12128b29e..8b20066c9de08bb30adbdbe755c3573f315aa4b3 100644 (file)
@@ -9,6 +9,8 @@ from Configure import conf
 @conf
 def SAMBA_CHECK_PYTHON(conf, mandatory=True, version=(2,4,2)):
     # enable tool to build python extensions
+    interpreters = []
+
     if conf.env['EXTRA_PYTHON']:
         conf.all_envs['extrapython'] = conf.env.copy()
         conf.setenv('extrapython')
@@ -21,6 +23,7 @@ def SAMBA_CHECK_PYTHON(conf, mandatory=True, version=(2,4,2)):
         except Exception:
             warn('extra-python needs to be Python 3.3 or later')
             raise
+        interpreters.append(conf.env['PYTHON'])
         conf.setenv('default')
 
     conf.find_program('python', var='PYTHON', mandatory=mandatory)
@@ -29,6 +32,9 @@ def SAMBA_CHECK_PYTHON(conf, mandatory=True, version=(2,4,2)):
     conf.env.PYTHON_SPECIFIED = (conf.env.PYTHON != path_python)
     conf.check_python_version(version)
 
+    interpreters.append(conf.env['PYTHON'])
+    conf.env.python_interpreters = interpreters
+
 
 @conf
 def SAMBA_CHECK_PYTHON_HEADERS(conf, mandatory=True):
index e8bc0f38bc2a563033bba6739411c9218a9e0c32..540fe447942bbb2598b4a8e9da18b5cfd21a1581 100644 (file)
@@ -386,6 +386,22 @@ def RUN_COMMAND(cmd,
     return -1
 
 
+def RUN_PYTHON_TESTS(testfiles, pythonpath=None):
+    env = LOAD_ENVIRONMENT()
+    if pythonpath is None:
+        pythonpath = os.path.join(Utils.g_module.blddir, 'python')
+    result = 0
+    for interp in env.python_interpreters:
+        for testfile in testfiles:
+            cmd = "PYTHONPATH=%s %s %s" % (pythonpath, interp, testfile)
+            print('Running Python test with %s: %s' % (interp, testfile))
+            ret = RUN_COMMAND(cmd)
+            if ret:
+                print('Python test failed: %s' % cmd)
+                result = ret
+    return result
+
+
 # make sure we have md5. some systems don't have it
 try:
     from hashlib import md5