1 # -*- Mode: Python; py-indent-offset: 4 -*-
2 # vim: tabstop=4 shiftwidth=4 expandtab
8 sys.path.insert(0, "../")
10 from compathelper import _long, _unicode, _bytes
12 from gi.repository import GLib
13 from gi.repository import GObject
14 from gi.repository import Gdk
15 from gi.repository import Gtk
16 from gi.repository import Gio
17 from gi.repository import Pango
18 from gi.repository import GdkPixbuf
19 import gi.overrides as overrides
22 class TestGLib(unittest.TestCase):
24 def test_gvariant_create(self):
27 variant = GLib.Variant('i', 42)
28 self.assertTrue(isinstance(variant, GLib.Variant))
29 self.assertEquals(variant.get_int32(), 42)
31 variant = GLib.Variant('s', '')
32 self.assertTrue(isinstance(variant, GLib.Variant))
33 self.assertEquals(variant.get_string(), '')
35 variant = GLib.Variant('s', 'hello')
36 self.assertTrue(isinstance(variant, GLib.Variant))
37 self.assertEquals(variant.get_string(), 'hello')
40 variant = GLib.Variant('v', GLib.Variant('i', 42))
41 self.assertTrue(isinstance(variant, GLib.Variant))
42 self.assertTrue(isinstance(variant.get_variant(), GLib.Variant))
43 self.assertEqual(variant.get_type_string(), 'v')
44 self.assertEqual(variant.get_variant().get_type_string(), 'i')
45 self.assertEquals(variant.get_variant().get_int32(), 42)
47 variant = GLib.Variant('v', GLib.Variant('v', GLib.Variant('i', 42)))
48 self.assertEqual(variant.get_type_string(), 'v')
49 self.assertEqual(variant.get_variant().get_type_string(), 'v')
50 self.assertEqual(variant.get_variant().get_variant().get_type_string(), 'i')
51 self.assertEquals(variant.get_variant().get_variant().get_int32(), 42)
55 variant = GLib.Variant('()', ())
56 self.assertEqual(variant.get_type_string(), '()')
57 self.assertEquals(variant.n_children(), 0)
59 variant = GLib.Variant('(i)', (3,))
60 self.assertEqual(variant.get_type_string(), '(i)')
61 self.assertTrue(isinstance(variant, GLib.Variant))
62 self.assertEquals(variant.n_children(), 1)
63 self.assertTrue(isinstance(variant.get_child_value(0), GLib.Variant))
64 self.assertEquals(variant.get_child_value(0).get_int32(), 3)
66 variant = GLib.Variant('(ss)', ('mec', 'mac'))
67 self.assertEqual(variant.get_type_string(), '(ss)')
68 self.assertTrue(isinstance(variant, GLib.Variant))
69 self.assertTrue(isinstance(variant.get_child_value(0), GLib.Variant))
70 self.assertTrue(isinstance(variant.get_child_value(1), GLib.Variant))
71 self.assertEquals(variant.get_child_value(0).get_string(), 'mec')
72 self.assertEquals(variant.get_child_value(1).get_string(), 'mac')
75 variant = GLib.Variant('((si)(ub))', (('hello', -1), (42, True)))
76 self.assertEqual(variant.get_type_string(), '((si)(ub))')
77 self.assertEqual(variant.unpack(), (('hello', -1), (_long(42), True)))
81 variant = GLib.Variant('a{si}', {})
82 self.assertTrue(isinstance(variant, GLib.Variant))
83 self.assertEqual(variant.get_type_string(), 'a{si}')
84 self.assertEquals(variant.n_children(), 0)
86 variant = GLib.Variant('a{si}', {'': 1, 'key1': 2, 'key2': 3})
87 self.assertEqual(variant.get_type_string(), 'a{si}')
88 self.assertTrue(isinstance(variant, GLib.Variant))
89 self.assertTrue(isinstance(variant.get_child_value(0), GLib.Variant))
90 self.assertTrue(isinstance(variant.get_child_value(1), GLib.Variant))
91 self.assertTrue(isinstance(variant.get_child_value(2), GLib.Variant))
92 self.assertEqual(variant.unpack(), {'': 1, 'key1': 2, 'key2': 3})
95 variant = GLib.Variant('a{sa{si}}', {})
96 self.assertTrue(isinstance(variant, GLib.Variant))
97 self.assertEqual(variant.get_type_string(), 'a{sa{si}}')
98 self.assertEquals(variant.n_children(), 0)
100 d = {'': {'': 1, 'keyn1': 2},
101 'key1': {'key11': 11, 'key12': 12}}
102 variant = GLib.Variant('a{sa{si}}', d)
103 self.assertEqual(variant.get_type_string(), 'a{sa{si}}')
104 self.assertTrue(isinstance(variant, GLib.Variant))
105 self.assertEqual(variant.unpack(), d)
109 variant = GLib.Variant('ai', [])
110 self.assertEqual(variant.get_type_string(), 'ai')
111 self.assertEquals(variant.n_children(), 0)
113 variant = GLib.Variant('ai', [1, 2])
114 self.assertEqual(variant.get_type_string(), 'ai')
115 self.assertTrue(isinstance(variant, GLib.Variant))
116 self.assertTrue(isinstance(variant.get_child_value(0), GLib.Variant))
117 self.assertTrue(isinstance(variant.get_child_value(1), GLib.Variant))
118 self.assertEquals(variant.get_child_value(0).get_int32(), 1)
119 self.assertEquals(variant.get_child_value(1).get_int32(), 2)
121 variant = GLib.Variant('as', [])
122 self.assertEqual(variant.get_type_string(), 'as')
123 self.assertEquals(variant.n_children(), 0)
125 variant = GLib.Variant('as', [''])
126 self.assertEqual(variant.get_type_string(), 'as')
127 self.assertTrue(isinstance(variant, GLib.Variant))
128 self.assertTrue(isinstance(variant.get_child_value(0), GLib.Variant))
129 self.assertEquals(variant.get_child_value(0).get_string(), '')
131 variant = GLib.Variant('as', ['hello', 'world'])
132 self.assertEqual(variant.get_type_string(), 'as')
133 self.assertTrue(isinstance(variant, GLib.Variant))
134 self.assertTrue(isinstance(variant.get_child_value(0), GLib.Variant))
135 self.assertTrue(isinstance(variant.get_child_value(1), GLib.Variant))
136 self.assertEquals(variant.get_child_value(0).get_string(), 'hello')
137 self.assertEquals(variant.get_child_value(1).get_string(), 'world')
140 variant = GLib.Variant('aai', [])
141 self.assertEqual(variant.get_type_string(), 'aai')
142 self.assertEquals(variant.n_children(), 0)
144 variant = GLib.Variant('aai', [[]])
145 self.assertEqual(variant.get_type_string(), 'aai')
146 self.assertEquals(variant.n_children(), 1)
147 self.assertEquals(variant.get_child_value(0).n_children(), 0)
149 variant = GLib.Variant('aai', [[1, 2], [3, 4, 5]])
150 self.assertEqual(variant.get_type_string(), 'aai')
151 self.assertEquals(variant.unpack(), [[1, 2], [3, 4, 5]])
157 variant = GLib.Variant('(as)', ([],))
158 self.assertEqual(variant.get_type_string(), '(as)')
159 self.assertEquals(variant.n_children(), 1)
160 self.assertEquals(variant.get_child_value(0).n_children(), 0)
162 variant = GLib.Variant('(as)', ([''],))
163 self.assertEqual(variant.get_type_string(), '(as)')
164 self.assertEquals(variant.n_children(), 1)
165 self.assertEquals(variant.get_child_value(0).n_children(), 1)
166 self.assertEquals(variant.get_child_value(0).get_child_value(0).get_string(), '')
168 variant = GLib.Variant('(as)', (['hello'],))
169 self.assertEqual(variant.get_type_string(), '(as)')
170 self.assertEquals(variant.n_children(), 1)
171 self.assertEquals(variant.get_child_value(0).n_children(), 1)
172 self.assertEquals(variant.get_child_value(0).get_child_value(0).get_string(), 'hello')
174 obj = {'a1': (1, True), 'a2': (2, False)}
175 variant = GLib.Variant('a{s(ib)}', obj)
176 self.assertEqual(variant.get_type_string(), 'a{s(ib)}')
177 self.assertEqual(variant.unpack(), obj)
179 obj = {'a1': (1, GLib.Variant('b', True)), 'a2': (2, GLib.Variant('y', 255))}
180 variant = GLib.Variant('a{s(iv)}', obj)
181 self.assertEqual(variant.get_type_string(), 'a{s(iv)}')
182 self.assertEqual(variant.unpack(), {'a1': (1, True), 'a2': (2, 255)})
184 obj = (1, {'a': {'a1': True, 'a2': False},
189 variant = GLib.Variant('(ia{sa{sb}}s)', obj)
190 self.assertEqual(variant.get_type_string(), '(ia{sa{sb}}s)')
191 self.assertEqual(variant.unpack(), obj)
193 def test_gvariant_create_errors(self):
195 self.assertRaises(TypeError, GLib.Variant, 'i', 42, 3)
196 self.assertRaises(TypeError, GLib.Variant, '(i)', (42, 3))
198 # not enough arguments
199 self.assertRaises(TypeError, GLib.Variant, '(ii)', (42,))
202 self.assertRaises(TypeError, GLib.Variant, 'i', 'hello')
203 self.assertRaises(TypeError, GLib.Variant, 's', 42)
204 self.assertRaises(TypeError, GLib.Variant, '(ss)', 'mec', 'mac')
206 # unimplemented data type
207 self.assertRaises(NotImplementedError, GLib.Variant, 'Q', 1)
209 def test_gvariant_unpack(self):
211 res = GLib.Variant.new_int32(-42).unpack()
212 self.assertEqual(res, -42)
214 res = GLib.Variant.new_uint64(34359738368).unpack()
215 self.assertEqual(res, 34359738368)
217 res = GLib.Variant.new_boolean(True).unpack()
218 self.assertEqual(res, True)
220 res = GLib.Variant.new_object_path('/foo/Bar').unpack()
221 self.assertEqual(res, '/foo/Bar')
224 res = GLib.Variant('v', GLib.Variant.new_int32(-42)).unpack()
225 self.assertEqual(res, -42)
227 variant = GLib.Variant('v', GLib.Variant('v', GLib.Variant('i', 42)))
228 self.assertEqual(res, -42)
231 res = GLib.Variant.new_tuple(GLib.Variant.new_int32(-1),
232 GLib.Variant.new_string('hello')).unpack()
233 self.assertEqual(res, (-1, 'hello'))
236 vb = GLib.VariantBuilder()
237 vb.init(gi._gi.variant_type_from_string('ai'))
238 vb.add_value(GLib.Variant.new_int32(-1))
239 vb.add_value(GLib.Variant.new_int32(3))
240 res = vb.end().unpack()
241 self.assertEqual(res, [-1, 3])
244 res = GLib.Variant('a{si}', {'key1': 1, 'key2': 2}).unpack()
245 self.assertEqual(res, {'key1': 1, 'key2': 2})
247 def test_gvariant_iteration(self):
249 vb = GLib.VariantBuilder()
250 vb.init(gi._gi.variant_type_from_string('ai'))
251 vb.add_value(GLib.Variant.new_int32(-1))
252 vb.add_value(GLib.Variant.new_int32(3))
255 self.assertEqual(len(v), 2)
256 self.assertEqual(v[0], -1)
257 self.assertEqual(v[1], 3)
258 self.assertEqual(v[-1], 3)
259 self.assertEqual(v[-2], -1)
260 self.assertRaises(IndexError, v.__getitem__, 2)
261 self.assertRaises(IndexError, v.__getitem__, -3)
262 self.assertRaises(ValueError, v.__getitem__, 'a')
265 self.assertEqual([x for x in v], [-1, 3])
266 self.assertEqual(list(v), [-1, 3])
269 v = GLib.Variant.new_tuple(GLib.Variant.new_int32(-1),
270 GLib.Variant.new_string('hello'))
271 self.assertEqual(len(v), 2)
272 self.assertEqual(v[0], -1)
273 self.assertEqual(v[1], 'hello')
274 self.assertEqual(v[-1], 'hello')
275 self.assertEqual(v[-2], -1)
276 self.assertRaises(IndexError, v.__getitem__, 2)
277 self.assertRaises(IndexError, v.__getitem__, -3)
278 self.assertRaises(ValueError, v.__getitem__, 'a')
281 self.assertEqual([x for x in v], [-1, 'hello'])
282 self.assertEqual(tuple(v), (-1, 'hello'))
284 # dictionary index access
285 vsi = GLib.Variant('a{si}', {'key1': 1, 'key2': 2})
286 vis = GLib.Variant('a{is}', {1: 'val1', 5: 'val2'})
288 self.assertEqual(len(vsi), 2)
289 self.assertEqual(vsi['key1'], 1)
290 self.assertEqual(vsi['key2'], 2)
291 self.assertRaises(KeyError, vsi.__getitem__, 'unknown')
293 self.assertEqual(len(vis), 2)
294 self.assertEqual(vis[1], 'val1')
295 self.assertEqual(vis[5], 'val2')
296 self.assertRaises(KeyError, vsi.__getitem__, 3)
298 # dictionary iteration
299 self.assertEqual(set(vsi.keys()), set(['key1', 'key2']))
300 self.assertEqual(set(vis.keys()), set([1, 5]))
302 # string index access
303 v = GLib.Variant('s', 'hello')
304 self.assertEqual(len(v), 5)
305 self.assertEqual(v[0], 'h')
306 self.assertEqual(v[4], 'o')
307 self.assertEqual(v[-1], 'o')
308 self.assertEqual(v[-5], 'h')
309 self.assertRaises(IndexError, v.__getitem__, 5)
310 self.assertRaises(IndexError, v.__getitem__, -6)
313 self.assertEqual([x for x in v], ['h', 'e', 'l', 'l', 'o'])
315 class TestPango(unittest.TestCase):
317 def test_default_font_description(self):
318 desc = Pango.FontDescription()
319 self.assertEquals(desc.get_variant(), Pango.Variant.NORMAL)
321 def test_font_description(self):
322 desc = Pango.FontDescription('monospace')
323 self.assertEquals(desc.get_family(), 'monospace')
324 self.assertEquals(desc.get_variant(), Pango.Variant.NORMAL)
326 def test_layout(self):
327 self.assertRaises(TypeError, Pango.Layout)
328 context = Pango.Context()
329 layout = Pango.Layout(context)
330 self.assertEquals(layout.get_context(), context)
332 class TestGdk(unittest.TestCase):
334 def test_constructor(self):
335 attribute = Gdk.WindowAttr()
336 attribute.window_type = Gdk.WindowType.CHILD
337 attributes_mask = Gdk.WindowAttributesType.X | \
338 Gdk.WindowAttributesType.Y
339 window = Gdk.Window(None, attribute, attributes_mask)
340 self.assertEquals(window.get_window_type(), Gdk.WindowType.CHILD)
342 def test_color(self):
343 color = Gdk.Color(100, 200, 300)
344 self.assertEquals(color.red, 100)
345 self.assertEquals(color.green, 200)
346 self.assertEquals(color.blue, 300)
349 self.assertEquals(Gdk.RGBA, overrides.Gdk.RGBA)
350 rgba = Gdk.RGBA(0.1, 0.2, 0.3, 0.4)
351 self.assertEquals(rgba.red, 0.1)
352 self.assertEquals(rgba.green, 0.2)
353 self.assertEquals(rgba.blue, 0.3)
354 self.assertEquals(rgba.alpha, 0.4)
356 self.assertEquals(rgba.green, 0.9)
358 def test_event(self):
359 event = Gdk.Event.new(Gdk.EventType.CONFIGURE)
360 self.assertEquals(event.type, Gdk.EventType.CONFIGURE)
361 self.assertEquals(event.send_event, 0)
363 event = Gdk.Event.new(Gdk.EventType.DRAG_MOTION)
364 event.x_root, event.y_root = 0, 5
365 self.assertEquals(event.x_root, 0)
366 self.assertEquals(event.y_root, 5)
369 event.type = Gdk.EventType.SCROLL
370 self.assertRaises(AttributeError, lambda: getattr(event, 'foo_bar'))
372 def test_event_structures(self):
373 def button_press_cb(button, event):
374 self.assertTrue(isinstance(event, Gdk.EventButton))
375 self.assertTrue(event.type == Gdk.EventType.BUTTON_PRESS)
376 self.assertEquals(event.send_event, 0)
377 self.assertEquals(event.get_state(), Gdk.ModifierType.CONTROL_MASK)
378 self.assertEquals(event.get_root_coords(), (2, 5))
381 self.assertEquals(event.get_time(), 12345)
385 b.connect('button-press-event', button_press_cb)
388 Gdk.test_simulate_button(b.get_window(),
391 Gdk.ModifierType.CONTROL_MASK,
392 Gdk.EventType.BUTTON_PRESS)
394 def test_cursor(self):
395 self.assertEquals(Gdk.Cursor, overrides.Gdk.Cursor)
396 c = Gdk.Cursor(Gdk.CursorType.WATCH)
397 self.assertNotEqual(c, None)
398 c = Gdk.Cursor(cursor_type = Gdk.CursorType.WATCH)
399 self.assertNotEqual(c, None)
401 display_manager = Gdk.DisplayManager.get()
402 display = display_manager.get_default_display()
404 test_pixbuf = GdkPixbuf.Pixbuf.new(GdkPixbuf.Colorspace.RGB,
410 c = Gdk.Cursor(display,
414 self.assertNotEqual(c, None)
415 self.assertRaises(ValueError, Gdk.Cursor, 1, 2, 3)
417 class TestGtk(unittest.TestCase):
419 def test_container(self):
426 self.assertTrue(label in box)
427 self.assertTrue(label2 in box)
428 self.assertEqual(len(box), 2)
431 self.assertEqual(l, [label, label2])
433 def test_actions(self):
434 self.assertEquals(Gtk.Action, overrides.Gtk.Action)
435 self.assertRaises(TypeError, Gtk.Action)
436 action = Gtk.Action("test", "Test", "Test Action", Gtk.STOCK_COPY)
437 self.assertEquals(action.get_name(), "test")
438 self.assertEquals(action.get_label(), "Test")
439 self.assertEquals(action.get_tooltip(), "Test Action")
440 self.assertEquals(action.get_stock_id(), Gtk.STOCK_COPY)
442 self.assertEquals(Gtk.RadioAction, overrides.Gtk.RadioAction)
443 self.assertRaises(TypeError, Gtk.RadioAction)
444 action = Gtk.RadioAction("test", "Test", "Test Action", Gtk.STOCK_COPY, 1)
445 self.assertEquals(action.get_name(), "test")
446 self.assertEquals(action.get_label(), "Test")
447 self.assertEquals(action.get_tooltip(), "Test Action")
448 self.assertEquals(action.get_stock_id(), Gtk.STOCK_COPY)
449 self.assertEquals(action.get_current_value(), 1)
451 def test_actiongroup(self):
452 self.assertEquals(Gtk.ActionGroup, overrides.Gtk.ActionGroup)
453 self.assertRaises(TypeError, Gtk.ActionGroup)
455 action_group = Gtk.ActionGroup (name = 'TestActionGroup')
456 callback_data = "callback data"
458 def test_action_callback_data(action, user_data):
459 self.assertEquals(user_data, callback_data);
461 def test_radio_action_callback_data(action, current, user_data):
462 self.assertEquals(user_data, callback_data);
464 action_group.add_actions ([
465 ('test-action1', None, 'Test Action 1',
466 None, None, test_action_callback_data),
467 ('test-action2', Gtk.STOCK_COPY, 'Test Action 2',
468 None, None, test_action_callback_data)], callback_data)
469 action_group.add_toggle_actions([
470 ('test-toggle-action1', None, 'Test Toggle Action 1',
471 None, None, test_action_callback_data, False),
472 ('test-toggle-action2', Gtk.STOCK_COPY, 'Test Toggle Action 2',
473 None, None, test_action_callback_data, True)], callback_data)
474 action_group.add_radio_actions([
475 ('test-radio-action1', None, 'Test Radio Action 1'),
476 ('test-radio-action2', Gtk.STOCK_COPY, 'Test Radio Action 2')], 1,
477 test_radio_action_callback_data,
480 expected_results = [('test-action1', Gtk.Action),
481 ('test-action2', Gtk.Action),
482 ('test-toggle-action1', Gtk.ToggleAction),
483 ('test-toggle-action2', Gtk.ToggleAction),
484 ('test-radio-action1', Gtk.RadioAction),
485 ('test-radio-action2', Gtk.RadioAction)]
487 for action in action_group.list_actions():
488 a = (action.get_name(), type(action))
489 self.assertTrue(a in expected_results)
490 expected_results.remove(a)
493 def test_uimanager(self):
494 self.assertEquals(Gtk.UIManager, overrides.Gtk.UIManager)
496 ui.add_ui_from_string(
499 <menubar name="menubar1"></menubar>
503 menubar = ui.get_widget("/menubar1")
504 self.assertEquals(type(menubar), Gtk.MenuBar)
506 ag = Gtk.ActionGroup (name="ag1")
507 ui.insert_action_group(ag)
508 ag2 = Gtk.ActionGroup (name="ag2")
509 ui.insert_action_group(ag2)
510 groups = ui.get_action_groups()
511 self.assertEquals(ag, groups[-2])
512 self.assertEquals(ag2, groups[-1])
514 def test_builder(self):
515 self.assertEquals(Gtk.Builder, overrides.Gtk.Builder)
517 class SignalTest(GObject.GObject):
518 __gtype_name__ = "GIOverrideSignalTest"
520 "test-signal": (GObject.SIGNAL_RUN_FIRST,
530 def on_signal_1(self, *args):
533 def on_signal_3(self, *args):
536 signal_checker = SignalCheck()
537 builder = Gtk.Builder()
539 # add object1 to the builder
540 builder.add_from_string(
543 <object class="GIOverrideSignalTest" id="object1">
544 <signal name="test-signal" handler="on_signal_1" />
549 # only add object3 to the builder
550 builder.add_objects_from_string(
553 <object class="GIOverrideSignalTest" id="object2">
554 <signal name="test-signal" handler="on_signal_2" />
556 <object class="GIOverrideSignalTest" id="object3">
557 <signal name="test-signal" handler="on_signal_3" />
559 <object class="GIOverrideSignalTest" id="object4">
560 <signal name="test-signal" handler="on_signal_4" />
568 builder.connect_signals(signal_checker)
570 # call their notify signals and check sentinel
571 objects = builder.get_objects()
572 self.assertEquals(len(objects), 2)
574 obj.emit('test-signal')
576 self.assertEquals(signal_checker.sentinel, 4)
578 def test_dialogs(self):
579 self.assertEquals(Gtk.Dialog, overrides.Gtk.Dialog)
580 self.assertEquals(Gtk.AboutDialog, overrides.Gtk.AboutDialog)
581 self.assertEquals(Gtk.MessageDialog, overrides.Gtk.MessageDialog)
582 self.assertEquals(Gtk.ColorSelectionDialog, overrides.Gtk.ColorSelectionDialog)
583 self.assertEquals(Gtk.FileChooserDialog, overrides.Gtk.FileChooserDialog)
584 self.assertEquals(Gtk.FontSelectionDialog, overrides.Gtk.FontSelectionDialog)
585 self.assertEquals(Gtk.RecentChooserDialog, overrides.Gtk.RecentChooserDialog)
588 dialog = Gtk.Dialog (title='Foo',
589 flags=Gtk.DialogFlags.MODAL,
590 buttons=('test-button1', 1))
592 dialog.add_buttons ('test-button2', 2, Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE)
594 self.assertEquals('Foo', dialog.get_title())
595 self.assertTrue(dialog.get_modal())
596 button = dialog.get_widget_for_response (1)
597 self.assertEquals('test-button1', button.get_label())
598 button = dialog.get_widget_for_response (2)
599 self.assertEquals('test-button2', button.get_label())
600 button = dialog.get_widget_for_response (Gtk.ResponseType.CLOSE)
601 self.assertEquals(Gtk.STOCK_CLOSE, button.get_label())
604 dialog = Gtk.AboutDialog()
607 dialog = Gtk.MessageDialog (title='message dialog test',
608 flags=Gtk.DialogFlags.MODAL,
609 buttons=Gtk.ButtonsType.OK,
610 message_format='dude!')
612 self.assertEquals('message dialog test', dialog.get_title())
613 self.assertTrue(dialog.get_modal())
614 text = dialog.get_property('text')
615 self.assertEquals('dude!', text)
617 dialog.format_secondary_text('2nd text')
618 self.assertEqual(dialog.get_property('secondary-text'), '2nd text')
619 self.assertFalse(dialog.get_property('secondary-use-markup'))
621 dialog.format_secondary_markup('2nd markup')
622 self.assertEqual(dialog.get_property('secondary-text'), '2nd markup')
623 self.assertTrue(dialog.get_property('secondary-use-markup'))
625 # Gtk.ColorSelectionDialog
626 dialog = Gtk.ColorSelectionDialog("color selection dialog test")
627 self.assertEquals('color selection dialog test', dialog.get_title())
629 # Gtk.FileChooserDialog
630 dialog = Gtk.FileChooserDialog (title='file chooser dialog test',
631 buttons=('test-button1', 1),
632 action=Gtk.FileChooserAction.SAVE)
634 dialog.add_buttons ('test-button2', 2, Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE)
635 self.assertEquals('file chooser dialog test', dialog.get_title())
636 button = dialog.get_widget_for_response (1)
637 self.assertEquals('test-button1', button.get_label())
638 button = dialog.get_widget_for_response (2)
639 self.assertEquals('test-button2', button.get_label())
640 button = dialog.get_widget_for_response (Gtk.ResponseType.CLOSE)
641 self.assertEquals(Gtk.STOCK_CLOSE, button.get_label())
642 action = dialog.get_property('action')
643 self.assertEquals(Gtk.FileChooserAction.SAVE, action)
646 # Gtk.FontSelectionDialog
647 dialog = Gtk.ColorSelectionDialog("font selection dialog test")
648 self.assertEquals('font selection dialog test', dialog.get_title())
650 # Gtk.RecentChooserDialog
651 test_manager = Gtk.RecentManager()
652 dialog = Gtk.RecentChooserDialog (title='recent chooser dialog test',
653 buttons=('test-button1', 1),
654 manager=test_manager)
656 dialog.add_buttons ('test-button2', 2, Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE)
657 self.assertEquals('recent chooser dialog test', dialog.get_title())
658 button = dialog.get_widget_for_response (1)
659 self.assertEquals('test-button1', button.get_label())
660 button = dialog.get_widget_for_response (2)
661 self.assertEquals('test-button2', button.get_label())
662 button = dialog.get_widget_for_response (Gtk.ResponseType.CLOSE)
663 self.assertEquals(Gtk.STOCK_CLOSE, button.get_label())
665 class TestClass(GObject.GObject):
666 __gtype_name__ = "GIOverrideTreeAPITest"
668 def __init__(self, tester, int_value, string_value):
669 super(TestGtk.TestClass, self).__init__()
671 self.int_value = int_value
672 self.string_value = string_value
674 def check(self, int_value, string_value):
675 self.tester.assertEquals(int_value, self.int_value)
676 self.tester.assertEquals(string_value, self.string_value)
678 def test_tree_store(self):
679 self.assertEquals(Gtk.TreeStore, overrides.Gtk.TreeStore)
680 self.assertEquals(Gtk.ListStore, overrides.Gtk.ListStore)
681 self.assertEquals(Gtk.TreeModel, overrides.Gtk.TreeModel)
682 self.assertEquals(Gtk.TreeViewColumn, overrides.Gtk.TreeViewColumn)
684 class TestPyObject(object):
687 test_pyobj = TestPyObject()
688 test_pydict = {1:1, "2":2, "3":"3"}
689 test_pylist = [1,"2", "3"]
690 tree_store = Gtk.TreeStore(int,
707 label = 'this is child #%d' % i
708 testobj = TestGtk.TestClass(self, i, label)
709 parent = tree_store.append(parent, (i,
719 -9223372036854775808,
725 # len gets the number of children in the root node
726 # since we kept appending to the previous node
727 # there should only be one child of the root
728 self.assertEquals(len(tree_store), 1)
730 # walk the tree to see if the values were stored correctly
734 treeiter = tree_store.iter_children(parent)
736 i = tree_store.get_value(treeiter, 0)
737 s = tree_store.get_value(treeiter, 1)
738 obj = tree_store.get_value(treeiter, 2)
741 pyobj = tree_store.get_value(treeiter, 3)
742 self.assertEquals(pyobj, test_pyobj)
743 pydict = tree_store.get_value(treeiter, 4)
744 self.assertEquals(pydict, test_pydict)
745 pylist = tree_store.get_value(treeiter, 5)
746 self.assertEquals(pylist, test_pylist)
748 bool_1 = tree_store.get_value(treeiter, 6)
749 bool_2 = tree_store.get_value(treeiter, 7)
750 self.assertEquals(bool_1, bool_2)
751 self.assertTrue(isinstance(bool_1, bool))
752 self.assertTrue(isinstance(bool_2, bool))
754 uint_ = tree_store.get_value(treeiter, 8)
755 self.assertEquals(uint_, i)
756 ulong_ = tree_store.get_value(treeiter, 9)
757 self.assertEquals(ulong_, 9223372036854775808)
758 int64_ = tree_store.get_value(treeiter, 10)
759 self.assertEquals(int64_, -9223372036854775808)
760 uint64_ = tree_store.get_value(treeiter, 11)
761 self.assertEquals(uint64_, 0xffffffffffffffff)
762 uchar_ = tree_store.get_value(treeiter, 12)
763 self.assertEquals(ord(uchar_), 254)
764 char_ = tree_store.get_value(treeiter, 13)
765 self.assertEquals(char_, 'a')
768 treeiter = tree_store.iter_children(parent)
770 self.assertEquals(i, 99)
772 def test_list_store(self):
773 class TestPyObject(object):
776 class TestPyGObject(GObject.Object):
777 __gtype_name__ = 'TestPyGObject'
778 def __init__(self, i):
779 GObject.Object.__init__(self)
780 self.sentinal = i + 5
782 test_pyobj = TestPyObject()
783 test_pydict = {1:1, "2":2, "3":"3"}
784 test_pylist = [1,"2", "3"]
786 list_store = Gtk.ListStore(int, str, 'GIOverrideTreeAPITest', object, object, object, bool, bool, object)
788 label = 'this is row #%d' % i
789 testobj = TestGtk.TestClass(self, i, label)
790 testpygobj = TestPyGObject(i)
791 parent = list_store.append((i,
802 label = _unicode('this is row #93')
803 treeiter = list_store.append()
804 list_store.set_value(treeiter, 0, i)
805 list_store.set_value(treeiter, 1, label)
806 list_store.set_value(treeiter, 2, TestGtk.TestClass(self, i, label))
807 list_store.set_value(treeiter, 3, test_pyobj)
808 list_store.set_value(treeiter, 4, test_pydict)
809 list_store.set_value(treeiter, 5, test_pylist)
810 list_store.set_value(treeiter, 6, 1)
811 list_store.set_value(treeiter, 7, True)
812 list_store.set_value(treeiter, 8, TestPyGObject(i))
814 # test automatic unicode->str conversion
816 label = _unicode('this is row #94')
817 treeiter = list_store.append((i,
819 TestGtk.TestClass(self, i, label),
827 # add sorted items out of order to test insert* apis
828 # also test sending in None to not set a column
830 label = 'this is row #97'
831 treeiter = list_store.append((None,
841 list_store.set_value(treeiter, 0, i)
842 list_store.set_value(treeiter, 1, label)
843 list_store.set_value(treeiter, 2, TestGtk.TestClass(self, i, label))
844 list_store.set_value(treeiter, 4, test_pydict)
845 list_store.set_value(treeiter, 7, True)
849 label = 'this is row #99'
850 list_store.insert(9999, (i,
852 TestGtk.TestClass(self, i, label),
861 label = 'this is row #96'
862 list_store.insert_before(treeiter, (i,
864 TestGtk.TestClass(self, i, label),
873 label = 'this is row #98'
874 list_store.insert_after(treeiter, (i,
876 TestGtk.TestClass(self, i, label),
886 label = 'this is row #95'
887 list_store.insert(95, (i,
889 TestGtk.TestClass(self, i, label),
897 self.assertEquals(len(list_store), 100)
899 # walk the list to see if the values were stored correctly
901 treeiter = list_store.get_iter_first()
905 i = list_store.get_value(treeiter, 0)
906 self.assertEquals(i, counter)
907 s = list_store.get_value(treeiter, 1)
908 obj = list_store.get_value(treeiter, 2)
911 pyobj = list_store.get_value(treeiter, 3)
912 self.assertEquals(pyobj, test_pyobj)
913 pydict = list_store.get_value(treeiter, 4)
914 self.assertEquals(pydict, test_pydict)
915 pylist = list_store.get_value(treeiter, 5)
916 self.assertEquals(pylist, test_pylist)
918 bool_1 = list_store.get_value(treeiter, 6)
919 bool_2 = list_store.get_value(treeiter, 7)
920 self.assertEquals(bool_1, bool_2)
921 self.assertTrue(isinstance(bool_1, bool))
922 self.assertTrue(isinstance(bool_2, bool))
924 pygobj = list_store.get_value(treeiter, 8)
925 self.assertEquals(pygobj.sentinal, i + 5)
927 treeiter = list_store.iter_next(treeiter)
931 self.assertEquals(i, 99)
933 def test_tree_path(self):
935 p2 = Gtk.TreePath.new_first()
936 self.assertEqual(p1, p2)
937 self.assertEqual(str(p1), '0')
939 p2 = Gtk.TreePath.new_from_string('2')
940 self.assertEqual(p1, p2)
941 self.assertEqual(str(p1), '2')
942 p1 = Gtk.TreePath('1:2:3')
943 p2 = Gtk.TreePath.new_from_string('1:2:3')
944 self.assertEqual(p1, p2)
945 self.assertEqual(str(p1), '1:2:3')
946 p1 = Gtk.TreePath((1,2,3))
947 p2 = Gtk.TreePath.new_from_string('1:2:3')
948 self.assertEqual(p1, p2)
949 self.assertEqual(str(p1), '1:2:3')
950 self.assertTrue(p1 != None)
951 self.assertFalse(p1 == None)
952 self.assertTrue(p1 > None)
953 self.assertTrue(p1 >= None)
954 self.assertFalse(p1 < None)
955 self.assertFalse(p1 <= None)
957 def test_tree_model(self):
958 tree_store = Gtk.TreeStore(int, str)
960 self.assertTrue(tree_store)
961 self.assertEqual(len(tree_store), 0)
962 self.assertEqual(tree_store.get_iter_first(), None)
964 def get_by_index(row, col=None):
966 return tree_store[row][col]
968 return tree_store[row]
970 self.assertRaises(TypeError, get_by_index, None)
971 self.assertRaises(TypeError, get_by_index, "")
972 self.assertRaises(TypeError, get_by_index, ())
974 self.assertRaises(IndexError, get_by_index, "0")
975 self.assertRaises(IndexError, get_by_index, 0)
976 self.assertRaises(IndexError, get_by_index, (0,))
978 self.assertRaises(ValueError, tree_store.get_iter, "0")
979 self.assertRaises(ValueError, tree_store.get_iter, 0)
980 self.assertRaises(ValueError, tree_store.get_iter, (0,))
982 self.assertRaises(ValueError, tree_store.get_iter_from_string, "0")
984 for row in tree_store:
985 self.fail("Should not be reached")
987 class DerivedIntType(int):
990 class DerivedStrType(str):
994 label = 'this is row #%d' % i
995 parent = tree_store.append(None, (DerivedIntType(i), DerivedStrType(label),))
996 self.assertNotEquals(parent, None)
998 label = 'this is child #%d of node #%d' % (j, i)
999 child = tree_store.append(parent, (j, label,))
1000 self.assertNotEqual(child, None)
1002 self.assertTrue(tree_store)
1003 self.assertEqual(len(tree_store), 100)
1005 for i,row in enumerate(tree_store):
1006 self.assertEqual(row.model, tree_store)
1007 self.assertEqual(row.parent, None)
1009 self.assertEqual(tree_store[i].path, row.path)
1010 self.assertEqual(tree_store[str(i)].path, row.path)
1011 self.assertEqual(tree_store[(i,)].path, row.path)
1013 self.assertEqual(tree_store[i][0], i)
1014 self.assertEqual(tree_store[i][1], "this is row #%d" % i)
1016 aiter = tree_store.get_iter(i)
1017 self.assertEqual(tree_store.get_path(aiter), row.path)
1019 aiter = tree_store.get_iter(str(i))
1020 self.assertEqual(tree_store.get_path(aiter), row.path)
1022 aiter = tree_store.get_iter((i,))
1023 self.assertEqual(tree_store.get_path(aiter), row.path)
1025 self.assertEqual(tree_store.iter_parent(aiter), row.parent)
1027 next = tree_store.iter_next(aiter)
1028 if i < len(tree_store) - 1:
1029 self.assertEqual(tree_store.get_path(next), row.next.path)
1031 self.assertEqual(next, None)
1033 self.assertEqual(tree_store.iter_n_children(row.iter), 20)
1035 child = tree_store.iter_children(row.iter)
1036 for j,childrow in enumerate(row.iterchildren()):
1037 child_path = tree_store.get_path(child)
1038 self.assertEqual(childrow.path, child_path)
1039 self.assertEqual(childrow.parent.path, row.path)
1040 self.assertEqual(childrow.path, tree_store[child].path)
1041 self.assertEqual(childrow.path, tree_store[child_path].path)
1043 self.assertEqual(childrow[0], tree_store[child][0])
1044 self.assertEqual(childrow[0], j)
1045 self.assertEqual(childrow[1], tree_store[child][1])
1046 self.assertEqual(childrow[1], 'this is child #%d of node #%d' % (j, i))
1048 self.assertRaises(IndexError, get_by_index, child, 2)
1050 tree_store[child][1] = 'this was child #%d of node #%d' % (j, i)
1051 self.assertEqual(childrow[1], 'this was child #%d of node #%d' % (j, i))
1053 nth_child = tree_store.iter_nth_child(row.iter, j)
1054 self.assertEqual(childrow.path, tree_store.get_path(nth_child))
1056 childrow2 = tree_store["%d:%d" % (i, j)]
1057 self.assertEqual(childrow.path, childrow2.path)
1059 childrow2 = tree_store[(i, j,)]
1060 self.assertEqual(childrow.path, childrow2.path)
1062 child = tree_store.iter_next(child)
1064 self.assertEqual(childrow.next.path, tree_store.get_path(child))
1066 self.assertEqual(child, childrow.next)
1067 self.assertEqual(child, None)
1069 self.assertEqual(j, 19)
1071 self.assertEqual(i, 99)
1074 for i in range(-1,-100,-1):
1076 self.assertEqual(tree_store[i][0], i_real)
1079 for j in range(-1, -20, -1):
1081 path = (i_real, j_real,)
1083 self.assertEqual(tree_store[path][-2], j_real)
1085 label = 'this was child #%d of node #%d' % (j_real, i_real)
1086 self.assertEqual(tree_store[path][-1], label)
1088 new_label = 'this still is child #%d of node #%d' % (j_real, i_real)
1089 tree_store[path][-1] = new_label
1090 self.assertEqual(tree_store[path][-1], new_label)
1092 self.assertRaises(IndexError, get_by_index, path, -3)
1094 self.assertRaises(IndexError, get_by_index, -101)
1096 last_row = tree_store[99]
1097 self.assertNotEqual(last_row, None)
1099 for i,childrow in enumerate(last_row.iterchildren()):
1101 self.assertTrue(tree_store.remove(childrow.iter))
1103 self.assertFalse(tree_store.remove(childrow.iter))
1105 self.assertEqual(i, 19)
1107 self.assertEqual(tree_store.iter_n_children(last_row.iter), 0)
1108 for childrow in last_row.iterchildren():
1109 self.fail("Should not be reached")
1111 aiter = tree_store.get_iter(10)
1112 self.assertRaises(TypeError, tree_store.get, aiter, 1, 'a')
1113 self.assertRaises(ValueError, tree_store.get, aiter, 1, -1)
1114 self.assertRaises(ValueError, tree_store.get, aiter, 1, 100)
1115 self.assertEqual(tree_store.get(aiter, 0, 1), (10, 'this is row #10'))
1117 def test_tree_view_column(self):
1118 cell = Gtk.CellRendererText()
1119 column = Gtk.TreeViewColumn(title='This is just a test',
1124 def test_tree_selection(self):
1125 store = Gtk.ListStore(int, str)
1127 store.append((i, "foo"))
1128 view = Gtk.TreeView()
1129 view.set_model(store)
1130 firstpath = store.get_path(store.get_iter_first())
1131 sel = view.get_selection()
1133 sel.select_path(firstpath)
1134 (m, s) = sel.get_selected()
1135 self.assertEqual(m, store)
1136 self.assertEqual(store.get_path(s), firstpath)
1139 (m, s) = sel.get_selected()
1140 self.assertEqual(m, store)
1141 self.assertEqual(store.get_path(s), firstpath)
1143 sel.select_path("0:0")
1144 (m, s) = sel.get_selected()
1145 self.assertEqual(m, store)
1146 self.assertEqual(store.get_path(s), firstpath)
1148 sel.select_path((0,0))
1149 (m, s) = sel.get_selected()
1150 self.assertEqual(m, store)
1151 self.assertEqual(store.get_path(s), firstpath)
1153 def test_text_buffer(self):
1154 self.assertEquals(Gtk.TextBuffer, overrides.Gtk.TextBuffer)
1155 buffer = Gtk.TextBuffer()
1156 tag = buffer.create_tag ('title', font = 'Sans 18')
1158 self.assertEquals(tag.props.name, 'title')
1159 self.assertEquals(tag.props.font, 'Sans 18')
1161 (start, end) = buffer.get_bounds()
1163 mark = buffer.create_mark(None, start)
1164 self.assertFalse(mark.get_left_gravity())
1166 buffer.set_text('Hello Jane Hello Bob')
1167 (start, end) = buffer.get_bounds()
1168 text = buffer.get_text(start, end, False)
1169 self.assertEquals(text, 'Hello Jane Hello Bob')
1172 (start, end) = buffer.get_bounds()
1173 text = buffer.get_text(start, end, False)
1174 self.assertEquals(text, '')
1176 buffer.insert(end, 'HelloHello')
1177 buffer.insert(end, ' Bob')
1179 cursor_iter = end.copy()
1180 cursor_iter.backward_chars(9)
1181 buffer.place_cursor(cursor_iter)
1182 buffer.insert_at_cursor(' Jane ')
1184 (start, end) = buffer.get_bounds()
1185 text = buffer.get_text(start, end, False)
1186 self.assertEquals(text, 'Hello Jane Hello Bob')
1188 sel = buffer.get_selection_bounds()
1189 self.assertEquals(sel, ())
1190 buffer.select_range(start, end)
1191 sel = buffer.get_selection_bounds()
1192 self.assertTrue(sel[0].equal(start))
1193 self.assertTrue(sel[1].equal(end))
1196 buffer.insert_with_tags(buffer.get_start_iter(), 'HelloHello', tag)
1197 (start, end) = buffer.get_bounds()
1198 self.assertTrue(start.begins_tag(tag))
1199 self.assertTrue(start.has_tag(tag))
1202 buffer.insert_with_tags_by_name(buffer.get_start_iter(), 'HelloHello', 'title')
1203 (start, end) = buffer.get_bounds()
1204 self.assertTrue(start.begins_tag(tag))
1205 self.assertTrue(start.has_tag(tag))
1207 self.assertRaises(ValueError, buffer.insert_with_tags_by_name,
1208 buffer.get_start_iter(), 'HelloHello', 'unknowntag')
1210 def test_text_iter(self):
1211 self.assertEquals(Gtk.TextIter, overrides.Gtk.TextIter)
1212 buffer = Gtk.TextBuffer()
1213 buffer.set_text('Hello Jane Hello Bob')
1214 tag = buffer.create_tag ('title', font = 'Sans 18')
1215 (start, end) = buffer.get_bounds()
1216 start.forward_chars(10)
1217 buffer.apply_tag(tag, start, end)
1218 self.assertTrue(start.begins_tag())
1219 self.assertTrue(end.ends_tag())
1220 self.assertTrue(start.toggles_tag())
1221 self.assertTrue(end.toggles_tag())
1222 start.backward_chars(1)
1223 self.assertFalse(start.begins_tag())
1224 self.assertFalse(start.ends_tag())
1225 self.assertFalse(start.toggles_tag())
1227 def test_buttons(self):
1228 self.assertEquals(Gtk.Button, overrides.Gtk.Button)
1231 button = Gtk.Button()
1232 button = Gtk.Button(stock=Gtk.STOCK_CLOSE)
1233 self.assertEquals(Gtk.STOCK_CLOSE, button.get_label())
1234 self.assertTrue(button.get_use_stock())
1235 self.assertTrue(button.get_use_underline())
1237 # test Gtk.LinkButton
1238 self.assertRaises(TypeError, Gtk.LinkButton)
1239 button = Gtk.LinkButton('http://www.gtk.org', 'Gtk')
1240 self.assertEquals('http://www.gtk.org', button.get_uri())
1241 self.assertEquals('Gtk', button.get_label())
1243 def test_inheritance(self):
1244 for name in overrides.Gtk.__all__:
1245 over = getattr(overrides.Gtk, name)
1246 for element in dir(Gtk):
1248 klass = getattr(Gtk, element)
1249 info = klass.__info__
1250 except (NotImplementedError, AttributeError):
1253 # Get all parent classes and interfaces klass inherits from
1254 if isinstance(info, gi.types.ObjectInfo):
1255 classes = list(info.get_interfaces())
1256 parent = info.get_parent()
1257 while parent.get_name() != "Object":
1258 classes.append(parent)
1259 parent = parent.get_parent()
1260 classes = [kl for kl in classes if kl.get_namespace() == "Gtk"]
1265 if kl.get_name() == name:
1266 self.assertTrue(issubclass(klass, over,),
1267 "%r does not inherit from override %r" % (klass, over,))
1269 def test_editable(self):
1270 self.assertEquals(Gtk.Editable, overrides.Gtk.Editable)
1272 # need to use Gtk.Entry because Editable is an interface
1274 pos = entry.insert_text('HeWorld', 0)
1275 self.assertEquals(pos, 7)
1276 pos = entry.insert_text('llo ', 2)
1277 self.assertEquals(pos, 6)
1278 text = entry.get_chars(0, 11)
1279 self.assertEquals('Hello World', text)
1281 def test_label(self):
1282 label = Gtk.Label('Hello')
1283 self.assertEquals(label.get_text(), 'Hello')
1285 def adjustment_check(self, adjustment, value=0.0, lower=0.0, upper=0.0,
1286 step_increment=0.0, page_increment=0.0, page_size=0.0):
1287 self.assertEquals(adjustment.get_value(), value)
1288 self.assertEquals(adjustment.get_lower(), lower)
1289 self.assertEquals(adjustment.get_upper(), upper)
1290 self.assertEquals(adjustment.get_step_increment(), step_increment)
1291 self.assertEquals(adjustment.get_page_increment(), page_increment)
1292 self.assertEquals(adjustment.get_page_size(), page_size)
1294 def test_adjustment(self):
1295 adjustment = Gtk.Adjustment(1, 0, 6, 4, 5, 3)
1296 self.adjustment_check(adjustment, 1, 0, 6, 4, 5, 3)
1298 adjustment = Gtk.Adjustment(1, 0, 6, 4, 5)
1299 self.adjustment_check(adjustment, 1, 0, 6, 4, 5)
1301 adjustment = Gtk.Adjustment(1, 0, 6, 4)
1302 self.adjustment_check(adjustment, 1, 0, 6, 4)
1304 adjustment = Gtk.Adjustment(1, 0, 6)
1305 self.adjustment_check(adjustment, 1, 0, 6)
1307 adjustment = Gtk.Adjustment()
1308 self.adjustment_check(adjustment)
1310 adjustment = Gtk.Adjustment(value=1, lower=0, upper=6,
1311 step_increment=4, page_increment=5, page_size=3)
1312 self.adjustment_check(adjustment, 1, 0, 6, 4, 5, 3)
1314 def test_table(self):
1316 self.assertEquals(table.get_size(), (1,1))
1317 self.assertEquals(table.get_homogeneous(), False)
1318 table = Gtk.Table(2, 3)
1319 self.assertEquals(table.get_size(), (2,3))
1320 self.assertEquals(table.get_homogeneous(), False)
1321 table = Gtk.Table(2, 3, True)
1322 self.assertEquals(table.get_size(), (2,3))
1323 self.assertEquals(table.get_homogeneous(), True)
1325 # Test PyGTK interface
1326 table = Gtk.Table(rows=3, columns=2)
1327 self.assertEquals(table.get_size(), (3,2))
1328 # Test using the actual property names
1329 table = Gtk.Table(n_rows=2, n_columns=3, homogeneous=True)
1330 self.assertEquals(table.get_size(), (2,3))
1331 self.assertEquals(table.get_homogeneous(), True)
1333 label = Gtk.Label('Hello')
1334 table.attach(label, 0, 1, 0, 1)
1335 self.assertEquals(label, table.get_children()[0])
1337 def test_scrolledwindow(self):
1338 sw = Gtk.ScrolledWindow()
1339 sb = sw.get_hscrollbar()
1340 self.assertEquals(sw.get_hadjustment(), sb.get_adjustment())
1341 sb = sw.get_vscrollbar()
1342 self.assertEquals(sw.get_vadjustment(), sb.get_adjustment())
1344 def test_widget_drag_methods(self):
1345 widget = Gtk.Button()
1347 # here we are not checking functionality, only that the methods exist
1348 # and except the right number of arguments
1350 widget.drag_check_threshold(0, 0, 0, 0)
1352 # drag_dest_ methods
1353 widget.drag_dest_set(Gtk.DestDefaults.DROP, None, Gdk.DragAction.COPY)
1354 widget.drag_dest_add_image_targets()
1355 widget.drag_dest_add_text_targets()
1356 widget.drag_dest_add_uri_targets()
1357 widget.drag_dest_get_track_motion()
1358 widget.drag_dest_set_track_motion(True)
1359 widget.drag_dest_get_target_list()
1360 widget.drag_dest_set_target_list(Gtk.TargetList.new([Gtk.TargetEntry()]))
1361 widget.drag_dest_unset()
1363 widget.drag_highlight()
1364 widget.drag_unhighlight()
1366 # drag_source_ methods
1367 widget.drag_source_set(Gdk.ModifierType.BUTTON1_MASK, None, Gdk.DragAction.MOVE)
1368 widget.drag_source_add_image_targets()
1369 widget.drag_source_add_text_targets()
1370 widget.drag_source_add_uri_targets()
1371 widget.drag_source_set_icon_name("")
1372 widget.drag_source_set_icon_pixbuf(GdkPixbuf.Pixbuf())
1373 widget.drag_source_set_icon_stock("")
1374 widget.drag_source_get_target_list()
1375 widget.drag_source_set_target_list(Gtk.TargetList.new([Gtk.TargetEntry()]))
1376 widget.drag_source_unset()
1378 # these methods cannot be called because they require a valid drag on
1379 # a real GdkWindow. So we only check that they exist and are callable.
1380 self.assertTrue(hasattr(widget.drag_dest_set_proxy, '__call__'))
1381 self.assertTrue(hasattr(widget.drag_get_data, '__call__'))
1383 class TestGio(unittest.TestCase):
1385 os.environ['GSETTINGS_BACKEND'] = 'memory'
1386 os.environ['GSETTINGS_SCHEMA_DIR'] = os.path.dirname(__file__)
1387 self.settings = Gio.Settings('org.gnome.test')
1388 # we change the values in the tests, so set them to predictable start
1390 self.settings.reset('test-string')
1391 self.settings.reset('test-array')
1393 def test_file_enumerator(self):
1394 self.assertEquals(Gio.FileEnumerator, overrides.Gio.FileEnumerator)
1395 f = Gio.file_new_for_path("./")
1398 for info in f.enumerate_children("standard::*", 0, None):
1399 iter_info.append(info.get_name())
1402 enumerator = f.enumerate_children("standard::*", 0, None)
1404 info = enumerator.next_file(None)
1407 next_info.append(info.get_name())
1409 self.assertEquals(iter_info, next_info)
1411 def test_gsettings_native(self):
1412 self.assertTrue('test-array' in self.settings.list_keys())
1415 v = self.settings.get_value('test-boolean')
1416 self.assertEqual(v.get_boolean(), True)
1417 self.assertEqual(self.settings.get_boolean('test-boolean'), True)
1419 v = self.settings.get_value('test-string')
1420 self.assertEqual(v.get_string(), 'Hello')
1421 self.assertEqual(self.settings.get_string('test-string'), 'Hello')
1423 v = self.settings.get_value('test-array')
1424 self.assertEqual(v.unpack(), [1, 2])
1426 v = self.settings.get_value('test-tuple')
1427 self.assertEqual(v.unpack(), (1, 2))
1430 self.settings.set_string('test-string', 'World')
1431 self.assertEqual(self.settings.get_string('test-string'), 'World')
1433 self.settings.set_value('test-string', GLib.Variant('s', 'Goodbye'))
1434 self.assertEqual(self.settings.get_string('test-string'), 'Goodbye')
1436 def test_gsettings_constructor(self):
1437 # default constructor uses path from schema
1438 self.assertEqual(self.settings.get_property('path'), '/tests/')
1440 # optional constructor arguments
1441 with_path = Gio.Settings('org.gnome.nopathtest', path='/mypath/')
1442 self.assertEqual(with_path.get_property('path'), '/mypath/')
1443 self.assertEqual(with_path['np-int'], 42)
1445 def test_gsettings_override(self):
1446 # dictionary interface
1447 self.assertEqual(len(self.settings), 4)
1448 self.assertTrue('test-array' in self.settings)
1449 self.assertTrue('test-array' in self.settings.keys())
1450 self.failIf('nonexisting' in self.settings)
1451 self.failIf(4 in self.settings)
1452 self.assertEqual(bool(self.settings), True)
1455 self.assertEqual(self.settings['test-boolean'], True)
1456 self.assertEqual(self.settings['test-string'], 'Hello')
1457 self.assertEqual(self.settings['test-array'], [1, 2])
1458 self.assertEqual(self.settings['test-tuple'], (1, 2))
1460 self.assertRaises(KeyError, self.settings.__getitem__, 'unknown')
1461 self.assertRaises(KeyError, self.settings.__getitem__, 2)
1464 self.settings['test-string'] = 'Goodbye'
1465 self.assertEqual(self.settings['test-string'], 'Goodbye')
1466 self.settings['test-array'] = [3, 4, 5]
1467 self.assertEqual(self.settings['test-array'], [3, 4, 5])
1469 self.assertRaises(TypeError, self.settings.__setitem__, 'test-string', 1)
1470 self.assertRaises(KeyError, self.settings.__setitem__, 'unknown', 'moo')
1472 def test_gsettings_empty(self):
1473 empty = Gio.Settings('org.gnome.empty', path='/tests/')
1474 self.assertEqual(len(empty), 0)
1475 self.assertEqual(bool(empty), True)
1476 self.assertEqual(empty.keys(), [])
1478 def test_closures(self):
1479 # make sure this doesn't crash
1483 ag = Gtk.AccelGroup()
1484 ag.connect(Gdk.KEY_l, Gdk.ModifierType.CONTROL_MASK, 0, fake_cb)