[evolution] tests: capture stdout



commit 1d748182ffeee4a3566a78edcd9d3a47b58eb4bb
Author: Vadim Rutkovsky <vrutkovs redhat com>
Date:   Tue Jun 10 13:09:58 2014 +0200

    tests: capture stdout

 tests/common_steps.py |   30 ++++++++++++++++++++++--------
 tests/environment.py  |   13 +++++++++----
 2 files changed, 31 insertions(+), 12 deletions(-)
---
diff --git a/tests/common_steps.py b/tests/common_steps.py
index d4ab62a..c814cb4 100644
--- a/tests/common_steps.py
+++ b/tests/common_steps.py
@@ -5,15 +5,15 @@ if isA11yEnabled() is False:
 
 from time import time, sleep
 from functools import wraps
-from os import strerror, errno, kill, system
-from signal import signal, alarm, SIGALRM, SIGKILL
-from subprocess import Popen
+from os import strerror, errno, system
+from signal import signal, alarm, SIGALRM
+from subprocess import Popen, PIPE
 from behave import step
 from gi.repository import GLib, Gio
+import fcntl, os
 
 from dogtail.rawinput import keyCombo, absoluteMotion, pressKey
 from dogtail.tree import root
-from dogtail.utils import run
 from unittest import TestCase
 
 
@@ -125,7 +125,8 @@ class App(object):
             self.a11yAppName = self.internCommand
 
         # Trap weird bus errors
-        for attempt in xrange(0, 10):
+        for attempt in xrange(0, 30):
+            sleep(1)
             try:
                 return self.a11yAppName in [x.name for x in root.applications()]
             except GLib.GError:
@@ -140,7 +141,7 @@ class App(object):
             keyCombo('<Control><Alt><Shift>R')
 
         try:
-            kill(self.pid, SIGKILL)
+            self.process.kill()
         except:
             # Fall back to killall
             Popen("killall " + self.appCommand, shell=True).wait()
@@ -153,8 +154,11 @@ class App(object):
             self.kill()
             assert not self.isRunning(), "Application cannot be stopped"
 
-        command = "%s %s" % (self.appCommand, self.parameters)
-        self.pid = run(command, timeout=5)
+        #command = "%s %s" % (self.appCommand, self.parameters)
+        #self.pid = run(command, timeout=5)
+        self.process = Popen(self.appCommand.split() + self.parameters.split(),
+                             stdout=PIPE, stderr=PIPE, bufsize=0)
+        self.pid = self.process.pid
 
         assert self.isRunning(), "Application failed to start"
         return root.application(self.a11yAppName)
@@ -222,3 +226,13 @@ def check_for_errors(context):
                 system("rm -rf %s > /dev/null" % folder)
 
             raise RuntimeError("Error occurred: %s" % messages)
+
+
+def non_block_read(output):
+    fd = output.fileno()
+    fl = fcntl.fcntl(fd, fcntl.F_GETFL)
+    fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NONBLOCK)
+    try:
+        return output.read()
+    except:
+        return ""
diff --git a/tests/environment.py b/tests/environment.py
index fdccd1a..e11c1a4 100644
--- a/tests/environment.py
+++ b/tests/environment.py
@@ -5,7 +5,7 @@ from dogtail.utils import isA11yEnabled, enableA11y
 if not isA11yEnabled():
     enableA11y(True)
 
-from common_steps import App, dummy, cleanup
+from common_steps import App, dummy, cleanup, non_block_read
 from dogtail.config import config
 import os
 
@@ -57,9 +57,6 @@ def after_scenario(context, scenario):
     Kill evolution (in order to make this reliable we send sigkill)
     """
     try:
-        # Stop evolution
-        context.app_class.kill()
-
         # Attach journalctl logs
         if hasattr(context, "embed"):
             os.system("pkexec journalctl /usr/bin/gnome-session --no-pager -o cat --since='%s'> 
/tmp/journal-session.log" % context.log_start_time)
@@ -67,6 +64,14 @@ def after_scenario(context, scenario):
             if data:
                 context.embed('text/plain', data)
 
+            context.app_class.kill()
+
+            stdout = non_block_read(context.app_class.process.stdout)
+            stderr = non_block_read(context.app_class.process.stderr)
+
+            context.embed('text/plain', '\n'.join(stdout))
+            context.embed('text/plain', '\n'.join(stderr))
+
         # Make some pause after scenario
         sleep(1)
     except Exception as e:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]