From d962d6e5f958ca64f5aefed632e729c9de1ea933 Mon Sep 17 00:00:00 2001 From: =?utf8?q?C=C3=A9dric=20Aguerre?= Date: Thu, 27 Oct 2016 14:09:25 +0200 Subject: [PATCH] remove unnecessary use of subprocess pipes --- bin/PortManager.py | 19 +++++++++++--- .../salome_tester/salome_test_driver.py | 21 +++------------- .../salomeCommand/TestLauncherSessionArgs.py | 6 ++--- bin/runTests.py | 25 +++---------------- 4 files changed, 25 insertions(+), 46 deletions(-) diff --git a/bin/PortManager.py b/bin/PortManager.py index 3d7e63c40..53ebacea9 100644 --- a/bin/PortManager.py +++ b/bin/PortManager.py @@ -89,11 +89,24 @@ def __isNetworkConnectionActiveOnPort(port): # :NOTE: Under windows: # netstat options -l and -t are unavailable # grep command is unavailable - from subprocess import Popen, PIPE if sys.platform == "win32": - out, _ = Popen(['netstat','-a','-n','-p tcp'], stdout=PIPE).communicate() + cmd = ['netstat','-a','-n','-p tcp'] else: - out, _ = Popen(['netstat','-ant'], stdout=PIPE).communicate() + cmd = ['netstat','-ant'] + pass + + err = None + try: + from subprocess import Popen, PIPE, STDOUT + p = Popen(cmd, stdout=PIPE, stderr=STDOUT) + out, err = p.communicate() + except: + print "Error when trying to access active network connections." + if err: print err + import traceback + traceback.print_exc() + return False + import StringIO buf = StringIO.StringIO(out) ports = buf.readlines() diff --git a/bin/appliskel/salome_tester/salome_test_driver.py b/bin/appliskel/salome_tester/salome_test_driver.py index 068bf89a0..60b8fd9a2 100644 --- a/bin/appliskel/salome_tester/salome_test_driver.py +++ b/bin/appliskel/salome_tester/salome_test_driver.py @@ -29,26 +29,12 @@ import signal # Run test def runTest(command): print "Running:", " ".join(command) - p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - out, err = p.communicate() + p = subprocess.Popen(command) + p.communicate() res = p.returncode # About res value: # A negative value -N indicates that the child was terminated by signal N (Unix only). # On Unix, the value 11 generally corresponds to a segmentation fault. - return res, out, err -# - -# Display output and errors -def processResult(res, out, err): - if out: - print out - pass - if err: - print " ** Detected error **" - print "Error code: ", res - print err, - print " ** end of message **" - pass return res # @@ -96,8 +82,7 @@ if __name__ == "__main__": try: salome_instance = SalomeInstance.start(shutdown_servers=True) port = salome_instance.get_port() - res, out, err = runTest(test_and_args) - res = processResult(res, out, err) + res = runTest(test_and_args) except TimeoutException: print "FAILED : timeout(%s) is reached"%timeout_delay except: diff --git a/bin/appliskel/tests/salomeCommand/TestLauncherSessionArgs.py b/bin/appliskel/tests/salomeCommand/TestLauncherSessionArgs.py index 62d4ddc35..df6218e13 100644 --- a/bin/appliskel/tests/salomeCommand/TestLauncherSessionArgs.py +++ b/bin/appliskel/tests/salomeCommand/TestLauncherSessionArgs.py @@ -147,9 +147,9 @@ class TestSessionArgs(unittest.TestCase): self.session(self.add3+self.add3+self.hello1) self.assertLogFileContentsEqual(self.add3Msg+self.add3Msg+self.hello1Msg) # -# def testHello0Add3Hello0Add3Hello0(self): -# self.session(self.hello1+self.add3+self.hello0+self.add3+self.hello0) -# self.assertLogFileContentsEqual(self.hello1Msg+self.add3Msg+self.hello0Msg+self.add3Msg+self.hello0Msg) + def testHello0Add3Hello0Add3Hello0(self): + self.session(self.hello1+self.add3+self.hello0+self.add3+self.hello0) + self.assertLogFileContentsEqual(self.hello1Msg+self.add3Msg+self.hello0Msg+self.add3Msg+self.hello0Msg) # # diff --git a/bin/runTests.py b/bin/runTests.py index 34a543f43..4255abaf0 100644 --- a/bin/runTests.py +++ b/bin/runTests.py @@ -74,25 +74,6 @@ For complete description of available options, pleaser refer to ctest documentat # tests must be in ${ABSOLUTE_APPLI_PATH}/${__testSubDir}/ __testSubDir = "bin/salome/test" -def __runTest(command, workdir): - p = subprocess.Popen(command, cwd=workdir, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - - while True: - 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 -# - def runTests(args, exe=None): args = __configureTests(args, exe) @@ -103,7 +84,7 @@ def runTests(args, exe=None): testPath = os.path.join(appliPath, __testSubDir) command = ["ctest"] + args - res = __runTest(command, testPath) - - sys.exit(res) + p = subprocess.Popen(command, cwd=testPath) + p.communicate() + sys.exit(p.returncode) # -- 2.39.2