diff options
author | Vadim Rutkovsky <vrutkovs@redhat.com> | 2014-06-10 19:09:58 +0800 |
---|---|---|
committer | Vadim Rutkovsky <vrutkovs@redhat.com> | 2014-06-10 22:32:38 +0800 |
commit | 1d748182ffeee4a3566a78edcd9d3a47b58eb4bb (patch) | |
tree | 03a3cb9b89e33dcdb5c33d6e0f892e0e5b72b353 /tests | |
parent | 2c3485e613914c1f65d96da9f87525b240fb890c (diff) | |
download | gsoc2013-evolution-1d748182ffeee4a3566a78edcd9d3a47b58eb4bb.tar gsoc2013-evolution-1d748182ffeee4a3566a78edcd9d3a47b58eb4bb.tar.gz gsoc2013-evolution-1d748182ffeee4a3566a78edcd9d3a47b58eb4bb.tar.bz2 gsoc2013-evolution-1d748182ffeee4a3566a78edcd9d3a47b58eb4bb.tar.lz gsoc2013-evolution-1d748182ffeee4a3566a78edcd9d3a47b58eb4bb.tar.xz gsoc2013-evolution-1d748182ffeee4a3566a78edcd9d3a47b58eb4bb.tar.zst gsoc2013-evolution-1d748182ffeee4a3566a78edcd9d3a47b58eb4bb.zip |
tests: capture stdout
Diffstat (limited to 'tests')
-rw-r--r-- | tests/common_steps.py | 30 | ||||
-rw-r--r-- | tests/environment.py | 13 |
2 files changed, 31 insertions, 12 deletions
diff --git a/tests/common_steps.py b/tests/common_steps.py index d4ab62aca5..c814cb4549 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 fdccd1ad56..e11c1a4453 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: |