]> SALOME platform Git repositories - modules/yacs.git/commitdiff
Salome HOME
remove unnecessary use of subprocess pipes
authorCédric Aguerre <cedric.aguerre@edf.fr>
Thu, 27 Oct 2016 12:09:25 +0000 (14:09 +0200)
committerCédric Aguerre <cedric.aguerre@edf.fr>
Thu, 27 Oct 2016 12:09:25 +0000 (14:09 +0200)
bin/PortManager.py
bin/appliskel/salome_tester/salome_test_driver.py
bin/appliskel/tests/salomeCommand/TestLauncherSessionArgs.py
bin/runTests.py

index 3d7e63c401d07c7b4c996a84a34a07ab6d9520f4..53ebacea9a7c9e86b59bd0958ee0b1234407c87c 100644 (file)
@@ -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()
index 068bf89a0ec549152ba908a355bf7294f9340902..60b8fd9a20d347d99529d7db00bd946d4c80adb2 100644 (file)
@@ -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:
index 62d4ddc35375ff39371c91058cf9547058b0a50f..df6218e13b48eb8b7f255674f506942d66910994 100644 (file)
@@ -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)
   #
 #
 
index 34a543f43d50b4671746a8af28193476cf358ccd..4255abaf08aebfd89d3eb65611c4ea80191c5d3a 100644 (file)
@@ -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)
 #