diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.in | 3 | ||||
-rw-r--r-- | tests/test_gi.py | 25 | ||||
-rw-r--r-- | tests/test_overrides.py | 366 |
3 files changed, 380 insertions, 14 deletions
diff --git a/tests/Makefile.in b/tests/Makefile.in index e9c6223..9773183 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -201,6 +201,8 @@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ PKG_CONFIG = @PKG_CONFIG@ +PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ +PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ PLATFORM = @PLATFORM@ PYCAIRO_CFLAGS = @PYCAIRO_CFLAGS@ PYCAIRO_LIBS = @PYCAIRO_LIBS@ @@ -258,7 +260,6 @@ libdir = @libdir@ libexecdir = @libexecdir@ localedir = @localedir@ localstatedir = @localstatedir@ -lt_ECHO = @lt_ECHO@ mandir = @mandir@ mkdir_p = @mkdir_p@ oldincludedir = @oldincludedir@ diff --git a/tests/test_gi.py b/tests/test_gi.py index fa9df70..50146a4 100644 --- a/tests/test_gi.py +++ b/tests/test_gi.py @@ -915,7 +915,6 @@ class TestGValue(unittest.TestCase): def test_gvalue_in(self): GIMarshallingTests.gvalue_in(42) - self.assertRaises(TypeError, GIMarshallingTests.gvalue_in, None) def test_gvalue_out(self): self.assertEquals(42, GIMarshallingTests.gvalue_out()) @@ -1510,3 +1509,27 @@ class TestOverrides(unittest.TestCase): def test_module_name(self): self.assertEquals(GIMarshallingTests.OverridesStruct.__module__, 'gi.overrides.GIMarshallingTests') self.assertEquals(GObject.InitiallyUnowned.__module__, 'gi.repository.GObject') + +class TestDir(unittest.TestCase): + def test_members_list(self): + list = dir(GIMarshallingTests) + self.assertTrue('OverridesStruct' in list) + self.assertTrue('BoxedStruct' in list) + self.assertTrue('OVERRIDES_CONSTANT' in list) + self.assertTrue('GEnum' in list) + self.assertTrue('int32_return_max' in list) + + def test_modules_list(self): + import gi.repository + list = dir(gi.repository) + self.assertTrue('GIMarshallingTests' in list) + + # FIXME: test to see if a module which was not imported is in the list + # we should be listing every typelib we find, not just the ones + # which are imported + # + # to test this I recommend we compile a fake module which + # our tests would never import and check to see if it is + # in the list: + # + # self.assertTrue('DoNotImportDummyTests' in list) diff --git a/tests/test_overrides.py b/tests/test_overrides.py index b1e3617..79c7093 100644 --- a/tests/test_overrides.py +++ b/tests/test_overrides.py @@ -14,6 +14,7 @@ from gi.repository import GObject from gi.repository import Gdk from gi.repository import Gtk import gi.overrides as overrides +import gi.types class TestGLib(unittest.TestCase): @@ -174,8 +175,16 @@ class TestGtk(unittest.TestCase): self.assertEquals(signal_checker.sentinel, 4) - def test_dialog(self): + def test_dialogs(self): self.assertEquals(Gtk.Dialog, overrides.Gtk.Dialog) + self.assertEquals(Gtk.AboutDialog, overrides.Gtk.AboutDialog) + self.assertEquals(Gtk.MessageDialog, overrides.Gtk.MessageDialog) + self.assertEquals(Gtk.ColorSelectionDialog, overrides.Gtk.ColorSelectionDialog) + self.assertEquals(Gtk.FileChooserDialog, overrides.Gtk.FileChooserDialog) + self.assertEquals(Gtk.FontSelectionDialog, overrides.Gtk.FontSelectionDialog) + self.assertEquals(Gtk.RecentChooserDialog, overrides.Gtk.RecentChooserDialog) + + # Gtk.Dialog dialog = Gtk.Dialog (title='Foo', flags=Gtk.DialogFlags.MODAL, buttons=('test-button1', 1)) @@ -191,6 +200,60 @@ class TestGtk(unittest.TestCase): button = dialog.get_widget_for_response (Gtk.ResponseType.CLOSE) self.assertEquals(Gtk.STOCK_CLOSE, button.get_label()) + # Gtk.AboutDialog + dialog = Gtk.AboutDialog() + + # Gtk.MessageDialog + dialog = Gtk.MessageDialog (title='message dialog test', + flags=Gtk.DialogFlags.MODAL, + buttons=Gtk.ButtonsType.OK, + message_format='dude!') + + self.assertEquals('message dialog test', dialog.get_title()) + self.assertTrue(dialog.get_modal()) + text = dialog.get_property('text') + self.assertEquals('dude!', text) + + # Gtk.ColorSelectionDialog + dialog = Gtk.ColorSelectionDialog("color selection dialog test") + self.assertEquals('color selection dialog test', dialog.get_title()) + + # Gtk.FileChooserDialog + dialog = Gtk.FileChooserDialog (title='file chooser dialog test', + buttons=('test-button1', 1), + action=Gtk.FileChooserAction.SAVE) + + dialog.add_buttons ('test-button2', 2, Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE) + self.assertEquals('file chooser dialog test', dialog.get_title()) + button = dialog.get_widget_for_response (1) + self.assertEquals('test-button1', button.get_label()) + button = dialog.get_widget_for_response (2) + self.assertEquals('test-button2', button.get_label()) + button = dialog.get_widget_for_response (Gtk.ResponseType.CLOSE) + self.assertEquals(Gtk.STOCK_CLOSE, button.get_label()) + action = dialog.get_property('action') + self.assertEquals(Gtk.FileChooserAction.SAVE, action) + + + # Gtk.FontSelectionDialog + dialog = Gtk.ColorSelectionDialog("font selection dialog test") + self.assertEquals('font selection dialog test', dialog.get_title()) + + # Gtk.RecentChooserDialog + test_manager = Gtk.RecentManager() + dialog = Gtk.RecentChooserDialog (title='recent chooser dialog test', + buttons=('test-button1', 1), + manager=test_manager) + + dialog.add_buttons ('test-button2', 2, Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE) + self.assertEquals('recent chooser dialog test', dialog.get_title()) + button = dialog.get_widget_for_response (1) + self.assertEquals('test-button1', button.get_label()) + button = dialog.get_widget_for_response (2) + self.assertEquals('test-button2', button.get_label()) + button = dialog.get_widget_for_response (Gtk.ResponseType.CLOSE) + self.assertEquals(Gtk.STOCK_CLOSE, button.get_label()) + class TestClass(GObject.GObject): __gtype_name__ = "GIOverrideTreeAPITest" @@ -210,12 +273,24 @@ class TestGtk(unittest.TestCase): self.assertEquals(Gtk.TreeModel, overrides.Gtk.TreeModel) self.assertEquals(Gtk.TreeViewColumn, overrides.Gtk.TreeViewColumn) - tree_store = Gtk.TreeStore(int, 'gchararray', TestGtk.TestClass) + class TestPyObject(object): + pass + + test_pyobj = TestPyObject() + test_pydict = {1:1, "2":2, "3":"3"} + test_pylist = [1,"2", "3"] + tree_store = Gtk.TreeStore(int, 'gchararray', TestGtk.TestClass, object, object, object) + parent = None for i in range(100): label = 'this is child #%d' % i testobj = TestGtk.TestClass(self, i, label) - parent = tree_store.append(parent, (i, label, testobj)) + parent = tree_store.append(parent, (i, + label, + testobj, + test_pyobj, + test_pydict, + test_pylist)) # len gets the number of children in the root node # since we kept appending to the previous node @@ -226,39 +301,268 @@ class TestGtk(unittest.TestCase): parent = None i = 0 - (has_children, treeiter) = tree_store.iter_children(parent) - while (has_children): + treeiter = tree_store.iter_children(parent) + while treeiter: + i = tree_store.get_value(treeiter, 0) + s = tree_store.get_value(treeiter, 1) + obj = tree_store.get_value(treeiter, 2) i = tree_store.get_value(treeiter, 0) s = tree_store.get_value(treeiter, 1) obj = tree_store.get_value(treeiter, 2) obj.check(i, s) + + pyobj = tree_store.get_value(treeiter, 3) + self.assertEquals(pyobj, test_pyobj) + pydict = tree_store.get_value(treeiter, 4) + self.assertEquals(pydict, test_pydict) + pylist = tree_store.get_value(treeiter, 5) + self.assertEquals(pylist, test_pylist) + parent = treeiter - (has_children, treeiter) = tree_store.iter_children(parent) + treeiter = tree_store.iter_children(parent) self.assertEquals(i, 99) def test_list_store(self): - list_store = Gtk.ListStore(int, str, 'GIOverrideTreeAPITest') - for i in range(100): + class TestPyObject(object): + pass + + test_pyobj = TestPyObject() + test_pydict = {1:1, "2":2, "3":"3"} + test_pylist = [1,"2", "3"] + + list_store = Gtk.ListStore(int, str, 'GIOverrideTreeAPITest', object, object, object) + for i in range(95): label = 'this is row #%d' % i testobj = TestGtk.TestClass(self, i, label) - parent = list_store.append((i, label, testobj)) + parent = list_store.append((i, + label, + testobj, + test_pyobj, + test_pydict, + test_pylist)) + + # add sorted items out of order to test insert* apis + i = 97 + label = 'this is row #97' + treeiter = list_store.append((i, + label, + TestGtk.TestClass(self, i, label), + test_pyobj, + test_pydict, + test_pylist)) + # this should append + i = 99 + label = 'this is row #99' + list_store.insert(9999, (i, + label, + TestGtk.TestClass(self, i, label), + test_pyobj, + test_pydict, + test_pylist)) + + i = 96 + label = 'this is row #96' + list_store.insert_before(treeiter, (i, + label, + TestGtk.TestClass(self, i, label), + test_pyobj, + test_pydict, + test_pylist)) + + i = 98 + label = 'this is row #98' + list_store.insert_after(treeiter, (i, + label, + TestGtk.TestClass(self, i, label), + test_pyobj, + test_pydict, + test_pylist)) + + + i = 95 + label = 'this is row #95' + list_store.insert(95, (i, + label, + TestGtk.TestClass(self, i, label), + test_pyobj, + test_pydict, + test_pylist)) self.assertEquals(len(list_store), 100) # walk the list to see if the values were stored correctly i = 0 - (has_more, treeiter) = list_store.get_iter_first() + treeiter = list_store.get_iter_first() - while has_more: + counter = 0 + while treeiter: i = list_store.get_value(treeiter, 0) + self.assertEquals(i, counter) s = list_store.get_value(treeiter, 1) obj = list_store.get_value(treeiter, 2) obj.check(i, s) - has_more = list_store.iter_next(treeiter) + + pyobj = list_store.get_value(treeiter, 3) + self.assertEquals(pyobj, test_pyobj) + pydict = list_store.get_value(treeiter, 4) + self.assertEquals(pydict, test_pydict) + pylist = list_store.get_value(treeiter, 5) + self.assertEquals(pylist, test_pylist) + treeiter = list_store.iter_next(treeiter) + + counter += 1 self.assertEquals(i, 99) + def test_tree_model(self): + tree_store = Gtk.TreeStore(int, str) + + self.assertTrue(tree_store) + self.assertEqual(len(tree_store), 0) + self.assertEqual(tree_store.get_iter_first(), None) + + def get_by_index(row, col=None): + if col: + return tree_store[row][col] + else: + return tree_store[row] + + self.assertRaises(TypeError, get_by_index, None) + self.assertRaises(TypeError, get_by_index, "") + self.assertRaises(TypeError, get_by_index, ()) + + self.assertRaises(IndexError, get_by_index, "0") + self.assertRaises(IndexError, get_by_index, 0) + self.assertRaises(IndexError, get_by_index, (0,)) + + self.assertRaises(ValueError, tree_store.get_iter, "0") + self.assertRaises(ValueError, tree_store.get_iter, 0) + self.assertRaises(ValueError, tree_store.get_iter, (0,)) + + self.assertRaises(ValueError, tree_store.get_iter_from_string, "0") + + for row in tree_store: + self.fail("Should not be reached") + + for i in range(100): + label = 'this is row #%d' % i + parent = tree_store.append(None, (i, label,)) + self.assertNotEquals(parent, None) + for j in range(20): + label = 'this is child #%d of node #%d' % (j, i) + child = tree_store.append(parent, (j, label,)) + self.assertNotEqual(child, None) + + self.assertTrue(tree_store) + self.assertEqual(len(tree_store), 100) + + for i,row in enumerate(tree_store): + self.assertEqual(row.model, tree_store) + self.assertEqual(row.parent, None) + + self.assertEqual(tree_store[i].path, row.path) + self.assertEqual(tree_store[str(i)].path, row.path) + self.assertEqual(tree_store[(i,)].path, row.path) + + self.assertEqual(tree_store[i][0], i) + self.assertEqual(tree_store[i][1], "this is row #%d" % i) + + aiter = tree_store.get_iter(i) + self.assertEqual(tree_store.get_path(aiter), row.path) + + aiter = tree_store.get_iter(str(i)) + self.assertEqual(tree_store.get_path(aiter), row.path) + + aiter = tree_store.get_iter((i,)) + self.assertEqual(tree_store.get_path(aiter), row.path) + + self.assertEqual(tree_store.iter_parent(aiter), row.parent) + + next = tree_store.iter_next(aiter) + if i < len(tree_store) - 1: + self.assertEqual(tree_store.get_path(next), row.next.path) + else: + self.assertEqual(next, None) + + self.assertEqual(tree_store.iter_n_children(row.iter), 20) + + child = tree_store.iter_children(row.iter) + for j,childrow in enumerate(row.iterchildren()): + child_path = tree_store.get_path(child) + self.assertEqual(childrow.path, child_path) + self.assertEqual(childrow.parent.path, row.path) + self.assertEqual(childrow.path, tree_store[child].path) + self.assertEqual(childrow.path, tree_store[child_path].path) + + self.assertEqual(childrow[0], tree_store[child][0]) + self.assertEqual(childrow[0], j) + self.assertEqual(childrow[1], tree_store[child][1]) + self.assertEqual(childrow[1], 'this is child #%d of node #%d' % (j, i)) + + self.assertRaises(IndexError, get_by_index, child, 2) + + tree_store[child][1] = 'this was child #%d of node #%d' % (j, i) + self.assertEqual(childrow[1], 'this was child #%d of node #%d' % (j, i)) + + nth_child = tree_store.iter_nth_child(row.iter, j) + self.assertEqual(childrow.path, tree_store.get_path(nth_child)) + + childrow2 = tree_store["%d:%d" % (i, j)] + self.assertEqual(childrow.path, childrow2.path) + + childrow2 = tree_store[(i, j,)] + self.assertEqual(childrow.path, childrow2.path) + + child = tree_store.iter_next(child) + if j < 19: + self.assertEqual(childrow.next.path, tree_store.get_path(child)) + else: + self.assertEqual(child, childrow.next) + self.assertEqual(child, None) + + self.assertEqual(j, 19) + + self.assertEqual(i, 99) + + # negative indices + for i in range(-1,-100,-1): + i_real = i + 100 + self.assertEqual(tree_store[i][0], i_real) + + row = tree_store[i] + for j in range(-1, -20, -1): + j_real = j + 20 + path = (i_real, j_real,) + + self.assertEqual(tree_store[path][-2], j_real) + + label = 'this was child #%d of node #%d' % (j_real, i_real) + self.assertEqual(tree_store[path][-1], label) + + new_label = 'this still is child #%d of node #%d' % (j_real, i_real) + tree_store[path][-1] = new_label + self.assertEqual(tree_store[path][-1], new_label) + + self.assertRaises(IndexError, get_by_index, path, -3) + + self.assertRaises(IndexError, get_by_index, -101) + + last_row = tree_store[99] + self.assertNotEqual(last_row, None) + + for i,childrow in enumerate(last_row.iterchildren()): + if i < 19: + self.assertTrue(tree_store.remove(childrow.iter)) + else: + self.assertFalse(tree_store.remove(childrow.iter)) + + self.assertEqual(i, 19) + + self.assertEqual(tree_store.iter_n_children(last_row.iter), 0) + for childrow in last_row.iterchildren(): + self.fail("Should not be reached") + def test_tree_view_column(self): cell = Gtk.CellRendererText() column = Gtk.TreeViewColumn(title='This is just a test', @@ -298,3 +602,41 @@ class TestGtk(unittest.TestCase): self.assertEquals(Gtk.STOCK_CLOSE, button.get_label()) self.assertTrue(button.get_use_stock()) self.assertTrue(button.get_use_underline()) + + def test_inheritance(self): + for name in overrides.Gtk.__all__: + over = getattr(overrides.Gtk, name) + for element in dir(Gtk): + try: + klass = getattr(Gtk, element) + info = klass.__info__ + except (NotImplementedError, AttributeError): + continue + + # Get all parent classes and interfaces klass inherits from + if isinstance(info, gi.types.ObjectInfo): + classes = list(info.get_interfaces()) + parent = info.get_parent() + while parent.get_name() != "Object": + classes.append(parent) + parent = parent.get_parent() + classes = [kl for kl in classes if kl.get_namespace() == "Gtk"] + else: + continue + + for kl in classes: + if kl.get_name() == name: + self.assertTrue(issubclass(klass, over,), + "%r does not inherit from override %r" % (klass, over,)) + + def test_editable(self): + self.assertEquals(Gtk.Editable, overrides.Gtk.Editable) + + # need to use Gtk.Entry because Editable is an interface + entry=Gtk.Entry() + pos = entry.insert_text('HeWorld', 0) + self.assertEquals(pos, 7) + pos = entry.insert_text('llo ', 2) + self.assertEquals(pos, 6) + text = entry.get_chars(0, 11) + self.assertEquals('Hello World', text) |