import unittest

import gtk

from kiwi.ui.comboentry import ComboEntry
from kiwi.ui.widgets.combo import ProxyComboEntry

class TestComboEntry(unittest.TestCase):
    def testSimple(self):
        entry = ComboEntry()
        self.failUnless(isinstance(entry, ComboEntry))

    def testPopup(self):
        entry = ComboEntry()
        win = gtk.Window()
        win.add(entry)
        win.show_all()
        entry.hide()
        entry.popup()
        entry.popdown()

class TestProxyComboEntry(unittest.TestCase):
    def testSelectItemByData(self):
        entry = ProxyComboEntry()
        entry.prefill([('one', 1), ('two', 2)])
        entry.select_item_by_data(1)
        self.assertEqual(entry.get_text(), 'one')
        entry.select_item_by_data(2)
        self.assertEqual(entry.get_text(), 'two')
        self.assertRaises(KeyError, entry.select_item_by_data, 3)

    def testSelectItemByLabel(self):
        entry = ProxyComboEntry()
        entry.prefill([('one', 1), ('two', 2)])
        entry.select_item_by_label('one')
        self.assertEqual(entry.get_text(), 'one')
        entry.select_item_by_label('two')
        self.assertEqual(entry.get_text(), 'two')
        self.assertRaises(KeyError, entry.select_item_by_label, 'three')

        entry = ProxyComboEntry()
        entry.prefill(['one', 'two'])
        entry.select_item_by_label('one')
        self.assertEqual(entry.get_text(), 'one')
        entry.select_item_by_label('two')
        self.assertEqual(entry.get_text(), 'two')
        self.assertRaises(KeyError, entry.select_item_by_label, 'three')

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

@@ -536,12 +536,13 @@
 emBy
-Data
+Label
 (sel
@@ -602,38 +602,28 @@
 refill(%5B
-(
 'one', 
-1), (
 'two'
-, 2)
 %5D)%0A     
@@ -650,14 +650,19 @@
 _by_
-data(1
+label('one'
 )%0A  
@@ -742,14 +742,19 @@
 _by_
-data(2
+label('two'
 )%0A  
@@ -862,15 +862,22 @@
 _by_
-data, 3
+label, 'three'
 )%0A%0A 
@@ -896,32 +896,42 @@
 electItemByLabel
+InDataMode
 (self):%0A        
@@ -1258,24 +1258,60 @@
 , 'three')%0A%0A
+    def testSelectItemByData(self):%0A
         entr
@@ -1351,36 +1351,46 @@
 ry.prefill(%5B
+(
 'one', 
+1), (
 'two'
+, 2)
 %5D)%0A        e
@@ -1405,35 +1405,30 @@
 ect_item_by_
-label('one'
+data(1
 )%0A        se
@@ -1492,35 +1492,30 @@
 ect_item_by_
-label('two'
+data(2
 )%0A        se
@@ -1611,30 +1611,209 @@
 item_by_
-label, 'three'
+data, 3)%0A%0A    def testSelectItemByDataInTextMode(self):%0A        entry = ProxyComboEntry()%0A        entry.prefill(%5B'one', 'two'%5D)%0A        self.assertRaises(TypeError, entry.select_item_by_data, 1
 )%0A%0Aif __

add another test, refactor