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 new_with_label(self, label):
        return self.widget_type(None, label)

    def new_with_group(self, group):
        return self.widget_type(group)

    def get_label(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.new_with_label('test-radio')
        self.assertEqual(self.get_label(radio), 'test-radio')

    def testGroup(self):
        if self.widget_type is None:
            return
        radio = self.new()
        radio2 = self.new_with_group(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 new_with_group(self, radio):
        obj = self.new()
        obj.set_group(radio)
        return obj

    def new_with_label(self, label):
        return gtk.RadioAction('RadioAction', label, '', '', 0)

class RadioToolButtonTest(RadioTest):
    widget_type = gtk.RadioToolButton
    
    def compareGroups(self, group1, group2):
        return cmp(map(id, group1),
                   map(id, group2))

    def new_with_label(self, label):
        radio = gtk.RadioToolButton(None)
        radio.set_label(label)
        return radio
    
class RadioMenuItem(RadioTest):
    widget_type = gtk.RadioMenuItem

    def get_label(self, obj):
        return obj.get_children()[0].get_text()

if __name__ == '__main__':
    unittest.main()

@@ -203,39 +203,33 @@
 gs)%0A%0A    def new
-_with_l
+L
 abel(self, label
@@ -280,39 +280,33 @@
 el)%0A%0A    def new
-_with_g
+G
 roup(self, group
@@ -351,34 +351,33 @@
 up)%0A%0A    def get
-_l
+L
 abel(self, obj):
@@ -794,23 +794,17 @@
 self.new
-_with_l
+L
 abel('te
@@ -847,18 +847,17 @@
 self.get
-_l
+L
 abel(rad
@@ -1009,23 +1009,17 @@
 self.new
-_with_g
+G
 roup(rad
@@ -1956,15 +1956,9 @@
  new
-_with_g
+G
 roup
@@ -1972,16 +1972,61 @@
 radio):%0A
+        # No constructor, so set it manually%0A
         
@@ -2094,39 +2094,33 @@
 obj%0A%0A    def new
-_with_l
+L
 abel(self, label
@@ -2263,20 +2263,16 @@
 lButton%0A
-    
 %0A    def
@@ -2313,24 +2313,148 @@
 2):%0A        
+# GtkRadioToolButton.set/get_groups return GtkRadioButtons,%0A        # so instead of doing a normal cmp, compare ids%0A        
 return cmp(m
@@ -2472,27 +2472,8 @@
 p1),
-%0A                  
  map
@@ -2502,15 +2502,9 @@
  new
-_with_l
+L
 abel
@@ -2510,32 +2510,149 @@
 l(self, label):%0A
+        # We don't have a constructor for which we can pass in a label%0A        # for, so just call set_label instead%0A
         radio = 
@@ -2814,18 +2814,17 @@
  def get
-_l
+L
 abel(sel
@@ -2824,32 +2824,139 @@
 bel(self, obj):%0A
+        # The label is stored in a gtk.AccelLabel, which is the only%0A        # child of the RadioMenuItem.%0A
         return o
@@ -2971,16 +2971,10 @@
 hild
-ren()%5B0%5D
+()
 .get

Add some comments