[pygobject/coverage-gtk-overrides] wip
- From: Christoph Reiter <creiter src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject/coverage-gtk-overrides] wip
- Date: Sun, 25 Nov 2018 14:14:27 +0000 (UTC)
commit fb7b74e2f99b06bf94e28e88c20fb96fceaaf1ac
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 | 65 +++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 71 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..afef2f6e 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,15 @@ 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() as warn:
+ m.popup(None, None, None, None, 0, 0)
+ assert len(warn) == 1
+
+
@unittest.skipUnless(Gtk, 'Gtk not available')
def test_wrapper_toggle_refs():
class MyButton(Gtk.Button):
@@ -222,8 +233,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 +366,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 +736,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 +879,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 +905,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 +2087,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)
@@ -2190,6 +2229,7 @@ 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 +2301,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 +2385,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]