[pygobject] tests: more pygtkcompat coverage



commit 7e6e5ae1cb587576774130a1b256b497665b9c9a
Author: Christoph Reiter <reiter christoph gmail com>
Date:   Sat Feb 16 17:02:35 2019 +0100

    tests: more pygtkcompat coverage

 pygtkcompat/pygtkcompat.py |  24 +----------
 tests/test_pygtkcompat.py  | 102 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 104 insertions(+), 22 deletions(-)
---
diff --git a/pygtkcompat/pygtkcompat.py b/pygtkcompat/pygtkcompat.py
index 85eb35b2..c9711c68 100644
--- a/pygtkcompat/pygtkcompat.py
+++ b/pygtkcompat/pygtkcompat.py
@@ -199,10 +199,7 @@ def enable_gtk(version='3.0'):
     _patch(Gdk, "PixbufLoader", GdkPixbuf.PixbufLoader.new_with_type)
     _patch(Gdk, "pixbuf_new_from_data", GdkPixbuf.Pixbuf.new_from_data)
     _patch(Gdk, "pixbuf_new_from_file", GdkPixbuf.Pixbuf.new_from_file)
-    try:
-        _patch(Gdk, "pixbuf_new_from_file_at_scale", GdkPixbuf.Pixbuf.new_from_file_at_scale)
-    except AttributeError:
-        pass
+    _patch(Gdk, "pixbuf_new_from_file_at_scale", GdkPixbuf.Pixbuf.new_from_file_at_scale)
     _patch(Gdk, "pixbuf_new_from_file_at_size", GdkPixbuf.Pixbuf.new_from_file_at_size)
     _patch(Gdk, "pixbuf_new_from_inline", GdkPixbuf.Pixbuf.new_from_inline)
     _patch(Gdk, "pixbuf_new_from_stream", GdkPixbuf.Pixbuf.new_from_stream)
@@ -230,20 +227,6 @@ def enable_gtk(version='3.0'):
 
     _patch(Gdk, "pixbuf_get_formats", get_formats)
 
-    orig_get_frame_extents = Gdk.Window.get_frame_extents
-
-    def get_frame_extents(window):
-        try:
-            try:
-                rect = Gdk.Rectangle(0, 0, 0, 0)
-            except TypeError:
-                rect = Gdk.Rectangle()
-            orig_get_frame_extents(window, rect)
-        except TypeError:
-            rect = orig_get_frame_extents(window)
-        return rect
-    _patch(Gdk.Window, "get_frame_extents", get_frame_extents)
-
     orig_get_origin = Gdk.Window.get_origin
 
     def get_origin(self):
@@ -412,10 +395,7 @@ def enable_gtk(version='3.0'):
     _patch(Gtk, "image_new_from_file", Gtk.Image.new_from_file)
     _patch(Gtk, "settings_get_default", Gtk.Settings.get_default)
     _patch(Gtk, "window_set_default_icon", Gtk.Window.set_default_icon)
-    try:
-        _patch(Gtk, "clipboard_get", Gtk.Clipboard.get)
-    except AttributeError:
-        pass
+    _patch(Gtk, "clipboard_get", Gtk.Clipboard.get)
 
     # AccelGroup
     _patch(Gtk.AccelGroup, "connect_group", Gtk.AccelGroup.connect)
diff --git a/tests/test_pygtkcompat.py b/tests/test_pygtkcompat.py
index da220b59..3e6a69ea 100644
--- a/tests/test_pygtkcompat.py
+++ b/tests/test_pygtkcompat.py
@@ -6,6 +6,8 @@ from __future__ import absolute_import
 import unittest
 import base64
 
+import pytest
+import gi
 import pygtkcompat
 from pygtkcompat.pygtkcompat import _disable_all as disable_all
 
@@ -114,6 +116,106 @@ class TestGTKCompat(unittest.TestCase):
     def tearDown(self):
         disable_all()
 
+    def test_window_get_frame_extents(self):
+        import gtk
+        import gtk.gdk
+        w = gtk.Window()
+        w.realize()
+        rect = w.window.get_frame_extents()
+        assert isinstance(rect, gtk.gdk.Rectangle)
+
+    def test_window_get_geometry(self):
+        import gtk
+        w = gtk.Window()
+        w.realize()
+        with capture_gi_deprecation_warnings():
+            geo = w.window.get_geometry()
+        assert isinstance(geo, tuple)
+        assert len(geo) == 5
+
+    def test_action_set_tool_item_type(self):
+        import gtk
+        with pytest.warns(gi.PyGIDeprecationWarning):
+            gtk.Action().set_tool_item_type(gtk.Action)
+
+    def test_treeviewcolumn_pack(self):
+        import gtk
+        col = gtk.TreeViewColumn()
+        col.pack_end(gtk.CellRendererText())
+        col.pack_start(gtk.CellRendererText())
+
+    def test_cell_layout_pack(self):
+        import gtk
+        layout = gtk.EntryCompletion()
+        layout.pack_end(gtk.CellRendererText())
+        layout.pack_start(gtk.CellRendererText())
+
+    def test_cell_layout_cell_data_func(self):
+        import gtk
+
+        def func(*args):
+            pass
+
+        layout = gtk.EntryCompletion()
+        render = gtk.CellRendererText()
+        layout.set_cell_data_func(render, func)
+
+    def test_combo_row_separator_func(self):
+        import gtk
+
+        def func(*args):
+            pass
+
+        combo = gtk.ComboBox()
+        combo.set_row_separator_func(func)
+
+    def test_container_install_child_property(self):
+        import gtk
+
+        box = gtk.Box()
+        with pytest.warns(gi.PyGIDeprecationWarning):
+            box.install_child_property(0, None)
+
+    def test_combo_box_new_text(self):
+        import gtk
+
+        combo = gtk.combo_box_new_text()
+        assert isinstance(combo, gtk.ComboBox)
+        combo.append_text("foo")
+
+    def test_scale(self):
+        import gtk
+
+        adjustment = gtk.Adjustment()
+        assert gtk.HScale()
+        assert gtk.HScale(adjustment).get_adjustment() == adjustment
+        adjustment = gtk.Adjustment()
+        assert gtk.VScale()
+        assert gtk.VScale(adjustment).get_adjustment() == adjustment
+
+    def test_stock_add(self):
+        import gtk
+
+        gtk.stock_add([])
+
+    def test_text_view_scroll_to_mark(self):
+        import gtk
+
+        view = gtk.TextView()
+        buf = view.get_buffer()
+        mark = gtk.TextMark(name="foo")
+        buf.add_mark(mark, buf.get_end_iter())
+        view.scroll_to_mark(mark, 0.0)
+
+    def test_window_set_geometry_hints(self):
+        import gtk
+
+        w = gtk.Window()
+        w.set_geometry_hints(None, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
+        w.set_geometry_hints(None, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1)
+        with pytest.raises(TypeError):
+            w.set_geometry_hints(None, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
+
     def test_buttons(self):
         import gtk.gdk
         self.assertEqual(gtk.gdk._2BUTTON_PRESS, 5)


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