summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSVN-Git Migration <python-modules-team@lists.alioth.debian.org>2015-10-08 09:28:01 -0700
committerSVN-Git Migration <python-modules-team@lists.alioth.debian.org>2015-10-08 09:28:01 -0700
commit5d183b3376d1d9250985468c05678e4c40e0bc61 (patch)
tree3f8f101315c1fcf72193294f1cc7fc12f94b575d /tests
parent928ccf929c26a5344c224303b5108e99c2eb597a (diff)
Imported Upstream version 1.9.9
Diffstat (limited to 'tests')
-rw-r--r--tests/actions.glade48
-rw-r--r--tests/test_ComboBox.py1
-rw-r--r--tests/test_ObjectList.py27
-rw-r--r--tests/test_argcheck.py27
-rw-r--r--tests/test_comboentry.py16
-rw-r--r--tests/test_datatypes.py166
-rw-r--r--tests/test_dateentry.py3
-rw-r--r--tests/test_proxy.py43
-rw-r--r--tests/test_ui.py55
-rw-r--r--tests/ui/diary.py42
-rw-r--r--tests/ui/diary2.py83
-rw-r--r--tests/ui/personalinformation.py115
12 files changed, 563 insertions, 63 deletions
diff --git a/tests/actions.glade b/tests/actions.glade
index 59c9a2f..dae9071 100644
--- a/tests/actions.glade
+++ b/tests/actions.glade
@@ -1,97 +1,97 @@
<?xml version="1.0" ?>
<glade-interface>
- <object class="GtkUIManager" id="uimanager">
+ <widget class="GtkUIManager" id="uimanager">
<child>
- <object class="GtkActionGroup" id="DefaultActions">
+ <widget class="GtkActionGroup" id="DefaultActions">
<child>
- <object class="GtkAction" id="FileMenu">
+ <widget class="GtkAction" id="FileMenu">
<property name="label">_File</property>
<property name="tooltip"></property>
<property name="callback"></property>
<property name="accelerator"></property>
- </object>
+ </widget>
</child>
<child>
- <object class="GtkAction" id="New">
+ <widget class="GtkAction" id="New">
<property name="label">_New</property>
<property name="tooltip">Create a new file</property>
<property name="stock_id">gtk-new</property>
<property name="callback"></property>
<property name="accelerator">&lt;control&gt;N</property>
- </object>
+ </widget>
</child>
<child>
- <object class="GtkAction" id="Open">
+ <widget class="GtkAction" id="Open">
<property name="label">_Open</property>
<property name="tooltip">Open a file</property>
<property name="stock_id">gtk-open</property>
<property name="callback"></property>
<property name="accelerator">&lt;control&gt;O</property>
- </object>
+ </widget>
</child>
<child>
- <object class="GtkAction" id="Save">
+ <widget class="GtkAction" id="Save">
<property name="label">_Save</property>
<property name="tooltip">Save a file</property>
<property name="stock_id">gtk-save</property>
<property name="callback"></property>
<property name="accelerator">&lt;control&gt;S</property>
- </object>
+ </widget>
</child>
<child>
- <object class="GtkAction" id="SaveAs">
+ <widget class="GtkAction" id="SaveAs">
<property name="label">Save _as</property>
<property name="tooltip">Save with a differente name</property>
<property name="stock_id">gtk-save-as</property>
<property name="callback"></property>
<property name="accelerator"></property>
- </object>
+ </widget>
</child>
<child>
- <object class="GtkAction" id="Quit">
+ <widget class="GtkAction" id="Quit">
<property name="label">_Quit</property>
<property name="tooltip">Quit the program</property>
<property name="stock_id">gtk-quit</property>
<property name="callback"></property>
<property name="accelerator">&lt;control&gt;Q</property>
- </object>
+ </widget>
</child>
<child>
- <object class="GtkAction" id="EditMenu">
+ <widget class="GtkAction" id="EditMenu">
<property name="label">_Edit</property>
<property name="tooltip"></property>
<property name="callback"></property>
<property name="accelerator"></property>
- </object>
+ </widget>
</child>
<child>
- <object class="GtkAction" id="Copy">
+ <widget class="GtkAction" id="Copy">
<property name="label">_Copy</property>
<property name="tooltip">Copy selected object into the clipboard</property>
<property name="stock_id">gtk-copy</property>
<property name="callback"></property>
<property name="accelerator">&lt;control&gt;C</property>
- </object>
+ </widget>
</child>
<child>
- <object class="GtkAction" id="Cut">
+ <widget class="GtkAction" id="Cut">
<property name="label">C_ut</property>
<property name="tooltip">Cut selected object into the clipboard</property>
<property name="stock_id">gtk-cut</property>
<property name="callback"></property>
<property name="accelerator">&lt;control&gt;X</property>
- </object>
+ </widget>
</child>
<child>
- <object class="GtkAction" id="Paste">
+ <widget class="GtkAction" id="Paste">
<property name="label">_Paste</property>
<property name="tooltip">Paste object from the Clipboard</property>
<property name="stock_id">gtk-paste</property>
<property name="callback"></property>
<property name="accelerator">&lt;control&gt;V</property>
- </object>
+ </widget>
</child>
- </object>
+ </widget>
</child>
<ui id="initial-state"><![CDATA[<ui>
<menubar action="menubar1" name="menubar1">
@@ -119,7 +119,7 @@
<toolitem action="Paste" name="Paste"/>
</toolbar>
</ui>]]></ui>
- </object>
+ </widget>
<widget class="GtkWindow" id="window1">
<property name="title" translatable="True"></property>
<property name="role"></property>
diff --git a/tests/test_ComboBox.py b/tests/test_ComboBox.py
index da7ac5f..5bebbe9 100644
--- a/tests/test_ComboBox.py
+++ b/tests/test_ComboBox.py
@@ -93,6 +93,7 @@ class BaseModelTest:
self.combo.prefill([('foo', 0),
('bar', 1)])
proxy.add_widget('attr', self.combo)
+ self.combo.show()
def testSelectItemByData(self):
self.combo.select_item_by_data(1)
diff --git a/tests/test_ObjectList.py b/tests/test_ObjectList.py
index 626155a..da9028f 100644
--- a/tests/test_ObjectList.py
+++ b/tests/test_ObjectList.py
@@ -328,5 +328,32 @@ class MethodTest(unittest.TestCase):
self.assertEqual(self.klist.get_previous(item3), item2)
self.assertRaises(ValueError, self.klist.get_previous, None)
+class BooleanDataTests(unittest.TestCase):
+ def setUp(self):
+ self.list = ObjectList([Column('value', data_type=bool, radio=True,
+ editable=True)])
+ self.list.append(Settable(value=True))
+ self.list.append(Settable(value=False))
+
+ def testAddingInstances(self):
+ self.assertEqual(self.list[0].value, True)
+ self.assertEqual(self.list[1].value, False)
+
+ def testSelect(self):
+ self.assertEqual(self.list[0].value, True)
+ self.assertEqual(self.list[1].value, False)
+
+ column = self.list.get_column_by_name('value')
+ treeview_column = self.list.get_treeview_column(column)
+ renderer = treeview_column.get_cell_renderers()
+ renderer[0].emit('toggled', 1)
+
+ self.assertEqual(self.list[0].value, False)
+ self.assertEqual(self.list[1].value, True)
+ renderer[0].emit('toggled', 0)
+
+ self.assertEqual(self.list[0].value, True)
+ self.assertEqual(self.list[1].value, False)
+
if __name__ == '__main__':
unittest.main()
diff --git a/tests/test_argcheck.py b/tests/test_argcheck.py
index 1682149..3eae1a8 100644
--- a/tests/test_argcheck.py
+++ b/tests/test_argcheck.py
@@ -1,8 +1,8 @@
import datetime
-from decimal import Decimal
import unittest
from kiwi.argcheck import argcheck, number, percent
+from kiwi.datatypes import Decimal
class ArgTest(unittest.TestCase):
def testOneArg(self):
@@ -42,9 +42,9 @@ class ArgTest(unittest.TestCase):
class Payment(object):
pass
- @argcheck(Payment, str)
def pay(payment, description):
pass
+ pay = argcheck(Payment, str)(pay)
pay(Payment(), 'foo')
self.assertRaises(TypeError, 'bar', 'bar')
self.assertRaises(TypeError, Payment(), Payment())
@@ -54,22 +54,23 @@ class ArgTest(unittest.TestCase):
pass
class Test:
- @argcheck(int, int)
def method1(self, foo, bar):
return foo + bar
+ method1 = argcheck(int, int)(method1)
- @argcheck(Custom, int, datetime.datetime, int, int,
- float, float)
def method2(self, a, b, c, d, e, f, g=0.0):
return g
+ method2 = argcheck(Custom, int, datetime.datetime,
+ int, int, float, float)(method2)
- @argcheck(str, datetime.datetime, datetime.datetime)
def method3(self, s, date=None, date2=None):
return
+ method3 = argcheck(str, datetime.datetime,
+ datetime.datetime)(method3)
- @argcheck(percent)
def method4(self, n):
return n
+ method4 = argcheck(percent)(method4)
t = Test()
self.assertEqual(t.method1(1, 2), 3)
@@ -95,18 +96,18 @@ class ArgTest(unittest.TestCase):
self.assertRaises(ValueError, t.method4, 101)
def testNone(self):
- @argcheck(datetime.datetime)
def func_none(date=None):
return date
+ func_none = argcheck(datetime.datetime)(func_none)
func_none()
func_none(None)
self.assertRaises(TypeError, func_none, True)
self.assertRaises(TypeError, func_none, date=True)
- @argcheck(str, datetime.datetime, datetime.datetime)
def func_none2(s, date=None, date2=None):
return date
-
+ func_none2 = argcheck(str, datetime.datetime,
+ datetime.datetime)(func_none2)
func_none2('foo')
func_none2('bar', None)
func_none2('baz', None, None)
@@ -121,18 +122,18 @@ class ArgTest(unittest.TestCase):
def testNumber(self):
- @argcheck(number)
def func(n):
return n
+ func = argcheck(number)(func)
self.assertEqual(func(0), 0)
self.assertEqual(func(0L), 0L)
self.assertEqual(func(0.0), 0.0)
self.assertEqual(func(Decimal(0)), Decimal(0))
def testPercent(self):
- @argcheck(percent)
def func(n):
return n
+ func = argcheck(percent)(func)
self.assertEqual(func(50), 50)
self.assertEqual(func(50L), 50L)
self.assertEqual(func(50.0), 50.0)
@@ -148,9 +149,9 @@ class ArgTest(unittest.TestCase):
def testDisable(self):
argcheck.disable()
- @argcheck(str)
def func(s):
pass
+ func = argcheck(str)(func)
func(10)
argcheck.enable()
diff --git a/tests/test_comboentry.py b/tests/test_comboentry.py
index b2d0501..55f9f8a 100644
--- a/tests/test_comboentry.py
+++ b/tests/test_comboentry.py
@@ -90,5 +90,21 @@ class TestProxyComboEntry(unittest.TestCase):
entry.select(2)
self.assertEqual(entry.get_selected(), 2)
+ def testDataMode(self):
+ from kiwi.ui.combomixin import (COMBO_MODE_UNKNOWN,
+ COMBO_MODE_DATA)
+ entry = ProxyComboEntry()
+ self.assertEqual(entry.mode, COMBO_MODE_UNKNOWN)
+ entry.prefill([('one', 1), ('two', 2)])
+ self.assertEqual(entry.mode, COMBO_MODE_DATA)
+
+ def testStringMode(self):
+ from kiwi.ui.combomixin import (COMBO_MODE_UNKNOWN,
+ COMBO_MODE_STRING)
+ entry = ProxyComboEntry()
+ self.assertEqual(entry.mode, COMBO_MODE_UNKNOWN)
+ entry.prefill(['one', 'two'])
+ self.assertEqual(entry.mode, COMBO_MODE_STRING)
+
if __name__ == '__main__':
unittest.main()
diff --git a/tests/test_datatypes.py b/tests/test_datatypes.py
index d82a2b4..4f80e69 100644
--- a/tests/test_datatypes.py
+++ b/tests/test_datatypes.py
@@ -1,25 +1,58 @@
-from decimal import Decimal
+import cPickle
import datetime
-import unittest
import locale
+import unittest
+import sys
-from kiwi.datatypes import currency, converter, ValidationError, ValueUnset
+from gtk import gdk
-import utils
+from kiwi.currency import currency
+from kiwi.datatypes import converter, ValidationError, ValueUnset, \
+ Decimal, BaseConverter
+from kiwi.environ import environ
+
+# pixbuf converter
+from kiwi.ui import proxywidget
+proxywidget # pyflakes
def set_locale(category, name):
# set the date format to the spanish one
try:
- locale.setlocale(category, name)
+ rv = locale.setlocale(category, name)
except locale.Error:
print 'skipping %s, locale not available' % name
return False
return True
+fake = type('fake', (object,), {})
+class FakeConverter(BaseConverter):
+ type = fake
+
class RegistryTest(unittest.TestCase):
def testAdd(self):
self.assertRaises(TypeError, converter.add, object)
+ def testRemove(self):
+ self.assertRaises(TypeError, converter.remove, object)
+
+ def testFake(self):
+ self.assertRaises(KeyError, converter.remove, FakeConverter)
+ converter.add(FakeConverter)
+ self.assertRaises(ValueError, converter.add, FakeConverter)
+ converter.remove(FakeConverter)
+ self.assertRaises(KeyError, converter.remove, FakeConverter)
+
+ def testGetConverters(self):
+ converters = converter.get_converters((Decimal,))
+ # Curreny is a subclass of Decimal, so it should be in converters
+ conv = converter.get_converter(currency)
+ self.assertTrue(conv in converters)
+
+ converters = converter.get_converters((object,))
+ # Object is treated specially. Make sure its in the list
+ conv = converter.get_converter(object)
+ self.assertTrue(conv in converters)
+
class BoolTest(unittest.TestCase):
def setUp(self):
self.conv = converter.get_converter(bool)
@@ -39,11 +72,12 @@ class BoolTest(unittest.TestCase):
class DateTest(unittest.TestCase):
def setUp(self):
+ set_locale(locale.LC_TIME, 'C')
self.date = datetime.date(1979, 2, 12)
self.conv = converter.get_converter(datetime.date)
def tearDown(self):
- set_locale(locale.LC_ALL, 'C')
+ set_locale(locale.LC_TIME, 'C')
def testFromStringES(self):
if not set_locale(locale.LC_TIME, 'es_ES'):
@@ -77,21 +111,46 @@ class DateTest(unittest.TestCase):
self.assertEqual(self.conv.as_string(self.date), "12-02-1979")
+ def testFromStringPortugueseBrazil(self):
+ if not set_locale(locale.LC_TIME, 'Portuguese_Brazil.1252'):
+ return
+
+ self.assertEqual(self.conv.from_string("12/2/1979"), self.date)
+ self.assertEqual(self.conv.from_string("12/02/1979"), self.date)
+
+ # test some invalid dates
+ self.assertRaises(ValidationError,
+ self.conv.from_string, "40/10/2005")
+ self.assertRaises(ValidationError,
+ self.conv.from_string, "30/02/2005")
+
+ def testAsStringPortugueseBrazil(self):
+ if not set_locale(locale.LC_TIME, 'Portuguese_Brazil.1252'):
+ return
+
+ self.assertEqual(self.conv.as_string(self.date), "12/02/1979")
+
class CurrencyTest(unittest.TestCase):
def setUp(self):
+ set_locale(locale.LC_ALL, 'C')
self.conv = converter.get_converter(currency)
def tearDown(self):
set_locale(locale.LC_ALL, 'C')
def testFormatBR(self):
- if not set_locale(locale.LC_MONETARY, 'pt_BR'):
+ if not set_locale(locale.LC_ALL, 'pt_BR'):
return
- self.assertEqual(currency(100).format(), 'R$100')
- self.assertEqual(currency('123.45').format(), 'R$123,45')
- self.assertEqual(currency(12345).format(), 'R$12.345')
- self.assertEqual(currency(-100).format(), 'R$-100')
+ self.assertEqual(currency(100).format(), 'R$ 100')
+ self.assertEqual(currency('123,45').format(), 'R$ 123,45')
+ self.assertEqual(currency(12345).format(), 'R$ 12.345')
+ self.assertEqual(currency(-100).format(), 'R$ -100')
+ try:
+ c = currency('R$1.234.567,40')
+ except:
+ raise AssertionError("monetary separator could not be removed")
+ self.assertEqual(c, Decimal('1234567.40'))
# Sometimes it works, sometimes it doesn''10,000,000.0't
#self.assertEqual(self.conv.from_string('0,5'), currency('0.5'))
@@ -117,6 +176,27 @@ class CurrencyTest(unittest.TestCase):
self.assertEqual(self.conv.as_string(currency(-10)), '$-10.00')
#self.assertEqual(ValidationError, self.conv.as_string, object)
+ def testPickle(self):
+ pickled_var = cPickle.dumps(currency("123.45"))
+ recoverd_var = cPickle.loads(pickled_var)
+ self.assertEqual(recoverd_var.format(), '$123.45')
+
+ def testPickleBR(self):
+ if not set_locale(locale.LC_ALL, 'pt_BR'):
+ return
+
+ pickled_var = cPickle.dumps(currency("123.45"))
+ recoverd_var = cPickle.loads(pickled_var)
+ self.assertEqual(recoverd_var.format(), 'R$ 123,45')
+
+ def testPickleUS(self):
+ if not set_locale(locale.LC_ALL, 'en_US'):
+ return
+
+ pickled_var = cPickle.dumps(currency("12123.45"))
+ recoverd_var = cPickle.loads(pickled_var)
+ self.assertEqual(recoverd_var.format(), '$12,123.45')
+
class UnicodeTest(unittest.TestCase):
def setUp(self):
self.conv = converter.get_converter(unicode)
@@ -227,10 +307,11 @@ class FloatTest(unittest.TestCase):
class DecimalTest(unittest.TestCase):
def setUp(self):
+ set_locale(locale.LC_NUMERIC, 'C')
self.conv = converter.get_converter(Decimal)
def tearDown(self):
- set_locale(locale.LC_ALL, 'C')
+ set_locale(locale.LC_NUMERIC, 'C')
def testFromString(self):
self.assertEqual(self.conv.from_string('-2.5'), Decimal('-2.5'))
@@ -243,16 +324,22 @@ class DecimalTest(unittest.TestCase):
self.assertEqual(self.conv.as_string(Decimal('0.0')), '0.0')
self.assertEqual(self.conv.as_string(Decimal('0.5')), '0.5')
self.assertEqual(self.conv.as_string(Decimal('-0.5')), '-0.5')
- self.assertEqual(self.conv.as_string(Decimal('0.123456789')), '0.123456789')
- self.assertEqual(self.conv.as_string(Decimal('-0.123456789')), '-0.123456789')
- self.assertEqual(self.conv.as_string(Decimal('10000000')), '10000000.0')
- self.assertEqual(self.conv.as_string(Decimal('10000000.0')), '10000000.0')
+ self.assertEqual(self.conv.as_string(Decimal('0.123456789')),
+ '0.123456789')
+ self.assertEqual(self.conv.as_string(Decimal('-0.123456789')),
+ '-0.123456789')
+ self.assertEqual(self.conv.as_string(Decimal('10000000')),
+ '10000000.0')
+ self.assertEqual(self.conv.as_string(Decimal('10000000.0')),
+ '10000000.0')
def testAsStringUS(self):
if not set_locale(locale.LC_NUMERIC, 'en_US'):
return
- self.assertEqual(self.conv.as_string(Decimal('10000000')), '10,000,000.0')
- self.assertEqual(self.conv.as_string(Decimal('10000000.0')), '10,000,000.0')
+ self.assertEqual(self.conv.as_string(Decimal('10000000')),
+ '10,000,000.0')
+ self.assertEqual(self.conv.as_string(Decimal('10000000.0')),
+ '10,000,000.0')
def testAsStringSE(self):
if not set_locale(locale.LC_NUMERIC, 'sv_SE'):
@@ -260,12 +347,47 @@ class DecimalTest(unittest.TestCase):
self.assertEqual(self.conv.as_string(Decimal('0.0')), '0,0')
self.assertEqual(self.conv.as_string(Decimal('0.5')), '0,5')
self.assertEqual(self.conv.as_string(Decimal('-0.5')), '-0,5')
- self.assertEqual(self.conv.as_string(Decimal('0.123456789')), '0,123456789')
- self.assertEqual(self.conv.as_string(Decimal('-0.123456789')), '-0,123456789')
- self.assertEqual(self.conv.as_string(Decimal('10000000')), '10000000,0')
- self.assertEqual(self.conv.as_string(Decimal('10000000.0')), '10000000,0')
+ self.assertEqual(self.conv.as_string(Decimal('0.123456789')),
+ '0,123456789')
+ self.assertEqual(self.conv.as_string(Decimal('-0.123456789')),
+ '-0,123456789')
+ self.assertEqual(self.conv.as_string(Decimal('10000000')),
+ '10000000,0')
+ self.assertEqual(self.conv.as_string(Decimal('10000000.0')),
+ '10000000,0')
+
+class PixbufTest(unittest.TestCase):
+ def setUp(self):
+ self.conv = converter.get_converter(gdk.Pixbuf)
+
+ def testPNGAsString(self):
+ if sys.platform == 'win32':
+ return
+ file_name = environ.find_resource('pixmap', 'validation-error-16.png')
+ f = file(file_name)
+ png_string = f.read()
+ f.close()
+ pixbuf = self.conv.from_string(png_string)
+ string = self.conv.as_string(pixbuf)
+ # XXX Not always equal. need to investigate
+ #self.assertEqual(string, png_string)
+
+ # Compare png header
+ self.assertEqual(string[0:8], '\x89\x50\x4e\x47\x0d\x0a\x1a\x0a')
+
+ def testPNGFromString(self):
+ if sys.platform == 'win32':
+ return
+ file_name = environ.find_resource('pixmap', 'validation-error-16.png')
+ f = file(file_name)
+ png_string = f.read()
+ f.close()
+
+ pixbuf = self.conv.from_string(png_string)
+ self.assertEqual(pixbuf.get_width(), 17)
+ self.assertEqual(pixbuf.get_height(), 17)
if __name__ == "__main__":
unittest.main()
diff --git a/tests/test_dateentry.py b/tests/test_dateentry.py
index 382fee3..0f3de31 100644
--- a/tests/test_dateentry.py
+++ b/tests/test_dateentry.py
@@ -1,4 +1,3 @@
-import sys
import datetime
import unittest
@@ -9,8 +8,6 @@ class TestDateEntry(unittest.TestCase):
self.date = datetime.date.today()
def testGetSetDate(self):
- if sys.platform == 'win32':
- return
entry = DateEntry()
entry.set_date(self.date)
self.assertEqual(entry.get_date(), self.date)
diff --git a/tests/test_proxy.py b/tests/test_proxy.py
index f8338d1..d04ef19 100644
--- a/tests/test_proxy.py
+++ b/tests/test_proxy.py
@@ -1,8 +1,14 @@
+import sys
import unittest
+from gtk import gdk
+
from kiwi import ValueUnset
+from kiwi.datatypes import converter
+from kiwi.environ import environ
from kiwi.python import Settable
from kiwi.ui.proxy import Proxy
+from kiwi.ui.widgets.button import ProxyButton
from kiwi.ui.widgets.checkbutton import ProxyCheckButton
from kiwi.ui.widgets.entry import ProxyEntry
from kiwi.ui.widgets.label import ProxyLabel
@@ -22,6 +28,7 @@ class FakeView(object):
setattr(self, name, widget)
self.widgets.append(name)
+ widget.show()
return widget
def handler_block(self, *args):
@@ -40,7 +47,8 @@ class Model(Settable):
spinbutton=100,
textview='sliff',
comboentry='CE1',
- combobox='CB1')
+ combobox='CB1',
+ button='button')
class TestProxy(unittest.TestCase):
def setUp(self):
@@ -49,6 +57,9 @@ class TestProxy(unittest.TestCase):
self.view.add('entry', str, ProxyEntry)
self.view.add('label', str, ProxyLabel)
self.view.add('spinbutton', int, ProxySpinButton)
+ self.view.add('button', str, ProxyButton)
+ self.view.add('buttonpixbuf', gdk.Pixbuf, ProxyButton)
+
self.view.add('textview', str, ProxyTextView)
self.radio_first = self.view.add('radiobutton', str, ProxyRadioButton)
self.radio_first.set_property('data_value', 'first')
@@ -58,9 +69,11 @@ class TestProxy(unittest.TestCase):
self.comboentry = self.view.add('comboentry', str, ProxyComboEntry)
self.comboentry.prefill(['CE1','CE2','CE3'])
+ self.comboentry.show()
self.combobox = self.view.add('combobox', str, ProxyComboBox)
self.combobox.prefill(['CB1','CB2','CB3'])
+ self.combobox.show()
self.model = Model()
self.proxy = Proxy(self.view, self.model, self.view.widgets)
@@ -109,6 +122,28 @@ class TestProxy(unittest.TestCase):
self.view.combobox.select('CB2')
self.assertEqual(self.model.combobox, 'CB2')
+ def testButton(self):
+ self.assertEqual(self.model.button, 'button')
+ self.view.button.update('sliff')
+ self.assertEqual(self.model.button, 'sliff')
+
+ def testButtonPixbuf(self):
+ if sys.platform == 'win32':
+ return
+
+ conv = converter.get_converter(gdk.Pixbuf)
+
+ filename = environ.find_resource('pixmap', 'validation-error-16.png')
+ pixbuf = gdk.pixbuf_new_from_file(filename)
+ self.assertEqual(self.view.buttonpixbuf.data_type, gdk.Pixbuf)
+ self.view.buttonpixbuf.update(pixbuf)
+ self.assertEqual(type(self.view.buttonpixbuf.read()), gdk.Pixbuf)
+ self.assertEqual(conv.as_string(self.model.buttonpixbuf),
+ conv.as_string(pixbuf))
+ self.view.buttonpixbuf.update(None)
+ self.assertEqual(self.view.buttonpixbuf.read(), None)
+ self.assertEqual(self.model.buttonpixbuf, None)
+
def testEmptyModel(self):
self.radio_second.set_active(True)
@@ -121,3 +156,9 @@ class TestProxy(unittest.TestCase):
self.assertEqual(self.view.textview.read(), '')
self.assertEqual(self.view.comboentry.read(), None)
self.assertEqual(self.view.combobox.read(), 'CB1')
+
+ def testValueUnset(self):
+ self.view.entry.update(ValueUnset)
+ self.assertEqual(self.view.entry.get_text(), "")
+ self.view.spinbutton.update(ValueUnset)
+ self.assertEqual(self.view.spinbutton.get_text(), "")
diff --git a/tests/test_ui.py b/tests/test_ui.py
new file mode 100644
index 0000000..9bfe1b7
--- /dev/null
+++ b/tests/test_ui.py
@@ -0,0 +1,55 @@
+import os
+import sys
+import traceback
+import unittest
+import popen2
+
+def setup(self, rootdir):
+ self._dir = os.getcwd()
+ os.chdir(rootdir)
+
+def teardown(self):
+ os.chdir(self._dir)
+
+def test_filename(rootdir, filename):
+ cmd = '%s %s %s' % (sys.executable,
+ os.path.join(rootdir, 'bin', 'kiwi-ui-test'),
+ os.path.join('tests', 'ui', filename))
+ if sys.platform == 'win32':
+ status = os.system(cmd)
+ else:
+ p = popen2.Popen3(cmd)
+ status = os.waitpid(p.pid, 0)[1]
+
+ if status != 0:
+ raise AssertionError("UI Test %s failed" % filename)
+
+def create():
+ testdir = os.path.dirname(__file__)
+ uidir = os.path.join(testdir, 'ui')
+ rootdir = os.path.dirname(testdir)
+
+ tests = {}
+ tests['setUp'] = lambda self, rootdir=rootdir: setup(self, rootdir)
+ tests['tearDown'] = lambda self, rootdir=rootdir: teardown(self)
+
+ for filename in os.listdir(uidir):
+ if not filename.endswith('.py'):
+ continue
+ name = 'test_' + filename[:-3]
+
+ full = os.path.join(uidir, filename)
+
+ func = lambda self, filename=filename: test_filename(rootdir, filename)
+ try:
+ func.__name__ = name
+ except TypeError:
+ pass
+ tests[name] = func
+
+ return type('TestUI', (unittest.TestCase,), tests)
+
+# Disable UI tests on win32, they do not quite work yet.
+if sys.platform != 'win32':
+ TestUI = create()
+
diff --git a/tests/ui/diary.py b/tests/ui/diary.py
new file mode 100644
index 0000000..a753c01
--- /dev/null
+++ b/tests/ui/diary.py
@@ -0,0 +1,42 @@
+from kiwi.ui.test.player import Player
+
+player = Player(['examples/framework/diary/diary.py'])
+app = player.get_app()
+
+player.wait_for_window("Diary")
+app.Diary.add.clicked()
+app.Diary.title.set_text("New title")
+app.Diary.title.set_text("")
+app.Diary.title.set_text("F")
+app.Diary.title.set_text("Fo")
+app.Diary.title.set_text("Foo")
+app.Diary.title.set_text("Foob")
+app.Diary.title.set_text("Fooba")
+app.Diary.title.set_text("Foobar")
+app.Diary.add.clicked()
+app.Diary.title.set_text("")
+app.Diary.title.set_text("New title")
+app.Diary.ObjectList.select_paths(['1'])
+app.Diary.title.set_text("")
+app.Diary.title.set_text("T")
+app.Diary.title.set_text("Te")
+app.Diary.title.set_text("Tes")
+app.Diary.title.set_text("Test")
+app.Diary.title.set_text("Testi")
+app.Diary.title.set_text("Testin")
+app.Diary.title.set_text("Testing")
+app.Diary.title.set_text("")
+app.Diary.title.set_text("Foobar")
+app.Diary.ObjectList.select_paths(['0'])
+app.Diary.remove.clicked()
+app.Diary.ObjectList.select_paths([])
+app.Diary.title.set_text("")
+app.Diary.title.set_text("Testing")
+app.Diary.ObjectList.select_paths(['0'])
+app.Diary.period.clicked()
+app.Diary.evening.clicked()
+app.Diary.remove.clicked()
+app.Diary.ObjectList.select_paths([])
+player.delete_window("Diary")
+
+player.finish()
diff --git a/tests/ui/diary2.py b/tests/ui/diary2.py
new file mode 100644
index 0000000..d71081c
--- /dev/null
+++ b/tests/ui/diary2.py
@@ -0,0 +1,83 @@
+from kiwi.ui.test.player import Player
+
+player = Player(['examples/framework/diary/diary2.py'])
+app = player.get_app()
+
+player.wait_for_window("Diary")
+app.Diary.add.clicked()
+app.Diary.title.set_text("Untitled")
+app.Diary.ObjectList.select_paths(['0'])
+app.Diary.title.set_text("")
+app.Diary.title.set_text("F")
+app.Diary.title.set_text("Fi")
+app.Diary.title.set_text("Fir")
+app.Diary.title.set_text("Firs")
+app.Diary.title.set_text("First")
+app.Diary.add.clicked()
+app.Diary.title.set_text("")
+app.Diary.title.set_text("Untitled")
+app.Diary.ObjectList.select_paths(['1'])
+app.Diary.title.set_text("")
+app.Diary.title.set_text("S")
+app.Diary.title.set_text("Se")
+app.Diary.title.set_text("Sec")
+app.Diary.title.set_text("Seco")
+app.Diary.title.set_text("Secon")
+app.Diary.title.set_text("Second")
+app.Diary.period.clicked()
+app.Diary.afternoon.clicked()
+app.Diary.add.clicked()
+app.Diary.afternoon.clicked()
+app.Diary.period.clicked()
+app.Diary.title.set_text("")
+app.Diary.title.set_text("Untitled")
+app.Diary.ObjectList.select_paths(['2'])
+app.Diary.title.set_text("")
+app.Diary.title.set_text("T")
+app.Diary.title.set_text("Th")
+app.Diary.title.set_text("Thi")
+app.Diary.title.set_text("Thir")
+app.Diary.title.set_text("Third")
+app.Diary.period.clicked()
+app.Diary.evening.clicked()
+app.Diary.evening.clicked()
+app.Diary.afternoon.clicked()
+app.Diary.title.set_text("")
+app.Diary.title.set_text("Second")
+app.Diary.ObjectList.select_paths(['1'])
+app.Diary.afternoon.clicked()
+app.Diary.period.clicked()
+app.Diary.title.set_text("")
+app.Diary.title.set_text("First")
+app.Diary.ObjectList.select_paths(['0'])
+app.Diary.period.clicked()
+app.Diary.afternoon.clicked()
+app.Diary.title.set_text("")
+app.Diary.title.set_text("Second")
+app.Diary.ObjectList.select_paths(['1'])
+app.Diary.afternoon.clicked()
+app.Diary.evening.clicked()
+app.Diary.title.set_text("")
+app.Diary.title.set_text("Third")
+app.Diary.ObjectList.select_paths(['2'])
+app.Diary.remove.clicked()
+app.Diary.ObjectList.select_paths([])
+app.Diary.evening.clicked()
+app.Diary.afternoon.clicked()
+app.Diary.title.set_text("")
+app.Diary.title.set_text("Second")
+app.Diary.ObjectList.select_paths(['1'])
+app.Diary.remove.clicked()
+app.Diary.ObjectList.select_paths([])
+app.Diary.afternoon.clicked()
+app.Diary.period.clicked()
+app.Diary.title.set_text("")
+app.Diary.title.set_text("First")
+app.Diary.ObjectList.select_paths(['0'])
+app.Diary.remove.clicked()
+app.Diary.ObjectList.select_paths([])
+app.Diary.title.set_text("")
+app.Diary.title.set_text("")
+player.delete_window("Diary")
+
+player.finish()
diff --git a/tests/ui/personalinformation.py b/tests/ui/personalinformation.py
new file mode 100644
index 0000000..390933c
--- /dev/null
+++ b/tests/ui/personalinformation.py
@@ -0,0 +1,115 @@
+from kiwi.ui.test.player import Player
+
+player = Player(['examples/validation/personalinformation.py'])
+app = player.get_app()
+
+player.wait_for_window("Form")
+app.Form.name.set_text("")
+app.Form.name.set_text("J")
+app.Form.name.set_text("Jo")
+app.Form.name.set_text("Joh")
+app.Form.name.set_text("Joha")
+app.Form.name.set_text("Johan")
+app.Form.age.set_text("")
+app.Form.age.set_text(" ")
+app.Form.age.set_text(" ")
+app.Form.age.set_text("1 ")
+app.Form.age.set_text("1")
+app.Form.age.set_text("12")
+app.Form.age.set_text("1")
+app.Form.age.set_text("1 ")
+app.Form.age.set_text(" ")
+app.Form.age.set_text(" ")
+app.Form.age.set_text(" ")
+app.Form.age.set_text("9 ")
+app.Form.age.set_text("9")
+app.Form.age.set_text("99")
+app.Form.GtkToggleButton.clicked()
+app.Form.ProxyEntry.set_text("")
+app.Form.ProxyEntry.set_text(" / / ")
+app.Form.ProxyEntry.set_text(" / / ")
+app.Form.ProxyEntry.set_text("/ / ")
+app.Form.ProxyEntry.set_text(" / ")
+app.Form.ProxyEntry.set_text(" / ")
+app.Form.ProxyEntry.set_text("/ ")
+app.Form.ProxyEntry.set_text(" ")
+app.Form.ProxyEntry.set_text(" ")
+app.Form.ProxyEntry.set_text(" ")
+app.Form.ProxyEntry.set_text(" ")
+app.Form.ProxyEntry.set_text("")
+app.Form.ProxyEntry.set_text("02/14/1969")
+app.Form.GtkToggleButton.clicked()
+app.Form.ProxyEntry.set_text("")
+app.Form.ProxyEntry.set_text(" / / ")
+app.Form.ProxyEntry.set_text(" / / ")
+app.Form.ProxyEntry.set_text("/ / ")
+app.Form.ProxyEntry.set_text(" / ")
+app.Form.ProxyEntry.set_text(" / ")
+app.Form.ProxyEntry.set_text("/ ")
+app.Form.ProxyEntry.set_text(" ")
+app.Form.ProxyEntry.set_text(" ")
+app.Form.ProxyEntry.set_text(" ")
+app.Form.ProxyEntry.set_text(" ")
+app.Form.ProxyEntry.set_text("")
+app.Form.ProxyEntry.set_text("02/13/1969")
+app.Form.height.set_text("")
+app.Form.height.set_text("1")
+app.Form.height.set_text("12")
+app.Form.height.set_text("123")
+app.Form.height.set_text("1234")
+app.Form.height.set_text("12345")
+app.Form.weight.set_text("")
+app.Form.weight.set_text("87")
+app.Form.weight.set_text("")
+app.Form.weight.set_text("88")
+app.Form.weight.set_text("")
+app.Form.weight.set_text("89")
+app.Form.weight.set_text("")
+app.Form.weight.set_text("90")
+app.Form.weight.set_text("")
+app.Form.weight.set_text("91")
+app.Form.weight.set_text("")
+app.Form.weight.set_text("92")
+app.Form.weight.set_text("")
+app.Form.weight.set_text("93")
+app.Form.weight.set_text("")
+app.Form.weight.set_text("92")
+app.Form.weight.set_text("")
+app.Form.weight.set_text("91")
+app.Form.weight.set_text("")
+app.Form.weight.set_text("90")
+app.Form.weight.set_text("")
+app.Form.weight.set_text("89")
+app.Form.weight.set_text("")
+app.Form.weight.set_text("90")
+app.Form.height.set_text("")
+app.Form.height.set_text("1")
+app.Form.height.set_text("12")
+app.Form.age.set_text("")
+app.Form.age.set_text(" ")
+app.Form.age.set_text(" ")
+app.Form.age.set_text("1 ")
+app.Form.age.set_text("1")
+app.Form.age.set_text("12")
+app.Form.GtkToggleButton.clicked()
+app.Form.ProxyEntry.set_text("")
+app.Form.ProxyEntry.set_text("Brazilian")
+app.Form.GtkToggleButton.clicked()
+app.Form.ProxyEntry.set_text("")
+app.Form.ProxyEntry.set_text("Yankee")
+app.Form.ProxyEntry.set_text("")
+app.Form.ProxyEntry.set_text("Other")
+app.Form.ProxyEntry.set_text("")
+app.Form.ProxyEntry.set_text("Yankee")
+app.Form.ProxyEntry.set_text("")
+app.Form.ProxyEntry.set_text("Brazilian")
+app.Form.ProxyEntry.set_text("")
+app.Form.ProxyEntry.set_text("Yankee")
+app.Form.gender.select_item_by_label("Male")
+app.Form.gender.select_item_by_label("Female")
+app.Form.status_single.clicked()
+app.Form.status.clicked()
+app.Form.status.clicked()
+app.Form.status_single.clicked()
+app.Form.ok_btn.clicked()
+player.finish()