1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
# -*- Mode: Python; py-indent-offset: 4 -*-
# vim: tabstop=4 shiftwidth=4 expandtab
import unittest
import base64
import gi
try:
try:
gi.require_version("Gtk", "3.0")
except ValueError as e:
raise ImportError(e)
from gi.repository import Gtk
from gi.repository import Pango
from gi.repository import Atk
from gi.repository import Gdk
(Atk, Gtk, Pango) # pyflakes
import pygtkcompat
pygtkcompat.enable()
pygtkcompat.enable_gtk(version='3.0')
import atk
import pango
import pangocairo
import gtk
import gtk.gdk
except ImportError:
Gtk = None
from helper import capture_gi_deprecation_warnings, capture_glib_warnings
@unittest.skipUnless(Gtk, 'Gtk not available')
class TestATKCompat(unittest.TestCase):
def test_object(self):
self.assertTrue(hasattr(atk, 'Object'))
@unittest.skipUnless(Gtk, 'Gtk not available')
class TestPangoCompat(unittest.TestCase):
def test_layout(self):
self.assertTrue(hasattr(pango, 'Layout'))
@unittest.skipUnless(Gtk, 'Gtk not available')
class TestPangoCairoCompat(unittest.TestCase):
def test_error_underline_path(self):
self.assertTrue(hasattr(pangocairo, 'error_underline_path'))
@unittest.skipUnless(Gtk, 'Gtk not available')
class TestGTKCompat(unittest.TestCase):
def test_buttons(self):
self.assertEqual(Gdk._2BUTTON_PRESS, 5)
self.assertEqual(Gdk.BUTTON_PRESS, 4)
def test_enums(self):
self.assertEqual(gtk.WINDOW_TOPLEVEL, Gtk.WindowType.TOPLEVEL)
self.assertEqual(gtk.PACK_START, Gtk.PackType.START)
def test_flags(self):
self.assertEqual(gtk.EXPAND, Gtk.AttachOptions.EXPAND)
self.assertEqual(gtk.gdk.SHIFT_MASK, Gdk.ModifierType.SHIFT_MASK)
def test_keysyms(self):
import gtk.keysyms
self.assertEqual(gtk.keysyms.Escape, Gdk.KEY_Escape)
self.assertTrue(gtk.keysyms._0, Gdk.KEY_0)
def test_style(self):
widget = gtk.Button()
with capture_gi_deprecation_warnings():
widget.get_style_context().set_state(gtk.STATE_NORMAL)
self.assertTrue(isinstance(widget.style.base[gtk.STATE_NORMAL],
gtk.gdk.Color))
def test_alignment(self):
# Creation of pygtk.Alignment causes hard warnings, ignore this in testing.
with capture_glib_warnings(allow_warnings=True):
a = gtk.Alignment()
self.assertEqual(a.props.xalign, 0.0)
self.assertEqual(a.props.yalign, 0.0)
self.assertEqual(a.props.xscale, 0.0)
self.assertEqual(a.props.yscale, 0.0)
def test_box(self):
box = gtk.Box()
child = gtk.Button()
box.pack_start(child)
expand, fill, padding, pack_type = box.query_child_packing(child)
self.assertTrue(expand)
self.assertTrue(fill)
self.assertEqual(padding, 0)
self.assertEqual(pack_type, gtk.PACK_START)
child = gtk.Button()
box.pack_end(child)
expand, fill, padding, pack_type = box.query_child_packing(child)
self.assertTrue(expand)
self.assertTrue(fill)
self.assertEqual(padding, 0)
self.assertEqual(pack_type, gtk.PACK_END)
def test_combobox_entry(self):
liststore = gtk.ListStore(int, str)
liststore.append((1, 'One'))
liststore.append((2, 'Two'))
liststore.append((3, 'Three'))
# might cause a Pango warning, do not break on this
with capture_glib_warnings(allow_warnings=True):
combo = gtk.ComboBoxEntry(model=liststore)
combo.set_text_column(1)
combo.set_active(0)
self.assertEqual(combo.get_text_column(), 1)
self.assertEqual(combo.get_child().get_text(), 'One')
combo = gtk.combo_box_entry_new()
combo.set_model(liststore)
combo.set_text_column(1)
combo.set_active(0)
self.assertEqual(combo.get_text_column(), 1)
self.assertEqual(combo.get_child().get_text(), 'One')
combo = gtk.combo_box_entry_new_with_model(liststore)
combo.set_text_column(1)
combo.set_active(0)
self.assertEqual(combo.get_text_column(), 1)
self.assertEqual(combo.get_child().get_text(), 'One')
def test_size_request(self):
box = gtk.Box()
with capture_gi_deprecation_warnings():
self.assertEqual(box.size_request(), [0, 0])
def test_pixbuf(self):
gtk.gdk.Pixbuf()
def test_pixbuf_loader(self):
# load a 1x1 pixel PNG from memory
data = base64.b64decode('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP4n8Dw'
'HwAGIAJf85Z3XgAAAABJRU5ErkJggg==')
loader = gtk.gdk.PixbufLoader('png')
loader.write(data)
loader.close()
pixbuf = loader.get_pixbuf()
self.assertEqual(pixbuf.get_width(), 1)
self.assertEqual(pixbuf.get_height(), 1)
def test_pixbuf_formats(self):
formats = gtk.gdk.pixbuf_get_formats()
self.assertEqual(type(formats[0]), dict)
self.assertTrue('name' in formats[0])
self.assertTrue('description' in formats[0])
self.assertTrue('mime_types' in formats[0])
self.assertEqual(type(formats[0]['extensions']), list)
def test_gdk_window(self):
w = gtk.Window()
w.realize()
self.assertEqual(w.get_window().get_origin(), (0, 0))
|