[pygobject/wip/jfelder/template-gtk4: 5/8] tests: Update builer tests to work with gtk4




commit 3b5ab03b44d85a25ceb91331f39b2ee6c4c605ec
Author: Jean Felder <jfelder src gnome org>
Date:   Sat Nov 21 15:01:51 2020 +0100

    tests: Update builer tests to work with gtk4

 tests/test_overrides_gtk.py | 59 +++++++++++++++++++++++++++++----------------
 1 file changed, 38 insertions(+), 21 deletions(-)
---
diff --git a/tests/test_overrides_gtk.py b/tests/test_overrides_gtk.py
index 52e781bf..21945d9f 100644
--- a/tests/test_overrides_gtk.py
+++ b/tests/test_overrides_gtk.py
@@ -1125,9 +1125,20 @@ class TestBuilder(unittest.TestCase):
         with pytest.raises(TypeError):
             Gtk._extract_handler_and_args({"foo": []}, "foo")
 
-    @unittest.skipIf(Gtk_version == "4.0", "FIXME!!")
     def test_builder_with_handler_and_args(self):
-        builder = Gtk.Builder()
+        args_collector = []
+
+        def on_signal(*args):
+            args_collector.append(args)
+
+        signals_dict = {'on_signal1': (on_signal, 1, 2),
+                        'on_signal2': on_signal}
+
+        if GTK4:
+            builder = Gtk.Builder(signals_dict)
+        else:
+            builder = Gtk.Builder()
+
         builder.add_from_string("""
             <interface>
               <object class="GIOverrideSignalTest" id="object_sig_test">
@@ -1137,13 +1148,8 @@ class TestBuilder(unittest.TestCase):
             </interface>
             """)
 
-        args_collector = []
-
-        def on_signal(*args):
-            args_collector.append(args)
-
-        builder.connect_signals({'on_signal1': (on_signal, 1, 2),
-                                 'on_signal2': on_signal})
+        if not GTK4:
+            builder.connect_signals(signals_dict)
 
         objects = builder.get_objects()
         self.assertEqual(len(objects), 1)
@@ -1154,9 +1160,20 @@ class TestBuilder(unittest.TestCase):
         self.assertSequenceEqual(args_collector[0], (obj, 1, 2))
         self.assertSequenceEqual(args_collector[1], (obj, ))
 
-    @unittest.skipIf(Gtk_version == "4.0", "FIXME!!")
     def test_builder_with_handler_object(self):
-        builder = Gtk.Builder()
+        args_collector = []
+
+        def on_signal(*args):
+            args_collector.append(args)
+
+        signals_dict = {'on_signal1': (on_signal, 1, 2),
+                        'on_signal2': on_signal}
+
+        if GTK4:
+            builder = Gtk.Builder(signals_dict)
+        else:
+            builder = Gtk.Builder()
+
         builder.add_from_string("""
             <interface>
               <object class="GIOverrideSignalTestObject" id="foo"/>
@@ -1167,13 +1184,9 @@ class TestBuilder(unittest.TestCase):
             </interface>
             """)
 
-        args_collector = []
-
-        def on_signal(*args):
-            args_collector.append(args)
+        if not GTK4:
+            builder.connect_signals(signals_dict)
 
-        builder.connect_signals({'on_signal1': (on_signal, 1, 2),
-                                 'on_signal2': on_signal})
         obj = builder.get_object("foo")
         emitter = builder.get_object("object_sig_test")
         emitter.emit("test-signal")
@@ -1181,7 +1194,6 @@ class TestBuilder(unittest.TestCase):
         assert args_collector[0] == (obj, 1, 2)
         assert args_collector[1] == (obj, )
 
-    @unittest.skipIf(Gtk_version == "4.0", "FIXME!!")
     def test_builder(self):
         self.assertEqual(Gtk.Builder, gi.overrides.Gtk.Builder)
 
@@ -1202,7 +1214,11 @@ class TestBuilder(unittest.TestCase):
                     self.after_sentinel += 1
 
         signal_checker = SignalCheck()
-        builder = Gtk.Builder()
+        signal_checker = SignalCheck()
+        if GTK4:
+            builder = Gtk.Builder(signal_checker)
+        else:
+            builder = Gtk.Builder()
 
         # add object1 to the builder
         builder.add_from_string("""
@@ -1229,8 +1245,9 @@ class TestBuilder(unittest.TestCase):
 </interface>
 """, ['object3'])
 
-        # hook up signals
-        builder.connect_signals(signal_checker)
+        # hook up signals for Gtk3
+        if not GTK4:
+            builder.connect_signals(signal_checker)
 
         # call their notify signals and check sentinel
         objects = builder.get_objects()


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