Move unit tests in source folder

darcs-hash:20070513183302-86b55-98a5e67621ece44958f215e98ba1c92e32c4ea51.gz
This commit is contained in:
David Rousselie
2007-05-13 20:33:02 +02:00
parent cde3a9f16f
commit 0f95cc4678
15 changed files with 87 additions and 40 deletions

View File

@@ -32,31 +32,14 @@ reload(sys)
sys.setdefaultencoding('utf8') sys.setdefaultencoding('utf8')
del sys.setdefaultencoding del sys.setdefaultencoding
import tests
from tests.jmc.jabber.test_component import *
from tests.jmc.model.test_account import *
from tests.jmc.test_lang import *
import jmc import jmc
import jmc.jabber import jmc.jabber
import jmc.jabber.component import jmc.jabber.component
def test_suite(): import jmc.tests as jmc
mail_account_suite = unittest.makeSuite(MailAccount_TestCase, "test")
imap_account_suite = unittest.makeSuite(IMAPAccount_TestCase, "test") def suite():
pop3_account_suite = unittest.makeSuite(POP3Account_TestCase, "test") return jmc.suite()
lang_suite = unittest.makeSuite(Lang_TestCase, "test")
mail_component_suite = unittest.makeSuite(MailComponent_TestCase, "test")
# jmc_suite = unittest.TestSuite((mail_component_suite))
# jmc_suite = unittest.TestSuite()
# jmc_suite.addTest(MailAccount_TestCase('test_format_message_summary_partial_encoded'))
jmc_suite = unittest.TestSuite((lang_suite, \
mail_account_suite, \
imap_account_suite, \
pop3_account_suite, \
mail_component_suite))
return jmc_suite
if __name__ == '__main__': if __name__ == '__main__':
logger = logging.getLogger() logger = logging.getLogger()
@@ -66,7 +49,7 @@ if __name__ == '__main__':
coverage.erase() coverage.erase()
coverage.start() coverage.start()
unittest.main() unittest.main(defaultTest='suite')
coverage.stop() coverage.stop()
coverage.analysis(jmc.jabber.component) coverage.analysis(jmc.jabber.component)

View File

@@ -31,4 +31,4 @@ setup(name = 'jmc', \
package_dir = {'': 'src'}, \ package_dir = {'': 'src'}, \
packages = ['jmc', 'jmc.jabber', 'jmc.model'], \ packages = ['jmc', 'jmc.jabber', 'jmc.model'], \
scripts = ['src/jmc.py'], \ scripts = ['src/jmc.py'], \
test_suite = 'run_tests.test_suite') test_suite = 'jmc.tests.suite')

View File

@@ -0,0 +1,14 @@
"""JMC test module"""
__revision__ = ""
import unittest
from jmc.jabber.tests import component
def suite():
suite = unittest.TestSuite()
suite.addTest(component.suite())
return suite
if __name__ == '__main__':
unittest.main(defaultTest='suite')

View File

@@ -503,3 +503,8 @@ class MailComponent_TestCase(unittest.TestCase):
self.assertTrue(account11.marked_all_as_read) self.assertTrue(account11.marked_all_as_read)
del account.hub.threadConnection del account.hub.threadConnection
def suite():
return unittest.makeSuite(MailComponent_TestCase, 'test')
if __name__ == '__main__':
unittest.main(defaultTest='suite')

View File

