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
|
import unittest
from common import gtk
class RadioTest(unittest.TestCase):
widget_type = None
constructor_args = ()
def new(self):
return self.widget_type(*self.constructor_args)
def newLabel(self, label):
return self.widget_type(None, label)
def newGroup(self, group):
return self.widget_type(group)
def getLabel(self, obj):
return obj.get_property('label')
def compareGroups(self, group1, group2):
return self.assertEqual(group1, group2)
def testCreate(self):
if self.widget_type is None:
return
radio = self.new()
self.assert_(isinstance(radio, self.widget_type))
def testLabel(self):
if self.widget_type is None:
return
radio = self.newLabel('test-radio')
self.assertEqual(self.getLabel(radio), 'test-radio')
def testGroup(self):
if self.widget_type is None:
return
radio = self.new()
radio2 = self.newGroup(radio)
self.compareGroups(radio.get_group(), radio2.get_group())
self.compareGroups(radio2.get_group(), radio.get_group())
def testEmptyGroup(self):
if self.widget_type is None:
return
radio = self.new()
radio2 = self.new()
self.compareGroups(radio.get_group(), [radio])
self.compareGroups(radio2.get_group(), [radio2])
radio2.set_group(radio)
self.compareGroups(radio.get_group(), radio2.get_group())
self.compareGroups(radio2.get_group(), radio.get_group())
radio2.set_group(None)
self.compareGroups(radio.get_group(), [radio])
self.compareGroups(radio2.get_group(), [radio2])
class RadioButtonTest(RadioTest):
widget_type = gtk.RadioButton
class RadioActionTest(RadioTest):
widget_type = gtk.RadioAction
constructor_args = ('RadioAction', 'test-radio-action', '', '', 0)
def newGroup(self, radio):
# No constructor, so set it manually
obj = self.new()
obj.set_group(radio)
return obj
def newLabel(self, label):
return gtk.RadioAction('RadioAction', label, '', '', 0)
class RadioToolButtonTest(RadioTest):
widget_type = gtk.RadioToolButton
def compareGroups(self, group1, group2):
# GtkRadioToolButton.set/get_groups return GtkRadioButtons,
# so instead of doing a normal cmp, compare ids
return cmp(map(id, group1), map(id, group2))
def newLabel(self, label):
# We don't have a constructor for which we can pass in a label
# for, so just call set_label instead
radio = gtk.RadioToolButton(None)
radio.set_label(label)
return radio
class RadioMenuItem(RadioTest):
widget_type = gtk.RadioMenuItem
def getLabel(self, obj):
# The label is stored in a gtk.AccelLabel, which is the only
# child of the RadioMenuItem.
return obj.get_child().get_text()
if __name__ == '__main__':
unittest.main()
|