Exemple #1
0
    def test_property(self):
        r = self.root()
        data = "\x01\x02\x03\x04\x05\x06\x07\x08"
        assert_raises(l.NoSuchProperty, l.XGetWindowProperty, r, "ASDF",
                      "ASDF")
        l.XChangeProperty(r, "ASDF", "GHJK", 32, data)
        assert_raises(l.BadPropertyType, l.XGetWindowProperty, r, "ASDF",
                      "ASDF")

        for n in (8, 16, 32):
            print(n)
            l.XChangeProperty(r, "ASDF", "GHJK", n, data)
            assert l.XGetWindowProperty(r, "ASDF", "GHJK") == data

        l.XDeleteProperty(r, "ASDF")
        assert_raises(l.NoSuchProperty, l.XGetWindowProperty, r, "ASDF",
                      "GHJK")

        badwin = self.window()
        badwin.destroy()
        assert_raises((l.PropertyError, XError), trap.call,
                      l.XGetWindowProperty, badwin, "ASDF", "ASDF")

        # Giant massive property
        l.XChangeProperty(r, "ASDF", "GHJK", 32, "\x00" * 512 * (2**10))
        assert_raises(l.PropertyOverflow, l.XGetWindowProperty, r, "ASDF",
                      "GHJK")
Exemple #2
0
    def test_acquisition_stealing(self):
        d1 = self.clone_display()
        d2 = self.clone_display()

        m1 = ManagerSelection(d1, "WM_S0")
        m2 = ManagerSelection(d2, "WM_S0")

        selection_lost_fired = {m1: False, m2: False}

        def cb(manager):
            selection_lost_fired[manager] = True

        m1.connect("selection-lost", cb)
        m2.connect("selection-lost", cb)

        assert not m1.owned()
        assert not m2.owned()
        m1.acquire(m1.IF_UNOWNED)
        assert m1.owned()
        assert m2.owned()

        assert_raises(AlreadyOwned, m2.acquire, m2.IF_UNOWNED)

        assert not selection_lost_fired[m1]
        assert not selection_lost_fired[m2]
        m2.acquire(m2.FORCE_AND_RETURN)
        assert selection_lost_fired[m1]
        assert not selection_lost_fired[m2]
Exemple #3
0
 def test_get_display_for(self):
     assert l.get_display_for(self.display) is self.display
     win = self.window()
     assert l.get_display_for(win) is self.display
     assert_raises(TypeError, l.get_display_for, None)
     widg = gtk.Window()
     assert l.get_display_for(widg) is self.display
     clipboard = gtk.Clipboard(self.display, "PRIMARY")
     assert l.get_display_for(clipboard) is self.display
Exemple #4
0
 def test_readonly(self):
     obj = APTestClass()
     assert obj.get_property("readonly") is None
     assert_raises(TypeError,
                   obj.set_property, "readonly", "blah")
     def setit(o):
         o._internal_set_property("readonly", "blah")
     assert_emits(setit, obj, "notify::readonly")
     assert obj.get_property("readonly") == "blah"
Exemple #5
0
 def test_readonly(self):
     obj = APTestClass()
     assert obj.get_property("readonly") is None
     assert_raises(TypeError,
                   obj.set_property, "readonly", "blah")
     def setit(o):
         o._internal_set_property("readonly", "blah")
     assert_emits(setit, obj, "notify::readonly")
     assert obj.get_property("readonly") == "blah"
Exemple #6
0
    def test_prop_get_set_errors(self):
        assert p.prop_get(self.win, "SADFSAFDSADFASDF", "utf8") is None
        self.win2.destroy()
        gtk.gdk.flush()
        assert_raises(wimpiggy.error.XError, wimpiggy.error.trap.call,
                      p.prop_set, self.win2, "ASDF", "utf8", u(""))

        assert p.prop_get(self.win2, "ASDF", "utf8") is None
        p.prop_set(self.win, "ASDF", "utf8", u(""))
        assert p.prop_get(self.win, "ASDF", "latin1") is None
