def test_min_max(self): class C(GObject.GObject): prop_int = GObject.Property(type=int, minimum=1, maximum=100, default=1) prop_float = GObject.Property(type=float, minimum=0.1, maximum=10.5, default=1.1) def __init__(self): GObject.GObject.__init__(self) # we test known-bad values here which cause Gtk-WARNING logs. # Explicitly allow these for this test. with capture_glib_warnings(allow_warnings=True): o = C() self.assertEqual(o.prop_int, 1) o.prop_int = 5 self.assertEqual(o.prop_int, 5) o.prop_int = 0 self.assertEqual(o.prop_int, 5) o.prop_int = 101 self.assertEqual(o.prop_int, 5) self.assertEqual(o.prop_float, 1.1) o.prop_float = 7.75 self.assertEqual(o.prop_float, 7.75) o.prop_float = 0.09 self.assertEqual(o.prop_float, 7.75) o.prop_float = 10.51 self.assertEqual(o.prop_float, 7.75)
def test_enum_double_registration_error(self): # a warning is printed for double registration and pygobject will # also raise a RuntimeError. GIMarshallingTests.Enum # cause enum registration info = repo.find_by_name('GIMarshallingTests', 'Enum') with capture_glib_warnings(allow_warnings=True): self.assertRaises(RuntimeError, GIRepository.enum_register_new_gtype_and_add, info)
def test_alignment(self): # Creation of pygtk.Alignment causes hard warnings, ignore this in testing. with capture_glib_warnings(allow_warnings=True): a = gtk.Alignment() self.assertEqual(a.props.xalign, 0.0) self.assertEqual(a.props.yalign, 0.0) self.assertEqual(a.props.xscale, 0.0) self.assertEqual(a.props.yscale, 0.0)
def test_remove(self): s = GLib.idle_add(dir) self.assertEqual(GLib.source_remove(s), True) # Removing sources not found cause critical with capture_glib_warnings(allow_criticals=True): # s is now removed, should fail now self.assertEqual(GLib.source_remove(s), False) # accepts large source IDs (they are unsigned) self.assertEqual(GLib.source_remove(GLib.MAXINT32), False) self.assertEqual(GLib.source_remove(GLib.MAXINT32 + 1), False) self.assertEqual(GLib.source_remove(GLib.MAXUINT32), False)
def test_combobox_entry(self): liststore = gtk.ListStore(int, str) liststore.append((1, 'One')) liststore.append((2, 'Two')) liststore.append((3, 'Three')) # might cause a Pango warning, do not break on this with capture_glib_warnings(allow_warnings=True): combo = gtk.ComboBoxEntry(model=liststore) combo.set_text_column(1) combo.set_active(0) self.assertEqual(combo.get_text_column(), 1) self.assertEqual(combo.get_child().get_text(), 'One') combo = gtk.combo_box_entry_new() combo.set_model(liststore) combo.set_text_column(1) combo.set_active(0) self.assertEqual(combo.get_text_column(), 1) self.assertEqual(combo.get_child().get_text(), 'One') combo = gtk.combo_box_entry_new_with_model(liststore) combo.set_text_column(1) combo.set_active(0) self.assertEqual(combo.get_text_column(), 1) self.assertEqual(combo.get_child().get_text(), 'One')