From 83d9ef49a347462464c49c217e37669c2d97e24f Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Fri, 8 Aug 2008 23:53:44 +0000 Subject: [PATCH] a script for running all the tests --- test/mocks.py | 2 +- test/runtests.py | 16 ++++++++++++++++ test/test_misc_interface.py | 9 ++------- test/test_roster.py | 22 +++++++++++----------- test/testlib.py | 5 +++-- 5 files changed, 33 insertions(+), 21 deletions(-) create mode 100755 test/runtests.py diff --git a/test/mocks.py b/test/mocks.py index f644954f1..5790dbde6 100644 --- a/test/mocks.py +++ b/test/mocks.py @@ -69,7 +69,7 @@ class MockInterface(Mock): class MockLogger(Mock): def __init__(self): - Mock.__init__(self, {'write': None}) + Mock.__init__(self, {'write': None, 'get_transports_type': {}}) class MockContact(Mock): def __nonzero__(self): diff --git a/test/runtests.py b/test/runtests.py new file mode 100755 index 000000000..73ac4f4c8 --- /dev/null +++ b/test/runtests.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python + +import unittest + +# new test modules need to be added manually +modules = ( 'test_caps', + 'test_dispatcher_nb', + 'test_misc_interface', + 'test_roster', + 'test_sessions', + ) +for mod in modules: + suite = unittest.defaultTestLoader.loadTestsFromName(mod) + unittest.TextTestRunner(verbosity=1).run(suite) + +# vim: se ts=3: diff --git a/test/test_misc_interface.py b/test/test_misc_interface.py index 860e89cd4..5225e6ea0 100644 --- a/test/test_misc_interface.py +++ b/test/test_misc_interface.py @@ -5,15 +5,10 @@ import testlib testlib.setup_env() from common import gajim -from common import xmpp - -from common.caps import CapsCache - -from mock import Mock - from gajim import Interface -gajim.logger = Mock() +from mocks import MockLogger +gajim.logger = MockLogger() Interface() diff --git a/test/test_roster.py b/test/test_roster.py index 0ad390b10..6da8715f9 100755 --- a/test/test_roster.py +++ b/test/test_roster.py @@ -21,7 +21,7 @@ class TestRosterWindow(unittest.TestCase): def setUp(self): gajim.interface = MockInterface() self.roster = roster_window.RosterWindow() - + # Please unuglify :-) self.C_NAME = roster_window.C_NAME self.C_TYPE = roster_window.C_TYPE @@ -52,7 +52,7 @@ class TestRosterWindow(unittest.TestCase): self.assertTrue(len(iters) == len(contact.get_shown_groups()), msg='Contact is not in all his groups') - # check for each group tag + # check for each group tag for titerC in iters: self.assertTrue(self.roster.model.iter_is_valid(titerC), msg='Contact iter invalid') @@ -67,7 +67,7 @@ class TestRosterWindow(unittest.TestCase): self.assertEquals(account, c_model[self.C_ACCOUNT], msg='Account missmatch') # TODO: Is our parent correct? (group or big b) - + def assert_group_is_in_roster(self, group, account): #TODO pass @@ -80,7 +80,7 @@ class TestRosterWindow(unittest.TestCase): acc_model = self.roster.model[titerA] self.assertEquals(acc_model[self.C_TYPE], 'account', msg='No account found') - + if not self.roster.regroup: self.assertEquals(acc_model[self.C_ACCOUNT], acc, msg='Account not found') @@ -88,7 +88,7 @@ class TestRosterWindow(unittest.TestCase): self_jid = gajim.get_jid_from_account(acc) self.assertEquals(acc_model[self.C_JID], self_jid, msg='Account JID not found in account row') - + def assert_model_is_in_sync(self): #TODO: check that iter_n_children returns the correct numbers pass @@ -97,18 +97,18 @@ class TestRosterWindow(unittest.TestCase): def test_fill_contacts_and_groups_dicts(self): for acc in contacts: self.roster.fill_contacts_and_groups_dicts(contacts[acc], acc) - + for jid in contacts[acc]: instances = gajim.contacts.get_contacts(acc, jid) # Created a contact for each single jid? self.assertTrue(len(instances) == 1) - + # Contacts kept their info contact = instances[0] self.assertEquals(contact.groups, contacts[acc][jid]['groups'], msg='Group Missmatch') - + groups = contacts[acc][jid]['groups'] or ['General',] # cleanup @@ -123,9 +123,9 @@ class TestRosterWindow(unittest.TestCase): self.roster.add_account(acc) self.assert_account_is_in_roster(acc) - self.roster.add_account_contacts(acc) + self.roster.add_account_contacts(acc) self.assert_all_contacts_are_in_roster(acc) - + self.assert_model_is_in_sync() @@ -166,6 +166,6 @@ class TestRosterWindowMetaContacts(TestRosterWindowRegrouped): if __name__ == '__main__': - unittest.main() + unittest.main() # vim: se ts=3: diff --git a/test/testlib.py b/test/testlib.py index 4beb43e14..3682ba86a 100644 --- a/test/testlib.py +++ b/test/testlib.py @@ -3,7 +3,8 @@ import os.path gajim_root = os.path.join(os.path.abspath(os.path.dirname(__file__)), '..') -sys.path.append(gajim_root + '/src') +# look for modules in the CWD, then gajim/src, then everywhere else +sys.path.insert(1, gajim_root + '/src') # a temporary version of ~/.gajim for testing configdir = gajim_root + '/test/tmp' @@ -34,4 +35,4 @@ def setup_env(): import gtkgui_helpers gtkgui_helpers.GLADE_DIR = gajim_root + '/data/glade' -# vim: se ts=3: \ No newline at end of file +# vim: se ts=3: