def test_main(self): obj = APTestClass() assert obj.get_property("readwrite") is None def setit(o): o.set_property("readwrite", "blah") assert_emits(setit, obj, "notify::readwrite") assert obj.get_property("readwrite") == "blah"
def test_custom_getset(self): class C(APTestClass): def __init__(self): APTestClass.__init__(self) self.custom = 10 def do_set_property_readwrite(self, name, value): assert name == "readwrite" self.custom = value def do_get_property_readwrite(self, name): assert name == "readwrite" return self.custom gobject.type_register(C) c = C() assert c.get_property("readwrite") == 10 c.set_property("readwrite", 3) assert c.custom == 3 assert c.get_property("readwrite") == 3 def setit(obj): obj._internal_set_property("readwrite", 12) assert_emits(setit, c, "notify::readwrite") assert c.get_property("readwrite") == 12 c.custom = 15 assert c.get_property("readwrite") == 15
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"
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
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