~ubuntu-branches/ubuntu/karmic/parti-all/karmic

« back to all changes in this revision

Viewing changes to wimpiggy/test_error.py

  • Committer: Bazaar Package Importer
  • Author(s): Evan Dandrea
  • Date: 2009-06-02 12:44:00 UTC
  • Revision ID: james.westby@ubuntu.com-20090602124400-xbkgh9vxjciey732
Tags: upstream-0.0.6
ImportĀ upstreamĀ versionĀ 0.0.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# This file is part of Parti.
 
2
# Copyright (C) 2008, 2009 Nathaniel Smith <njs@pobox.com>
 
3
# Parti is released under the terms of the GNU GPL v2, or, at your option, any
 
4
# later version. See the file COPYING for details.
 
5
 
 
6
from wimpiggy.test import *
 
7
from wimpiggy.error import *
 
8
# Need a way to generate X errors...
 
9
import wimpiggy.lowlevel
 
10
 
 
11
import gtk.gdk
 
12
 
 
13
class TestError(TestWithSession):
 
14
    def cause_badwindow(self):
 
15
        root = self.display.get_default_screen().get_root_window()
 
16
        win = gtk.gdk.Window(root, width=10, height=10,
 
17
                             window_type=gtk.gdk.WINDOW_TOPLEVEL,
 
18
                             wclass=gtk.gdk.INPUT_OUTPUT,
 
19
                             event_mask=0)
 
20
        win.destroy()
 
21
        wimpiggy.lowlevel.XAddToSaveSet(win)
 
22
        return 3
 
23
 
 
24
    def test_call(self):
 
25
        assert trap.call(lambda: 0) == 0
 
26
        assert trap.call(lambda: 1) == 1
 
27
        try:
 
28
            trap.call(self.cause_badwindow)
 
29
        except XError, e:
 
30
            assert e.args == (wimpiggy.lowlevel.const["BadWindow"],)
 
31
 
 
32
    def test_swallow(self):
 
33
        assert trap.swallow(lambda: 0) is None
 
34
        assert trap.swallow(lambda: 1) is None
 
35
        assert trap.swallow(self.cause_badwindow) is None
 
36
 
 
37
    def test_assert_out(self):
 
38
        def foo():
 
39
            assert_raises(AssertionError, trap.assert_out)
 
40
        trap.call(foo)