From 74aa7b02df4a3143ae02c82743a7b3544a9585d4 Mon Sep 17 00:00:00 2001 From: David Rousselie Date: Sun, 13 May 2007 16:11:50 +0200 Subject: [PATCH] Move unit tests in src module hierarchy - Python cannot merge a same module from to different folder so merge 'src' and 'tests' folder into one. darcs-hash:20070513141150-86b55-892f79fdc18fb69f5b8513ea7a31b01f8eb68f0e.gz --- run_tests.py | 40 +------ setup.py | 2 +- src/jcl/jabber/tests/__init__.py | 15 +++ .../jcl/jabber/tests/component.py | 8 +- .../jcl/jabber/tests/feeder.py | 15 ++- src/jcl/model/tests/__init__.py | 14 +++ .../jcl/model/tests/account.py | 89 ++++++++++++++- src/jcl/tests/__init__.py | 18 +++ .../jcl/test_lang.py => src/jcl/tests/lang.py | 5 + tests/__init__.py | 0 tests/jcl/__init__.py | 0 tests/jcl/jabber/__init__.py | 0 tests/jcl/model/__init__.py | 0 tests/jcl/model/account.py | 108 ------------------ 14 files changed, 164 insertions(+), 150 deletions(-) create mode 100644 src/jcl/jabber/tests/__init__.py rename tests/jcl/jabber/test_component.py => src/jcl/jabber/tests/component.py (99%) rename tests/jcl/jabber/test_feeder.py => src/jcl/jabber/tests/feeder.py (94%) create mode 100644 src/jcl/model/tests/__init__.py rename tests/jcl/model/test_account.py => src/jcl/model/tests/account.py (64%) create mode 100644 src/jcl/tests/__init__.py rename tests/jcl/test_lang.py => src/jcl/tests/lang.py (94%) delete mode 100644 tests/__init__.py delete mode 100644 tests/jcl/__init__.py delete mode 100644 tests/jcl/jabber/__init__.py delete mode 100644 tests/jcl/model/__init__.py delete mode 100644 tests/jcl/model/account.py diff --git a/run_tests.py b/run_tests.py index 96bb3cf..aab02c1 100644 --- a/run_tests.py +++ b/run_tests.py @@ -24,7 +24,6 @@ import coverage import logging import unittest -from test import test_support import sys sys.path.append("src") @@ -32,41 +31,10 @@ reload(sys) sys.setdefaultencoding('utf8') del sys.setdefaultencoding -import tests -from tests.jcl.jabber.test_component import * -from tests.jcl.jabber.test_feeder import * -from tests.jcl.test_lang import * -from tests.jcl.model.test_account import * +import jcl.tests -import jcl - -def test_suite(): - component_suite = unittest.makeSuite(JCLComponent_TestCase, "test") - feeder_component_suite = unittest.makeSuite(FeederComponent_TestCase, "test") - feeder_suite = unittest.makeSuite(Feeder_TestCase, "test") - sender_suite = unittest.makeSuite(Sender_TestCase, "test") - lang_suite = unittest.makeSuite(Lang_TestCase, "test") - account_module_suite = unittest.makeSuite(AccountModule_TestCase, "test") - account_suite = unittest.makeSuite(Account_TestCase, "test") - presence_account_suite = unittest.makeSuite(PresenceAccount_TestCase, "test") - - jcl_suite = unittest.TestSuite() -# jcl_suite.addTest(FeederComponent_TestCase('test_handle_tick')) -# jcl_suite.addTest(JCLComponent_TestCase('test_run_go_offline')) -# jcl_suite.addTest(PresenceAccount_TestCase('test_possibles_actions')) -# jcl_suite = unittest.TestSuite((component_suite)) -# jcl_suite = unittest.TestSuite((presence_account_suite)) - - jcl_suite = unittest.TestSuite((component_suite, \ - feeder_component_suite, \ - feeder_suite, \ - sender_suite, \ - lang_suite, \ - account_module_suite, \ - account_suite, \ - presence_account_suite)) - - return jcl_suite +def suite(): + return jcl.tests.suite() if __name__ == '__main__': logger = logging.getLogger() @@ -76,7 +44,7 @@ if __name__ == '__main__': coverage.erase() coverage.start() - unittest.main() + unittest.main(defaultTest='suite') coverage.stop() coverage.analysis(jcl.jabber.component) diff --git a/setup.py b/setup.py index 901919f..cfd64f3 100644 --- a/setup.py +++ b/setup.py @@ -30,4 +30,4 @@ setup(name = 'jcl', \ url = 'http://people.happycoders.org/dax/projects/jcl', \ package_dir = {'': 'src'}, \ packages = ['jcl', 'jcl.jabber', 'jcl.model'], \ - test_suite = 'run_tests.test_suite') + test_suite = 'jcl.tests.suite') diff --git a/src/jcl/jabber/tests/__init__.py b/src/jcl/jabber/tests/__init__.py new file mode 100644 index 0000000..00e163e --- /dev/null +++ b/src/jcl/jabber/tests/__init__.py @@ -0,0 +1,15 @@ +"""JCL test module""" +__revision__ = "" + +import unittest + +from jcl.jabber.tests import component, feeder + +def suite(): + suite = unittest.TestSuite() + suite.addTest(component.suite()) + suite.addTest(feeder.suite()) + return suite + +if __name__ == '__main__': + unittest.main(defaultTest='suite') diff --git a/tests/jcl/jabber/test_component.py b/src/jcl/jabber/tests/component.py similarity index 99% rename from tests/jcl/jabber/test_component.py rename to src/jcl/jabber/tests/component.py index 35b5d27..bbe3916 100644 --- a/tests/jcl/jabber/test_component.py +++ b/src/jcl/jabber/tests/component.py @@ -45,7 +45,7 @@ from jcl.model import account from jcl.model.account import Account from jcl.lang import Lang -from tests.jcl.model.account import ExampleAccount, Example2Account +from jcl.model.tests.account import ExampleAccount, Example2Account if sys.platform == "win32": DB_PATH = "/c|/temp/test.db" @@ -1958,3 +1958,9 @@ class JCLComponent_TestCase(unittest.TestCase): exception = Exception("test exception") self.comp.send_error(_account, exception) self.assertEqual(len(self.comp.stream.sent), 0) + +def suite(): + return unittest.makeSuite(JCLComponent_TestCase, 'test') + +if __name__ == '__main__': + unittest.main(defaultTest='suite') diff --git a/tests/jcl/jabber/test_feeder.py b/src/jcl/jabber/tests/feeder.py similarity index 94% rename from tests/jcl/jabber/test_feeder.py rename to src/jcl/jabber/tests/feeder.py index 9cff208..9be21f9 100644 --- a/tests/jcl/jabber/test_feeder.py +++ b/src/jcl/jabber/tests/feeder.py @@ -32,14 +32,13 @@ from sqlobject.dbconnection import TheURIOpener from pyxmpp.message import Message -from tests.jcl.jabber.test_component import JCLComponent_TestCase, MockStream - from jcl.jabber.component import JCLComponent from jcl.jabber.feeder import FeederComponent, Feeder, Sender from jcl.model.account import Account from jcl.model import account -from tests.jcl.model.account import ExampleAccount, Example2Account +from jcl.model.tests.account import ExampleAccount, Example2Account +from jcl.jabber.tests.component import JCLComponent_TestCase, MockStream if sys.platform == "win32": DB_PATH = "/c|/temp/test.db" @@ -175,3 +174,13 @@ class Sender_TestCase(unittest.TestCase): def test_send_exist(self): sender = Sender() self.assertRaises(NotImplementedError, sender.send, None, None) + +def suite(): + suite = unittest.TestSuite() + suite.addTest(unittest.makeSuite(FeederComponent_TestCase, 'test')) + suite.addTest(unittest.makeSuite(Feeder_TestCase, 'test')) + suite.addTest(unittest.makeSuite(Sender_TestCase, 'test')) + return suite + +if __name__ == '__main__': + unittest.main(defaultTest='suite') diff --git a/src/jcl/model/tests/__init__.py b/src/jcl/model/tests/__init__.py new file mode 100644 index 0000000..a6ad454 --- /dev/null +++ b/src/jcl/model/tests/__init__.py @@ -0,0 +1,14 @@ +"""JCL test module""" +__revision__ = "" + +import unittest + +from jcl.model.tests import account + +def suite(): + suite = unittest.TestSuite() + suite.addTest(account.suite()) + return suite + +if __name__ == '__main__': + unittest.main(defaultTest='suite') diff --git a/tests/jcl/model/test_account.py b/src/jcl/model/tests/account.py similarity index 64% rename from tests/jcl/model/test_account.py rename to src/jcl/model/tests/account.py index 824516f..69a0509 100644 --- a/tests/jcl/model/test_account.py +++ b/src/jcl/model/tests/account.py @@ -31,7 +31,84 @@ from jcl.jabber.error import FieldError from jcl.model import account from jcl.model.account import Account, PresenceAccount -from tests.jcl.model.account import ExampleAccount, PresenceAccountExample +class ExampleAccount(Account): + login = StringCol(default = "") + password = StringCol(default = None) + store_password = BoolCol(default = True) + waiting_password_reply = BoolCol(default = False) + + test_enum = EnumCol(default = "choice1", enumValues = ["choice1", "choice2", "choice3"]) + test_int = IntCol(default = 42) + + def _get_register_fields(cls, real_class = None): + def password_post_func(password): + if password is None or password == "": + return None + return password + + if real_class is None: + real_class = cls + return Account.get_register_fields(real_class) + \ + [("login", "text-single", None, \ + lambda field_value, default_func: account.mandatory_field(field_value), \ + lambda : ""), \ + ("password", "text-private", None, \ + lambda field_value, default_func: password_post_func(field_value), \ + lambda : ""), \ + ("store_password", "boolean", None, account.default_post_func, \ + lambda : True), \ + ("test_enum", "list-single", ["choice1", "choice2", "choice3"], \ + account.default_post_func, \ + lambda : "choice2"), \ + ("test_int", "text-single", None, account.int_post_func, \ + lambda : 44)] + + get_register_fields = classmethod(_get_register_fields) + +class Example2Account(Account): + test_new_int = IntCol(default = 42) + + def _get_register_fields(cls, real_class = None): + if real_class is None: + real_class = cls + return Account.get_register_fields(real_class) + \ + [("test_new_int", "text-single", None, account.int_post_func, \ + lambda : 43)] + get_register_fields = classmethod(_get_register_fields) + +class PresenceAccountExample(PresenceAccount): + DO_SOMETHING_ELSE = 2 + possibles_actions = [PresenceAccount.DO_NOTHING, \ + PresenceAccount.DO_SOMETHING, \ + DO_SOMETHING_ELSE] + + def _get_presence_actions_fields(cls): + """See PresenceAccount._get_presence_actions_fields + """ + return {'chat_action': (cls.possibles_actions, \ + PresenceAccountExample.DO_SOMETHING_ELSE), \ + 'online_action': (cls.possibles_actions, \ + PresenceAccountExample.DO_SOMETHING_ELSE), \ + 'away_action': (cls.possibles_actions, \ + PresenceAccountExample.DO_SOMETHING_ELSE), \ + 'xa_action': (cls.possibles_actions, \ + PresenceAccountExample.DO_SOMETHING_ELSE), \ + 'dnd_action': (cls.possibles_actions, \ + PresenceAccountExample.DO_SOMETHING_ELSE), \ + 'offline_action': (cls.possibles_actions, \ + PresenceAccountExample.DO_SOMETHING_ELSE)} + + get_presence_actions_fields = classmethod(_get_presence_actions_fields) + + test_new_int = IntCol(default = 42) + + def _get_register_fields(cls, real_class = None): + if real_class is None: + real_class = cls + return PresenceAccount.get_register_fields(real_class) + \ + [("test_new_int", "text-single", None, account.int_post_func, \ + lambda : 43)] + get_register_fields = classmethod(_get_register_fields) if sys.platform == "win32": DB_PATH = "/c|/temp/test.db" @@ -171,3 +248,13 @@ class PresenceAccount_TestCase(unittest.TestCase): int(possible_action)) self.assertTrue(str(default_func()) in possibles_actions) del account.hub.threadConnection + +def suite(): + suite = unittest.TestSuite() + suite.addTest(unittest.makeSuite(AccountModule_TestCase, 'test')) + suite.addTest(unittest.makeSuite(Account_TestCase, 'test')) + suite.addTest(unittest.makeSuite(PresenceAccount_TestCase, 'test')) + return suite + +if __name__ == '__main__': + unittest.main(defaultTest='suite') diff --git a/src/jcl/tests/__init__.py b/src/jcl/tests/__init__.py new file mode 100644 index 0000000..e6219d6 --- /dev/null +++ b/src/jcl/tests/__init__.py @@ -0,0 +1,18 @@ +"""JCL test module""" +__revision__ = "" + +import unittest + +from jcl.tests import lang +from jcl.jabber import tests as jabber +from jcl.model import tests as model + +def suite(): + suite = unittest.TestSuite() + suite.addTest(lang.suite()) + suite.addTest(jabber.suite()) + suite.addTest(model.suite()) + return suite + +if __name__ == '__main__': + unittest.main(defaultTest='suite') diff --git a/tests/jcl/test_lang.py b/src/jcl/tests/lang.py similarity index 94% rename from tests/jcl/test_lang.py rename to src/jcl/tests/lang.py index 93bc0db..0305b2a 100644 --- a/tests/jcl/test_lang.py +++ b/src/jcl/tests/lang.py @@ -63,3 +63,8 @@ class Lang_TestCase(unittest.TestCase): lang = self.lang.get_lang_class_from_node(iq_node) self.assertEquals(lang, Lang.fr) +def suite(): + return unittest.makeSuite(Lang_TestCase, 'test') + +if __name__ == '__main__': + unittest.main(defaultTest='suite') diff --git a/tests/__init__.py b/tests/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/jcl/__init__.py b/tests/jcl/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/jcl/jabber/__init__.py b/tests/jcl/jabber/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/jcl/model/__init__.py b/tests/jcl/model/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/jcl/model/account.py b/tests/jcl/model/account.py deleted file mode 100644 index 0656e28..0000000 --- a/tests/jcl/model/account.py +++ /dev/null @@ -1,108 +0,0 @@ -## -## account.py -## Login : David Rousselie -## Started on Sat Oct 28 17:03:30 2006 David Rousselie -## $Id$ -## -## Copyright (C) 2006 David Rousselie -## This program is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2 of the License, or -## (at your option) any later version. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; if not, write to the Free Software -## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -## - -from sqlobject.main import SQLObject -from sqlobject.col import StringCol, BoolCol, EnumCol, IntCol - -from jcl.lang import Lang - -from jcl.model import account -from jcl.model.account import Account, PresenceAccount - -class ExampleAccount(Account): - login = StringCol(default = "") - password = StringCol(default = None) - store_password = BoolCol(default = True) - waiting_password_reply = BoolCol(default = False) - - test_enum = EnumCol(default = "choice1", enumValues = ["choice1", "choice2", "choice3"]) - test_int = IntCol(default = 42) - - def _get_register_fields(cls, real_class = None): - def password_post_func(password): - if password is None or password == "": - return None - return password - - if real_class is None: - real_class = cls - return Account.get_register_fields(real_class) + \ - [("login", "text-single", None, \ - lambda field_value, default_func: account.mandatory_field(field_value), \ - lambda : ""), \ - ("password", "text-private", None, \ - lambda field_value, default_func: password_post_func(field_value), \ - lambda : ""), \ - ("store_password", "boolean", None, account.default_post_func, \ - lambda : True), \ - ("test_enum", "list-single", ["choice1", "choice2", "choice3"], \ - account.default_post_func, \ - lambda : "choice2"), \ - ("test_int", "text-single", None, account.int_post_func, \ - lambda : 44)] - - get_register_fields = classmethod(_get_register_fields) - -class Example2Account(Account): - test_new_int = IntCol(default = 42) - - def _get_register_fields(cls, real_class = None): - if real_class is None: - real_class = cls - return Account.get_register_fields(real_class) + \ - [("test_new_int", "text-single", None, account.int_post_func, \ - lambda : 43)] - get_register_fields = classmethod(_get_register_fields) - -class PresenceAccountExample(PresenceAccount): - DO_SOMETHING_ELSE = 2 - possibles_actions = [PresenceAccount.DO_NOTHING, \ - PresenceAccount.DO_SOMETHING, \ - DO_SOMETHING_ELSE] - - def _get_presence_actions_fields(cls): - """See PresenceAccount._get_presence_actions_fields - """ - return {'chat_action': (cls.possibles_actions, \ - PresenceAccountExample.DO_SOMETHING_ELSE), \ - 'online_action': (cls.possibles_actions, \ - PresenceAccountExample.DO_SOMETHING_ELSE), \ - 'away_action': (cls.possibles_actions, \ - PresenceAccountExample.DO_SOMETHING_ELSE), \ - 'xa_action': (cls.possibles_actions, \ - PresenceAccountExample.DO_SOMETHING_ELSE), \ - 'dnd_action': (cls.possibles_actions, \ - PresenceAccountExample.DO_SOMETHING_ELSE), \ - 'offline_action': (cls.possibles_actions, \ - PresenceAccountExample.DO_SOMETHING_ELSE)} - - get_presence_actions_fields = classmethod(_get_presence_actions_fields) - - test_new_int = IntCol(default = 42) - - def _get_register_fields(cls, real_class = None): - if real_class is None: - real_class = cls - return PresenceAccount.get_register_fields(real_class) + \ - [("test_new_int", "text-single", None, account.int_post_func, \ - lambda : 43)] - get_register_fields = classmethod(_get_register_fields)