@@ -133,7 +133,7 @@ class MailAccount(PresenceAccount):
# Define constants # Define constants
DIGEST = 1 DIGEST = 1
RETRIEVE = 2 RETRIEVE = 2
default_encoding = "iso-8859-1" default_encoding = "utf-8"
possibles_actions = [PresenceAccount.DO_NOTHING, \ possibles_actions = [PresenceAccount.DO_NOTHING, \
DIGEST, \ DIGEST, \
RETRIEVE] RETRIEVE]
@@ -223,13 +223,13 @@ class MailAccount(PresenceAccount):
if content_charset: if content_charset:
result = unicode(part.get_payload(decode=True).decode(content_charset)) result = unicode(part.get_payload(decode=True).decode(content_charset))
else: else:
result = unicode(part.get_payload(decode=True)) result = unicode(part.get_payload(decode=True).decode(MailAccount.default_encoding))
except Exception, e: except Exception, e:
try: try:
result = unicode(part.get_payload(decode=True).decode("iso-8859-1")) result = unicode(part.get_payload(decode=True))
except Exception, e: except Exception, e:
try: try:
result = unicode(part.get_payload(decode=True).decode(default_encoding)) result = unicode(part.get_payload(decode=True).decode("iso-8859-1"))
except Exception, e: except Exception, e:
if charset_hint is not None: if charset_hint is not None:
try: try:
@@ -252,13 +252,13 @@ class MailAccount(PresenceAccount):
charset_hint = from_decoded[i][1] charset_hint = from_decoded[i][1]
email_from += unicode(from_decoded[i][0].decode(from_decoded[i][1])) email_from += unicode(from_decoded[i][0].decode(from_decoded[i][1]))
else: else:
email_from += unicode(from_decoded[i][0]) email_from += unicode(from_decoded[i][0].decode(MailAccount.default_encoding))
except Exception,e: except Exception,e:
try: try:
email_from += unicode(from_decoded[i][0].decode("iso-8859-1")) email_from += unicode(from_decoded[i][0])
except Exception, e: except Exception, e:
try: try:
email_from += unicode(from_decoded[i][0].decode(default_encoding)) email_from += unicode(from_decoded[i][0].decode("iso-8859-1"))
except Exception, e: except Exception, e:
type, value, stack = sys.exc_info() type, value, stack = sys.exc_info()
print >>sys.stderr, "".join(traceback.format_exception print >>sys.stderr, "".join(traceback.format_exception
@@ -273,13 +273,13 @@ class MailAccount(PresenceAccount):
charset_hint = subject_decoded[i][1] charset_hint = subject_decoded[i][1]
result += unicode(subject_decoded[i][0].decode(subject_decoded[i][1])) result += unicode(subject_decoded[i][0].decode(subject_decoded[i][1]))
else: else:
result += unicode(subject_decoded[i][0]) result += unicode(subject_decoded[i][0].decode(MailAccount.default_encoding))
except Exception,e: except Exception,e:
try: try:
result += unicode(subject_decoded[i][0].decode("iso-8859-1")) result += unicode(subject_decoded[i][0])
except Exception, e: except Exception, e:
try: try:
result += unicode(subject_decoded[i][0].decode(default_encoding)) result += unicode(subject_decoded[i][0].decode("iso-8859-1"))
except Exception, e: except Exception, e:
if charset_hint is not None: if charset_hint is not None:
try: try:

View File

@@ -0,0 +1,14 @@
"""JMC test module"""
__revision__ = ""
import unittest
from jmc.model.tests import account
def suite():
suite = unittest.TestSuite()
suite.addTest(account.suite())
return suite
if __name__ == '__main__':
unittest.main(defaultTest='suite')

View File

@@ -34,7 +34,7 @@ from jcl.model.account import Account, PresenceAccount
from jmc.model.account import MailAccount, POP3Account, IMAPAccount from jmc.model.account import MailAccount, POP3Account, IMAPAccount
from jcl.model.tests.account import PresenceAccount_TestCase from jcl.model.tests.account import PresenceAccount_TestCase
from tests.jmc import email_generator, dummy_server from jmc.model.tests import email_generator, server
if sys.platform == "win32": if sys.platform == "win32":
DB_PATH = "/c|/temp/test.db" DB_PATH = "/c|/temp/test.db"
@@ -184,7 +184,7 @@ class POP3Account_TestCase(unittest.TestCase):
def make_test(responses = None, queries = None, core = None): def make_test(responses = None, queries = None, core = None):
def inner(self): def inner(self):
self.server = dummy_server.DummyServer("localhost", 1110) self.server = server.DummyServer("localhost", 1110)
thread.start_new_thread(self.server.serve, ()) thread.start_new_thread(self.server.serve, ())
self.server.responses = ["+OK connected\r\n", \ self.server.responses = ["+OK connected\r\n", \
"+OK name is a valid mailbox\r\n", \ "+OK name is a valid mailbox\r\n", \
@@ -314,7 +314,7 @@ class IMAPAccount_TestCase(unittest.TestCase):
def make_test(responses = None, queries = None, core = None): def make_test(responses = None, queries = None, core = None):
def inner(self): def inner(self):
self.server = dummy_server.DummyServer("localhost", 1143) self.server = server.DummyServer("localhost", 1143)
thread.start_new_thread(self.server.serve, ()) thread.start_new_thread(self.server.serve, ())
self.server.responses = ["* OK [CAPABILITY IMAP4 LOGIN-REFERRALS " + \ self.server.responses = ["* OK [CAPABILITY IMAP4 LOGIN-REFERRALS " + \
"AUTH=PLAIN]\n", \ "AUTH=PLAIN]\n", \
@@ -387,3 +387,14 @@ class IMAPAccount_TestCase(unittest.TestCase):
def test_get_register_fields(self): def test_get_register_fields(self):
register_fields = IMAPAccount.get_register_fields() register_fields = IMAPAccount.get_register_fields()
self.assertEquals(len(register_fields), 15) self.assertEquals(len(register_fields), 15)
def suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(MailAccount_TestCase, 'test'))
suite.addTest(unittest.makeSuite(POP3Account_TestCase, 'test'))
suite.addTest(unittest.makeSuite(IMAPAccount_TestCase, 'test'))
return suite
if __name__ == '__main__':
unittest.main(defaultTest='suite')

18
src/jmc/tests/__init__.py Normal file
View File

@@ -0,0 +1,18 @@
"""JMC test module"""
__revision__ = ""
import unittest
from jmc.tests import lang
from jmc.jabber import tests as jabber
from jmc.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')

View File

@@ -20,6 +20,7 @@
## along with this program; if not, write to the Free Software ## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
## ##
# TODO : Reuse JCL Lang tests
import unittest import unittest
from jmc.lang import Lang from jmc.lang import Lang
@@ -63,3 +64,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')

View File

View File

@@ -1,2 +0,0 @@
"""JMC test module"""
__revision__ = ""

View File

@@ -1,2 +0,0 @@
"""JMC jabber test module"""
__revision__ = ""