From a9e2ea94058d1f5a0478fd068d72e41feb052ba7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?C=C3=A9dric=20Aguerre?= Date: Mon, 2 May 2016 10:20:55 +0200 Subject: [PATCH] simplify test process call --- bin/PortManager.py | 6 +++--- bin/appliskel/salome | 2 +- bin/runTests.py | 28 ++++++++-------------------- bin/salomeContext.py | 4 ++-- 4 files changed, 14 insertions(+), 26 deletions(-) diff --git a/bin/PortManager.py b/bin/PortManager.py index d324bdebc..3d7e63c40 100644 --- a/bin/PortManager.py +++ b/bin/PortManager.py @@ -91,11 +91,11 @@ def __isNetworkConnectionActiveOnPort(port): # grep command is unavailable from subprocess import Popen, PIPE if sys.platform == "win32": - stdout, _ = Popen(['netstat','-a','-n','-p tcp'], stdout=PIPE).communicate() + out, _ = Popen(['netstat','-a','-n','-p tcp'], stdout=PIPE).communicate() else: - stdout, _ = Popen(['netstat','-ant'], stdout=PIPE).communicate() + out, _ = Popen(['netstat','-ant'], stdout=PIPE).communicate() import StringIO - buf = StringIO.StringIO(stdout) + buf = StringIO.StringIO(out) ports = buf.readlines() # search for TCP - LISTEN connections import re diff --git a/bin/appliskel/salome b/bin/appliskel/salome index 5d56e01f2..90d5e1028 100755 --- a/bin/appliskel/salome +++ b/bin/appliskel/salome @@ -58,7 +58,7 @@ def main(args): context.addToVariable(key,val) # Start SALOME, parsing command line arguments - (out, err), returncode = context.runSalome(args) + out, err, returncode = context.runSalome(args) if out: sys.stdout.write(out) if err: diff --git a/bin/runTests.py b/bin/runTests.py index 0013129ea..34a543f43 100644 --- a/bin/runTests.py +++ b/bin/runTests.py @@ -74,35 +74,23 @@ For complete description of available options, pleaser refer to ctest documentat # tests must be in ${ABSOLUTE_APPLI_PATH}/${__testSubDir}/ __testSubDir = "bin/salome/test" -# Both display process stdout&stderr to console and capture them to variables def __runTest(command, workdir): - p = subprocess.Popen(command, cwd=workdir, stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=0) - stdout = [] - stderr = [] + p = subprocess.Popen(command, cwd=workdir, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) while True: - reads = [p.stdout.fileno(), p.stderr.fileno()] - ret = select.select(reads, [], [], 0) - - for fd in ret[0]: - if fd == p.stdout.fileno(): - read = p.stdout.readline() - sys.stdout.write(read) - stdout.append(read) - pass - if fd == p.stderr.fileno(): - read = p.stderr.readline() - sys.stderr.write(read) - stderr.append(read) - pass + try: + out = p.stdout.readline() + sys.stdout.write(out) + except: # raised IOError or OSError if output is empty pass returncode = p.poll() if not returncode is None: + sys.stdout.flush() break pass - return p.returncode, "".join(stdout), "".join(stderr) + return p.returncode # def runTests(args, exe=None): @@ -115,7 +103,7 @@ def runTests(args, exe=None): testPath = os.path.join(appliPath, __testSubDir) command = ["ctest"] + args - res, out, err = __runTest(command, testPath) + res = __runTest(command, testPath) sys.exit(res) # diff --git a/bin/salomeContext.py b/bin/salomeContext.py index 00ded0acf..2bed90404 100644 --- a/bin/salomeContext.py +++ b/bin/salomeContext.py @@ -143,8 +143,8 @@ class SalomeContext: absoluteAppliPath = os.getenv('ABSOLUTE_APPLI_PATH','') env_copy = os.environ.copy() proc = subprocess.Popen(['python', os.path.join(absoluteAppliPath,"bin","salome","salomeContext.py"), pickle.dumps(self), pickle.dumps(args)], shell=False, close_fds=True, env=env_copy) - msg = proc.communicate() - return msg, proc.returncode + out, err = proc.communicate() + return out, err, proc.returncode # """Append value to PATH environment variable""" -- 2.39.2