From 0f95cc4678fc7c8c0188c842027739fd77aaad4d Mon Sep 17 00:00:00 2001 From: David Rousselie Date: Sun, 13 May 2007 20:33:02 +0200 Subject: [PATCH] Move unit tests in source folder darcs-hash:20070513183302-86b55-98a5e67621ece44958f215e98ba1c92e32c4ea51.gz --- run_tests.py | 27 ++++--------------- setup.py | 2 +- src/jmc/jabber/tests/__init__.py | 14 ++++++++++ .../jmc/jabber/tests/component.py | 5 ++++ src/jmc/model/account.py | 20 +++++++------- src/jmc/model/tests/__init__.py | 14 ++++++++++ .../jmc/model/tests/account.py | 17 +++++++++--- .../jmc/model/tests}/email_generator.py | 0 .../jmc/model/tests/server.py | 0 src/jmc/tests/__init__.py | 18 +++++++++++++ .../jmc/test_lang.py => src/jmc/tests/lang.py | 6 +++++ tests/__init__.py | 0 tests/jmc/__init__.py | 2 -- tests/jmc/jabber/__init__.py | 2 -- tests/jmc/model/__init__.py | 0 15 files changed, 87 insertions(+), 40 deletions(-) create mode 100644 src/jmc/jabber/tests/__init__.py rename tests/jmc/jabber/test_component.py => src/jmc/jabber/tests/component.py (99%) create mode 100644 src/jmc/model/tests/__init__.py rename tests/jmc/model/test_account.py => src/jmc/model/tests/account.py (97%) rename {tests/jmc => src/jmc/model/tests}/email_generator.py (100%) rename tests/jmc/dummy_server.py => src/jmc/model/tests/server.py (100%) create mode 100644 src/jmc/tests/__init__.py rename tests/jmc/test_lang.py => src/jmc/tests/lang.py (93%) delete mode 100644 tests/__init__.py delete mode 100644 tests/jmc/__init__.py delete mode 100644 tests/jmc/jabber/__init__.py delete mode 100644 tests/jmc/model/__init__.py diff --git a/run_tests.py b/run_tests.py index 3093966..edd7d95 100644 --- a/run_tests.py +++ b/run_tests.py @@ -32,31 +32,14 @@ reload(sys) sys.setdefaultencoding('utf8') 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.jabber import jmc.jabber.component -def test_suite(): - mail_account_suite = unittest.makeSuite(MailAccount_TestCase, "test") - imap_account_suite = unittest.makeSuite(IMAPAccount_TestCase, "test") - pop3_account_suite = unittest.makeSuite(POP3Account_TestCase, "test") - 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 +import jmc.tests as jmc + +def suite(): + return jmc.suite() if __name__ == '__main__': logger = logging.getLogger() @@ -66,7 +49,7 @@ if __name__ == '__main__': coverage.erase() coverage.start() - unittest.main() + unittest.main(defaultTest='suite') coverage.stop() coverage.analysis(jmc.jabber.component) diff --git a/setup.py b/setup.py index c786fef..49803d7 100644 --- a/setup.py +++ b/setup.py @@ -31,4 +31,4 @@ setup(name = 'jmc', \ package_dir = {'': 'src'}, \ packages = ['jmc', 'jmc.jabber', 'jmc.model'], \ scripts = ['src/jmc.py'], \ - test_suite = 'run_tests.test_suite') + test_suite = 'jmc.tests.suite') diff --git a/src/jmc/jabber/tests/__init__.py b/src/jmc/jabber/tests/__init__.py new file mode 100644 index 0000000..a1d804c --- /dev/null +++ b/src/jmc/jabber/tests/__init__.py @@ -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') diff --git a/tests/jmc/jabber/test_component.py b/src/jmc/jabber/tests/component.py similarity index 99% rename from tests/jmc/jabber/test_component.py rename to src/jmc/jabber/tests/component.py index 17b7268..1bc65b8 100644 --- a/tests/jmc/jabber/test_component.py +++ b/src/jmc/jabber/tests/component.py @@ -503,3 +503,8 @@ class MailComponent_TestCase(unittest.TestCase): self.assertTrue(account11.marked_all_as_read) del account.hub.threadConnection +def suite(): + return unittest.makeSuite(MailComponent_TestCase, 'test') + +if __name__ == '__main__': + unittest.main(defaultTest='suite') diff --git a/src/jmc/model/account.py b/src/jmc/model/account.py index e1e8b12..df9c642 100644 --- a/src/jmc/model/account.py +++ b/src/jmc/model/account.py @@ -133,7 +133,7 @@ class MailAccount(PresenceAccount): # Define constants DIGEST = 1 RETRIEVE = 2 - default_encoding = "iso-8859-1" + default_encoding = "utf-8" possibles_actions = [PresenceAccount.DO_NOTHING, \ DIGEST, \ RETRIEVE] @@ -223,13 +223,13 @@ class MailAccount(PresenceAccount): if content_charset: result = unicode(part.get_payload(decode=True).decode(content_charset)) else: - result = unicode(part.get_payload(decode=True)) + result = unicode(part.get_payload(decode=True).decode(MailAccount.default_encoding)) except Exception, e: try: - result = unicode(part.get_payload(decode=True).decode("iso-8859-1")) + result = unicode(part.get_payload(decode=True)) except Exception, e: 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: if charset_hint is not None: try: @@ -252,13 +252,13 @@ class MailAccount(PresenceAccount): charset_hint = from_decoded[i][1] email_from += unicode(from_decoded[i][0].decode(from_decoded[i][1])) else: - email_from += unicode(from_decoded[i][0]) + email_from += unicode(from_decoded[i][0].decode(MailAccount.default_encoding)) except Exception,e: try: - email_from += unicode(from_decoded[i][0].decode("iso-8859-1")) + email_from += unicode(from_decoded[i][0]) except Exception, e: 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: type, value, stack = sys.exc_info() print >>sys.stderr, "".join(traceback.format_exception @@ -273,13 +273,13 @@ class MailAccount(PresenceAccount): charset_hint = subject_decoded[i][1] result += unicode(subject_decoded[i][0].decode(subject_decoded[i][1])) else: - result += unicode(subject_decoded[i][0]) + result += unicode(subject_decoded[i][0].decode(MailAccount.default_encoding)) except Exception,e: try: - result += unicode(subject_decoded[i][0].decode("iso-8859-1")) + result += unicode(subject_decoded[i][0]) except Exception, e: try: - result += unicode(subject_decoded[i][0].decode(default_encoding)) + result += unicode(subject_decoded[i][0].decode("iso-8859-1")) except Exception, e: if charset_hint is not None: try: diff --git a/src/jmc/model/tests/__init__.py b/src/jmc/model/tests/__init__.py new file mode 100644 index 0000000..c0494a1 --- /dev/null +++ b/src/jmc/model/tests/__init__.py @@ -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') diff --git a/tests/jmc/model/test_account.py b/src/jmc/model/tests/account.py similarity index 97% rename from tests/jmc/model/test_account.py rename to src/jmc/model/tests/account.py index f1bba49..e7ca4c9 100644 --- a/tests/jmc/model/test_account.py +++ b/src/jmc/model/tests/account.py @@ -34,7 +34,7 @@ from jcl.model.account import Account, PresenceAccount from jmc.model.account import MailAccount, POP3Account, IMAPAccount 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": 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 inner(self): - self.server = dummy_server.DummyServer("localhost", 1110) + self.server = server.DummyServer("localhost", 1110) thread.start_new_thread(self.server.serve, ()) self.server.responses = ["+OK connected\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 inner(self): - self.server = dummy_server.DummyServer("localhost", 1143) + self.server = server.DummyServer("localhost", 1143) thread.start_new_thread(self.server.serve, ()) self.server.responses = ["* OK [CAPABILITY IMAP4 LOGIN-REFERRALS " + \ "AUTH=PLAIN]\n", \ @@ -387,3 +387,14 @@ class IMAPAccount_TestCase(unittest.TestCase): def test_get_register_fields(self): register_fields = IMAPAccount.get_register_fields() 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') diff --git a/tests/jmc/email_generator.py b/src/jmc/model/tests/email_generator.py similarity index 100% rename from tests/jmc/email_generator.py rename to src/jmc/model/tests/email_generator.py diff --git a/tests/jmc/dummy_server.py b/src/jmc/model/tests/server.py similarity index 100% rename from tests/jmc/dummy_server.py rename to src/jmc/model/tests/server.py diff --git a/src/jmc/tests/__init__.py b/src/jmc/tests/__init__.py new file mode 100644 index 0000000..a97a7a5 --- /dev/null +++ b/src/jmc/tests/__init__.py @@ -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') diff --git a/tests/jmc/test_lang.py b/src/jmc/tests/lang.py similarity index 93% rename from tests/jmc/test_lang.py rename to src/jmc/tests/lang.py index af47ce5..5f0acb9 100644 --- a/tests/jmc/test_lang.py +++ b/src/jmc/tests/lang.py @@ -20,6 +20,7 @@ ## along with this program; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ## +# TODO : Reuse JCL Lang tests import unittest from jmc.lang import Lang @@ -63,3 +64,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/jmc/__init__.py b/tests/jmc/__init__.py deleted file mode 100644 index d424a64..0000000 --- a/tests/jmc/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -"""JMC test module""" -__revision__ = "" diff --git a/tests/jmc/jabber/__init__.py b/tests/jmc/jabber/__init__.py deleted file mode 100644 index 9ef7a58..0000000 --- a/tests/jmc/jabber/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -"""JMC jabber test module""" -__revision__ = "" diff --git a/tests/jmc/model/__init__.py b/tests/jmc/model/__init__.py deleted file mode 100644 index e69de29..0000000