[pygobject/coverage-gtk-overrides] wip



commit b63b5072c6374b901f5481a1e24a8f341a22345d
Author: Christoph Reiter <reiter christoph gmail com>
Date:   Sun Nov 25 15:13:59 2018 +0100

    wip

 gi/overrides/Gtk.py         |  24 ++++------
 tests/test_overrides_gtk.py | 112 +++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 118 insertions(+), 18 deletions(-)
---
diff --git a/gi/overrides/Gtk.py b/gi/overrides/Gtk.py
index 7e00c611..6f8ee546 100644
--- a/gi/overrides/Gtk.py
+++ b/gi/overrides/Gtk.py
@@ -553,8 +553,7 @@ class Dialog(Gtk.Dialog, Container):
                           'Please use the "add_buttons" method for adding buttons. '
                           'See: https://wiki.gnome.org/PyGObject/InitializerDeprecations',
                           PyGTKDeprecationWarning, stacklevel=stacklevel)
-            if 'buttons' in new_kwargs:
-                del new_kwargs['buttons']
+            new_kwargs.pop('buttons', None)
         else:
             add_buttons = None
 
@@ -600,15 +599,15 @@ class Dialog(Gtk.Dialog, Container):
         """
         def _button(b):
             while b:
-                t, r = b[0:2]
+                try:
+                    t, r = b[0:2]
+                except ValueError:
+                    raise ValueError('Must pass an even number of arguments')
                 b = b[2:]
                 yield t, r
 
-        try:
-            for text, response in _button(args):
-                self.add_button(text, response)
-        except (IndexError):
-            raise TypeError('Must pass an even number of arguments')
+        for text, response in _button(args):
+            self.add_button(text, response)
 
 
 Dialog = override(Dialog)
@@ -720,13 +719,6 @@ __all__.append('RecentInfo')
 
 
 class TextBuffer(Gtk.TextBuffer):
-    def _get_or_create_tag_table(self):
-        table = self.get_tag_table()
-        if table is None:
-            table = Gtk.TextTagTable()
-            self.set_tag_table(table)
-
-        return table
 
     def create_tag(self, tag_name=None, **properties):
         """Creates a tag and adds it to the tag table of the TextBuffer.
@@ -753,7 +745,7 @@ class TextBuffer(Gtk.TextBuffer):
         """
 
         tag = Gtk.TextTag(name=tag_name, **properties)
-        self._get_or_create_tag_table().add(tag)
+        self.get_tag_table().add(tag)
         return tag
 
     def create_mark(self, mark_name, where, left_gravity=False):
diff --git a/tests/test_overrides_gtk.py b/tests/test_overrides_gtk.py
index 887a4f3d..bb8f0bff 100644
--- a/tests/test_overrides_gtk.py
+++ b/tests/test_overrides_gtk.py
@@ -11,6 +11,8 @@ import sys
 import gc
 import warnings
 
+import pytest
+
 from .helper import ignore_gi_deprecation_warnings, capture_glib_warnings
 
 import gi.overrides
@@ -104,6 +106,24 @@ def test_freeze_child_notif():
     assert events.count("pack-type") == 1
 
 
+@unittest.skipUnless(Gtk, 'Gtk not available')
+@unittest.skipIf(Gtk_version == "4.0", "not in gtk4")
+def test_menu_popup():
+    m = Gtk.Menu()
+    with capture_glib_warnings():
+        m.popup(None, None, None, None, 0, 0)
+        m.popdown()
+
+
+@unittest.skipUnless(Gtk, 'Gtk not available')
+@unittest.skipIf(Gtk_version == "4.0", "not in gtk4")
+def test_button_stock():
+    with capture_glib_warnings():
+        button = Gtk.Button(stock=Gtk.STOCK_OK)
+    assert button.props.label == Gtk.STOCK_OK
+    assert button.props.use_stock
+
+
 @unittest.skipUnless(Gtk, 'Gtk not available')
 def test_wrapper_toggle_refs():
     class MyButton(Gtk.Button):
@@ -222,8 +242,7 @@ class TestGtk(unittest.TestCase):
         ui.add_ui_from_string("""<ui>
     <menubar name="menubar1"></menubar>
 </ui>
-"""
-)
+""")
         menubar = ui.get_widget("/menubar1")
         self.assertEqual(type(menubar), Gtk.MenuBar)
 
@@ -356,6 +375,15 @@ class TestGtk(unittest.TestCase):
         button = dialog.get_widget_for_response(Gtk.ResponseType.CLOSE)
         self.assertEqual('gtk-close', button.get_label())
 
+        with pytest.raises(ValueError, match="even number"):
+            dialog.add_buttons('test-button2', 2, 'gtk-close')
+
+    @unittest.skipIf(Gtk_version == "4.0", "not in gtk4")
+    def test_dialog_deprecated_attributes(self):
+        dialog = Gtk.Dialog()
+        assert dialog.action_area == dialog.get_action_area()
+        assert dialog.vbox == dialog.get_content_area()
+
     def test_about_dialog(self):
         dialog = Gtk.AboutDialog()
         self.assertTrue(isinstance(dialog, Gtk.Dialog))
@@ -717,6 +745,11 @@ class TestGtk(unittest.TestCase):
         pixbuf = GdkPixbuf.Pixbuf()
         Gtk.IconSet.new_from_pixbuf(pixbuf)
 
