Ticket #1001: tilting.py

File tilting.py, 2.1 KB (added by davidsarah, at 2010-04-13T02:54:31Z)

Simple hack to run Windmill tests from a trial test suite

Line 
1# Note: may be Apache 2.0 license-contaminated.
2# (I haven't checked whether there is a significant license compatibility issue here.)
3
4import sys
5import windmill
6from windmill.bin import admin_lib
7from twisted.internet import defer
8from foolscap.api import eventually
9from allmydata.util import log
10
11
12class TiltingMixin:
13    # adapted from
14    # http://github.com/windmill/windmill/blob/master/windmill/authoring/unit.py
15    # http://github.com/windmill/windmill/blob/master/windmill/bin/shell_objects.py
16
17    def setUp(self):
18        self.browser_debugging = False
19        self.settings = {}
20        self.configure()
21
22        log.msg("starting gateway")
23        self.start_gateway()
24
25        log.msg("setting up Windmill for browser '%s'" % (self.browserName,))
26        windmill.block_exit = True
27        windmill.stdout = sys.stdout
28        windmill.stdin = sys.stdin
29
30        admin_lib.configure_global_settings()
31        for (setting, value) in self.settings.iteritems():
32            windmill.settings[setting] = value
33        windmill.settings['controllers'] = []
34        self.shell_objects = admin_lib.setup()
35
36        log.msg("starting browser")
37        self.shell_objects['start_' + self.browserName]()
38
39        d = defer.Deferred()
40        admin_lib.on_ide_awake.append(lambda: eventually(d.callback, None))
41        d.addCallback(lambda ign: log.msg("browser started"))
42
43        if self.browser_debugging:
44            self.xmlrpc = windmill.tools.make_xmlrpc_client()
45            d.addCallback(lambda ign:
46                          self.xmlrpc.add_command({'method':'commands.setOptions',
47                                                   'params':{'runTests':False, 'priority':'normal'}}))
48        return d
49
50    def tearDown(self):
51        windmill.block_exit = False
52        if self.browser_debugging:
53            self.xmlrpc.add_command({'method':'commands.setOptions',
54                                     'params':{'runTests':True, 'priority':'normal'}})
55        else:
56            log.msg("shutting down browser '%s'" % (self.browserName,))
57            admin_lib.teardown(self.shell_objects)
58            log.msg("browser shutdown done")