1 # -*- Mode: Python; py-indent-offset: 4 -*-
2 # vim: tabstop=4 shiftwidth=4 expandtab
7 sys.path.insert(0, "../")
9 from compathelper import _long, _unicode, _bytes
11 from gi.repository import GLib
12 from gi.repository import GObject
13 from gi.repository import Gdk
14 from gi.repository import Gtk
15 from gi.repository import Gio
16 from gi.repository import Pango
17 from gi.repository import GdkPixbuf
18 import gi.overrides as overrides
22 class TestRegistry(unittest.TestCase):
24 def test_non_gi(self):
29 overrides.override(MyClass)
30 self.fail('unexpected success of overriding non-GI class')
31 except TypeError as e:
32 self.assertTrue('Can not override a type MyClass' in str(e))
35 class TestGLib(unittest.TestCase):
37 def test_gvariant_create(self):
40 variant = GLib.Variant('i', 42)
41 self.assertTrue(isinstance(variant, GLib.Variant))
42 self.assertEqual(variant.get_int32(), 42)
44 variant = GLib.Variant('s', '')
45 self.assertTrue(isinstance(variant, GLib.Variant))
46 self.assertEqual(variant.get_string(), '')
48 variant = GLib.Variant('s', 'hello')
49 self.assertTrue(isinstance(variant, GLib.Variant))
50 self.assertEqual(variant.get_string(), 'hello')
53 variant = GLib.Variant('v', GLib.Variant('i', 42))
54 self.assertTrue(isinstance(variant, GLib.Variant))
55 self.assertTrue(isinstance(variant.get_variant(), GLib.Variant))
56 self.assertEqual(variant.get_type_string(), 'v')
57 self.assertEqual(variant.get_variant().get_type_string(), 'i')
58 self.assertEqual(variant.get_variant().get_int32(), 42)
60 variant = GLib.Variant('v', GLib.Variant('v', GLib.Variant('i', 42)))
61 self.assertEqual(variant.get_type_string(), 'v')
62 self.assertEqual(variant.get_variant().get_type_string(), 'v')
63 self.assertEqual(variant.get_variant().get_variant().get_type_string(), 'i')
64 self.assertEqual(variant.get_variant().get_variant().get_int32(), 42)
68 variant = GLib.Variant('()', ())
69 self.assertEqual(variant.get_type_string(), '()')
70 self.assertEqual(variant.n_children(), 0)
72 variant = GLib.Variant('(i)', (3,))
73 self.assertEqual(variant.get_type_string(), '(i)')
74 self.assertTrue(isinstance(variant, GLib.Variant))
75 self.assertEqual(variant.n_children(), 1)
76 self.assertTrue(isinstance(variant.get_child_value(0), GLib.Variant))
77 self.assertEqual(variant.get_child_value(0).get_int32(), 3)
79 variant = GLib.Variant('(ss)', ('mec', 'mac'))
80 self.assertEqual(variant.get_type_string(), '(ss)')
81 self.assertTrue(isinstance(variant, GLib.Variant))
82 self.assertTrue(isinstance(variant.get_child_value(0), GLib.Variant))
83 self.assertTrue(isinstance(variant.get_child_value(1), GLib.Variant))
84 self.assertEqual(variant.get_child_value(0).get_string(), 'mec')
85 self.assertEqual(variant.get_child_value(1).get_string(), 'mac')
88 variant = GLib.Variant('((si)(ub))', (('hello', -1), (42, True)))
89 self.assertEqual(variant.get_type_string(), '((si)(ub))')
90 self.assertEqual(variant.unpack(), (('hello', -1), (_long(42), True)))
94 variant = GLib.Variant('a{si}', {})
95 self.assertTrue(isinstance(variant, GLib.Variant))
96 self.assertEqual(variant.get_type_string(), 'a{si}')
97 self.assertEqual(variant.n_children(), 0)
99 variant = GLib.Variant('a{si}', {'': 1, 'key1': 2, 'key2': 3})
100 self.assertEqual(variant.get_type_string(), 'a{si}')
101 self.assertTrue(isinstance(variant, GLib.Variant))
102 self.assertTrue(isinstance(variant.get_child_value(0), GLib.Variant))
103 self.assertTrue(isinstance(variant.get_child_value(1), GLib.Variant))
104 self.assertTrue(isinstance(variant.get_child_value(2), GLib.Variant))
105 self.assertEqual(variant.unpack(), {'': 1, 'key1': 2, 'key2': 3})
107 # nested dictionaries
108 variant = GLib.Variant('a{sa{si}}', {})
109 self.assertTrue(isinstance(variant, GLib.Variant))
110 self.assertEqual(variant.get_type_string(), 'a{sa{si}}')
111 self.assertEqual(variant.n_children(), 0)
113 d = {'': {'': 1, 'keyn1': 2},
114 'key1': {'key11': 11, 'key12': 12}}
115 variant = GLib.Variant('a{sa{si}}', d)
116 self.assertEqual(variant.get_type_string(), 'a{sa{si}}')
117 self.assertTrue(isinstance(variant, GLib.Variant))
118 self.assertEqual(variant.unpack(), d)
122 variant = GLib.Variant('ai', [])
123 self.assertEqual(variant.get_type_string(), 'ai')
124 self.assertEqual(variant.n_children(), 0)
126 variant = GLib.Variant('ai', [1, 2])
127 self.assertEqual(variant.get_type_string(), 'ai')
128 self.assertTrue(isinstance(variant, GLib.Variant))
129 self.assertTrue(isinstance(variant.get_child_value(0), GLib.Variant))
130 self.assertTrue(isinstance(variant.get_child_value(1), GLib.Variant))
131 self.assertEqual(variant.get_child_value(0).get_int32(), 1)
132 self.assertEqual(variant.get_child_value(1).get_int32(), 2)
134 variant = GLib.Variant('as', [])
135 self.assertEqual(variant.get_type_string(), 'as')
136 self.assertEqual(variant.n_children(), 0)
138 variant = GLib.Variant('as', [''])
139 self.assertEqual(variant.get_type_string(), 'as')
140 self.assertTrue(isinstance(variant, GLib.Variant))
141 self.assertTrue(isinstance(variant.get_child_value(0), GLib.Variant))
142 self.assertEqual(variant.get_child_value(0).get_string(), '')
144 variant = GLib.Variant('as', ['hello', 'world'])
145 self.assertEqual(variant.get_type_string(), 'as')
146 self.assertTrue(isinstance(variant, GLib.Variant))
147 self.assertTrue(isinstance(variant.get_child_value(0), GLib.Variant))
148 self.assertTrue(isinstance(variant.get_child_value(1), GLib.Variant))
149 self.assertEqual(variant.get_child_value(0).get_string(), 'hello')
150 self.assertEqual(variant.get_child_value(1).get_string(), 'world')
153 variant = GLib.Variant('aai', [])
154 self.assertEqual(variant.get_type_string(), 'aai')
155 self.assertEqual(variant.n_children(), 0)
157 variant = GLib.Variant('aai', [[]])
158 self.assertEqual(variant.get_type_string(), 'aai')
159 self.assertEqual(variant.n_children(), 1)
160 self.assertEqual(variant.get_child_value(0).n_children(), 0)
162 variant = GLib.Variant('aai', [[1, 2], [3, 4, 5]])
163 self.assertEqual(variant.get_type_string(), 'aai')
164 self.assertEqual(variant.unpack(), [[1, 2], [3, 4, 5]])
170 variant = GLib.Variant('(as)', ([],))
171 self.assertEqual(variant.get_type_string(), '(as)')
172 self.assertEqual(variant.n_children(), 1)
173 self.assertEqual(variant.get_child_value(0).n_children(), 0)
175 variant = GLib.Variant('(as)', ([''],))
176 self.assertEqual(variant.get_type_string(), '(as)')
177 self.assertEqual(variant.n_children(), 1)
178 self.assertEqual(variant.get_child_value(0).n_children(), 1)
179 self.assertEqual(variant.get_child_value(0).get_child_value(0).get_string(), '')
181 variant = GLib.Variant('(as)', (['hello'],))
182 self.assertEqual(variant.get_type_string(), '(as)')
183 self.assertEqual(variant.n_children(), 1)
184 self.assertEqual(variant.get_child_value(0).n_children(), 1)
185 self.assertEqual(variant.get_child_value(0).get_child_value(0).get_string(), 'hello')
187 obj = {'a1': (1, True), 'a2': (2, False)}
188 variant = GLib.Variant('a{s(ib)}', obj)
189 self.assertEqual(variant.get_type_string(), 'a{s(ib)}')
190 self.assertEqual(variant.unpack(), obj)
192 obj = {'a1': (1, GLib.Variant('b', True)), 'a2': (2, GLib.Variant('y', 255))}
193 variant = GLib.Variant('a{s(iv)}', obj)
194 self.assertEqual(variant.get_type_string(), 'a{s(iv)}')
195 self.assertEqual(variant.unpack(), {'a1': (1, True), 'a2': (2, 255)})
197 obj = (1, {'a': {'a1': True, 'a2': False},
202 variant = GLib.Variant('(ia{sa{sb}}s)', obj)
203 self.assertEqual(variant.get_type_string(), '(ia{sa{sb}}s)')
204 self.assertEqual(variant.unpack(), obj)
206 obj = {"frequency": GLib.Variant('t', 738000000),
207 "hierarchy": GLib.Variant('i', 0),
208 "bandwidth": GLib.Variant('x', 8),
209 "code-rate-hp": GLib.Variant('d', 2.0 / 3.0),
210 "constellation": GLib.Variant('s', "QAM16"),
211 "guard-interval": GLib.Variant('u', 4)}
212 variant = GLib.Variant('a{sv}', obj)
213 self.assertEqual(variant.get_type_string(), 'a{sv}')
214 self.assertEqual(variant.unpack(), {"frequency": 738000000,
217 "code-rate-hp": 2.0 / 3.0,
218 "constellation": "QAM16",
219 "guard-interval": 4})
221 def test_gvariant_create_errors(self):
223 self.assertRaises(TypeError, GLib.Variant, 'i', 42, 3)
224 self.assertRaises(TypeError, GLib.Variant, '(i)', (42, 3))
226 # not enough arguments
227 self.assertRaises(TypeError, GLib.Variant, '(ii)', (42,))
230 self.assertRaises(TypeError, GLib.Variant, 'i', 'hello')
231 self.assertRaises(TypeError, GLib.Variant, 's', 42)
232 self.assertRaises(TypeError, GLib.Variant, '(ss)', 'mec', 'mac')
234 # unimplemented data type
235 self.assertRaises(NotImplementedError, GLib.Variant, 'Q', 1)
237 def test_gvariant_unpack(self):
239 res = GLib.Variant.new_int32(-42).unpack()
240 self.assertEqual(res, -42)
242 res = GLib.Variant.new_uint64(34359738368).unpack()
243 self.assertEqual(res, 34359738368)
245 res = GLib.Variant.new_boolean(True).unpack()
246 self.assertEqual(res, True)
248 res = GLib.Variant.new_object_path('/foo/Bar').unpack()
249 self.assertEqual(res, '/foo/Bar')
252 res = GLib.Variant('v', GLib.Variant.new_int32(-42)).unpack()
253 self.assertEqual(res, -42)
255 GLib.Variant('v', GLib.Variant('v', GLib.Variant('i', 42)))
256 self.assertEqual(res, -42)
259 res = GLib.Variant.new_tuple(GLib.Variant.new_int32(-1),
260 GLib.Variant.new_string('hello')).unpack()
261 self.assertEqual(res, (-1, 'hello'))
264 vb = GLib.VariantBuilder.new(gi._gi.variant_type_from_string('ai'))
265 vb.add_value(GLib.Variant.new_int32(-1))
266 vb.add_value(GLib.Variant.new_int32(3))
267 res = vb.end().unpack()
268 self.assertEqual(res, [-1, 3])
271 res = GLib.Variant('a{si}', {'key1': 1, 'key2': 2}).unpack()
272 self.assertEqual(res, {'key1': 1, 'key2': 2})
274 def test_gvariant_iteration(self):
276 vb = GLib.VariantBuilder.new(gi._gi.variant_type_from_string('ai'))
277 vb.add_value(GLib.Variant.new_int32(-1))
278 vb.add_value(GLib.Variant.new_int32(3))
281 self.assertEqual(len(v), 2)
282 self.assertEqual(v[0], -1)
283 self.assertEqual(v[1], 3)
284 self.assertEqual(v[-1], 3)
285 self.assertEqual(v[-2], -1)
286 self.assertRaises(IndexError, v.__getitem__, 2)
287 self.assertRaises(IndexError, v.__getitem__, -3)
288 self.assertRaises(ValueError, v.__getitem__, 'a')
291 self.assertEqual([x for x in v], [-1, 3])
292 self.assertEqual(list(v), [-1, 3])
295 v = GLib.Variant.new_tuple(GLib.Variant.new_int32(-1),
296 GLib.Variant.new_string('hello'))
297 self.assertEqual(len(v), 2)
298 self.assertEqual(v[0], -1)
299 self.assertEqual(v[1], 'hello')
300 self.assertEqual(v[-1], 'hello')
301 self.assertEqual(v[-2], -1)
302 self.assertRaises(IndexError, v.__getitem__, 2)
303 self.assertRaises(IndexError, v.__getitem__, -3)
304 self.assertRaises(ValueError, v.__getitem__, 'a')
307 self.assertEqual([x for x in v], [-1, 'hello'])
308 self.assertEqual(tuple(v), (-1, 'hello'))
310 # dictionary index access
311 vsi = GLib.Variant('a{si}', {'key1': 1, 'key2': 2})
312 vis = GLib.Variant('a{is}', {1: 'val1', 5: 'val2'})
314 self.assertEqual(len(vsi), 2)
315 self.assertEqual(vsi['key1'], 1)
316 self.assertEqual(vsi['key2'], 2)
317 self.assertRaises(KeyError, vsi.__getitem__, 'unknown')
319 self.assertEqual(len(vis), 2)
320 self.assertEqual(vis[1], 'val1')
321 self.assertEqual(vis[5], 'val2')
322 self.assertRaises(KeyError, vsi.__getitem__, 3)
324 # dictionary iteration
325 self.assertEqual(set(vsi.keys()), set(['key1', 'key2']))
326 self.assertEqual(set(vis.keys()), set([1, 5]))
328 # string index access
329 v = GLib.Variant('s', 'hello')
330 self.assertEqual(len(v), 5)
331 self.assertEqual(v[0], 'h')
332 self.assertEqual(v[4], 'o')
333 self.assertEqual(v[-1], 'o')
334 self.assertEqual(v[-5], 'h')
335 self.assertRaises(IndexError, v.__getitem__, 5)
336 self.assertRaises(IndexError, v.__getitem__, -6)
339 self.assertEqual([x for x in v], ['h', 'e', 'l', 'l', 'o'])
341 def test_variant_split_signature(self):
342 self.assertEqual(GLib.Variant.split_signature('()'), [])
344 self.assertEqual(GLib.Variant.split_signature('s'), ['s'])
346 self.assertEqual(GLib.Variant.split_signature('as'), ['as'])
348 self.assertEqual(GLib.Variant.split_signature('(s)'), ['s'])
350 self.assertEqual(GLib.Variant.split_signature('(iso)'), ['i', 's', 'o'])
352 self.assertEqual(GLib.Variant.split_signature('(s(ss)i(ii))'),
353 ['s', '(ss)', 'i', '(ii)'])
355 self.assertEqual(GLib.Variant.split_signature('(as)'), ['as'])
357 self.assertEqual(GLib.Variant.split_signature('(s(ss)iaiaasa(ii))'),
358 ['s', '(ss)', 'i', 'ai', 'aas', 'a(ii)'])
360 self.assertEqual(GLib.Variant.split_signature('(a{iv}(ii)((ss)a{s(ss)}))'),
361 ['a{iv}', '(ii)', '((ss)a{s(ss)})'])
363 def test_variant_hash(self):
364 v1 = GLib.Variant('s', 'somestring')
365 v2 = GLib.Variant('s', 'somestring')
366 v3 = GLib.Variant('s', 'somestring2')
368 self.assertTrue(v2 in set([v1, v3]))
369 self.assertTrue(v2 in frozenset([v1, v3]))
370 self.assertTrue(v2 in {v1: '1', v3: '2'})
372 def test_variant_compare(self):
373 # Check if identical GVariant are equal
375 def assert_equal(vtype, value):
376 self.assertEqual(GLib.Variant(vtype, value), GLib.Variant(vtype, value))
378 def assert_not_equal(vtype1, value1, vtype2, value2):
379 self.assertNotEqual(GLib.Variant(vtype1, value1), GLib.Variant(vtype2, value2))
381 numbers = ['y', 'n', 'q', 'i', 'u', 'x', 't', 'h', 'd']
383 assert_equal(num, 42)
384 assert_not_equal(num, 42, num, 41)
385 assert_not_equal(num, 42, 's', '42')
387 assert_equal('s', 'something')
388 assert_not_equal('s', 'something', 's', 'somethingelse')
389 assert_not_equal('s', 'something', 'i', 1234)
391 assert_equal('g', 'dustybinqhogx')
392 assert_not_equal('g', 'dustybinqhogx', 'g', 'dustybin')
393 assert_not_equal('g', 'dustybinqhogx', 'i', 1234)
395 assert_equal('o', '/dev/null')
396 assert_not_equal('o', '/dev/null', 'o', '/dev/zero')
397 assert_not_equal('o', '/dev/null', 'i', 1234)
399 assert_equal('(s)', ('strtuple',))
400 assert_not_equal('(s)', ('strtuple',), '(s)', ('strtuple2',))
402 assert_equal('a{si}', {'str': 42})
403 assert_not_equal('a{si}', {'str': 42}, 'a{si}', {'str': 43})
405 assert_equal('v', GLib.Variant('i', 42))
406 assert_not_equal('v', GLib.Variant('i', 42), 'v', GLib.Variant('i', 43))
408 def test_variant_bool(self):
409 # Check if the GVariant bool matches the unpacked Pythonic bool
411 def assert_equals_bool(vtype, value):
412 self.assertEqual(bool(GLib.Variant(vtype, value)), bool(value))
415 assert_equals_bool('b', True)
416 assert_equals_bool('b', False)
418 numbers = ['y', 'n', 'q', 'i', 'u', 'x', 't', 'h', 'd']
419 for number in numbers:
420 assert_equals_bool(number, 0)
421 assert_equals_bool(number, 1)
423 assert_equals_bool('s', '')
424 assert_equals_bool('g', '')
425 assert_equals_bool('s', 'something')
426 assert_equals_bool('o', '/dev/null')
427 assert_equals_bool('g', 'dustybinqhogx')
430 assert_equals_bool('ab', [True])
431 assert_equals_bool('ab', [False])
432 for number in numbers:
433 assert_equals_bool('a' + number, [])
434 assert_equals_bool('a' + number, [0])
435 assert_equals_bool('as', [])
436 assert_equals_bool('as', [''])
437 assert_equals_bool('ao', [])
438 assert_equals_bool('ao', ['/'])
439 assert_equals_bool('ag', [])
440 assert_equals_bool('ag', [''])
441 assert_equals_bool('aai', [[]])
444 assert_equals_bool('()', ())
445 for number in numbers:
446 assert_equals_bool('(' + number + ')', (0,))
447 assert_equals_bool('(s)', ('',))
448 assert_equals_bool('(o)', ('/',))
449 assert_equals_bool('(g)', ('',))
450 assert_equals_bool('(())', ((),))
453 assert_equals_bool('a{si}', {})
454 assert_equals_bool('a{si}', {'': 0})
456 # complex types, always True
457 assert_equals_bool('(as)', ([],))
458 assert_equals_bool('a{s(i)}', {'': (0,)})
460 # variant types, recursive unpacking
461 assert_equals_bool('v', GLib.Variant('i', 0))
462 assert_equals_bool('v', GLib.Variant('i', 1))
465 class TestPango(unittest.TestCase):
467 def test_default_font_description(self):
468 desc = Pango.FontDescription()
469 self.assertEqual(desc.get_variant(), Pango.Variant.NORMAL)
471 def test_font_description(self):
472 desc = Pango.FontDescription('monospace')
473 self.assertEqual(desc.get_family(), 'monospace')
474 self.assertEqual(desc.get_variant(), Pango.Variant.NORMAL)
476 def test_layout(self):
477 self.assertRaises(TypeError, Pango.Layout)
478 context = Pango.Context()
479 layout = Pango.Layout(context)
480 self.assertEqual(layout.get_context(), context)
482 layout.set_markup("Foobar")
483 self.assertEqual(layout.get_text(), "Foobar")
486 class TestGdk(unittest.TestCase):
488 def test_constructor(self):
489 attribute = Gdk.WindowAttr()
490 attribute.window_type = Gdk.WindowType.CHILD
491 attributes_mask = Gdk.WindowAttributesType.X | \
492 Gdk.WindowAttributesType.Y
493 window = Gdk.Window(None, attribute, attributes_mask)
494 self.assertEqual(window.get_window_type(), Gdk.WindowType.CHILD)
496 def test_color(self):
497 color = Gdk.Color(100, 200, 300)
498 self.assertEqual(color.red, 100)
499 self.assertEqual(color.green, 200)
500 self.assertEqual(color.blue, 300)
501 self.assertEqual(color, Gdk.Color(100, 200, 300))
502 self.assertNotEquals(color, Gdk.Color(1, 2, 3))
505 self.assertEqual(Gdk.RGBA, overrides.Gdk.RGBA)
506 rgba = Gdk.RGBA(0.1, 0.2, 0.3, 0.4)
507 self.assertEqual(rgba, Gdk.RGBA(0.1, 0.2, 0.3, 0.4))
508 self.assertNotEquals(rgba, Gdk.RGBA(0.0, 0.2, 0.3, 0.4))
509 self.assertEqual(rgba.red, 0.1)
510 self.assertEqual(rgba.green, 0.2)
511 self.assertEqual(rgba.blue, 0.3)
512 self.assertEqual(rgba.alpha, 0.4)
514 self.assertEqual(rgba.green, 0.9)
516 def test_event(self):
517 event = Gdk.Event.new(Gdk.EventType.CONFIGURE)
518 self.assertEqual(event.type, Gdk.EventType.CONFIGURE)
519 self.assertEqual(event.send_event, 0)
521 event = Gdk.Event.new(Gdk.EventType.DRAG_MOTION)
522 event.x_root, event.y_root = 0, 5
523 self.assertEqual(event.x_root, 0)
524 self.assertEqual(event.y_root, 5)
527 event.type = Gdk.EventType.SCROLL
528 self.assertRaises(AttributeError, lambda: getattr(event, 'foo_bar'))
530 def test_event_structures(self):
531 def button_press_cb(button, event):
532 self.assertTrue(isinstance(event, Gdk.EventButton))
533 self.assertTrue(event.type == Gdk.EventType.BUTTON_PRESS)
534 self.assertEqual(event.send_event, 0)
535 self.assertEqual(event.get_state(), Gdk.ModifierType.CONTROL_MASK)
536 self.assertEqual(event.get_root_coords(), (2, 5))
539 self.assertEqual(event.get_time(), 12345)
543 b.connect('button-press-event', button_press_cb)
546 Gdk.test_simulate_button(b.get_window(),
549 Gdk.ModifierType.CONTROL_MASK,
550 Gdk.EventType.BUTTON_PRESS)
552 def test_cursor(self):
553 self.assertEqual(Gdk.Cursor, overrides.Gdk.Cursor)
554 c = Gdk.Cursor(Gdk.CursorType.WATCH)
555 self.assertNotEqual(c, None)
556 c = Gdk.Cursor(cursor_type=Gdk.CursorType.WATCH)
557 self.assertNotEqual(c, None)
559 display_manager = Gdk.DisplayManager.get()
560 display = display_manager.get_default_display()
562 test_pixbuf = GdkPixbuf.Pixbuf.new(GdkPixbuf.Colorspace.RGB,
568 c = Gdk.Cursor(display,
572 self.assertNotEqual(c, None)
573 self.assertRaises(ValueError, Gdk.Cursor, 1, 2, 3)
576 class TestGtk(unittest.TestCase):
578 def test_container(self):
580 self.assertTrue(isinstance(box, Gtk.Box))
581 self.assertTrue(isinstance(box, Gtk.Container))
582 self.assertTrue(isinstance(box, Gtk.Widget))
588 self.assertTrue(label in box)
589 self.assertTrue(label2 in box)
590 self.assertEqual(len(box), 2)
593 self.assertEqual(l, [label, label2])
595 def test_actions(self):
596 self.assertEqual(Gtk.Action, overrides.Gtk.Action)
597 self.assertRaises(TypeError, Gtk.Action)
598 action = Gtk.Action("test", "Test", "Test Action", Gtk.STOCK_COPY)
599 self.assertEqual(action.get_name(), "test")
600 self.assertEqual(action.get_label(), "Test")
601 self.assertEqual(action.get_tooltip(), "Test Action")
602 self.assertEqual(action.get_stock_id(), Gtk.STOCK_COPY)
604 self.assertEqual(Gtk.RadioAction, overrides.Gtk.RadioAction)
605 self.assertRaises(TypeError, Gtk.RadioAction)
606 action = Gtk.RadioAction("test", "Test", "Test Action", Gtk.STOCK_COPY, 1)
607 self.assertEqual(action.get_name(), "test")
608 self.assertEqual(action.get_label(), "Test")
609 self.assertEqual(action.get_tooltip(), "Test Action")
610 self.assertEqual(action.get_stock_id(), Gtk.STOCK_COPY)
611 self.assertEqual(action.get_current_value(), 1)
613 def test_actiongroup(self):
614 self.assertEqual(Gtk.ActionGroup, overrides.Gtk.ActionGroup)
615 self.assertRaises(TypeError, Gtk.ActionGroup)
617 action_group = Gtk.ActionGroup(name='TestActionGroup')
618 callback_data = "callback data"
620 def test_action_callback_data(action, user_data):
621 self.assertEqual(user_data, callback_data)
623 def test_radio_action_callback_data(action, current, user_data):
624 self.assertEqual(user_data, callback_data)
626 action_group.add_actions([
627 ('test-action1', None, 'Test Action 1',
628 None, None, test_action_callback_data),
629 ('test-action2', Gtk.STOCK_COPY, 'Test Action 2',
630 None, None, test_action_callback_data)], callback_data)
631 action_group.add_toggle_actions([
632 ('test-toggle-action1', None, 'Test Toggle Action 1',
633 None, None, test_action_callback_data, False),
634 ('test-toggle-action2', Gtk.STOCK_COPY, 'Test Toggle Action 2',
635 None, None, test_action_callback_data, True)], callback_data)
636 action_group.add_radio_actions([
637 ('test-radio-action1', None, 'Test Radio Action 1'),
638 ('test-radio-action2', Gtk.STOCK_COPY, 'Test Radio Action 2')], 1,
639 test_radio_action_callback_data,
642 expected_results = [('test-action1', Gtk.Action),
643 ('test-action2', Gtk.Action),
644 ('test-toggle-action1', Gtk.ToggleAction),
645 ('test-toggle-action2', Gtk.ToggleAction),
646 ('test-radio-action1', Gtk.RadioAction),
647 ('test-radio-action2', Gtk.RadioAction)]
649 for action in action_group.list_actions():
650 a = (action.get_name(), type(action))
651 self.assertTrue(a in expected_results)
652 expected_results.remove(a)
655 def test_uimanager(self):
656 self.assertEqual(Gtk.UIManager, overrides.Gtk.UIManager)
658 ui.add_ui_from_string(
661 <menubar name="menubar1"></menubar>
665 menubar = ui.get_widget("/menubar1")
666 self.assertEqual(type(menubar), Gtk.MenuBar)
668 ag = Gtk.ActionGroup(name="ag1")
669 ui.insert_action_group(ag)
670 ag2 = Gtk.ActionGroup(name="ag2")
671 ui.insert_action_group(ag2)
672 groups = ui.get_action_groups()
673 self.assertEqual(ag, groups[-2])
674 self.assertEqual(ag2, groups[-1])
676 def test_builder(self):
677 self.assertEqual(Gtk.Builder, overrides.Gtk.Builder)
679 class SignalTest(GObject.GObject):
680 __gtype_name__ = "GIOverrideSignalTest"
682 "test-signal": (GObject.SignalFlags.RUN_FIRST,
690 self.after_sentinel = 0
692 def on_signal_1(self, *args):
694 self.after_sentinel += 1
696 def on_signal_3(self, *args):
699 def on_signal_after(self, *args):
700 if self.after_sentinel == 1:
701 self.after_sentinel += 1
703 signal_checker = SignalCheck()
704 builder = Gtk.Builder()
706 # add object1 to the builder
707 builder.add_from_string(
710 <object class="GIOverrideSignalTest" id="object1">
711 <signal name="test-signal" after="yes" handler="on_signal_after" />
712 <signal name="test-signal" handler="on_signal_1" />
717 # only add object3 to the builder
718 builder.add_objects_from_string(
721 <object class="GIOverrideSignalTest" id="object2">
722 <signal name="test-signal" handler="on_signal_2" />
724 <object class="GIOverrideSignalTest" id="object3">
725 <signal name="test-signal" handler="on_signal_3" />
727 <object class="GIOverrideSignalTest" id="object4">
728 <signal name="test-signal" handler="on_signal_4" />
736 builder.connect_signals(signal_checker)
738 # call their notify signals and check sentinel
739 objects = builder.get_objects()
740 self.assertEqual(len(objects), 2)
742 obj.emit('test-signal')
744 self.assertEqual(signal_checker.sentinel, 4)
745 self.assertEqual(signal_checker.after_sentinel, 2)
747 def test_dialogs(self):
748 self.assertEqual(Gtk.Dialog, overrides.Gtk.Dialog)
749 self.assertEqual(Gtk.AboutDialog, overrides.Gtk.AboutDialog)
750 self.assertEqual(Gtk.MessageDialog, overrides.Gtk.MessageDialog)
751 self.assertEqual(Gtk.ColorSelectionDialog, overrides.Gtk.ColorSelectionDialog)
752 self.assertEqual(Gtk.FileChooserDialog, overrides.Gtk.FileChooserDialog)
753 self.assertEqual(Gtk.FontSelectionDialog, overrides.Gtk.FontSelectionDialog)
754 self.assertEqual(Gtk.RecentChooserDialog, overrides.Gtk.RecentChooserDialog)
757 dialog = Gtk.Dialog(title='Foo',
758 flags=Gtk.DialogFlags.MODAL,
759 buttons=('test-button1', 1))
760 self.assertTrue(isinstance(dialog, Gtk.Dialog))
761 self.assertTrue(isinstance(dialog, Gtk.Window))
763 dialog.add_buttons('test-button2', 2, Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE)
765 self.assertEqual('Foo', dialog.get_title())
766 self.assertTrue(dialog.get_modal())
767 button = dialog.get_widget_for_response(1)
768 self.assertEqual('test-button1', button.get_label())
769 button = dialog.get_widget_for_response(2)
770 self.assertEqual('test-button2', button.get_label())
771 button = dialog.get_widget_for_response(Gtk.ResponseType.CLOSE)
772 self.assertEqual(Gtk.STOCK_CLOSE, button.get_label())
775 dialog = Gtk.AboutDialog()
776 self.assertTrue(isinstance(dialog, Gtk.Dialog))
777 self.assertTrue(isinstance(dialog, Gtk.Window))
780 dialog = Gtk.MessageDialog(title='message dialog test',
781 flags=Gtk.DialogFlags.MODAL,
782 buttons=Gtk.ButtonsType.OK,
783 message_format='dude!')
784 self.assertTrue(isinstance(dialog, Gtk.Dialog))
785 self.assertTrue(isinstance(dialog, Gtk.Window))
787 self.assertEqual('message dialog test', dialog.get_title())
788 self.assertTrue(dialog.get_modal())
789 text = dialog.get_property('text')
790 self.assertEqual('dude!', text)
792 dialog.format_secondary_text('2nd text')
793 self.assertEqual(dialog.get_property('secondary-text'), '2nd text')
794 self.assertFalse(dialog.get_property('secondary-use-markup'))
796 dialog.format_secondary_markup('2nd markup')
797 self.assertEqual(dialog.get_property('secondary-text'), '2nd markup')
798 self.assertTrue(dialog.get_property('secondary-use-markup'))
800 # Gtk.ColorSelectionDialog
801 dialog = Gtk.ColorSelectionDialog("color selection dialog test")
802 self.assertTrue(isinstance(dialog, Gtk.Dialog))
803 self.assertTrue(isinstance(dialog, Gtk.Window))
804 self.assertEqual('color selection dialog test', dialog.get_title())
806 # Gtk.FileChooserDialog
807 dialog = Gtk.FileChooserDialog(title='file chooser dialog test',
808 buttons=('test-button1', 1),
809 action=Gtk.FileChooserAction.SAVE)
810 self.assertTrue(isinstance(dialog, Gtk.Dialog))
811 self.assertTrue(isinstance(dialog, Gtk.Window))
813 dialog.add_buttons('test-button2', 2, Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE)
814 self.assertEqual('file chooser dialog test', dialog.get_title())
815 button = dialog.get_widget_for_response(1)
816 self.assertEqual('test-button1', button.get_label())
817 button = dialog.get_widget_for_response(2)
818 self.assertEqual('test-button2', button.get_label())
819 button = dialog.get_widget_for_response(Gtk.ResponseType.CLOSE)
820 self.assertEqual(Gtk.STOCK_CLOSE, button.get_label())
821 action = dialog.get_property('action')
822 self.assertEqual(Gtk.FileChooserAction.SAVE, action)
824 # Gtk.FontSelectionDialog
825 dialog = Gtk.ColorSelectionDialog("font selection dialog test")
826 self.assertTrue(isinstance(dialog, Gtk.Dialog))
827 self.assertTrue(isinstance(dialog, Gtk.Window))
828 self.assertEqual('font selection dialog test', dialog.get_title())
830 # Gtk.RecentChooserDialog
831 test_manager = Gtk.RecentManager()
832 dialog = Gtk.RecentChooserDialog(title='recent chooser dialog test',
833 buttons=('test-button1', 1),
834 manager=test_manager)
835 self.assertTrue(isinstance(dialog, Gtk.Dialog))
836 self.assertTrue(isinstance(dialog, Gtk.Window))
838 dialog.add_buttons('test-button2', 2, Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE)
839 self.assertEqual('recent chooser dialog test', dialog.get_title())
840 button = dialog.get_widget_for_response(1)
841 self.assertEqual('test-button1', button.get_label())
842 button = dialog.get_widget_for_response(2)
843 self.assertEqual('test-button2', button.get_label())
844 button = dialog.get_widget_for_response(Gtk.ResponseType.CLOSE)
845 self.assertEqual(Gtk.STOCK_CLOSE, button.get_label())
847 class TestClass(GObject.GObject):
848 __gtype_name__ = "GIOverrideTreeAPITest"
850 def __init__(self, tester, int_value, string_value):
851 super(TestGtk.TestClass, self).__init__()
853 self.int_value = int_value
854 self.string_value = string_value
856 def check(self, int_value, string_value):
857 self.tester.assertEqual(int_value, self.int_value)
858 self.tester.assertEqual(string_value, self.string_value)
860 def test_tree_store(self):
861 self.assertEqual(Gtk.TreeStore, overrides.Gtk.TreeStore)
862 self.assertEqual(Gtk.ListStore, overrides.Gtk.ListStore)
863 self.assertEqual(Gtk.TreeModel, overrides.Gtk.TreeModel)
864 self.assertEqual(Gtk.TreeViewColumn, overrides.Gtk.TreeViewColumn)
866 class TestPyObject(object):
869 test_pyobj = TestPyObject()
870 test_pydict = {1: 1, "2": 2, "3": "3"}
871 test_pylist = [1, "2", "3"]
872 tree_store = Gtk.TreeStore(int,
875 GObject.TYPE_PYOBJECT,
890 label = 'this is child #%d' % i
891 testobj = TestGtk.TestClass(self, i, label)
892 parent = tree_store.append(parent, (i,
909 parent = tree_store.append(parent)
911 label = 'this is child #%d' % i
912 testobj = TestGtk.TestClass(self, i, label)
913 tree_store.set(parent, 0, i,
923 10, GObject.G_MAXULONG,
924 11, GObject.G_MININT64,
925 12, 0xffffffffffffffff,
929 parent = tree_store.append(parent)
931 label = 'this is child #%d' % i
932 testobj = TestGtk.TestClass(self, i, label)
933 tree_store.set(parent, {0: i,
943 10: GObject.G_MAXULONG,
944 11: GObject.G_MININT64,
945 12: 0xffffffffffffffff,
949 parent = tree_store.append(parent)
951 label = 'this is child #%d' % i
952 testobj = TestGtk.TestClass(self, i, label)
953 tree_store.set(parent, (0, 2, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14),
970 # len gets the number of children in the root node
971 # since we kept appending to the previous node
972 # there should only be one child of the root
973 self.assertEqual(len(tree_store), 1)
975 # walk the tree to see if the values were stored correctly
979 treeiter = tree_store.iter_children(parent)
981 i = tree_store.get_value(treeiter, 0)
982 s = tree_store.get_value(treeiter, 1)
983 obj = tree_store.get_value(treeiter, 2)
985 obj2 = tree_store.get_value(treeiter, 3)
986 self.assertEqual(obj, obj2)
988 pyobj = tree_store.get_value(treeiter, 4)
989 self.assertEqual(pyobj, test_pyobj)
990 pydict = tree_store.get_value(treeiter, 5)
991 self.assertEqual(pydict, test_pydict)
992 pylist = tree_store.get_value(treeiter, 6)
993 self.assertEqual(pylist, test_pylist)
995 bool_1 = tree_store.get_value(treeiter, 7)
996 bool_2 = tree_store.get_value(treeiter, 8)
997 self.assertEqual(bool_1, bool_2)
998 self.assertTrue(isinstance(bool_1, bool))
999 self.assertTrue(isinstance(bool_2, bool))
1001 uint_ = tree_store.get_value(treeiter, 9)
1002 self.assertEqual(uint_, i)
1003 ulong_ = tree_store.get_value(treeiter, 10)
1004 self.assertEqual(ulong_, GObject.G_MAXULONG)
1005 int64_ = tree_store.get_value(treeiter, 11)
1006 self.assertEqual(int64_, GObject.G_MININT64)
1007 uint64_ = tree_store.get_value(treeiter, 12)
1008 self.assertEqual(uint64_, 0xffffffffffffffff)
1009 uchar_ = tree_store.get_value(treeiter, 13)
1010 self.assertEqual(ord(uchar_), 254)
1011 char_ = tree_store.get_value(treeiter, 14)
1012 self.assertEqual(char_, 'a')
1015 treeiter = tree_store.iter_children(parent)
1017 self.assertEqual(i, 99)
1019 def test_tree_store_signals(self):
1020 tree_store = Gtk.TreeStore(int, bool)
1022 def on_row_inserted(tree_store, tree_path, tree_iter, signal_list):
1023 signal_list.append('row-inserted')
1025 def on_row_changed(tree_store, tree_path, tree_iter, signal_list):
1026 signal_list.append('row-changed')
1029 tree_store.connect('row-inserted', on_row_inserted, signals)
1030 tree_store.connect('row-changed', on_row_changed, signals)
1032 # adding rows with and without data should only call one signal
1033 tree_store.append(None, (0, False))
1034 self.assertEqual(signals, ['row-inserted'])
1037 tree_store.append(None)
1038 self.assertEqual(signals, ['row-inserted'])
1041 tree_store.prepend(None, (0, False))
1042 self.assertEqual(signals, ['row-inserted'])
1045 tree_store.prepend(None)
1046 self.assertEqual(signals, ['row-inserted'])
1049 tree_store.insert(None, 1, (0, False))
1050 self.assertEqual(signals, ['row-inserted'])
1053 tree_store.insert(None, 1)
1054 self.assertEqual(signals, ['row-inserted'])
1056 def test_list_store(self):
1057 class TestPyObject(object):
1060 test_pyobj = TestPyObject()
1061 test_pydict = {1: 1, "2": 2, "3": "3"}
1062 test_pylist = [1, "2", "3"]
1064 list_store = Gtk.ListStore(int, str, 'GIOverrideTreeAPITest', object, object, object, bool, bool)
1065 for i in range(1, 93):
1066 label = 'this is row #%d' % i
1067 testobj = TestGtk.TestClass(self, i, label)
1068 list_store.append((i,
1078 label = _unicode('this is row #93')
1079 treeiter = list_store.append()
1080 list_store.set_value(treeiter, 0, i)
1081 list_store.set_value(treeiter, 1, label)
1082 list_store.set_value(treeiter, 2, TestGtk.TestClass(self, i, label))
1083 list_store.set_value(treeiter, 3, test_pyobj)
1084 list_store.set_value(treeiter, 4, test_pydict)
1085 list_store.set_value(treeiter, 5, test_pylist)
1086 list_store.set_value(treeiter, 6, 1)
1087 list_store.set_value(treeiter, 7, True)
1090 label = 'this is row #0'
1091 list_store.prepend((0,
1093 TestGtk.TestClass(self, 0, label),
1100 # test automatic unicode->str conversion
1102 label = _unicode('this is row #94')
1103 treeiter = list_store.append((i,
1105 TestGtk.TestClass(self, i, label),
1112 # add sorted items out of order to test insert* apis
1113 # also test sending in None to not set a column
1115 label = 'this is row #97'
1116 treeiter = list_store.append((None,
1125 list_store.set_value(treeiter, 0, i)
1126 list_store.set_value(treeiter, 1, label)
1127 list_store.set_value(treeiter, 2, TestGtk.TestClass(self, i, label))
1128 list_store.set_value(treeiter, 4, test_pydict)
1129 list_store.set_value(treeiter, 7, True)
1131 # this should append
1133 label = 'this is row #99'
1134 list_store.insert(9999, (i,
1136 TestGtk.TestClass(self, i, label),
1144 label = 'this is row #96'
1145 list_store.insert_before(treeiter, (i,
1147 TestGtk.TestClass(self, i, label),
1155 label = 'this is row #98'
1156 list_store.insert_after(treeiter, (i,
1158 TestGtk.TestClass(self, i, label),
1166 label = 'this is row #95'
1167 list_store.insert(95, (i,
1169 TestGtk.TestClass(self, i, label),
1177 label = 'this is row #100'
1178 treeiter = list_store.append()
1179 list_store.set(treeiter, 1, label,
1181 2, TestGtk.TestClass(self, i, label),
1188 label = 'this is row #101'
1189 treeiter = list_store.append()
1190 list_store.set(treeiter, {1: label,
1192 2: TestGtk.TestClass(self, i, label),
1199 label = 'this is row #102'
1200 treeiter = list_store.append()
1201 list_store.set(treeiter, (1, 0, 2, 3, 4, 5, 6, 7),
1204 TestGtk.TestClass(self, i, label),
1211 self.assertEqual(len(list_store), 103)
1213 # walk the list to see if the values were stored correctly
1215 treeiter = list_store.get_iter_first()
1219 i = list_store.get_value(treeiter, 0)
1220 self.assertEqual(i, counter)
1221 s = list_store.get_value(treeiter, 1)
1222 obj = list_store.get_value(treeiter, 2)
1225 pyobj = list_store.get_value(treeiter, 3)
1226 self.assertEqual(pyobj, test_pyobj)
1227 pydict = list_store.get_value(treeiter, 4)
1228 self.assertEqual(pydict, test_pydict)
1229 pylist = list_store.get_value(treeiter, 5)
1230 self.assertEqual(pylist, test_pylist)
1232 bool_1 = list_store.get_value(treeiter, 6)
1233 bool_2 = list_store.get_value(treeiter, 7)
1234 self.assertEqual(bool_1, bool_2)
1235 self.assertTrue(isinstance(bool_1, bool))
1236 self.assertTrue(isinstance(bool_2, bool))
1238 treeiter = list_store.iter_next(treeiter)
1242 self.assertEqual(i, 102)
1244 def test_list_store_sort(self):
1245 def comp1(model, row1, row2, user_data):
1249 # make "m" smaller than anything else
1250 if v1.startswith('m') and not v2.startswith('m'):
1252 if v2.startswith('m') and not v1.startswith('m'):
1256 list_store = Gtk.ListStore(int, str)
1257 list_store.set_sort_func(2, comp1, None)
1258 list_store.append((1, 'apples'))
1259 list_store.append((3, 'oranges'))
1260 list_store.append((2, 'mango'))
1262 # not sorted yet, should be original order
1263 self.assertEqual([list(i) for i in list_store],
1264 [[1, 'apples'], [3, 'oranges'], [2, 'mango']])
1266 # sort with our custom function
1267 list_store.set_sort_column_id(2, Gtk.SortType.ASCENDING)
1268 self.assertEqual([list(i) for i in list_store],
1269 [[2, 'mango'], [1, 'apples'], [3, 'oranges']])
1271 list_store.set_sort_column_id(2, Gtk.SortType.DESCENDING)
1272 self.assertEqual([list(i) for i in list_store],
1273 [[3, 'oranges'], [1, 'apples'], [2, 'mango']])
1275 def test_list_store_signals(self):
1276 list_store = Gtk.ListStore(int, bool)
1278 def on_row_inserted(list_store, tree_path, tree_iter, signal_list):
1279 signal_list.append('row-inserted')
1281 def on_row_changed(list_store, tree_path, tree_iter, signal_list):
1282 signal_list.append('row-changed')
1285 list_store.connect('row-inserted', on_row_inserted, signals)
1286 list_store.connect('row-changed', on_row_changed, signals)
1288 # adding rows with and without data should only call one signal
1289 list_store.append((0, False))
1290 self.assertEqual(signals, ['row-inserted'])
1294 self.assertEqual(signals, ['row-inserted'])
1297 list_store.prepend((0, False))
1298 self.assertEqual(signals, ['row-inserted'])
1301 list_store.prepend()
1302 self.assertEqual(signals, ['row-inserted'])
1305 list_store.insert(1, (0, False))
1306 self.assertEqual(signals, ['row-inserted'])
1309 list_store.insert(1)
1310 self.assertEqual(signals, ['row-inserted'])
1312 def test_tree_path(self):
1314 p2 = Gtk.TreePath.new_first()
1315 self.assertEqual(p1, p2)
1316 self.assertEqual(str(p1), '0')
1317 p1 = Gtk.TreePath(2)
1318 p2 = Gtk.TreePath.new_from_string('2')
1319 self.assertEqual(p1, p2)
1320 self.assertEqual(str(p1), '2')
1321 p1 = Gtk.TreePath('1:2:3')
1322 p2 = Gtk.TreePath.new_from_string('1:2:3')
1323 self.assertEqual(p1, p2)
1324 self.assertEqual(str(p1), '1:2:3')
1325 p1 = Gtk.TreePath((1, 2, 3))
1326 p2 = Gtk.TreePath.new_from_string('1:2:3')
1327 self.assertEqual(p1, p2)
1328 self.assertEqual(str(p1), '1:2:3')
1329 self.assertTrue(p1 != None)
1330 self.assertFalse(p1 == None)
1331 self.assertTrue(p1 > None)
1332 self.assertTrue(p1 >= None)
1333 self.assertFalse(p1 < None)
1334 self.assertFalse(p1 <= None)
1336 self.assertEqual(tuple(p1), (1, 2, 3))
1338 def test_tree_model(self):
1339 tree_store = Gtk.TreeStore(int, str)
1341 self.assertTrue(tree_store)
1342 self.assertEqual(len(tree_store), 0)
1343 self.assertEqual(tree_store.get_iter_first(), None)
1345 def get_by_index(row, col=None):
1347 return tree_store[row][col]
1349 return tree_store[row]
1351 self.assertRaises(TypeError, get_by_index, None)
1352 self.assertRaises(TypeError, get_by_index, "")
1353 self.assertRaises(TypeError, get_by_index, ())
1355 self.assertRaises(IndexError, get_by_index, "0")
1356 self.assertRaises(IndexError, get_by_index, 0)
1357 self.assertRaises(IndexError, get_by_index, (0,))
1359 self.assertRaises(ValueError, tree_store.get_iter, "0")
1360 self.assertRaises(ValueError, tree_store.get_iter, 0)
1361 self.assertRaises(ValueError, tree_store.get_iter, (0,))
1363 self.assertRaises(ValueError, tree_store.get_iter_from_string, "0")
1365 for row in tree_store:
1366 self.fail("Should not be reached")
1368 class DerivedIntType(int):
1371 class DerivedStrType(str):
1374 for i in range(100):
1375 label = 'this is row #%d' % i
1376 parent = tree_store.append(None, (DerivedIntType(i), DerivedStrType(label),))
1377 self.assertNotEquals(parent, None)
1379 label = 'this is child #%d of node #%d' % (j, i)
1380 child = tree_store.append(parent, (j, label,))
1381 self.assertNotEqual(child, None)
1383 self.assertTrue(tree_store)
1384 self.assertEqual(len(tree_store), 100)
1386 self.assertEqual(tree_store.iter_previous(tree_store.get_iter(0)), None)
1388 for i, row in enumerate(tree_store):
1389 self.assertEqual(row.model, tree_store)
1390 self.assertEqual(row.parent, None)
1392 self.assertEqual(tree_store[i].path, row.path)
1393 self.assertEqual(tree_store[str(i)].path, row.path)
1394 self.assertEqual(tree_store[(i,)].path, row.path)
1396 self.assertEqual(tree_store[i][0], i)
1397 self.assertEqual(tree_store[i][1], "this is row #%d" % i)
1399 aiter = tree_store.get_iter(i)
1400 self.assertEqual(tree_store.get_path(aiter), row.path)
1402 aiter = tree_store.get_iter(str(i))
1403 self.assertEqual(tree_store.get_path(aiter), row.path)
1405 aiter = tree_store.get_iter((i,))
1406 self.assertEqual(tree_store.get_path(aiter), row.path)
1408 self.assertEqual(tree_store.iter_parent(aiter), row.parent)
1410 next = tree_store.iter_next(aiter)
1411 if i < len(tree_store) - 1:
1412 self.assertEqual(tree_store.get_path(next), row.next.path)
1413 self.assertEqual(tree_store.get_path(tree_store.iter_previous(next)),
1414 tree_store.get_path(aiter))
1416 self.assertEqual(next, None)
1418 self.assertEqual(tree_store.iter_n_children(row.iter), 20)
1420 child = tree_store.iter_children(row.iter)
1421 for j, childrow in enumerate(row.iterchildren()):
1422 child_path = tree_store.get_path(child)
1423 self.assertEqual(childrow.path, child_path)
1424 self.assertEqual(childrow.parent.path, row.path)
1425 self.assertEqual(childrow.path, tree_store[child].path)
1426 self.assertEqual(childrow.path, tree_store[child_path].path)
1428 self.assertEqual(childrow[0], tree_store[child][0])
1429 self.assertEqual(childrow[0], j)
1430 self.assertEqual(childrow[1], tree_store[child][1])
1431 self.assertEqual(childrow[1], 'this is child #%d of node #%d' % (j, i))
1433 self.assertRaises(IndexError, get_by_index, child, 2)
1435 tree_store[child][1] = 'this was child #%d of node #%d' % (j, i)
1436 self.assertEqual(childrow[1], 'this was child #%d of node #%d' % (j, i))
1438 nth_child = tree_store.iter_nth_child(row.iter, j)
1439 self.assertEqual(childrow.path, tree_store.get_path(nth_child))
1441 childrow2 = tree_store["%d:%d" % (i, j)]
1442 self.assertEqual(childrow.path, childrow2.path)
1444 childrow2 = tree_store[(i, j,)]
1445 self.assertEqual(childrow.path, childrow2.path)
1447 child = tree_store.iter_next(child)
1449 self.assertEqual(childrow.next.path, tree_store.get_path(child))
1451 self.assertEqual(child, childrow.next)
1452 self.assertEqual(child, None)
1454 self.assertEqual(j, 19)
1456 self.assertEqual(i, 99)
1459 for i in range(-1, -100, -1):
1461 self.assertEqual(tree_store[i][0], i_real)
1464 for j in range(-1, -20, -1):
1466 path = (i_real, j_real,)
1468 self.assertEqual(tree_store[path][-2], j_real)
1470 label = 'this was child #%d of node #%d' % (j_real, i_real)
1471 self.assertEqual(tree_store[path][-1], label)
1473 new_label = 'this still is child #%d of node #%d' % (j_real, i_real)
1474 tree_store[path][-1] = new_label
1475 self.assertEqual(tree_store[path][-1], new_label)
1477 self.assertRaises(IndexError, get_by_index, path, -3)
1479 self.assertRaises(IndexError, get_by_index, -101)
1481 last_row = tree_store[99]
1482 self.assertNotEqual(last_row, None)
1484 for i, childrow in enumerate(last_row.iterchildren()):
1486 self.assertTrue(tree_store.remove(childrow.iter))
1488 self.assertFalse(tree_store.remove(childrow.iter))
1490 self.assertEqual(i, 19)
1492 self.assertEqual(tree_store.iter_n_children(last_row.iter), 0)
1493 for childrow in last_row.iterchildren():
1494 self.fail("Should not be reached")
1496 aiter = tree_store.get_iter(10)
1497 self.assertRaises(TypeError, tree_store.get, aiter, 1, 'a')
1498 self.assertRaises(ValueError, tree_store.get, aiter, 1, -1)
1499 self.assertRaises(ValueError, tree_store.get, aiter, 1, 100)
1500 self.assertEqual(tree_store.get(aiter, 0, 1), (10, 'this is row #10'))
1502 def test_tree_model_edit(self):
1503 model = Gtk.ListStore(int, str, float)
1504 model.append([1, "one", -0.1])
1505 model.append([2, "two", -0.2])
1510 self.assertRaises(TypeError, set_row, 3)
1511 self.assertRaises(TypeError, set_row, "three")
1512 self.assertRaises(ValueError, set_row, [])
1513 self.assertRaises(ValueError, set_row, [3, "three"])
1515 model[0] = (3, "three", -0.3)
1517 def test_tree_row_slice(self):
1518 model = Gtk.ListStore(int, str, float)
1519 model.append([1, "one", -0.1])
1521 self.assertEqual([1, "one", -0.1], model[0][:])
1522 self.assertEqual([1, "one"], model[0][:2])
1523 self.assertEqual(["one", -0.1], model[0][1:])
1524 self.assertEqual(["one"], model[0][1:-1])
1525 self.assertEqual([1], model[0][:-2])
1526 self.assertEqual([], model[0][5:])
1527 self.assertEqual([1, -0.1], model[0][0:3:2])
1529 model[0][:] = (2, "two", -0.2)
1530 self.assertEqual([2, "two", -0.2], model[0][:])
1532 model[0][:2] = (3, "three")
1533 self.assertEqual([3, "three", -0.2], model[0][:])
1535 model[0][1:] = ("four", -0.4)
1536 self.assertEqual([3, "four", -0.4], model[0][:])
1538 model[0][1:-1] = ("five",)
1539 self.assertEqual([3, "five", -0.4], model[0][:])
1541 model[0][0:3:2] = (6, -0.6)
1542 self.assertEqual([6, "five", -0.6], model[0][:])
1545 model[0][5:] = ("doesn't", "matter",)
1547 self.assertRaises(ValueError, set_row1)
1550 model[0][:1] = (0, "zero", 0)
1552 self.assertRaises(ValueError, set_row2)
1555 model[0][:2] = ("0", 0)
1557 self.assertRaises(ValueError, set_row3)
1559 def test_tree_view(self):
1560 store = Gtk.ListStore(int, str)
1561 store.append((0, "foo"))
1562 store.append((1, "bar"))
1563 view = Gtk.TreeView()
1564 # FIXME: We can't easily call get_cursor() to make sure this works as
1565 # expected as we need to realize and focus the column; the following
1566 # will raise a Gtk-CRITICAL which we ignore for now
1567 old_mask = GLib.log_set_always_fatal(
1568 GLib.LogLevelFlags.LEVEL_WARNING | GLib.LogLevelFlags.LEVEL_ERROR)
1569 view.set_cursor(store[1].path)
1570 view.set_cursor(str(store[1].path))
1572 view.get_cell_area(store[1].path)
1573 view.get_cell_area(str(store[1].path))
1575 GLib.log_set_always_fatal(old_mask)
1577 def test_tree_view_column(self):
1578 cell = Gtk.CellRendererText()
1579 Gtk.TreeViewColumn(title='This is just a test',
1584 def test_tree_selection(self):
1585 store = Gtk.ListStore(int, str)
1587 store.append((i, "foo"))
1588 view = Gtk.TreeView()
1589 view.set_model(store)
1590 firstpath = store.get_path(store.get_iter_first())
1591 sel = view.get_selection()
1593 sel.select_path(firstpath)
1594 (m, s) = sel.get_selected()
1595 self.assertEqual(m, store)
1596 self.assertEqual(store.get_path(s), firstpath)
1599 (m, s) = sel.get_selected()
1600 self.assertEqual(m, store)
1601 self.assertEqual(store.get_path(s), firstpath)
1603 sel.select_path("0:0")
1604 (m, s) = sel.get_selected()
1605 self.assertEqual(m, store)
1606 self.assertEqual(store.get_path(s), firstpath)
1608 sel.select_path((0, 0))
1609 (m, s) = sel.get_selected()
1610 self.assertEqual(m, store)
1611 self.assertEqual(store.get_path(s), firstpath)
1613 def test_text_buffer(self):
1614 self.assertEqual(Gtk.TextBuffer, overrides.Gtk.TextBuffer)
1615 buffer = Gtk.TextBuffer()
1616 tag = buffer.create_tag('title', font='Sans 18')
1618 self.assertEqual(tag.props.name, 'title')
1619 self.assertEqual(tag.props.font, 'Sans 18')
1621 (start, end) = buffer.get_bounds()
1623 mark = buffer.create_mark(None, start)
1624 self.assertFalse(mark.get_left_gravity())
1626 buffer.set_text('Hello Jane Hello Bob')
1627 (start, end) = buffer.get_bounds()
1628 text = buffer.get_text(start, end, False)
1629 self.assertEqual(text, 'Hello Jane Hello Bob')
1632 (start, end) = buffer.get_bounds()
1633 text = buffer.get_text(start, end, False)
1634 self.assertEqual(text, '')
1636 buffer.insert(end, 'HelloHello')
1637 buffer.insert(end, ' Bob')
1639 cursor_iter = end.copy()
1640 cursor_iter.backward_chars(9)
1641 buffer.place_cursor(cursor_iter)
1642 buffer.insert_at_cursor(' Jane ')
1644 (start, end) = buffer.get_bounds()
1645 text = buffer.get_text(start, end, False)
1646 self.assertEqual(text, 'Hello Jane Hello Bob')
1648 sel = buffer.get_selection_bounds()
1649 self.assertEqual(sel, ())
1650 buffer.select_range(start, end)
1651 sel = buffer.get_selection_bounds()
1652 self.assertTrue(sel[0].equal(start))
1653 self.assertTrue(sel[1].equal(end))
1656 buffer.insert_with_tags(buffer.get_start_iter(), 'HelloHello', tag)
1657 (start, end) = buffer.get_bounds()
1658 self.assertTrue(start.begins_tag(tag))
1659 self.assertTrue(start.has_tag(tag))
1662 buffer.insert_with_tags_by_name(buffer.get_start_iter(), 'HelloHello', 'title')
1663 (start, end) = buffer.get_bounds()
1664 self.assertTrue(start.begins_tag(tag))
1665 self.assertTrue(start.has_tag(tag))
1667 self.assertRaises(ValueError, buffer.insert_with_tags_by_name,
1668 buffer.get_start_iter(), 'HelloHello', 'unknowntag')
1670 def test_text_iter(self):
1671 self.assertEqual(Gtk.TextIter, overrides.Gtk.TextIter)
1672 buffer = Gtk.TextBuffer()
1673 buffer.set_text('Hello Jane Hello Bob')
1674 tag = buffer.create_tag('title', font='Sans 18')
1675 (start, end) = buffer.get_bounds()
1676 start.forward_chars(10)
1677 buffer.apply_tag(tag, start, end)
1678 self.assertTrue(start.begins_tag())
1679 self.assertTrue(end.ends_tag())
1680 self.assertTrue(start.toggles_tag())
1681 self.assertTrue(end.toggles_tag())
1682 start.backward_chars(1)
1683 self.assertFalse(start.begins_tag())
1684 self.assertFalse(start.ends_tag())
1685 self.assertFalse(start.toggles_tag())
1687 def test_buttons(self):
1688 self.assertEqual(Gtk.Button, overrides.Gtk.Button)
1691 button = Gtk.Button()
1692 self.assertTrue(isinstance(button, Gtk.Button))
1693 self.assertTrue(isinstance(button, Gtk.Container))
1694 self.assertTrue(isinstance(button, Gtk.Widget))
1695 button = Gtk.Button(stock=Gtk.STOCK_CLOSE)
1696 self.assertEqual(Gtk.STOCK_CLOSE, button.get_label())
1697 self.assertTrue(button.get_use_stock())
1698 self.assertTrue(button.get_use_underline())
1700 # test Gtk.Button use_stock
1701 button = Gtk.Button(label=Gtk.STOCK_CLOSE, use_stock=True, use_underline=True)
1702 self.assertEqual(Gtk.STOCK_CLOSE, button.get_label())
1703 self.assertTrue(button.get_use_stock())
1704 self.assertTrue(button.get_use_underline())
1706 # test Gtk.LinkButton
1707 self.assertRaises(TypeError, Gtk.LinkButton)
1708 button = Gtk.LinkButton('http://www.Gtk.org', 'Gtk')
1709 self.assertTrue(isinstance(button, Gtk.Button))
1710 self.assertTrue(isinstance(button, Gtk.Container))
1711 self.assertTrue(isinstance(button, Gtk.Widget))
1712 self.assertEqual('http://www.Gtk.org', button.get_uri())
1713 self.assertEqual('Gtk', button.get_label())
1715 def test_inheritance(self):
1716 for name in overrides.Gtk.__all__:
1717 over = getattr(overrides.Gtk, name)
1718 for element in dir(Gtk):
1720 klass = getattr(Gtk, element)
1721 info = klass.__info__
1722 except (NotImplementedError, AttributeError):
1725 # Get all parent classes and interfaces klass inherits from
1726 if isinstance(info, gi.types.ObjectInfo):
1727 classes = list(info.get_interfaces())
1728 parent = info.get_parent()
1729 while parent.get_name() != "Object":
1730 classes.append(parent)
1731 parent = parent.get_parent()
1732 classes = [kl for kl in classes if kl.get_namespace() == "Gtk"]
1737 if kl.get_name() == name:
1738 self.assertTrue(issubclass(klass, over,),
1739 "%r does not inherit from override %r" % (klass, over,))
1741 def test_editable(self):
1742 self.assertEqual(Gtk.Editable, overrides.Gtk.Editable)
1744 # need to use Gtk.Entry because Editable is an interface
1746 pos = entry.insert_text('HeWorld', 0)
1747 self.assertEqual(pos, 7)
1748 pos = entry.insert_text('llo ', 2)
1749 self.assertEqual(pos, 6)
1750 text = entry.get_chars(0, 11)
1751 self.assertEqual('Hello World', text)
1753 def test_label(self):
1754 label = Gtk.Label(label='Hello')
1755 self.assertTrue(isinstance(label, Gtk.Widget))
1756 self.assertEqual(label.get_text(), 'Hello')
1758 def adjustment_check(self, adjustment, value=0.0, lower=0.0, upper=0.0,
1759 step_increment=0.0, page_increment=0.0, page_size=0.0):
1760 self.assertEqual(adjustment.get_value(), value)
1761 self.assertEqual(adjustment.get_lower(), lower)
1762 self.assertEqual(adjustment.get_upper(), upper)
1763 self.assertEqual(adjustment.get_step_increment(), step_increment)
1764 self.assertEqual(adjustment.get_page_increment(), page_increment)
1765 self.assertEqual(adjustment.get_page_size(), page_size)
1767 def test_adjustment(self):
1768 adjustment = Gtk.Adjustment(1, 0, 6, 4, 5, 3)
1769 self.adjustment_check(adjustment, 1, 0, 6, 4, 5, 3)
1771 adjustment = Gtk.Adjustment(1, 0, 6, 4, 5)
1772 self.adjustment_check(adjustment, 1, 0, 6, 4, 5)
1774 adjustment = Gtk.Adjustment(1, 0, 6, 4)
1775 self.adjustment_check(adjustment, 1, 0, 6, 4)
1777 adjustment = Gtk.Adjustment(1, 0, 6)
1778 self.adjustment_check(adjustment, 1, 0, 6)
1780 adjustment = Gtk.Adjustment()
1781 self.adjustment_check(adjustment)
1783 adjustment = Gtk.Adjustment(value=1, lower=0, upper=6,
1784 step_increment=4, page_increment=5, page_size=3)
1785 self.adjustment_check(adjustment, 1, 0, 6, 4, 5, 3)
1787 def test_table(self):
1789 self.assertTrue(isinstance(table, Gtk.Table))
1790 self.assertTrue(isinstance(table, Gtk.Container))
1791 self.assertTrue(isinstance(table, Gtk.Widget))
1792 self.assertEqual(table.get_size(), (1, 1))
1793 self.assertEqual(table.get_homogeneous(), False)
1794 table = Gtk.Table(2, 3)
1795 self.assertEqual(table.get_size(), (2, 3))
1796 self.assertEqual(table.get_homogeneous(), False)
1797 table = Gtk.Table(2, 3, True)
1798 self.assertEqual(table.get_size(), (2, 3))
1799 self.assertEqual(table.get_homogeneous(), True)
1801 # Test PyGTK interface
1802 table = Gtk.Table(rows=3, columns=2)
1803 self.assertEqual(table.get_size(), (3, 2))
1804 # Test using the actual property names
1805 table = Gtk.Table(n_rows=2, n_columns=3, homogeneous=True)
1806 self.assertEqual(table.get_size(), (2, 3))
1807 self.assertEqual(table.get_homogeneous(), True)
1809 label = Gtk.Label(label='Hello')
1810 self.assertTrue(isinstance(label, Gtk.Widget))
1811 table.attach(label, 0, 1, 0, 1)
1812 self.assertEqual(label, table.get_children()[0])
1814 def test_scrolledwindow(self):
1815 sw = Gtk.ScrolledWindow()
1816 self.assertTrue(isinstance(sw, Gtk.ScrolledWindow))
1817 self.assertTrue(isinstance(sw, Gtk.Container))
1818 self.assertTrue(isinstance(sw, Gtk.Widget))
1819 sb = sw.get_hscrollbar()
1820 self.assertEqual(sw.get_hadjustment(), sb.get_adjustment())
1821 sb = sw.get_vscrollbar()
1822 self.assertEqual(sw.get_vadjustment(), sb.get_adjustment())
1824 def test_widget_drag_methods(self):
1825 widget = Gtk.Button()
1827 # here we are not checking functionality, only that the methods exist
1828 # and except the right number of arguments
1830 widget.drag_check_threshold(0, 0, 0, 0)
1832 # drag_dest_ methods
1833 widget.drag_dest_set(Gtk.DestDefaults.DROP, None, Gdk.DragAction.COPY)
1834 widget.drag_dest_add_image_targets()
1835 widget.drag_dest_add_text_targets()
1836 widget.drag_dest_add_uri_targets()
1837 widget.drag_dest_get_track_motion()
1838 widget.drag_dest_set_track_motion(True)
1839 widget.drag_dest_get_target_list()
1840 widget.drag_dest_set_target_list(Gtk.TargetList.new([Gtk.TargetEntry.new('test', 0, 0)]))
1841 widget.drag_dest_unset()
1843 widget.drag_highlight()
1844 widget.drag_unhighlight()
1846 # drag_source_ methods
1847 widget.drag_source_set(Gdk.ModifierType.BUTTON1_MASK, None, Gdk.DragAction.MOVE)
1848 widget.drag_source_add_image_targets()
1849 widget.drag_source_add_text_targets()
1850 widget.drag_source_add_uri_targets()
1851 widget.drag_source_set_icon_name("")
1852 widget.drag_source_set_icon_pixbuf(GdkPixbuf.Pixbuf())
1853 widget.drag_source_set_icon_stock("")
1854 widget.drag_source_get_target_list()
1855 widget.drag_source_set_target_list(Gtk.TargetList.new([Gtk.TargetEntry.new('test', 0, 0)]))
1856 widget.drag_source_unset()
1858 # these methods cannot be called because they require a valid drag on
1859 # a real GdkWindow. So we only check that they exist and are callable.
1860 self.assertTrue(hasattr(widget.drag_dest_set_proxy, '__call__'))
1861 self.assertTrue(hasattr(widget.drag_get_data, '__call__'))
1863 def test_scrollbar(self):
1865 adjustment = Gtk.Adjustment()
1867 hscrollbar = Gtk.HScrollbar()
1868 vscrollbar = Gtk.VScrollbar()
1869 self.assertNotEquals(hscrollbar.props.adjustment, adjustment)
1870 self.assertNotEquals(vscrollbar.props.adjustment, adjustment)
1872 hscrollbar = Gtk.HScrollbar(adjustment)
1873 vscrollbar = Gtk.VScrollbar(adjustment)
1874 self.assertEqual(hscrollbar.props.adjustment, adjustment)
1875 self.assertEqual(vscrollbar.props.adjustment, adjustment)
1877 def test_iconview(self):
1879 iconview = Gtk.IconView()
1880 self.assertEqual(iconview.props.model, None)
1882 model = Gtk.ListStore(str)
1883 iconview = Gtk.IconView(model)
1884 self.assertEqual(iconview.props.model, model)
1886 def test_toolbutton(self):
1888 button = Gtk.ToolButton()
1889 self.assertEqual(button.props.stock_id, None)
1891 button = Gtk.ToolButton('gtk-new')
1892 self.assertEqual(button.props.stock_id, 'gtk-new')
1894 icon = Gtk.Image.new_from_stock(Gtk.STOCK_OPEN, Gtk.IconSize.SMALL_TOOLBAR)
1896 button = Gtk.ToolButton(label='mylabel', icon_widget=icon)
1897 self.assertEqual(button.props.label, 'mylabel')
1898 self.assertEqual(button.props.icon_widget, icon)
1900 def test_iconset(self):
1903 pixbuf = GdkPixbuf.Pixbuf()
1906 def test_viewport(self):
1908 vadjustment = Gtk.Adjustment()
1909 hadjustment = Gtk.Adjustment()
1911 viewport = Gtk.Viewport(hadjustment=hadjustment,
1912 vadjustment=vadjustment)
1914 self.assertEqual(viewport.props.vadjustment, vadjustment)
1915 self.assertEqual(viewport.props.hadjustment, hadjustment)
1918 class TestGio(unittest.TestCase):
1920 self.settings = Gio.Settings('org.gnome.test')
1921 # we change the values in the tests, so set them to predictable start
1923 self.settings.reset('test-string')
1924 self.settings.reset('test-array')
1926 def test_file_enumerator(self):
1927 self.assertEqual(Gio.FileEnumerator, overrides.Gio.FileEnumerator)
1928 f = Gio.file_new_for_path("./")
1931 for info in f.enumerate_children("standard::*", 0, None):
1932 iter_info.append(info.get_name())
1935 enumerator = f.enumerate_children("standard::*", 0, None)
1937 info = enumerator.next_file(None)
1940 next_info.append(info.get_name())
1942 self.assertEqual(iter_info, next_info)
1944 def test_gsettings_native(self):
1945 self.assertTrue('test-array' in self.settings.list_keys())
1948 v = self.settings.get_value('test-boolean')
1949 self.assertEqual(v.get_boolean(), True)
1950 self.assertEqual(self.settings.get_boolean('test-boolean'), True)
1952 v = self.settings.get_value('test-string')
1953 self.assertEqual(v.get_string(), 'Hello')
1954 self.assertEqual(self.settings.get_string('test-string'), 'Hello')
1956 v = self.settings.get_value('test-array')
1957 self.assertEqual(v.unpack(), [1, 2])
1959 v = self.settings.get_value('test-tuple')
1960 self.assertEqual(v.unpack(), (1, 2))
1963 self.settings.set_string('test-string', 'World')
1964 self.assertEqual(self.settings.get_string('test-string'), 'World')
1966 self.settings.set_value('test-string', GLib.Variant('s', 'Goodbye'))
1967 self.assertEqual(self.settings.get_string('test-string'), 'Goodbye')
1969 def test_gsettings_constructor(self):
1970 # default constructor uses path from schema
1971 self.assertEqual(self.settings.get_property('path'), '/tests/')
1973 # optional constructor arguments
1974 with_path = Gio.Settings('org.gnome.nopathtest', path='/mypath/')
1975 self.assertEqual(with_path.get_property('path'), '/mypath/')
1976 self.assertEqual(with_path['np-int'], 42)
1978 def test_gsettings_override(self):
1979 # dictionary interface
1980 self.assertEqual(len(self.settings), 4)
1981 self.assertTrue('test-array' in self.settings)
1982 self.assertTrue('test-array' in self.settings.keys())
1983 self.assertFalse('nonexisting' in self.settings)
1984 self.assertFalse(4 in self.settings)
1985 self.assertEqual(bool(self.settings), True)
1988 self.assertEqual(self.settings['test-boolean'], True)
1989 self.assertEqual(self.settings['test-string'], 'Hello')
1990 self.assertEqual(self.settings['test-array'], [1, 2])
1991 self.assertEqual(self.settings['test-tuple'], (1, 2))
1993 self.assertRaises(KeyError, self.settings.__getitem__, 'unknown')
1994 self.assertRaises(KeyError, self.settings.__getitem__, 2)
1997 self.settings['test-string'] = 'Goodbye'
1998 self.assertEqual(self.settings['test-string'], 'Goodbye')
1999 self.settings['test-array'] = [3, 4, 5]
2000 self.assertEqual(self.settings['test-array'], [3, 4, 5])
2002 self.assertRaises(TypeError, self.settings.__setitem__, 'test-string', 1)
2003 self.assertRaises(KeyError, self.settings.__setitem__, 'unknown', 'moo')
2005 def test_gsettings_empty(self):
2006 empty = Gio.Settings('org.gnome.empty', path='/tests/')
2007 self.assertEqual(len(empty), 0)
2008 self.assertEqual(bool(empty), True)
2009 self.assertEqual(empty.keys(), [])