import unittest
import sys
-import os
sys.path.insert(0, "../")
from compathelper import _long, _unicode, _bytes
import gi.overrides as overrides
import gi.types
+
+class TestRegistry(unittest.TestCase):
+
+ def test_non_gi(self):
+ class MyClass:
+ pass
+
+ try:
+ overrides.override(MyClass)
+ self.fail('unexpected success of overriding non-GI class')
+ except TypeError as e:
+ self.assertTrue('Can not override a type MyClass' in str(e))
+
+
class TestGLib(unittest.TestCase):
def test_gvariant_create(self):
variant = GLib.Variant('i', 42)
self.assertTrue(isinstance(variant, GLib.Variant))
- self.assertEquals(variant.get_int32(), 42)
+ self.assertEqual(variant.get_int32(), 42)
variant = GLib.Variant('s', '')
self.assertTrue(isinstance(variant, GLib.Variant))
- self.assertEquals(variant.get_string(), '')
+ self.assertEqual(variant.get_string(), '')
variant = GLib.Variant('s', 'hello')
self.assertTrue(isinstance(variant, GLib.Variant))
- self.assertEquals(variant.get_string(), 'hello')
+ self.assertEqual(variant.get_string(), 'hello')
# boxed variant
variant = GLib.Variant('v', GLib.Variant('i', 42))
self.assertTrue(isinstance(variant.get_variant(), GLib.Variant))
self.assertEqual(variant.get_type_string(), 'v')
self.assertEqual(variant.get_variant().get_type_string(), 'i')
- self.assertEquals(variant.get_variant().get_int32(), 42)
+ self.assertEqual(variant.get_variant().get_int32(), 42)
variant = GLib.Variant('v', GLib.Variant('v', GLib.Variant('i', 42)))
self.assertEqual(variant.get_type_string(), 'v')
self.assertEqual(variant.get_variant().get_type_string(), 'v')
self.assertEqual(variant.get_variant().get_variant().get_type_string(), 'i')
- self.assertEquals(variant.get_variant().get_variant().get_int32(), 42)
+ self.assertEqual(variant.get_variant().get_variant().get_int32(), 42)
# tuples
variant = GLib.Variant('()', ())
self.assertEqual(variant.get_type_string(), '()')
- self.assertEquals(variant.n_children(), 0)
+ self.assertEqual(variant.n_children(), 0)
variant = GLib.Variant('(i)', (3,))
self.assertEqual(variant.get_type_string(), '(i)')
self.assertTrue(isinstance(variant, GLib.Variant))
- self.assertEquals(variant.n_children(), 1)
+ self.assertEqual(variant.n_children(), 1)
self.assertTrue(isinstance(variant.get_child_value(0), GLib.Variant))
- self.assertEquals(variant.get_child_value(0).get_int32(), 3)
+ self.assertEqual(variant.get_child_value(0).get_int32(), 3)
variant = GLib.Variant('(ss)', ('mec', 'mac'))
self.assertEqual(variant.get_type_string(), '(ss)')
self.assertTrue(isinstance(variant, GLib.Variant))
self.assertTrue(isinstance(variant.get_child_value(0), GLib.Variant))
self.assertTrue(isinstance(variant.get_child_value(1), GLib.Variant))
- self.assertEquals(variant.get_child_value(0).get_string(), 'mec')
- self.assertEquals(variant.get_child_value(1).get_string(), 'mac')
+ self.assertEqual(variant.get_child_value(0).get_string(), 'mec')
+ self.assertEqual(variant.get_child_value(1).get_string(), 'mac')
# nested tuples
variant = GLib.Variant('((si)(ub))', (('hello', -1), (42, True)))
variant = GLib.Variant('a{si}', {})
self.assertTrue(isinstance(variant, GLib.Variant))
self.assertEqual(variant.get_type_string(), 'a{si}')
- self.assertEquals(variant.n_children(), 0)
+ self.assertEqual(variant.n_children(), 0)
variant = GLib.Variant('a{si}', {'': 1, 'key1': 2, 'key2': 3})
self.assertEqual(variant.get_type_string(), 'a{si}')
variant = GLib.Variant('a{sa{si}}', {})
self.assertTrue(isinstance(variant, GLib.Variant))
self.assertEqual(variant.get_type_string(), 'a{sa{si}}')
- self.assertEquals(variant.n_children(), 0)
+ self.assertEqual(variant.n_children(), 0)
- d = {'': {'': 1, 'keyn1': 2},
+ d = {'': {'': 1, 'keyn1': 2},
'key1': {'key11': 11, 'key12': 12}}
variant = GLib.Variant('a{sa{si}}', d)
self.assertEqual(variant.get_type_string(), 'a{sa{si}}')
variant = GLib.Variant('ai', [])
self.assertEqual(variant.get_type_string(), 'ai')
- self.assertEquals(variant.n_children(), 0)
+ self.assertEqual(variant.n_children(), 0)
variant = GLib.Variant('ai', [1, 2])
self.assertEqual(variant.get_type_string(), 'ai')
self.assertTrue(isinstance(variant, GLib.Variant))
self.assertTrue(isinstance(variant.get_child_value(0), GLib.Variant))
self.assertTrue(isinstance(variant.get_child_value(1), GLib.Variant))
- self.assertEquals(variant.get_child_value(0).get_int32(), 1)
- self.assertEquals(variant.get_child_value(1).get_int32(), 2)
+ self.assertEqual(variant.get_child_value(0).get_int32(), 1)
+ self.assertEqual(variant.get_child_value(1).get_int32(), 2)
variant = GLib.Variant('as', [])
self.assertEqual(variant.get_type_string(), 'as')
- self.assertEquals(variant.n_children(), 0)
+ self.assertEqual(variant.n_children(), 0)
variant = GLib.Variant('as', [''])
self.assertEqual(variant.get_type_string(), 'as')
self.assertTrue(isinstance(variant, GLib.Variant))
self.assertTrue(isinstance(variant.get_child_value(0), GLib.Variant))
- self.assertEquals(variant.get_child_value(0).get_string(), '')
+ self.assertEqual(variant.get_child_value(0).get_string(), '')
variant = GLib.Variant('as', ['hello', 'world'])
self.assertEqual(variant.get_type_string(), 'as')
self.assertTrue(isinstance(variant, GLib.Variant))
self.assertTrue(isinstance(variant.get_child_value(0), GLib.Variant))
self.assertTrue(isinstance(variant.get_child_value(1), GLib.Variant))
- self.assertEquals(variant.get_child_value(0).get_string(), 'hello')
- self.assertEquals(variant.get_child_value(1).get_string(), 'world')
+ self.assertEqual(variant.get_child_value(0).get_string(), 'hello')
+ self.assertEqual(variant.get_child_value(1).get_string(), 'world')
# nested arrays
variant = GLib.Variant('aai', [])
self.assertEqual(variant.get_type_string(), 'aai')
- self.assertEquals(variant.n_children(), 0)
+ self.assertEqual(variant.n_children(), 0)
variant = GLib.Variant('aai', [[]])
self.assertEqual(variant.get_type_string(), 'aai')
- self.assertEquals(variant.n_children(), 1)
- self.assertEquals(variant.get_child_value(0).n_children(), 0)
+ self.assertEqual(variant.n_children(), 1)
+ self.assertEqual(variant.get_child_value(0).n_children(), 0)
variant = GLib.Variant('aai', [[1, 2], [3, 4, 5]])
self.assertEqual(variant.get_type_string(), 'aai')
- self.assertEquals(variant.unpack(), [[1, 2], [3, 4, 5]])
+ self.assertEqual(variant.unpack(), [[1, 2], [3, 4, 5]])
#
# complex types
variant = GLib.Variant('(as)', ([],))
self.assertEqual(variant.get_type_string(), '(as)')
- self.assertEquals(variant.n_children(), 1)
- self.assertEquals(variant.get_child_value(0).n_children(), 0)
+ self.assertEqual(variant.n_children(), 1)
+ self.assertEqual(variant.get_child_value(0).n_children(), 0)
variant = GLib.Variant('(as)', ([''],))
self.assertEqual(variant.get_type_string(), '(as)')
- self.assertEquals(variant.n_children(), 1)
- self.assertEquals(variant.get_child_value(0).n_children(), 1)
- self.assertEquals(variant.get_child_value(0).get_child_value(0).get_string(), '')
+ self.assertEqual(variant.n_children(), 1)
+ self.assertEqual(variant.get_child_value(0).n_children(), 1)
+ self.assertEqual(variant.get_child_value(0).get_child_value(0).get_string(), '')
variant = GLib.Variant('(as)', (['hello'],))
self.assertEqual(variant.get_type_string(), '(as)')
- self.assertEquals(variant.n_children(), 1)
- self.assertEquals(variant.get_child_value(0).n_children(), 1)
- self.assertEquals(variant.get_child_value(0).get_child_value(0).get_string(), 'hello')
+ self.assertEqual(variant.n_children(), 1)
+ self.assertEqual(variant.get_child_value(0).n_children(), 1)
+ self.assertEqual(variant.get_child_value(0).get_child_value(0).get_string(), 'hello')
obj = {'a1': (1, True), 'a2': (2, False)}
variant = GLib.Variant('a{s(ib)}', obj)
self.assertEqual(variant.unpack(), obj)
obj = {"frequency": GLib.Variant('t', 738000000),
- "hierarchy": GLib.Variant('i', 0),
- "bandwidth": GLib.Variant('x', 8),
- "code-rate-hp": GLib.Variant('d', 2.0/3.0),
- "constellation": GLib.Variant('s', "QAM16"),
- "guard-interval": GLib.Variant('u', 4),}
+ "hierarchy": GLib.Variant('i', 0),
+ "bandwidth": GLib.Variant('x', 8),
+ "code-rate-hp": GLib.Variant('d', 2.0 / 3.0),
+ "constellation": GLib.Variant('s', "QAM16"),
+ "guard-interval": GLib.Variant('u', 4)}
variant = GLib.Variant('a{sv}', obj)
self.assertEqual(variant.get_type_string(), 'a{sv}')
- self.assertEqual(variant.unpack(), {"frequency": 738000000,
- "hierarchy": 0,
- "bandwidth": 8,
- "code-rate-hp": 2.0/3.0,
- "constellation": "QAM16",
- "guard-interval": 4})
+ self.assertEqual(variant.unpack(),
+ {"frequency": 738000000,
+ "hierarchy": 0,
+ "bandwidth": 8,
+ "code-rate-hp": 2.0 / 3.0,
+ "constellation": "QAM16",
+ "guard-interval": 4
+ })
def test_gvariant_create_errors(self):
# excess arguments
self.assertRaises(TypeError, GLib.Variant, 'i', 'hello')
self.assertRaises(TypeError, GLib.Variant, 's', 42)
self.assertRaises(TypeError, GLib.Variant, '(ss)', 'mec', 'mac')
+ self.assertRaises(TypeError, GLib.Variant, '(s)', 'hello')
# unimplemented data type
self.assertRaises(NotImplementedError, GLib.Variant, 'Q', 1)
res = GLib.Variant('v', GLib.Variant.new_int32(-42)).unpack()
self.assertEqual(res, -42)
- variant = GLib.Variant('v', GLib.Variant('v', GLib.Variant('i', 42)))
+ GLib.Variant('v', GLib.Variant('v', GLib.Variant('i', 42)))
self.assertEqual(res, -42)
# tuple
res = GLib.Variant.new_tuple(GLib.Variant.new_int32(-1),
- GLib.Variant.new_string('hello')).unpack()
+ GLib.Variant.new_string('hello')).unpack()
self.assertEqual(res, (-1, 'hello'))
# array
- vb = GLib.VariantBuilder()
- vb.init(gi._gi.variant_type_from_string('ai'))
+ vb = GLib.VariantBuilder.new(gi._gi.variant_type_from_string('ai'))
vb.add_value(GLib.Variant.new_int32(-1))
vb.add_value(GLib.Variant.new_int32(3))
res = vb.end().unpack()
def test_gvariant_iteration(self):
# array index access
- vb = GLib.VariantBuilder()
- vb.init(gi._gi.variant_type_from_string('ai'))
+ vb = GLib.VariantBuilder.new(gi._gi.variant_type_from_string('ai'))
vb.add_value(GLib.Variant.new_int32(-1))
vb.add_value(GLib.Variant.new_int32(3))
v = vb.end()
# tuple index access
v = GLib.Variant.new_tuple(GLib.Variant.new_int32(-1),
- GLib.Variant.new_string('hello'))
+ GLib.Variant.new_string('hello'))
self.assertEqual(len(v), 2)
self.assertEqual(v[0], -1)
self.assertEqual(v[1], 'hello')
# string iteration
self.assertEqual([x for x in v], ['h', 'e', 'l', 'l', 'o'])
+ def test_variant_split_signature(self):
+ self.assertEqual(GLib.Variant.split_signature('()'), [])
+
+ self.assertEqual(GLib.Variant.split_signature('s'), ['s'])
+
+ self.assertEqual(GLib.Variant.split_signature('as'), ['as'])
+
+ self.assertEqual(GLib.Variant.split_signature('(s)'), ['s'])
+
+ self.assertEqual(GLib.Variant.split_signature('(iso)'), ['i', 's', 'o'])
+
+ self.assertEqual(GLib.Variant.split_signature('(s(ss)i(ii))'),
+ ['s', '(ss)', 'i', '(ii)'])
+
+ self.assertEqual(GLib.Variant.split_signature('(as)'), ['as'])
+
+ self.assertEqual(GLib.Variant.split_signature('(s(ss)iaiaasa(ii))'),
+ ['s', '(ss)', 'i', 'ai', 'aas', 'a(ii)'])
+
+ self.assertEqual(GLib.Variant.split_signature('(a{iv}(ii)((ss)a{s(ss)}))'),
+ ['a{iv}', '(ii)', '((ss)a{s(ss)})'])
+
+ def test_variant_hash(self):
+ v1 = GLib.Variant('s', 'somestring')
+ v2 = GLib.Variant('s', 'somestring')
+ v3 = GLib.Variant('s', 'somestring2')
+
+ self.assertTrue(v2 in set([v1, v3]))
+ self.assertTrue(v2 in frozenset([v1, v3]))
+ self.assertTrue(v2 in {v1: '1', v3: '2'})
+
+ def test_variant_compare(self):
+ # Check if identical GVariant are equal
+
+ def assert_equal(vtype, value):
+ self.assertEqual(GLib.Variant(vtype, value), GLib.Variant(vtype, value))
+
+ def assert_not_equal(vtype1, value1, vtype2, value2):
+ self.assertNotEqual(GLib.Variant(vtype1, value1), GLib.Variant(vtype2, value2))
+
+ numbers = ['y', 'n', 'q', 'i', 'u', 'x', 't', 'h', 'd']
+ for num in numbers:
+ assert_equal(num, 42)
+ assert_not_equal(num, 42, num, 41)
+ assert_not_equal(num, 42, 's', '42')
+
+ assert_equal('s', 'something')
+ assert_not_equal('s', 'something', 's', 'somethingelse')
+ assert_not_equal('s', 'something', 'i', 1234)
+
+ assert_equal('g', 'dustybinqhogx')
+ assert_not_equal('g', 'dustybinqhogx', 'g', 'dustybin')
+ assert_not_equal('g', 'dustybinqhogx', 'i', 1234)
+
+ assert_equal('o', '/dev/null')
+ assert_not_equal('o', '/dev/null', 'o', '/dev/zero')
+ assert_not_equal('o', '/dev/null', 'i', 1234)
+
+ assert_equal('(s)', ('strtuple',))
+ assert_not_equal('(s)', ('strtuple',), '(s)', ('strtuple2',))
+
+ assert_equal('a{si}', {'str': 42})
+ assert_not_equal('a{si}', {'str': 42}, 'a{si}', {'str': 43})
+
+ assert_equal('v', GLib.Variant('i', 42))
+ assert_not_equal('v', GLib.Variant('i', 42), 'v', GLib.Variant('i', 43))
+
+ def test_variant_bool(self):
+ # Check if the GVariant bool matches the unpacked Pythonic bool
+
+ def assert_equals_bool(vtype, value):
+ self.assertEqual(bool(GLib.Variant(vtype, value)), bool(value))
+
+ # simple values
+ assert_equals_bool('b', True)
+ assert_equals_bool('b', False)
+
+ numbers = ['y', 'n', 'q', 'i', 'u', 'x', 't', 'h', 'd']
+ for number in numbers:
+ assert_equals_bool(number, 0)
+ assert_equals_bool(number, 1)
+
+ assert_equals_bool('s', '')
+ assert_equals_bool('g', '')
+ assert_equals_bool('s', 'something')
+ assert_equals_bool('o', '/dev/null')
+ assert_equals_bool('g', 'dustybinqhogx')
+
+ # arrays
+ assert_equals_bool('ab', [True])
+ assert_equals_bool('ab', [False])
+ for number in numbers:
+ assert_equals_bool('a' + number, [])
+ assert_equals_bool('a' + number, [0])
+ assert_equals_bool('as', [])
+ assert_equals_bool('as', [''])
+ assert_equals_bool('ao', [])
+ assert_equals_bool('ao', ['/'])
+ assert_equals_bool('ag', [])
+ assert_equals_bool('ag', [''])
+ assert_equals_bool('aai', [[]])
+
+ # tuples
+ assert_equals_bool('()', ())
+ for number in numbers:
+ assert_equals_bool('(' + number + ')', (0,))
+ assert_equals_bool('(s)', ('',))
+ assert_equals_bool('(o)', ('/',))
+ assert_equals_bool('(g)', ('',))
+ assert_equals_bool('(())', ((),))
+
+ # dictionaries
+ assert_equals_bool('a{si}', {})
+ assert_equals_bool('a{si}', {'': 0})
+
+ # complex types, always True
+ assert_equals_bool('(as)', ([],))
+ assert_equals_bool('a{s(i)}', {'': (0,)})
+
+ # variant types, recursive unpacking
+ assert_equals_bool('v', GLib.Variant('i', 0))
+ assert_equals_bool('v', GLib.Variant('i', 1))
+
+
class TestPango(unittest.TestCase):
def test_default_font_description(self):
desc = Pango.FontDescription()
- self.assertEquals(desc.get_variant(), Pango.Variant.NORMAL)
+ self.assertEqual(desc.get_variant(), Pango.Variant.NORMAL)
def test_font_description(self):
desc = Pango.FontDescription('monospace')
- self.assertEquals(desc.get_family(), 'monospace')
- self.assertEquals(desc.get_variant(), Pango.Variant.NORMAL)
+ self.assertEqual(desc.get_family(), 'monospace')
+ self.assertEqual(desc.get_variant(), Pango.Variant.NORMAL)
def test_layout(self):
self.assertRaises(TypeError, Pango.Layout)
context = Pango.Context()
layout = Pango.Layout(context)
- self.assertEquals(layout.get_context(), context)
+ self.assertEqual(layout.get_context(), context)
+
+ layout.set_markup("Foobar")
+ self.assertEqual(layout.get_text(), "Foobar")
+
class TestGdk(unittest.TestCase):
attributes_mask = Gdk.WindowAttributesType.X | \
Gdk.WindowAttributesType.Y
window = Gdk.Window(None, attribute, attributes_mask)
- self.assertEquals(window.get_window_type(), Gdk.WindowType.CHILD)
+ self.assertEqual(window.get_window_type(), Gdk.WindowType.CHILD)
def test_color(self):
color = Gdk.Color(100, 200, 300)
- self.assertEquals(color.red, 100)
- self.assertEquals(color.green, 200)
- self.assertEquals(color.blue, 300)
- self.assertEquals(color, Gdk.Color(100, 200, 300))
- self.assertNotEquals(color, Gdk.Color(1, 2, 3))
+ self.assertEqual(color.red, 100)
+ self.assertEqual(color.green, 200)
+ self.assertEqual(color.blue, 300)
+ self.assertEqual(color, Gdk.Color(100, 200, 300))
+ self.assertNotEqual(color, Gdk.Color(1, 2, 3))
+
+ def test_color_floats(self):
+ self.assertEqual(Gdk.Color(13107, 21845, 65535),
+ Gdk.Color.from_floats(0.2, 1.0 / 3.0, 1.0))
+
+ self.assertEqual(Gdk.Color(13107, 21845, 65535).to_floats(),
+ (0.2, 1.0 / 3.0, 1.0))
+
+ self.assertEqual(Gdk.RGBA(0.2, 1.0 / 3.0, 1.0, 0.5).to_color(),
+ Gdk.Color.from_floats(0.2, 1.0 / 3.0, 1.0))
+
+ self.assertEqual(Gdk.RGBA.from_color(Gdk.Color(13107, 21845, 65535)),
+ Gdk.RGBA(0.2, 1.0 / 3.0, 1.0, 1.0))
def test_rgba(self):
- self.assertEquals(Gdk.RGBA, overrides.Gdk.RGBA)
+ self.assertEqual(Gdk.RGBA, overrides.Gdk.RGBA)
rgba = Gdk.RGBA(0.1, 0.2, 0.3, 0.4)
- self.assertEquals(rgba, Gdk.RGBA(0.1, 0.2, 0.3, 0.4))
- self.assertNotEquals(rgba, Gdk.RGBA(0.0, 0.2, 0.3, 0.4))
- self.assertEquals(rgba.red, 0.1)
- self.assertEquals(rgba.green, 0.2)
- self.assertEquals(rgba.blue, 0.3)
- self.assertEquals(rgba.alpha, 0.4)
+ self.assertEqual(rgba, Gdk.RGBA(0.1, 0.2, 0.3, 0.4))
+ self.assertNotEqual(rgba, Gdk.RGBA(0.0, 0.2, 0.3, 0.4))
+ self.assertEqual(rgba.red, 0.1)
+ self.assertEqual(rgba.green, 0.2)
+ self.assertEqual(rgba.blue, 0.3)
+ self.assertEqual(rgba.alpha, 0.4)
rgba.green = 0.9
- self.assertEquals(rgba.green, 0.9)
+ self.assertEqual(rgba.green, 0.9)
+
+ # Iterator/tuple convsersion
+ self.assertEqual(tuple(Gdk.RGBA(0.1, 0.2, 0.3, 0.4)),
+ (0.1, 0.2, 0.3, 0.4))
def test_event(self):
event = Gdk.Event.new(Gdk.EventType.CONFIGURE)
- self.assertEquals(event.type, Gdk.EventType.CONFIGURE)
- self.assertEquals(event.send_event, 0)
+ self.assertEqual(event.type, Gdk.EventType.CONFIGURE)
+ self.assertEqual(event.send_event, 0)
event = Gdk.Event.new(Gdk.EventType.DRAG_MOTION)
event.x_root, event.y_root = 0, 5
- self.assertEquals(event.x_root, 0)
- self.assertEquals(event.y_root, 5)
+ self.assertEqual(event.x_root, 0)
+ self.assertEqual(event.y_root, 5)
event = Gdk.Event()
event.type = Gdk.EventType.SCROLL
def button_press_cb(button, event):
self.assertTrue(isinstance(event, Gdk.EventButton))
self.assertTrue(event.type == Gdk.EventType.BUTTON_PRESS)
- self.assertEquals(event.send_event, 0)
- self.assertEquals(event.get_state(), Gdk.ModifierType.CONTROL_MASK)
- self.assertEquals(event.get_root_coords(), (2, 5))
+ self.assertEqual(event.send_event, 0)
+ self.assertEqual(event.get_state(), Gdk.ModifierType.CONTROL_MASK)
+ self.assertEqual(event.get_root_coords(), (2, 5))
event.time = 12345
- self.assertEquals(event.get_time(), 12345)
+ self.assertEqual(event.get_time(), 12345)
w = Gtk.Window()
b = Gtk.Button()
Gdk.EventType.BUTTON_PRESS)
def test_cursor(self):
- self.assertEquals(Gdk.Cursor, overrides.Gdk.Cursor)
+ self.assertEqual(Gdk.Cursor, overrides.Gdk.Cursor)
c = Gdk.Cursor(Gdk.CursorType.WATCH)
self.assertNotEqual(c, None)
- c = Gdk.Cursor(cursor_type = Gdk.CursorType.WATCH)
+ c = Gdk.Cursor(cursor_type=Gdk.CursorType.WATCH)
self.assertNotEqual(c, None)
display_manager = Gdk.DisplayManager.get()
self.assertNotEqual(c, None)
self.assertRaises(ValueError, Gdk.Cursor, 1, 2, 3)
+
class TestGtk(unittest.TestCase):
def test_container(self):
box = Gtk.Box()
+ self.assertTrue(isinstance(box, Gtk.Box))
+ self.assertTrue(isinstance(box, Gtk.Container))
+ self.assertTrue(isinstance(box, Gtk.Widget))
self.assertTrue(box)
label = Gtk.Label()
label2 = Gtk.Label()
self.assertEqual(l, [label, label2])
def test_actions(self):
- self.assertEquals(Gtk.Action, overrides.Gtk.Action)
+ self.assertEqual(Gtk.Action, overrides.Gtk.Action)
self.assertRaises(TypeError, Gtk.Action)
action = Gtk.Action("test", "Test", "Test Action", Gtk.STOCK_COPY)
- self.assertEquals(action.get_name(), "test")
- self.assertEquals(action.get_label(), "Test")
- self.assertEquals(action.get_tooltip(), "Test Action")
- self.assertEquals(action.get_stock_id(), Gtk.STOCK_COPY)
+ self.assertEqual(action.get_name(), "test")
+ self.assertEqual(action.get_label(), "Test")
+ self.assertEqual(action.get_tooltip(), "Test Action")
+ self.assertEqual(action.get_stock_id(), Gtk.STOCK_COPY)
- self.assertEquals(Gtk.RadioAction, overrides.Gtk.RadioAction)
+ self.assertEqual(Gtk.RadioAction, overrides.Gtk.RadioAction)
self.assertRaises(TypeError, Gtk.RadioAction)
action = Gtk.RadioAction("test", "Test", "Test Action", Gtk.STOCK_COPY, 1)
- self.assertEquals(action.get_name(), "test")
- self.assertEquals(action.get_label(), "Test")
- self.assertEquals(action.get_tooltip(), "Test Action")
- self.assertEquals(action.get_stock_id(), Gtk.STOCK_COPY)
- self.assertEquals(action.get_current_value(), 1)
+ self.assertEqual(action.get_name(), "test")
+ self.assertEqual(action.get_label(), "Test")
+ self.assertEqual(action.get_tooltip(), "Test Action")
+ self.assertEqual(action.get_stock_id(), Gtk.STOCK_COPY)
+ self.assertEqual(action.get_current_value(), 1)
def test_actiongroup(self):
- self.assertEquals(Gtk.ActionGroup, overrides.Gtk.ActionGroup)
+ self.assertEqual(Gtk.ActionGroup, overrides.Gtk.ActionGroup)
self.assertRaises(TypeError, Gtk.ActionGroup)
- action_group = Gtk.ActionGroup (name = 'TestActionGroup')
+ action_group = Gtk.ActionGroup(name='TestActionGroup')
callback_data = "callback data"
def test_action_callback_data(action, user_data):
- self.assertEquals(user_data, callback_data);
+ self.assertEqual(user_data, callback_data)
def test_radio_action_callback_data(action, current, user_data):
- self.assertEquals(user_data, callback_data);
+ self.assertEqual(user_data, callback_data)
- action_group.add_actions ([
+ action_group.add_actions([
('test-action1', None, 'Test Action 1',
None, None, test_action_callback_data),
('test-action2', Gtk.STOCK_COPY, 'Test Action 2',
- None, None, test_action_callback_data)], callback_data)
+ None, None, test_action_callback_data)], callback_data)
action_group.add_toggle_actions([
('test-toggle-action1', None, 'Test Toggle Action 1',
None, None, test_action_callback_data, False),
('test-toggle-action2', Gtk.STOCK_COPY, 'Test Toggle Action 2',
- None, None, test_action_callback_data, True)], callback_data)
+ None, None, test_action_callback_data, True)], callback_data)
action_group.add_radio_actions([
('test-radio-action1', None, 'Test Radio Action 1'),
('test-radio-action2', Gtk.STOCK_COPY, 'Test Radio Action 2')], 1,
action.activate()
def test_uimanager(self):
- self.assertEquals(Gtk.UIManager, overrides.Gtk.UIManager)
+ self.assertEqual(Gtk.UIManager, overrides.Gtk.UIManager)
ui = Gtk.UIManager()
- ui.add_ui_from_string(
-"""
-<ui>
+ ui.add_ui_from_string("""<ui>
<menubar name="menubar1"></menubar>
</ui>
"""
)
menubar = ui.get_widget("/menubar1")
- self.assertEquals(type(menubar), Gtk.MenuBar)
+ self.assertEqual(type(menubar), Gtk.MenuBar)
- ag = Gtk.ActionGroup (name="ag1")
+ ag = Gtk.ActionGroup(name="ag1")
ui.insert_action_group(ag)
- ag2 = Gtk.ActionGroup (name="ag2")
+ ag2 = Gtk.ActionGroup(name="ag2")
ui.insert_action_group(ag2)
groups = ui.get_action_groups()
- self.assertEquals(ag, groups[-2])
- self.assertEquals(ag2, groups[-1])
+ self.assertEqual(ag, groups[-2])
+ self.assertEqual(ag2, groups[-1])
def test_builder(self):
- self.assertEquals(Gtk.Builder, overrides.Gtk.Builder)
+ self.assertEqual(Gtk.Builder, overrides.Gtk.Builder)
class SignalTest(GObject.GObject):
__gtype_name__ = "GIOverrideSignalTest"
__gsignals__ = {
- "test-signal": (GObject.SIGNAL_RUN_FIRST,
- GObject.TYPE_NONE,
+ "test-signal": (GObject.SignalFlags.RUN_FIRST,
+ None,
[]),
}
-
class SignalCheck:
def __init__(self):
self.sentinel = 0
+ self.after_sentinel = 0
def on_signal_1(self, *args):
self.sentinel += 1
+ self.after_sentinel += 1
def on_signal_3(self, *args):
self.sentinel += 3
+ def on_signal_after(self, *args):
+ if self.after_sentinel == 1:
+ self.after_sentinel += 1
+
signal_checker = SignalCheck()
builder = Gtk.Builder()
# add object1 to the builder
- builder.add_from_string(
-"""
+ builder.add_from_string("""
<interface>
<object class="GIOverrideSignalTest" id="object1">
+ <signal name="test-signal" after="yes" handler="on_signal_after" />
<signal name="test-signal" handler="on_signal_1" />
</object>
</interface>
""")
# only add object3 to the builder
- builder.add_objects_from_string(
-"""
+ builder.add_objects_from_string("""
<interface>
<object class="GIOverrideSignalTest" id="object2">
<signal name="test-signal" handler="on_signal_2" />
<signal name="test-signal" handler="on_signal_4" />
</object>
</interface>
-
-""",
- ['object3'])
+""", ['object3'])
# hook up signals
builder.connect_signals(signal_checker)
# call their notify signals and check sentinel
objects = builder.get_objects()
- self.assertEquals(len(objects), 2)
+ self.assertEqual(len(objects), 2)
for obj in objects:
obj.emit('test-signal')
- self.assertEquals(signal_checker.sentinel, 4)
+ self.assertEqual(signal_checker.sentinel, 4)
+ self.assertEqual(signal_checker.after_sentinel, 2)
+
+ def test_window(self):
+ # standard Window
+ w = Gtk.Window()
+ self.assertEqual(w.get_property('type'), Gtk.WindowType.TOPLEVEL)
+
+ # type works as keyword argument
+ w = Gtk.Window(type=Gtk.WindowType.POPUP)
+ self.assertEqual(w.get_property('type'), Gtk.WindowType.POPUP)
+
+ # pygtk compatible positional argument
+ w = Gtk.Window(Gtk.WindowType.POPUP)
+ self.assertEqual(w.get_property('type'), Gtk.WindowType.POPUP)
+
+ class TestWindow(Gtk.Window):
+ __gtype_name__ = "TestWindow"
+
+ # works from builder
+ builder = Gtk.Builder()
+ builder.add_from_string('''
+<interface>
+ <object class="GtkWindow" id="win">
+ <property name="type">popup</property>
+ </object>
+ <object class="TestWindow" id="testwin">
+ </object>
+ <object class="TestWindow" id="testpop">
+ <property name="type">popup</property>
+ </object>
+</interface>''')
+ self.assertEqual(builder.get_object('win').get_property('type'),
+ Gtk.WindowType.POPUP)
+ self.assertEqual(builder.get_object('testwin').get_property('type'),
+ Gtk.WindowType.TOPLEVEL)
+ self.assertEqual(builder.get_object('testpop').get_property('type'),
+ Gtk.WindowType.POPUP)
def test_dialogs(self):
- self.assertEquals(Gtk.Dialog, overrides.Gtk.Dialog)
- self.assertEquals(Gtk.AboutDialog, overrides.Gtk.AboutDialog)
- self.assertEquals(Gtk.MessageDialog, overrides.Gtk.MessageDialog)
- self.assertEquals(Gtk.ColorSelectionDialog, overrides.Gtk.ColorSelectionDialog)
- self.assertEquals(Gtk.FileChooserDialog, overrides.Gtk.FileChooserDialog)
- self.assertEquals(Gtk.FontSelectionDialog, overrides.Gtk.FontSelectionDialog)
- self.assertEquals(Gtk.RecentChooserDialog, overrides.Gtk.RecentChooserDialog)
+ self.assertEqual(Gtk.Dialog, overrides.Gtk.Dialog)
+ self.assertEqual(Gtk.AboutDialog, overrides.Gtk.AboutDialog)
+ self.assertEqual(Gtk.MessageDialog, overrides.Gtk.MessageDialog)
+ self.assertEqual(Gtk.ColorSelectionDialog, overrides.Gtk.ColorSelectionDialog)
+ self.assertEqual(Gtk.FileChooserDialog, overrides.Gtk.FileChooserDialog)
+ self.assertEqual(Gtk.FontSelectionDialog, overrides.Gtk.FontSelectionDialog)
+ self.assertEqual(Gtk.RecentChooserDialog, overrides.Gtk.RecentChooserDialog)
# Gtk.Dialog
- dialog = Gtk.Dialog (title='Foo',
- flags=Gtk.DialogFlags.MODAL,
- buttons=('test-button1', 1))
+ dialog = Gtk.Dialog(title='Foo',
+ flags=Gtk.DialogFlags.MODAL,
+ buttons=('test-button1', 1))
+ self.assertTrue(isinstance(dialog, Gtk.Dialog))
+ self.assertTrue(isinstance(dialog, Gtk.Window))
- dialog.add_buttons ('test-button2', 2, Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE)
+ dialog.add_buttons('test-button2', 2, Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE)
- self.assertEquals('Foo', dialog.get_title())
+ self.assertEqual('Foo', dialog.get_title())
self.assertTrue(dialog.get_modal())
- button = dialog.get_widget_for_response (1)
- self.assertEquals('test-button1', button.get_label())
- button = dialog.get_widget_for_response (2)
- self.assertEquals('test-button2', button.get_label())
- button = dialog.get_widget_for_response (Gtk.ResponseType.CLOSE)
- self.assertEquals(Gtk.STOCK_CLOSE, button.get_label())
+ button = dialog.get_widget_for_response(1)
+ self.assertEqual('test-button1', button.get_label())
+ button = dialog.get_widget_for_response(2)
+ self.assertEqual('test-button2', button.get_label())
+ button = dialog.get_widget_for_response(Gtk.ResponseType.CLOSE)
+ self.assertEqual(Gtk.STOCK_CLOSE, button.get_label())
# Gtk.AboutDialog
dialog = Gtk.AboutDialog()
+ self.assertTrue(isinstance(dialog, Gtk.Dialog))
+ self.assertTrue(isinstance(dialog, Gtk.Window))
# Gtk.MessageDialog
- dialog = Gtk.MessageDialog (title='message dialog test',
- flags=Gtk.DialogFlags.MODAL,
- buttons=Gtk.ButtonsType.OK,
- message_format='dude!')
-
- self.assertEquals('message dialog test', dialog.get_title())
+ dialog = Gtk.MessageDialog(title='message dialog test',
+ flags=Gtk.DialogFlags.MODAL,
+ buttons=Gtk.ButtonsType.OK,
+ message_format='dude!')
+ self.assertTrue(isinstance(dialog, Gtk.Dialog))
+ self.assertTrue(isinstance(dialog, Gtk.Window))
+
+ self.assertEqual('message dialog test', dialog.get_title())
self.assertTrue(dialog.get_modal())
text = dialog.get_property('text')
- self.assertEquals('dude!', text)
+ self.assertEqual('dude!', text)
dialog.format_secondary_text('2nd text')
self.assertEqual(dialog.get_property('secondary-text'), '2nd text')
# Gtk.ColorSelectionDialog
dialog = Gtk.ColorSelectionDialog("color selection dialog test")
- self.assertEquals('color selection dialog test', dialog.get_title())
+ self.assertTrue(isinstance(dialog, Gtk.Dialog))
+ self.assertTrue(isinstance(dialog, Gtk.Window))
+ self.assertEqual('color selection dialog test', dialog.get_title())
# Gtk.FileChooserDialog
- dialog = Gtk.FileChooserDialog (title='file chooser dialog test',
- buttons=('test-button1', 1),
- action=Gtk.FileChooserAction.SAVE)
-
- dialog.add_buttons ('test-button2', 2, Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE)
- self.assertEquals('file chooser dialog test', dialog.get_title())
- button = dialog.get_widget_for_response (1)
- self.assertEquals('test-button1', button.get_label())
- button = dialog.get_widget_for_response (2)
- self.assertEquals('test-button2', button.get_label())
- button = dialog.get_widget_for_response (Gtk.ResponseType.CLOSE)
- self.assertEquals(Gtk.STOCK_CLOSE, button.get_label())
+ dialog = Gtk.FileChooserDialog(title='file chooser dialog test',
+ buttons=('test-button1', 1),
+ action=Gtk.FileChooserAction.SAVE)
+ self.assertTrue(isinstance(dialog, Gtk.Dialog))
+ self.assertTrue(isinstance(dialog, Gtk.Window))
+
+ dialog.add_buttons('test-button2', 2, Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE)
+ self.assertEqual('file chooser dialog test', dialog.get_title())
+ button = dialog.get_widget_for_response(1)
+ self.assertEqual('test-button1', button.get_label())
+ button = dialog.get_widget_for_response(2)
+ self.assertEqual('test-button2', button.get_label())
+ button = dialog.get_widget_for_response(Gtk.ResponseType.CLOSE)
+ self.assertEqual(Gtk.STOCK_CLOSE, button.get_label())
action = dialog.get_property('action')
- self.assertEquals(Gtk.FileChooserAction.SAVE, action)
-
+ self.assertEqual(Gtk.FileChooserAction.SAVE, action)
# Gtk.FontSelectionDialog
dialog = Gtk.ColorSelectionDialog("font selection dialog test")
- self.assertEquals('font selection dialog test', dialog.get_title())
+ self.assertTrue(isinstance(dialog, Gtk.Dialog))
+ self.assertTrue(isinstance(dialog, Gtk.Window))
+ self.assertEqual('font selection dialog test', dialog.get_title())
# Gtk.RecentChooserDialog
test_manager = Gtk.RecentManager()
- dialog = Gtk.RecentChooserDialog (title='recent chooser dialog test',
- buttons=('test-button1', 1),
- manager=test_manager)
-
- dialog.add_buttons ('test-button2', 2, Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE)
- self.assertEquals('recent chooser dialog test', dialog.get_title())
- button = dialog.get_widget_for_response (1)
- self.assertEquals('test-button1', button.get_label())
- button = dialog.get_widget_for_response (2)
- self.assertEquals('test-button2', button.get_label())
- button = dialog.get_widget_for_response (Gtk.ResponseType.CLOSE)
- self.assertEquals(Gtk.STOCK_CLOSE, button.get_label())
+ dialog = Gtk.RecentChooserDialog(title='recent chooser dialog test',
+ buttons=('test-button1', 1),
+ manager=test_manager)
+ self.assertTrue(isinstance(dialog, Gtk.Dialog))
+ self.assertTrue(isinstance(dialog, Gtk.Window))
+
+ dialog.add_buttons('test-button2', 2, Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE)
+ self.assertEqual('recent chooser dialog test', dialog.get_title())
+ button = dialog.get_widget_for_response(1)
+ self.assertEqual('test-button1', button.get_label())
+ button = dialog.get_widget_for_response(2)
+ self.assertEqual('test-button2', button.get_label())
+ button = dialog.get_widget_for_response(Gtk.ResponseType.CLOSE)
+ self.assertEqual(Gtk.STOCK_CLOSE, button.get_label())
class TestClass(GObject.GObject):
__gtype_name__ = "GIOverrideTreeAPITest"
self.string_value = string_value
def check(self, int_value, string_value):
- self.tester.assertEquals(int_value, self.int_value)
- self.tester.assertEquals(string_value, self.string_value)
+ self.tester.assertEqual(int_value, self.int_value)
+ self.tester.assertEqual(string_value, self.string_value)
def test_tree_store(self):
- self.assertEquals(Gtk.TreeStore, overrides.Gtk.TreeStore)
- self.assertEquals(Gtk.ListStore, overrides.Gtk.ListStore)
- self.assertEquals(Gtk.TreeModel, overrides.Gtk.TreeModel)
- self.assertEquals(Gtk.TreeViewColumn, overrides.Gtk.TreeViewColumn)
+ self.assertEqual(Gtk.TreeStore, overrides.Gtk.TreeStore)
+ self.assertEqual(Gtk.ListStore, overrides.Gtk.ListStore)
+ self.assertEqual(Gtk.TreeModel, overrides.Gtk.TreeModel)
+ self.assertEqual(Gtk.TreeViewColumn, overrides.Gtk.TreeViewColumn)
class TestPyObject(object):
pass
test_pyobj = TestPyObject()
- test_pydict = {1:1, "2":2, "3":"3"}
- test_pylist = [1,"2", "3"]
+ test_pydict = {1: 1, "2": 2, "3": "3"}
+ test_pylist = [1, "2", "3"]
tree_store = Gtk.TreeStore(int,
'gchararray',
TestGtk.TestClass,
+ GObject.TYPE_PYOBJECT,
object,
object,
object,
GObject.TYPE_CHAR)
parent = None
- for i in range(100):
+ for i in range(97):
label = 'this is child #%d' % i
testobj = TestGtk.TestClass(self, i, label)
parent = tree_store.append(parent, (i,
label,
testobj,
+ testobj,
test_pyobj,
test_pydict,
test_pylist,
i % 2,
bool(i % 2),
i,
- 9223372036854775808,
- -9223372036854775808,
+ GObject.G_MAXULONG,
+ GObject.G_MININT64,
0xffffffffffffffff,
254,
_bytes('a')
))
+ # test set
+ parent = tree_store.append(parent)
+ i = 97
+ label = 'this is child #%d' % i
+ testobj = TestGtk.TestClass(self, i, label)
+ tree_store.set(parent, 0, i,
+ 2, testobj,
+ 1, label,
+ 3, testobj,
+ 4, test_pyobj,
+ 5, test_pydict,
+ 6, test_pylist,
+ 7, i % 2,
+ 8, bool(i % 2),
+ 9, i,
+ 10, GObject.G_MAXULONG,
+ 11, GObject.G_MININT64,
+ 12, 0xffffffffffffffff,
+ 13, 254,
+ 14, _bytes('a'))
+
+ parent = tree_store.append(parent)
+ i = 98
+ label = 'this is child #%d' % i
+ testobj = TestGtk.TestClass(self, i, label)
+ tree_store.set(parent, {0: i,
+ 2: testobj,
+ 1: label,
+ 3: testobj,
+ 4: test_pyobj,
+ 5: test_pydict,
+ 6: test_pylist,
+ 7: i % 2,
+ 8: bool(i % 2),
+ 9: i,
+ 10: GObject.G_MAXULONG,
+ 11: GObject.G_MININT64,
+ 12: 0xffffffffffffffff,
+ 13: 254,
+ 14: _bytes('a')})
+
+ parent = tree_store.append(parent)
+ i = 99
+ label = 'this is child #%d' % i
+ testobj = TestGtk.TestClass(self, i, label)
+ tree_store.set(parent, (0, 2, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14),
+ (i,
+ testobj,
+ label,
+ testobj,
+ test_pyobj,
+ test_pydict,
+ test_pylist,
+ i % 2,
+ bool(i % 2),
+ i,
+ GObject.G_MAXULONG,
+ GObject.G_MININT64,
+ 0xffffffffffffffff,
+ 254,
+ _bytes('a')))
# len gets the number of children in the root node
# since we kept appending to the previous node
# there should only be one child of the root
- self.assertEquals(len(tree_store), 1)
+ self.assertEqual(len(tree_store), 1)
# walk the tree to see if the values were stored correctly
parent = None
treeiter = tree_store.iter_children(parent)
while treeiter:
- i = tree_store.get_value(treeiter, 0)
- s = tree_store.get_value(treeiter, 1)
- obj = tree_store.get_value(treeiter, 2)
- obj.check(i, s)
-
- pyobj = tree_store.get_value(treeiter, 3)
- self.assertEquals(pyobj, test_pyobj)
- pydict = tree_store.get_value(treeiter, 4)
- self.assertEquals(pydict, test_pydict)
- pylist = tree_store.get_value(treeiter, 5)
- self.assertEquals(pylist, test_pylist)
-
- bool_1 = tree_store.get_value(treeiter, 6)
- bool_2 = tree_store.get_value(treeiter, 7)
- self.assertEquals(bool_1, bool_2)
- self.assertTrue(isinstance(bool_1, bool))
- self.assertTrue(isinstance(bool_2, bool))
-
- uint_ = tree_store.get_value(treeiter, 8)
- self.assertEquals(uint_, i)
- ulong_ = tree_store.get_value(treeiter, 9)
- self.assertEquals(ulong_, 9223372036854775808)
- int64_ = tree_store.get_value(treeiter, 10)
- self.assertEquals(int64_, -9223372036854775808)
- uint64_ = tree_store.get_value(treeiter, 11)
- self.assertEquals(uint64_, 0xffffffffffffffff)
- uchar_ = tree_store.get_value(treeiter, 12)
- self.assertEquals(ord(uchar_), 254)
- char_ = tree_store.get_value(treeiter, 13)
- self.assertEquals(char_, 'a')
-
- parent = treeiter
- treeiter = tree_store.iter_children(parent)
-
- self.assertEquals(i, 99)
+ i = tree_store.get_value(treeiter, 0)
+ s = tree_store.get_value(treeiter, 1)
+ obj = tree_store.get_value(treeiter, 2)
+ obj.check(i, s)
+ obj2 = tree_store.get_value(treeiter, 3)
+ self.assertEqual(obj, obj2)
+
+ pyobj = tree_store.get_value(treeiter, 4)
+ self.assertEqual(pyobj, test_pyobj)
+ pydict = tree_store.get_value(treeiter, 5)
+ self.assertEqual(pydict, test_pydict)
+ pylist = tree_store.get_value(treeiter, 6)
+ self.assertEqual(pylist, test_pylist)
+
+ bool_1 = tree_store.get_value(treeiter, 7)
+ bool_2 = tree_store.get_value(treeiter, 8)
+ self.assertEqual(bool_1, bool_2)
+ self.assertTrue(isinstance(bool_1, bool))
+ self.assertTrue(isinstance(bool_2, bool))
+
+ uint_ = tree_store.get_value(treeiter, 9)
+ self.assertEqual(uint_, i)
+ ulong_ = tree_store.get_value(treeiter, 10)
+ self.assertEqual(ulong_, GObject.G_MAXULONG)
+ int64_ = tree_store.get_value(treeiter, 11)
+ self.assertEqual(int64_, GObject.G_MININT64)
+ uint64_ = tree_store.get_value(treeiter, 12)
+ self.assertEqual(uint64_, 0xffffffffffffffff)
+ uchar_ = tree_store.get_value(treeiter, 13)
+ self.assertEqual(ord(uchar_), 254)
+ char_ = tree_store.get_value(treeiter, 14)
+ self.assertEqual(char_, 'a')
+
+ parent = treeiter
+ treeiter = tree_store.iter_children(parent)
+
+ self.assertEqual(i, 99)
+
+ def test_tree_store_signals(self):
+ tree_store = Gtk.TreeStore(int, bool)
+
+ def on_row_inserted(tree_store, tree_path, tree_iter, signal_list):
+ signal_list.append('row-inserted')
+
+ def on_row_changed(tree_store, tree_path, tree_iter, signal_list):
+ signal_list.append('row-changed')
+
+ signals = []
+ tree_store.connect('row-inserted', on_row_inserted, signals)
+ tree_store.connect('row-changed', on_row_changed, signals)
+
+ # adding rows with and without data should only call one signal
+ tree_store.append(None, (0, False))
+ self.assertEqual(signals, ['row-inserted'])
+
+ signals.pop()
+ tree_store.append(None)
+ self.assertEqual(signals, ['row-inserted'])
+
+ signals.pop()
+ tree_store.prepend(None, (0, False))
+ self.assertEqual(signals, ['row-inserted'])
+
+ signals.pop()
+ tree_store.prepend(None)
+ self.assertEqual(signals, ['row-inserted'])
+
+ signals.pop()
+ tree_store.insert(None, 1, (0, False))
+ self.assertEqual(signals, ['row-inserted'])
+
+ signals.pop()
+ tree_store.insert(None, 1)
+ self.assertEqual(signals, ['row-inserted'])
def test_list_store(self):
class TestPyObject(object):
pass
- class TestPyGObject(GObject.Object):
- __gtype_name__ = 'TestPyGObject'
- def __init__(self, i):
- GObject.Object.__init__(self)
- self.sentinal = i + 5
-
test_pyobj = TestPyObject()
- test_pydict = {1:1, "2":2, "3":"3"}
- test_pylist = [1,"2", "3"]
+ test_pydict = {1: 1, "2": 2, "3": "3"}
+ test_pylist = [1, "2", "3"]
- list_store = Gtk.ListStore(int, str, 'GIOverrideTreeAPITest', object, object, object, bool, bool, object)
- for i in range(93):
+ list_store = Gtk.ListStore(int, str, 'GIOverrideTreeAPITest', object, object, object, bool, bool)
+ for i in range(1, 93):
label = 'this is row #%d' % i
testobj = TestGtk.TestClass(self, i, label)
- testpygobj = TestPyGObject(i)
- parent = list_store.append((i,
- label,
- testobj,
- test_pyobj,
- test_pydict,
- test_pylist,
- i % 2,
- bool(i % 2),
- testpygobj))
+ list_store.append((i,
+ label,
+ testobj,
+ test_pyobj,
+ test_pydict,
+ test_pylist,
+ i % 2,
+ bool(i % 2)))
i = 93
label = _unicode('this is row #93')
list_store.set_value(treeiter, 5, test_pylist)
list_store.set_value(treeiter, 6, 1)
list_store.set_value(treeiter, 7, True)
- list_store.set_value(treeiter, 8, TestPyGObject(i))
+
+ # test prepend
+ label = 'this is row #0'
+ list_store.prepend((0,
+ label,
+ TestGtk.TestClass(self, 0, label),
+ test_pyobj,
+ test_pydict,
+ test_pylist,
+ 0,
+ False))
# test automatic unicode->str conversion
i = 94
test_pydict,
test_pylist,
0,
- False,
- TestPyGObject(i)))
+ False))
# add sorted items out of order to test insert* apis
# also test sending in None to not set a column
None,
test_pylist,
1,
- None,
- TestPyGObject(i)))
+ None))
list_store.set_value(treeiter, 0, i)
list_store.set_value(treeiter, 1, label)
list_store.set_value(treeiter, 2, TestGtk.TestClass(self, i, label))
list_store.set_value(treeiter, 4, test_pydict)
list_store.set_value(treeiter, 7, True)
-
+
# this should append
i = 99
label = 'this is row #99'
test_pydict,
test_pylist,
1,
- True,
- TestPyGObject(i)))
+ True))
i = 96
label = 'this is row #96'
test_pydict,
test_pylist,
0,
- False,
- TestPyGObject(i)))
+ False))
i = 98
label = 'this is row #98'
test_pydict,
test_pylist,
0,
- False,
- TestPyGObject(i)))
-
+ False))
i = 95
label = 'this is row #95'
test_pydict,
test_pylist,
1,
- True,
- TestPyGObject(i)))
+ True))
- self.assertEquals(len(list_store), 100)
+ i = 100
+ label = 'this is row #100'
+ treeiter = list_store.append()
+ list_store.set(treeiter, 1, label,
+ 0, i,
+ 2, TestGtk.TestClass(self, i, label),
+ 3, test_pyobj,
+ 4, test_pydict,
+ 5, test_pylist,
+ 6, 0,
+ 7, False)
+ i = 101
+ label = 'this is row #101'
+ treeiter = list_store.append()
+ list_store.set(treeiter, {1: label,
+ 0: i,
+ 2: TestGtk.TestClass(self, i, label),
+ 3: test_pyobj,
+ 4: test_pydict,
+ 5: test_pylist,
+ 6: 1,
+ 7: True})
+ i = 102
+ label = 'this is row #102'
+ treeiter = list_store.append()
+ list_store.set(treeiter, (1, 0, 2, 3, 4, 5, 6, 7),
+ (label,
+ i,
+ TestGtk.TestClass(self, i, label),
+ test_pyobj,
+ test_pydict,
+ test_pylist,
+ 0,
+ False))
+
+ self.assertEqual(len(list_store), 103)
# walk the list to see if the values were stored correctly
i = 0
counter = 0
while treeiter:
i = list_store.get_value(treeiter, 0)
- self.assertEquals(i, counter)
+ self.assertEqual(i, counter)
s = list_store.get_value(treeiter, 1)
obj = list_store.get_value(treeiter, 2)
obj.check(i, s)
pyobj = list_store.get_value(treeiter, 3)
- self.assertEquals(pyobj, test_pyobj)
+ self.assertEqual(pyobj, test_pyobj)
pydict = list_store.get_value(treeiter, 4)
- self.assertEquals(pydict, test_pydict)
+ self.assertEqual(pydict, test_pydict)
pylist = list_store.get_value(treeiter, 5)
- self.assertEquals(pylist, test_pylist)
+ self.assertEqual(pylist, test_pylist)
bool_1 = list_store.get_value(treeiter, 6)
bool_2 = list_store.get_value(treeiter, 7)
- self.assertEquals(bool_1, bool_2)
+ self.assertEqual(bool_1, bool_2)
self.assertTrue(isinstance(bool_1, bool))
self.assertTrue(isinstance(bool_2, bool))
- pygobj = list_store.get_value(treeiter, 8)
- self.assertEquals(pygobj.sentinal, i + 5)
-
treeiter = list_store.iter_next(treeiter)
counter += 1
- self.assertEquals(i, 99)
+ self.assertEqual(i, 102)
+
+ def test_list_store_sort(self):
+ def comp1(model, row1, row2, user_data):
+ v1 = model[row1][1]
+ v2 = model[row2][1]
+
+ # make "m" smaller than anything else
+ if v1.startswith('m') and not v2.startswith('m'):
+ return -1
+ if v2.startswith('m') and not v1.startswith('m'):
+ return 1
+ return (v1 > v2) - (v1 < v2)
+
+ list_store = Gtk.ListStore(int, str)
+ list_store.set_sort_func(2, comp1, None)
+ list_store.append((1, 'apples'))
+ list_store.append((3, 'oranges'))
+ list_store.append((2, 'mango'))
+
+ # not sorted yet, should be original order
+ self.assertEqual([list(i) for i in list_store],
+ [[1, 'apples'], [3, 'oranges'], [2, 'mango']])
+
+ # sort with our custom function
+ list_store.set_sort_column_id(2, Gtk.SortType.ASCENDING)
+ self.assertEqual([list(i) for i in list_store],
+ [[2, 'mango'], [1, 'apples'], [3, 'oranges']])
+
+ list_store.set_sort_column_id(2, Gtk.SortType.DESCENDING)
+ self.assertEqual([list(i) for i in list_store],
+ [[3, 'oranges'], [1, 'apples'], [2, 'mango']])
+
+ def test_list_store_signals(self):
+ list_store = Gtk.ListStore(int, bool)
+
+ def on_row_inserted(list_store, tree_path, tree_iter, signal_list):
+ signal_list.append('row-inserted')
+
+ def on_row_changed(list_store, tree_path, tree_iter, signal_list):
+ signal_list.append('row-changed')
+
+ signals = []
+ list_store.connect('row-inserted', on_row_inserted, signals)
+ list_store.connect('row-changed', on_row_changed, signals)
+
+ # adding rows with and without data should only call one signal
+ list_store.append((0, False))
+ self.assertEqual(signals, ['row-inserted'])
+
+ signals.pop()
+ list_store.append()
+ self.assertEqual(signals, ['row-inserted'])
+
+ signals.pop()
+ list_store.prepend((0, False))
+ self.assertEqual(signals, ['row-inserted'])
+
+ signals.pop()
+ list_store.prepend()
+ self.assertEqual(signals, ['row-inserted'])
+
+ signals.pop()
+ list_store.insert(1, (0, False))
+ self.assertEqual(signals, ['row-inserted'])
+
+ signals.pop()
+ list_store.insert(1)
+ self.assertEqual(signals, ['row-inserted'])
def test_tree_path(self):
p1 = Gtk.TreePath()
p2 = Gtk.TreePath.new_from_string('1:2:3')
self.assertEqual(p1, p2)
self.assertEqual(str(p1), '1:2:3')
- p1 = Gtk.TreePath((1,2,3))
+ p1 = Gtk.TreePath((1, 2, 3))
p2 = Gtk.TreePath.new_from_string('1:2:3')
self.assertEqual(p1, p2)
self.assertEqual(str(p1), '1:2:3')
- self.assertTrue(p1 != None)
- self.assertFalse(p1 == None)
+ self.assertNotEqual(p1, None)
self.assertTrue(p1 > None)
self.assertTrue(p1 >= None)
self.assertFalse(p1 < None)
self.assertFalse(p1 <= None)
+ self.assertEqual(tuple(p1), (1, 2, 3))
+
def test_tree_model(self):
tree_store = Gtk.TreeStore(int, str)
for i in range(100):
label = 'this is row #%d' % i
parent = tree_store.append(None, (DerivedIntType(i), DerivedStrType(label),))
- self.assertNotEquals(parent, None)
+ self.assertNotEqual(parent, None)
for j in range(20):
label = 'this is child #%d of node #%d' % (j, i)
child = tree_store.append(parent, (j, label,))
self.assertTrue(tree_store)
self.assertEqual(len(tree_store), 100)
- for i,row in enumerate(tree_store):
+ self.assertEqual(tree_store.iter_previous(tree_store.get_iter(0)), None)
+
+ for i, row in enumerate(tree_store):
self.assertEqual(row.model, tree_store)
self.assertEqual(row.parent, None)
next = tree_store.iter_next(aiter)
if i < len(tree_store) - 1:
self.assertEqual(tree_store.get_path(next), row.next.path)
+ self.assertEqual(tree_store.get_path(tree_store.iter_previous(next)),
+ tree_store.get_path(aiter))
else:
self.assertEqual(next, None)
self.assertEqual(tree_store.iter_n_children(row.iter), 20)
child = tree_store.iter_children(row.iter)
- for j,childrow in enumerate(row.iterchildren()):
+ for j, childrow in enumerate(row.iterchildren()):
child_path = tree_store.get_path(child)
self.assertEqual(childrow.path, child_path)
self.assertEqual(childrow.parent.path, row.path)
self.assertEqual(i, 99)
# negative indices
- for i in range(-1,-100,-1):
+ for i in range(-1, -100, -1):
i_real = i + 100
self.assertEqual(tree_store[i][0], i_real)
last_row = tree_store[99]
self.assertNotEqual(last_row, None)
- for i,childrow in enumerate(last_row.iterchildren()):
+ for i, childrow in enumerate(last_row.iterchildren()):
if i < 19:
self.assertTrue(tree_store.remove(childrow.iter))
else:
self.assertRaises(ValueError, tree_store.get, aiter, 1, 100)
self.assertEqual(tree_store.get(aiter, 0, 1), (10, 'this is row #10'))
+ # check __delitem__
+ self.assertEqual(len(tree_store), 100)
+ aiter = tree_store.get_iter(10)
+ del tree_store[aiter]
+ self.assertEqual(len(tree_store), 99)
+ self.assertRaises(TypeError, tree_store.__delitem__, None)
+ self.assertRaises(IndexError, tree_store.__delitem__, -101)
+ self.assertRaises(IndexError, tree_store.__delitem__, 101)
+
+ def test_tree_model_edit(self):
+ model = Gtk.ListStore(int, str, float)
+ model.append([1, "one", -0.1])
+ model.append([2, "two", -0.2])
+
+ def set_row(value):
+ model[1] = value
+
+ self.assertRaises(TypeError, set_row, 3)
+ self.assertRaises(TypeError, set_row, "three")
+ self.assertRaises(ValueError, set_row, [])
+ self.assertRaises(ValueError, set_row, [3, "three"])
+
+ model[0] = (3, "three", -0.3)
+
+ def test_tree_row_slice(self):
+ model = Gtk.ListStore(int, str, float)
+ model.append([1, "one", -0.1])
+
+ self.assertEqual([1, "one", -0.1], model[0][:])
+ self.assertEqual([1, "one"], model[0][:2])
+ self.assertEqual(["one", -0.1], model[0][1:])
+ self.assertEqual(["one"], model[0][1:-1])
+ self.assertEqual([1], model[0][:-2])
+ self.assertEqual([], model[0][5:])
+ self.assertEqual([1, -0.1], model[0][0:3:2])
+
+ model[0][:] = (2, "two", -0.2)
+ self.assertEqual([2, "two", -0.2], model[0][:])
+
+ model[0][:2] = (3, "three")
+ self.assertEqual([3, "three", -0.2], model[0][:])
+
+ model[0][1:] = ("four", -0.4)
+ self.assertEqual([3, "four", -0.4], model[0][:])
+
+ model[0][1:-1] = ("five",)
+ self.assertEqual([3, "five", -0.4], model[0][:])
+
+ model[0][0:3:2] = (6, -0.6)
+ self.assertEqual([6, "five", -0.6], model[0][:])
+
+ def set_row1():
+ model[0][5:] = ("doesn't", "matter",)
+
+ self.assertRaises(ValueError, set_row1)
+
+ def set_row2():
+ model[0][:1] = (0, "zero", 0)
+
+ self.assertRaises(ValueError, set_row2)
+
+ def set_row3():
+ model[0][:2] = ("0", 0)
+
+ self.assertRaises(ValueError, set_row3)
+
+ def test_tree_view(self):
+ store = Gtk.ListStore(int, str)
+ store.append((0, "foo"))
+ store.append((1, "bar"))
+ view = Gtk.TreeView()
+ # FIXME: We can't easily call get_cursor() to make sure this works as
+ # expected as we need to realize and focus the column; the following
+ # will raise a Gtk-CRITICAL which we ignore for now
+ old_mask = GLib.log_set_always_fatal(
+ GLib.LogLevelFlags.LEVEL_WARNING | GLib.LogLevelFlags.LEVEL_ERROR)
+ view.set_cursor(store[1].path)
+ view.set_cursor(str(store[1].path))
+
+ view.get_cell_area(store[1].path)
+ view.get_cell_area(str(store[1].path))
+
+ GLib.log_set_always_fatal(old_mask)
+
def test_tree_view_column(self):
cell = Gtk.CellRendererText()
- column = Gtk.TreeViewColumn(title='This is just a test',
- cell_renderer=cell,
- text=0,
- style=2)
+ Gtk.TreeViewColumn(title='This is just a test',
+ cell_renderer=cell,
+ text=0,
+ style=2)
def test_tree_selection(self):
store = Gtk.ListStore(int, str)
self.assertEqual(m, store)
self.assertEqual(store.get_path(s), firstpath)
- sel.select_path((0,0))
+ sel.select_path((0, 0))
(m, s) = sel.get_selected()
self.assertEqual(m, store)
self.assertEqual(store.get_path(s), firstpath)
def test_text_buffer(self):
- self.assertEquals(Gtk.TextBuffer, overrides.Gtk.TextBuffer)
+ self.assertEqual(Gtk.TextBuffer, overrides.Gtk.TextBuffer)
buffer = Gtk.TextBuffer()
- tag = buffer.create_tag ('title', font = 'Sans 18')
+ tag = buffer.create_tag('title', font='Sans 18')
- self.assertEquals(tag.props.name, 'title')
- self.assertEquals(tag.props.font, 'Sans 18')
+ self.assertEqual(tag.props.name, 'title')
+ self.assertEqual(tag.props.font, 'Sans 18')
(start, end) = buffer.get_bounds()
buffer.set_text('Hello Jane Hello Bob')
(start, end) = buffer.get_bounds()
text = buffer.get_text(start, end, False)
- self.assertEquals(text, 'Hello Jane Hello Bob')
+ self.assertEqual(text, 'Hello Jane Hello Bob')
buffer.set_text('')
(start, end) = buffer.get_bounds()
text = buffer.get_text(start, end, False)
- self.assertEquals(text, '')
+ self.assertEqual(text, '')
buffer.insert(end, 'HelloHello')
buffer.insert(end, ' Bob')
(start, end) = buffer.get_bounds()
text = buffer.get_text(start, end, False)
- self.assertEquals(text, 'Hello Jane Hello Bob')
+ self.assertEqual(text, 'Hello Jane Hello Bob')
sel = buffer.get_selection_bounds()
- self.assertEquals(sel, ())
+ self.assertEqual(sel, ())
buffer.select_range(start, end)
sel = buffer.get_selection_bounds()
self.assertTrue(sel[0].equal(start))
self.assertTrue(start.has_tag(tag))
self.assertRaises(ValueError, buffer.insert_with_tags_by_name,
- buffer.get_start_iter(), 'HelloHello', 'unknowntag')
+ buffer.get_start_iter(), 'HelloHello', 'unknowntag')
def test_text_iter(self):
- self.assertEquals(Gtk.TextIter, overrides.Gtk.TextIter)
+ self.assertEqual(Gtk.TextIter, overrides.Gtk.TextIter)
buffer = Gtk.TextBuffer()
buffer.set_text('Hello Jane Hello Bob')
- tag = buffer.create_tag ('title', font = 'Sans 18')
+ tag = buffer.create_tag('title', font='Sans 18')
(start, end) = buffer.get_bounds()
start.forward_chars(10)
buffer.apply_tag(tag, start, end)
self.assertFalse(start.toggles_tag())
def test_buttons(self):
- self.assertEquals(Gtk.Button, overrides.Gtk.Button)
+ self.assertEqual(Gtk.Button, overrides.Gtk.Button)
# test Gtk.Button
button = Gtk.Button()
+ self.assertTrue(isinstance(button, Gtk.Button))
+ self.assertTrue(isinstance(button, Gtk.Container))
+ self.assertTrue(isinstance(button, Gtk.Widget))
button = Gtk.Button(stock=Gtk.STOCK_CLOSE)
- self.assertEquals(Gtk.STOCK_CLOSE, button.get_label())
+ self.assertEqual(Gtk.STOCK_CLOSE, button.get_label())
+ self.assertTrue(button.get_use_stock())
+ self.assertTrue(button.get_use_underline())
+
+ # test Gtk.Button use_stock
+ button = Gtk.Button(label=Gtk.STOCK_CLOSE, use_stock=True, use_underline=True)
+ self.assertEqual(Gtk.STOCK_CLOSE, button.get_label())
self.assertTrue(button.get_use_stock())
self.assertTrue(button.get_use_underline())
# test Gtk.LinkButton
self.assertRaises(TypeError, Gtk.LinkButton)
- button = Gtk.LinkButton('http://www.gtk.org', 'Gtk')
- self.assertEquals('http://www.gtk.org', button.get_uri())
- self.assertEquals('Gtk', button.get_label())
+ button = Gtk.LinkButton('http://www.Gtk.org', 'Gtk')
+ self.assertTrue(isinstance(button, Gtk.Button))
+ self.assertTrue(isinstance(button, Gtk.Container))
+ self.assertTrue(isinstance(button, Gtk.Widget))
+ self.assertEqual('http://www.Gtk.org', button.get_uri())
+ self.assertEqual('Gtk', button.get_label())
def test_inheritance(self):
for name in overrides.Gtk.__all__:
for kl in classes:
if kl.get_name() == name:
self.assertTrue(issubclass(klass, over,),
- "%r does not inherit from override %r" % (klass, over,))
+ "%r does not inherit from override %r" % (klass, over,))
def test_editable(self):
- self.assertEquals(Gtk.Editable, overrides.Gtk.Editable)
+ self.assertEqual(Gtk.Editable, overrides.Gtk.Editable)
# need to use Gtk.Entry because Editable is an interface
- entry=Gtk.Entry()
+ entry = Gtk.Entry()
pos = entry.insert_text('HeWorld', 0)
- self.assertEquals(pos, 7)
+ self.assertEqual(pos, 7)
pos = entry.insert_text('llo ', 2)
- self.assertEquals(pos, 6)
+ self.assertEqual(pos, 6)
text = entry.get_chars(0, 11)
- self.assertEquals('Hello World', text)
+ self.assertEqual('Hello World', text)
def test_label(self):
- label = Gtk.Label('Hello')
- self.assertEquals(label.get_text(), 'Hello')
+ label = Gtk.Label(label='Hello')
+ self.assertTrue(isinstance(label, Gtk.Widget))
+ self.assertEqual(label.get_text(), 'Hello')
def adjustment_check(self, adjustment, value=0.0, lower=0.0, upper=0.0,
step_increment=0.0, page_increment=0.0, page_size=0.0):
- self.assertEquals(adjustment.get_value(), value)
- self.assertEquals(adjustment.get_lower(), lower)
- self.assertEquals(adjustment.get_upper(), upper)
- self.assertEquals(adjustment.get_step_increment(), step_increment)
- self.assertEquals(adjustment.get_page_increment(), page_increment)
- self.assertEquals(adjustment.get_page_size(), page_size)
+ self.assertEqual(adjustment.get_value(), value)
+ self.assertEqual(adjustment.get_lower(), lower)
+ self.assertEqual(adjustment.get_upper(), upper)
+ self.assertEqual(adjustment.get_step_increment(), step_increment)
+ self.assertEqual(adjustment.get_page_increment(), page_increment)
+ self.assertEqual(adjustment.get_page_size(), page_size)
def test_adjustment(self):
- adjustment = Gtk.Adjustment(1, 0, 6, 4, 5, 3)
+ adjustment = Gtk.Adjustment(1, 0, 6, 4, 5, 3)
self.adjustment_check(adjustment, 1, 0, 6, 4, 5, 3)
- adjustment = Gtk.Adjustment(1, 0, 6, 4, 5)
+ adjustment = Gtk.Adjustment(1, 0, 6, 4, 5)
self.adjustment_check(adjustment, 1, 0, 6, 4, 5)
- adjustment = Gtk.Adjustment(1, 0, 6, 4)
+ adjustment = Gtk.Adjustment(1, 0, 6, 4)
self.adjustment_check(adjustment, 1, 0, 6, 4)
- adjustment = Gtk.Adjustment(1, 0, 6)
+ adjustment = Gtk.Adjustment(1, 0, 6)
self.adjustment_check(adjustment, 1, 0, 6)
adjustment = Gtk.Adjustment()
def test_table(self):
table = Gtk.Table()
- self.assertEquals(table.get_size(), (1,1))
- self.assertEquals(table.get_homogeneous(), False)
+ self.assertTrue(isinstance(table, Gtk.Table))
+ self.assertTrue(isinstance(table, Gtk.Container))
+ self.assertTrue(isinstance(table, Gtk.Widget))
+ self.assertEqual(table.get_size(), (1, 1))
+ self.assertEqual(table.get_homogeneous(), False)
table = Gtk.Table(2, 3)
- self.assertEquals(table.get_size(), (2,3))
- self.assertEquals(table.get_homogeneous(), False)
+ self.assertEqual(table.get_size(), (2, 3))
+ self.assertEqual(table.get_homogeneous(), False)
table = Gtk.Table(2, 3, True)
- self.assertEquals(table.get_size(), (2,3))
- self.assertEquals(table.get_homogeneous(), True)
+ self.assertEqual(table.get_size(), (2, 3))
+ self.assertEqual(table.get_homogeneous(), True)
# Test PyGTK interface
table = Gtk.Table(rows=3, columns=2)
- self.assertEquals(table.get_size(), (3,2))
+ self.assertEqual(table.get_size(), (3, 2))
# Test using the actual property names
table = Gtk.Table(n_rows=2, n_columns=3, homogeneous=True)
- self.assertEquals(table.get_size(), (2,3))
- self.assertEquals(table.get_homogeneous(), True)
+ self.assertEqual(table.get_size(), (2, 3))
+ self.assertEqual(table.get_homogeneous(), True)
- label = Gtk.Label('Hello')
+ label = Gtk.Label(label='Hello')
+ self.assertTrue(isinstance(label, Gtk.Widget))
table.attach(label, 0, 1, 0, 1)
- self.assertEquals(label, table.get_children()[0])
+ self.assertEqual(label, table.get_children()[0])
def test_scrolledwindow(self):
sw = Gtk.ScrolledWindow()
+ self.assertTrue(isinstance(sw, Gtk.ScrolledWindow))
+ self.assertTrue(isinstance(sw, Gtk.Container))
+ self.assertTrue(isinstance(sw, Gtk.Widget))
sb = sw.get_hscrollbar()
- self.assertEquals(sw.get_hadjustment(), sb.get_adjustment())
+ self.assertEqual(sw.get_hadjustment(), sb.get_adjustment())
sb = sw.get_vscrollbar()
- self.assertEquals(sw.get_vadjustment(), sb.get_adjustment())
+ self.assertEqual(sw.get_vadjustment(), sb.get_adjustment())
def test_widget_drag_methods(self):
widget = Gtk.Button()
widget.drag_dest_get_track_motion()
widget.drag_dest_set_track_motion(True)
widget.drag_dest_get_target_list()
- widget.drag_dest_set_target_list(Gtk.TargetList.new([Gtk.TargetEntry()]))
+ widget.drag_dest_set_target_list(Gtk.TargetList.new([Gtk.TargetEntry.new('test', 0, 0)]))
widget.drag_dest_unset()
widget.drag_highlight()
widget.drag_source_set_icon_pixbuf(GdkPixbuf.Pixbuf())
widget.drag_source_set_icon_stock("")
widget.drag_source_get_target_list()
- widget.drag_source_set_target_list(Gtk.TargetList.new([Gtk.TargetEntry()]))
+ widget.drag_source_set_target_list(Gtk.TargetList.new([Gtk.TargetEntry.new('test', 0, 0)]))
widget.drag_source_unset()
# these methods cannot be called because they require a valid drag on
self.assertTrue(hasattr(widget.drag_dest_set_proxy, '__call__'))
self.assertTrue(hasattr(widget.drag_get_data, '__call__'))
+ def test_scrollbar(self):
+ # PyGTK compat
+ adjustment = Gtk.Adjustment()
+
+ hscrollbar = Gtk.HScrollbar()
+ vscrollbar = Gtk.VScrollbar()
+ self.assertNotEqual(hscrollbar.props.adjustment, adjustment)
+ self.assertNotEqual(vscrollbar.props.adjustment, adjustment)
+
+ hscrollbar = Gtk.HScrollbar(adjustment)
+ vscrollbar = Gtk.VScrollbar(adjustment)
+ self.assertEqual(hscrollbar.props.adjustment, adjustment)
+ self.assertEqual(vscrollbar.props.adjustment, adjustment)
+
+ def test_iconview(self):
+ # PyGTK compat
+ iconview = Gtk.IconView()
+ self.assertEqual(iconview.props.model, None)
+
+ model = Gtk.ListStore(str)
+ iconview = Gtk.IconView(model)
+ self.assertEqual(iconview.props.model, model)
+
+ def test_toolbutton(self):
+ # PyGTK compat
+ button = Gtk.ToolButton()
+ self.assertEqual(button.props.stock_id, None)
+
+ button = Gtk.ToolButton('gtk-new')
+ self.assertEqual(button.props.stock_id, 'gtk-new')
+
+ icon = Gtk.Image.new_from_stock(Gtk.STOCK_OPEN, Gtk.IconSize.SMALL_TOOLBAR)
+
+ button = Gtk.ToolButton(label='mylabel', icon_widget=icon)
+ self.assertEqual(button.props.label, 'mylabel')
+ self.assertEqual(button.props.icon_widget, icon)
+
+ def test_iconset(self):
+ # PyGTK compat
+ Gtk.IconSet()
+ pixbuf = GdkPixbuf.Pixbuf()
+ Gtk.IconSet(pixbuf)
+
+ def test_viewport(self):
+ # PyGTK compat
+ vadjustment = Gtk.Adjustment()
+ hadjustment = Gtk.Adjustment()
+
+ viewport = Gtk.Viewport(hadjustment=hadjustment,
+ vadjustment=vadjustment)
+
+ self.assertEqual(viewport.props.vadjustment, vadjustment)
+ self.assertEqual(viewport.props.hadjustment, hadjustment)
+
+
class TestGio(unittest.TestCase):
def setUp(self):
- os.environ['GSETTINGS_BACKEND'] = 'memory'
- # support a separate build tree, so look in build dir first
- os.environ['GSETTINGS_SCHEMA_DIR'] = os.environ.get('TESTS_BUILDDIR',
- os.path.dirname(__file__))
self.settings = Gio.Settings('org.gnome.test')
# we change the values in the tests, so set them to predictable start
# value
self.settings.reset('test-array')
def test_file_enumerator(self):
- self.assertEquals(Gio.FileEnumerator, overrides.Gio.FileEnumerator)
+ self.assertEqual(Gio.FileEnumerator, overrides.Gio.FileEnumerator)
f = Gio.file_new_for_path("./")
iter_info = []
break
next_info.append(info.get_name())
- self.assertEquals(iter_info, next_info)
+ self.assertEqual(iter_info, next_info)
def test_gsettings_native(self):
self.assertTrue('test-array' in self.settings.list_keys())
self.assertEqual(len(self.settings), 4)
self.assertTrue('test-array' in self.settings)
self.assertTrue('test-array' in self.settings.keys())
- self.failIf('nonexisting' in self.settings)
- self.failIf(4 in self.settings)
+ self.assertFalse('nonexisting' in self.settings)
+ self.assertFalse(4 in self.settings)
self.assertEqual(bool(self.settings), True)
# get various types
self.assertEqual(len(empty), 0)
self.assertEqual(bool(empty), True)
self.assertEqual(empty.keys(), [])
-
- def test_closures(self):
- # make sure this doesn't crash
- def fake_cb(*args):
- pass
-
- ag = Gtk.AccelGroup()
- ag.connect(Gdk.KEY_l, Gdk.ModifierType.CONTROL_MASK, 0, fake_cb)