Exemple #7
0
    def test_get_xwindow_pywindow(self):
        d2 = self.clone_display()
        r1 = self.root()
        r2 = self.root(d2)
        assert r1 is not r2
        assert l.get_xwindow(r1) == l.get_xwindow(r2)
        win = self.window()
        assert l.get_xwindow(r1) != l.get_xwindow(win)
        assert l.get_pywindow(r2, l.get_xwindow(r1)) is r2

        assert_raises(l.XError, l.get_pywindow, self.display, 0)

        # This is necessary to stop some mysterious failure (perhaps d2 being
        # garbage collected before r2):
        del r2
Exemple #8
0
    def test_assert_emits(self):
        class C(gobject.GObject):
            __gsignals__ = {
                "foo": (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
                        (gobject.TYPE_PYOBJECT, )),
            }

        gobject.type_register(C)

        def do_emit(obj):
            obj.emit("foo", "asdf")

        def dont_emit(obj):
            pass

        c = C()
        assert_emits(do_emit, c, "foo")
        assert_raises(AssertionError, assert_emits, dont_emit, c, "foo")

        def slot_wants_asdf(obj, arg):
            assert isinstance(obj, C)
            assert arg == "asdf"

        def slot_wants_hjkl(obj, arg):
            assert isinstance(obj, C)
            assert arg == "hjkl"

        assert_emits(do_emit, c, "foo", slot_wants_asdf)
        assert_raises(AssertionError, assert_emits, do_emit, c, "foo",
                      slot_wants_hjkl)

        # Make sure that assert_emits disconnects after itself.
        self.gotcalled = False

        def f(*args):
            self.gotcalled = True

        assert_emits(do_emit, c, "foo", f)
        assert self.gotcalled
        self.gotcalled = False
        do_emit(c)
        assert not self.gotcalled

        # ...even if there was an error.
        # Errors can come from emission failure...
        assert_raises(AssertionError, assert_emits, dont_emit, c, "foo", f)

        # ..and from slots raising errors.
        def g(*args):
            assert False
            self.gotcalled = True

        assert_raises(AssertionError, assert_emits, do_emit, c, "foo", g)
        # In neither case should a handler be left around:
        self.gotcalled = False
        do_emit(c)
        assert not self.gotcalled
Exemple #9
0
 def test_get_rectangle_from_region(self):
     print(1)
     region = gtk.gdk.Region()
     assert_raises(ValueError, l.get_rectangle_from_region, region)
     print(2)
     rect1 = gtk.gdk.Rectangle(1, 2, 3, 4)
     region = gtk.gdk.region_rectangle(rect1)
     (x, y, w, h) = l.get_rectangle_from_region(region)
     assert (x, y, w, h) == (1, 2, 3, 4)
     print(3)
     region.union_with_rect(gtk.gdk.Rectangle(10, 11, 12, 13))
     (x, y, w, h) = l.get_rectangle_from_region(region)
     assert (x, y, w, h) in [(1, 2, 3, 4), (10, 11, 12, 13)]
     print(4)
     region.subtract(gtk.gdk.region_rectangle(rect1))
     (x, y, w, h) = l.get_rectangle_from_region(region)
     assert (x, y, w, h) == (10, 11, 12, 13)
     print(5)
Exemple #10
0
    def test_assert_emits(self):
        class C(gobject.GObject):
            __gsignals__ = { "foo":
                             (gobject.SIGNAL_RUN_LAST,
                              gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,)),
                             }
        gobject.type_register(C)
        def do_emit(obj):
            obj.emit("foo", "asdf")
        def dont_emit(obj):
            pass
        c = C()
        assert_emits(do_emit, c, "foo")
        assert_raises(AssertionError, assert_emits, dont_emit, c, "foo")

        def slot_wants_asdf(obj, arg):
            assert isinstance(obj, C)
            assert arg == "asdf"
        def slot_wants_hjkl(obj, arg):
            assert isinstance(obj, C)
            assert arg == "hjkl"

        assert_emits(do_emit, c, "foo", slot_wants_asdf)
        assert_raises(AssertionError,
                      assert_emits, do_emit, c, "foo", slot_wants_hjkl)

        # Make sure that assert_emits disconnects after itself.
        self.gotcalled = False
        def f(*args):
            self.gotcalled = True
        assert_emits(do_emit, c, "foo", f)
        assert self.gotcalled
        self.gotcalled = False
        do_emit(c)
        assert not self.gotcalled

        # ...even if there was an error.
        # Errors can come from emission failure...
        assert_raises(AssertionError,
                      assert_emits, dont_emit, c, "foo", f)
        # ..and from slots raising errors.
        def g(*args):
            assert False
            self.gotcalled = True
        assert_raises(AssertionError,
                      assert_emits, do_emit, c, "foo", g)
        # In neither case should a handler be left around:
        self.gotcalled = False
        do_emit(c)
        assert not self.gotcalled
