blob: 2caa0b4824cc0c5fc780f42a73eacfe084bf496d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# -*- coding: utf-8 -*-
import unittest
class GtkDemoTest(unittest.TestCase):
"""
TestCase subclass which handles bringing up and shutting down gtk-demo as a fixture. Used for writing other test cases.
"""
def setUp(self):
import dogtail.config
dogtail.config.config.logDebugToStdOut = True
dogtail.config.config.logDebugToFile = False
import dogtail.utils
self.pid = dogtail.utils.run('gtk3-demo')
self.app = dogtail.tree.root.application('gtk3-demo')
def tearDown(self):
import os
import signal
import time
os.kill(self.pid, signal.SIGKILL)
# Sleep just enough to let the app actually die.
# AT-SPI doesn't like being hammered too fast.
time.sleep(0.5)
def runDemo(self, demoName):
"""
Click on the named demo within the gtk-demo app.
"""
tree = self.app.child(roleName="tree table")
tree.child(demoName).doActionNamed('activate')
def trap_stdout(function, args=None):
"""
Grab stdout output during function execution
"""
import sys
from StringIO import StringIO
saved_stdout = sys.stdout
try:
out = StringIO()
sys.stdout = out
if type(args) is dict:
function(**args)
elif args:
function(args)
else:
function()
output = out.getvalue().strip()
finally:
sys.stdout = saved_stdout
return output
|