diff options
-rw-r--r-- | tests/.cvsignore | 2 | ||||
-rw-r--r-- | tests/Makefile.am | 9 | ||||
-rw-r--r-- | tests/conversion.py | 43 | ||||
-rw-r--r-- | tests/runtests.py | 25 | ||||
-rw-r--r-- | tests/signal.py | 46 | ||||
-rw-r--r-- | tests/testconversion.py | 47 | ||||
-rw-r--r-- | tests/testsupport.py | 30 |
7 files changed, 125 insertions, 77 deletions
diff --git a/tests/.cvsignore b/tests/.cvsignore new file mode 100644 index 0000000..282522d --- /dev/null +++ b/tests/.cvsignore @@ -0,0 +1,2 @@ +Makefile +Makefile.in diff --git a/tests/Makefile.am b/tests/Makefile.am new file mode 100644 index 0000000..8324aef --- /dev/null +++ b/tests/Makefile.am @@ -0,0 +1,9 @@ +tests = \ + conversion.py \ + signal.py + +check-local: + @PYTHONPATH=$(top_builddir):$(top_builddir)/.libs:$(top_builddir)/gtk/.libs $(PYTHON) $(srcdir)/runtests.py + @rm -fr *.pyc + +EXTRA_DIST = $(tests) runtests.py diff --git a/tests/conversion.py b/tests/conversion.py new file mode 100644 index 0000000..1fe8c22 --- /dev/null +++ b/tests/conversion.py @@ -0,0 +1,43 @@ +# -*- Mode: Python -*- + +import unittest + +import gtk + +class Tests(unittest.TestCase): + + def testUnicharArg(self): + """ Test unichar values when used as arguments. """ + + entry = gtk.Entry() + for valid_value in ['a', u'b', u'\ufff0', u'\ufff0'.encode()]: + entry.set_invisible_char(valid_value) + assert entry.get_invisible_char() == unicode(valid_value) + + for invalid_value in ['12', None, 1, '']: + try: + entry.set_invisible_char(invalid_value) + except: + pass + else: + raise AssertionError('exception not raised on invalid value w/ set_invisible_char: %s' + % invalid_value) + + def testUnicharProperty(self): + """ Test unichar values when used as properties. """ + + entry = gtk.Entry() + for valid_value in ['a', u'b', u'\ufff0', u'\ufff0'.encode()]: + entry.set_property('invisible_char', valid_value) + assert entry.get_property('invisible_char') == valid_value + + for invalid_value in ['12', None, 1, '']: + try: + entry.set_property('invisible_char', invalid_value) + except: + pass + else: + raise AssertionError('exception not raised on invalid value w/ set_property: %s' + % invalid_value) +if __name__ == '__main__': + unittest.main() diff --git a/tests/runtests.py b/tests/runtests.py new file mode 100644 index 0000000..f3559f5 --- /dev/null +++ b/tests/runtests.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python +import glob +import os +import sys +import unittest + +SKIP_FILES = ['runtests'] + +dir = os.path.split(os.path.abspath(__file__))[0] +os.chdir(dir) + +def gettestnames(): + files = glob.glob('*.py') + names = map(lambda x: x[:-3], files) + map(names.remove, SKIP_FILES) + return names + +suite = unittest.TestSuite() +loader = unittest.TestLoader() + +for name in gettestnames(): + suite.addTest(loader.loadTestsFromName(name)) + +testRunner = unittest.TextTestRunner() +testRunner.run(suite) diff --git a/tests/signal.py b/tests/signal.py new file mode 100644 index 0000000..ce32801 --- /dev/null +++ b/tests/signal.py @@ -0,0 +1,46 @@ +# -*- Mode: Python -*- + +import unittest + +import gobject + +class C(gobject.GObject): + __gsignals__ = { 'my_signal': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, + (gobject.TYPE_INT,)) } + def do_my_signal(self, arg): + self.arg = arg +gobject.type_register(C) + +class D(C): + def do_my_signal(self, arg2): + self.arg2 = arg2 + C.do_my_signal(self, arg2) +gobject.type_register(D) + +class TestChaining(unittest.TestCase): + def setUp(self): + self.inst = C() + self.inst.connect("my_signal", self.my_signal_handler_cb, 1, 2, 3) + + def my_signal_handler_cb(self, *args): + assert len(args) == 5 + assert isinstance(args[0], C) + assert args[0] == self.inst + + assert isinstance(args[1], int) + assert args[1] == 42 + + assert args[2:] == (1, 2, 3) + + def testChaining(self): + self.inst.emit("my_signal", 42) + assert self.inst.arg == 42 + + def testChaining(self): + inst2 = D() + inst2.emit("my_signal", 44) + assert inst2.arg == 44 + assert inst2.arg2 == 44 + +if __name__ == '__main__': + unittest.main() diff --git a/tests/testconversion.py b/tests/testconversion.py deleted file mode 100644 index 22debdc..0000000 --- a/tests/testconversion.py +++ /dev/null @@ -1,47 +0,0 @@ -# -*- Mode: Python; py-indent-offset: 4 -*- - -import unittest -import testsupport - -import gtk - -class Tests(unittest.TestCase): - - def testUnicharArg(self): - """ Test unichar values when used as arguments. """ - - entry = gtk.Entry() - for valid_value in ['a', u'b', u'\ufff0', u'\ufff0'.encode()]: - entry.set_invisible_char(valid_value) - assert entry.get_invisible_char() == unicode(valid_value) - - for invalid_value in ['12', None, 1, '']: - try: - entry.set_invisible_char(invalid_value) - except: - pass - else: - raise AssertionError('exception not raised on invalid value w/ set_invisible_char: %s' - % invalid_value) - - def testUnicharProperty(self): - """ Test unichar values when used as properties. """ - - entry = gtk.Entry() - for valid_value in ['a', u'b', u'\ufff0', u'\ufff0'.encode()]: - entry.set_property('invisible_char', valid_value) - assert entry.get_property('invisible_char') == valid_value - - for invalid_value in ['12', None, 1, '']: - try: - entry.set_property('invisible_char', invalid_value) - except: - pass - else: - raise AssertionError('exception not raised on invalid value w/ set_property: %s' - % invalid_value) -def main(): - testsupport.run_all_tests() - -if __name__ == '__main__': - main()
\ No newline at end of file diff --git a/tests/testsupport.py b/tests/testsupport.py deleted file mode 100644 index bc23975..0000000 --- a/tests/testsupport.py +++ /dev/null @@ -1,30 +0,0 @@ -# -*- Mode: Python; py-indent-offset: 4 -*- - -import sys -import os -import unittest -import __main__ - -# Insert parent directory into path -def insert_pygtk_python_paths(): - try: - filename = __file__ - except: - filename = sys.argv[0] - this_dir = os.path.dirname(os.path.abspath(filename)) - parent_dir = os.path.dirname(this_dir) - sys.path.insert(0, parent_dir) - -insert_pygtk_python_paths() - -def run_all_tests(mods = [__main__]): - runner = unittest.TextTestRunner() - for mod in mods: - for name in dir(mod): - val = getattr(mod, name) - try: - if issubclass(val, unittest.TestCase): - suite = unittest.makeSuite(val, 'test') - runner.run(suite) - except TypeError: - pass |