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
This commit is contained in:
40
run_tests.py
40
run_tests.py
@@ -24,7 +24,6 @@
|
|||||||
import coverage
|
import coverage
|
||||||
import logging
|
import logging
|
||||||
import unittest
|
import unittest
|
||||||
from test import test_support
|
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
sys.path.append("src")
|
sys.path.append("src")
|
||||||
@@ -32,41 +31,10 @@ reload(sys)
|
|||||||
sys.setdefaultencoding('utf8')
|
sys.setdefaultencoding('utf8')
|
||||||
del sys.setdefaultencoding
|
del sys.setdefaultencoding
|
||||||
|
|
||||||
import tests
|
import jcl.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
|
def suite():
|
||||||
|
return jcl.tests.suite()
|
||||||
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
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
@@ -76,7 +44,7 @@ if __name__ == '__main__':
|
|||||||
coverage.erase()
|
coverage.erase()
|
||||||
coverage.start()
|
coverage.start()
|
||||||
|
|
||||||
unittest.main()
|
unittest.main(defaultTest='suite')
|
||||||
|
|
||||||
coverage.stop()
|
coverage.stop()
|
||||||
coverage.analysis(jcl.jabber.component)
|
coverage.analysis(jcl.jabber.component)
|
||||||
|
|||||||
2
setup.py
2
setup.py
@@ -30,4 +30,4 @@ setup(name = 'jcl', \
|
|||||||
url = 'http://people.happycoders.org/dax/projects/jcl', \
|
url = 'http://people.happycoders.org/dax/projects/jcl', \
|
||||||
package_dir = {'': 'src'}, \
|
package_dir = {'': 'src'}, \
|
||||||
packages = ['jcl', 'jcl.jabber', 'jcl.model'], \
|
packages = ['jcl', 'jcl.jabber', 'jcl.model'], \
|
||||||
test_suite = 'run_tests.test_suite')
|
test_suite = 'jcl.tests.suite')
|
||||||
|
|||||||
15
src/jcl/jabber/tests/__init__.py
Normal file
15
src/jcl/jabber/tests/__init__.py
Normal file
@@ -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')
|
||||||
@@ -45,7 +45,7 @@ from jcl.model import account
|
|||||||
from jcl.model.account import Account
|
from jcl.model.account import Account
|
||||||
from jcl.lang import Lang
|
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":
|
if sys.platform == "win32":
|
||||||
DB_PATH = "/c|/temp/test.db"
|
DB_PATH = "/c|/temp/test.db"
|
||||||
@@ -1958,3 +1958,9 @@ class JCLComponent_TestCase(unittest.TestCase):
|
|||||||
exception = Exception("test exception")
|
exception = Exception("test exception")
|
||||||
self.comp.send_error(_account, exception)
|
self.comp.send_error(_account, exception)
|
||||||
self.assertEqual(len(self.comp.stream.sent), 0)
|
self.assertEqual(len(self.comp.stream.sent), 0)
|
||||||
|
|
||||||
|
def suite():
|
||||||
|
return unittest.makeSuite(JCLComponent_TestCase, 'test')
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main(defaultTest='suite')
|
||||||
@@ -32,14 +32,13 @@ from sqlobject.dbconnection import TheURIOpener
|
|||||||
|
|
||||||
from pyxmpp.message import Message
|
from pyxmpp.message import Message
|
||||||
|
|
||||||
from tests.jcl.jabber.test_component import JCLComponent_TestCase, MockStream
|
|
||||||
|
|
||||||
from jcl.jabber.component import JCLComponent
|
from jcl.jabber.component import JCLComponent
|
||||||
from jcl.jabber.feeder import FeederComponent, Feeder, Sender
|
from jcl.jabber.feeder import FeederComponent, Feeder, Sender
|
||||||
from jcl.model.account import Account
|
from jcl.model.account import Account
|
||||||
from jcl.model 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":
|
if sys.platform == "win32":
|
||||||
DB_PATH = "/c|/temp/test.db"
|
DB_PATH = "/c|/temp/test.db"
|
||||||
@@ -175,3 +174,13 @@ class Sender_TestCase(unittest.TestCase):
|
|||||||
def test_send_exist(self):
|
def test_send_exist(self):
|
||||||
sender = Sender()
|
sender = Sender()
|
||||||
self.assertRaises(NotImplementedError, sender.send, None, None)
|
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')
|
||||||
14
src/jcl/model/tests/__init__.py
Normal file
14
src/jcl/model/tests/__init__.py
Normal file
@@ -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')
|
||||||
@@ -31,7 +31,84 @@ from jcl.jabber.error import FieldError
|
|||||||
from jcl.model import account
|
from jcl.model import account
|
||||||
from jcl.model.account import Account, PresenceAccount
|
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":
|
if sys.platform == "win32":
|
||||||
DB_PATH = "/c|/temp/test.db"
|
DB_PATH = "/c|/temp/test.db"
|
||||||
@@ -171,3 +248,13 @@ class PresenceAccount_TestCase(unittest.TestCase):
|
|||||||
int(possible_action))
|
int(possible_action))
|
||||||
self.assertTrue(str(default_func()) in possibles_actions)
|
self.assertTrue(str(default_func()) in possibles_actions)
|
||||||
del account.hub.threadConnection
|
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')
|
||||||
18
src/jcl/tests/__init__.py
Normal file
18
src/jcl/tests/__init__.py
Normal file
@@ -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')
|
||||||
@@ -63,3 +63,8 @@ class Lang_TestCase(unittest.TestCase):
|
|||||||
lang = self.lang.get_lang_class_from_node(iq_node)
|
lang = self.lang.get_lang_class_from_node(iq_node)
|
||||||
self.assertEquals(lang, Lang.fr)
|
self.assertEquals(lang, Lang.fr)
|
||||||
|
|
||||||
|
def suite():
|
||||||
|
return unittest.makeSuite(Lang_TestCase, 'test')
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main(defaultTest='suite')
|
||||||
@@ -1,108 +0,0 @@
|
|||||||
##
|
|
||||||
## account.py
|
|
||||||
## Login : David Rousselie <dax@happycoders.org>
|
|
||||||
## 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)
|
|
||||||
Reference in New Issue
Block a user