Exemple #11
0
 def foo():
     assert_raises(AssertionError, trap.assert_out)
Exemple #12
0
 def test_BadProperty_on_empty(self):
     win = self.window()
     l.XChangeProperty(win, "ASDF", "GHJK", 32, "")
     assert l.XGetWindowProperty(win, "ASDF", "GHJK") == ""
     assert_raises(l.BadPropertyType, l.XGetWindowProperty, win, "ASDF",
                   "ASDF")
Exemple #13
0
    def test_assert_raises(self):
        class FooError(Exception):
            pass

        class BarError(Exception):
            pass

        def raises_foo():
            raise FooError("aiiieee")

        def raises_bar():
            raise BarError("arrrggghhh")

        def raises_nothing():
            pass

        def wants_args_raises_foo(*args, **kwargs):
            assert args == (1, 2)
            assert kwargs == {"a": 3, "b": 4}
            raise FooError("blearrghhh")

        # No exception:
        assert_raises(FooError, raises_foo)
        try:
            # Should raise AssertionError:
            assert_raises(FooError, raises_bar)
            raise FooError
        except AssertionError:
            pass
        try:
            # Should raise AssertionError:
            assert_raises(FooError, raises_nothing)
            raise FooError
        except AssertionError:
            pass
        # No exception:
        assert_raises(FooError, wants_args_raises_foo, 1, 2, a=3, b=4)
        assert_raises(AssertionError, wants_args_raises_foo)
        # Tuples allowed:
        # No exception
        assert_raises((FooError, BarError), raises_foo)
        assert_raises((FooError, BarError), raises_bar)
        try:
            # Should raise AssertionError
            assert_raises((FooError, BarError), raises_nothing)
            raise FooError
        except AssertionError:
            pass
        try:
            # Should raise AssertionError
            assert_raises((FooError, TypeError), raises_bar)
            raise FooError
        except AssertionError:
            pass
Exemple #14
0
 def foo():
     assert_raises(AssertionError, trap.assert_out)
Exemple #15
0
 def test_assert_raises(self):
     class FooError(Exception):
         pass
     class BarError(Exception):
         pass
     def raises_foo():
         raise FooError("aiiieee")
     def raises_bar():
         raise BarError("arrrggghhh")
     def raises_nothing():
         pass
     def wants_args_raises_foo(*args, **kwargs):
         assert args == (1, 2)
         assert kwargs == {"a": 3, "b": 4}
         raise FooError("blearrghhh")
     # No exception:
     assert_raises(FooError, raises_foo)
     try:
         # Should raise AssertionError:
         assert_raises(FooError, raises_bar)
         raise FooError
     except AssertionError:
         pass
     try:
         # Should raise AssertionError:
         assert_raises(FooError, raises_nothing)
         raise FooError
     except AssertionError:
         pass
     # No exception:
     assert_raises(FooError, wants_args_raises_foo, 1, 2, a=3, b=4)
     assert_raises(AssertionError, wants_args_raises_foo)
     # Tuples allowed:
     # No exception
     assert_raises((FooError, BarError), raises_foo)
     assert_raises((FooError, BarError), raises_bar)
     try:
         # Should raise AssertionError
         assert_raises((FooError, BarError), raises_nothing)
         raise FooError
     except AssertionError:
         pass
     try:
         # Should raise AssertionError
         assert_raises((FooError, TypeError), raises_bar)
         raise FooError
     except AssertionError:
         pass