From: Petr Viktorin Date: Tue, 10 Mar 2015 17:19:14 +0000 (+0100) Subject: buildtools: Add a helper for running Python tests X-Git-Tag: tevent-0.9.25~454 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=91b407fc94fcd0015fe91b84619f3a6d1d3595f2;p=thirdparty%2Fsamba.git buildtools: Add a helper for running Python tests 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 Reviewed-by: Andrew Bartlett Reviewed-by: Jelmer Vernooij --- diff --git a/buildtools/wafsamba/samba_python.py b/buildtools/wafsamba/samba_python.py index a0e0ffa9f6b..8b20066c9de 100644 --- a/buildtools/wafsamba/samba_python.py +++ b/buildtools/wafsamba/samba_python.py @@ -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): diff --git a/buildtools/wafsamba/samba_utils.py b/buildtools/wafsamba/samba_utils.py index e8bc0f38bc2..540fe447942 100644 --- a/buildtools/wafsamba/samba_utils.py +++ b/buildtools/wafsamba/samba_utils.py @@ -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