+        with warnings.catch_warnings(record=True) as warn:
+            warnings.simplefilter('always')
+            Gtk.IconSet(pixbuf)
+        assert issubclass(warn[0].category, PyGTKDeprecationWarning)
+
     def test_viewport(self):
         vadjustment = Gtk.Adjustment()
         hadjustment = Gtk.Adjustment()
@@ -855,6 +888,10 @@ class TestBuilder(unittest.TestCase):
 
     def test_add_from_string(self):
         builder = Gtk.Builder()
+
+        with pytest.raises(TypeError):
+            builder.add_from_string(object())
+
         builder.add_from_string(u"")
         builder.add_from_string("")
 
@@ -877,6 +914,9 @@ class TestBuilder(unittest.TestCase):
         builder.add_objects_from_string("", [''])
         builder.add_objects_from_string(get_example(u"รค" * 1000), [''])
 
+        with pytest.raises(TypeError):
+            builder.add_objects_from_string(object(), [])
+
     def test_extract_handler_and_args_object(self):
         class Obj():
             pass
@@ -2056,6 +2096,14 @@ class TestTreeModel(unittest.TestCase):
         filtered[0][1] = 'ONE'
         self.assertEqual(filtered[0][1], 'ONE')
 
+        def foo(store, iter_, data):
+            assert data is None
+            return False
+
+        filtered.set_visible_func(foo)
+        filtered.refilter()
+        assert len(filtered) == 0
+
     def test_list_store_performance(self):
         model = Gtk.ListStore(int, str)
 
@@ -2074,6 +2122,26 @@ class TestTreeModel(unittest.TestCase):
         filt = model.filter_new()
         self.assertTrue(filt is not None)
 
+    def test_tree_store_set(self):
+        tree_store = Gtk.TreeStore(int, int)
+        iter_ = tree_store.append(None)
+        tree_store.set(iter_, 0, 42)
+        assert tree_store.get_value(iter_, 0) == 42
+        assert tree_store.get_value(iter_, 1) == 0
+        tree_store.set(iter_, 0, 42, 1, 24)
+        assert tree_store.get_value(iter_, 1) == 24
+        tree_store.set(iter_, 1, 124)
+        assert tree_store.get_value(iter_, 1) == 124
+
+        with pytest.raises(TypeError):
+            tree_store.set(iter_, 0, 42, "foo", 24)
+        with pytest.raises(TypeError):
+            tree_store.set(iter_, "foo")
+        with pytest.raises(TypeError):
+            tree_store.set(iter_, [1, 2, 3])
+        with pytest.raises(TypeError):
+            tree_store.set(iter_, 0, 42, 24)
+
 
 @unittest.skipIf(sys.platform == "darwin", "hangs")
 @unittest.skipUnless(Gtk, 'Gtk not available')
@@ -2184,12 +2252,31 @@ class TestTreeView(unittest.TestCase):
         self.assertEqual(m, store)
         self.assertEqual(store.get_path(s), firstpath)
 
+        sel.unselect_all()
+        (m, s) = sel.get_selected()
+        assert s is None
+
+        sel.select_path(0)
+        m, r = sel.get_selected_rows()
+        assert m == store
+        assert len(r) == 1
+        assert r[0] == store[0].path
+
+    def test_scroll_to_cell(self):
+        store = Gtk.ListStore(int, str)
+        store.append((0, "foo"))
+        view = Gtk.TreeView()
+        view.set_model(store)
+        view.scroll_to_cell(store[0].path)
+        view.scroll_to_cell(0)
+
 
 @unittest.skipUnless(Gtk, 'Gtk not available')
 class TestTextBuffer(unittest.TestCase):
     def test_text_buffer(self):
         self.assertEqual(Gtk.TextBuffer, gi.overrides.Gtk.TextBuffer)
         buffer = Gtk.TextBuffer()
+        assert buffer.get_tag_table() is not None
         tag = buffer.create_tag('title', font='Sans 18')
 
         self.assertEqual(tag.props.name, 'title')
@@ -2261,6 +2348,15 @@ class TestTextBuffer(unittest.TestCase):
         self.assertRaises(ValueError, buffer.insert_with_tags_by_name,
                           buffer.get_start_iter(), 'HelloHello', 'unknowntag')
 
+    def test_insert(self):
+        buffer = Gtk.TextBuffer()
+        start = buffer.get_bounds()[0]
+        with pytest.raises(TypeError):
+            buffer.insert(start, 42)
+
+        with pytest.raises(TypeError):
+            buffer.insert_at_cursor(42)
+
     def test_text_iter(self):
         try:
             starts_tag = Gtk.TextIter.starts_tag
@@ -2336,6 +2432,18 @@ class TestTextBuffer(unittest.TestCase):
         self.assertEqual(values, [u"c", u"b", u"a"])
 
 
+@unittest.skipUnless(Gtk, 'Gtk not available')
+class TestPaned(unittest.TestCase):
+
+    def test_pack_defaults(self):
+        p = Gtk.Paned()
+        l1 = Gtk.Label()
+        l2 = Gtk.Label()
+        p.pack1(l1)
+        p.pack2(l2)
+        assert p.get_children() == [l1, l2]
+
+
 @unittest.skipUnless(Gtk, 'Gtk not available')
 class TestContainer(unittest.TestCase):
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]