diff --git a/setup.py b/setup.py index e684cda..3d04af2 100644 --- a/setup.py +++ b/setup.py @@ -25,7 +25,7 @@ import os from distutils.core import setup, Command import offlineimap import logging -from test.OLItest import OLITextTestRunner, TestLoader, OLITestLib +from test.OLItest import TextTestRunner, TestLoader, OLITestLib class TestCommand(Command): """runs the OLI testsuite""" @@ -44,7 +44,7 @@ class TestCommand(Command): OLITestLib(cred_file='./test/credentials.conf', cmd='./offlineimap.py') suite = TestLoader().discover('./test/tests') #TODO: failfast does not seem to exist in python2.6? - OLITextTestRunner(verbosity=2,failfast=True).run(suite) + TextTestRunner(verbosity=2,failfast=True).run(suite) setup(name = "offlineimap", diff --git a/test/OLItest/TestRunner.py b/test/OLItest/TestRunner.py index 0d0730b..183f67a 100644 --- a/test/OLItest/TestRunner.py +++ b/test/OLItest/TestRunner.py @@ -99,8 +99,34 @@ class OLITestLib(): return (e.returncode, e.output) return (0, output) -class OLITextTestRunner(unittest.TextTestRunner): + @classmethod + def create_maildir(cls, folder): + """Create empty maildir 'folder' in our test maildir - def __init__(self,*args, **kwargs): - logging.warning("OfflineImap testsuite") - return super(OLITextTestRunner, self).__init__(*args, **kwargs) + Does not fail if it already exists""" + assert cls.testdir != None + maildir = os.path.join(cls.testdir, 'mail', folder) + for subdir in ('','tmp','cur','new'): + try: + os.mkdir(os.path.join(maildir, subdir)) + except OSError as e: + if e.errno != 17: # 'already exists' is ok. + raise + + @classmethod + def count_maildir_mails(cls, folder): + """Returns the number of mails in maildir 'folder' + + Counting only those in cur&new (ignoring tmp).""" + assert cls.testdir != None + maildir = os.path.join(cls.testdir, 'mail', folder) + + boxes, mails = 0, 0 + for dirpath, dirs, files in os.walk(maildir, False): + if set(dirs) == set(['cur', 'new', 'tmp']): + # New maildir folder + boxes += 1 + #raise RuntimeError("%s is not Maildir" % maildir) + if dirpath.endswith(('/cur', '/new')): + mails += len(files) + return boxes, mails diff --git a/test/OLItest/__init__.py b/test/OLItest/__init__.py index c9bda69..2f85210 100644 --- a/test/OLItest/__init__.py +++ b/test/OLItest/__init__.py @@ -15,7 +15,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -__all__ = ['OLITestLib', 'OLITextTestRunner','TestLoader'] +__all__ = ['OLITestLib', 'TextTestRunner','TestLoader'] __productname__ = 'OfflineIMAP Test suite' __version__ = '0' @@ -29,6 +29,6 @@ banner = """%(__productname__)s %(__version__)s %(__license__)s""" % locals() import unittest -from unittest import TestLoader +from unittest import TestLoader, TextTestRunner from globals import default_conf -from TestRunner import OLITestLib, OLITextTestRunner +from TestRunner import OLITestLib diff --git a/test/OLItest/globals.py b/test/OLItest/globals.py index 4009b9b..5d1f122 100644 --- a/test/OLItest/globals.py +++ b/test/OLItest/globals.py @@ -33,5 +33,5 @@ localfolders = [Repository IMAP] type=IMAP -folderfilter= lambda f: f.startswith('OLItest') +folderfilter= lambda f: f.startswith('INBOX.OLItest') """) diff --git a/test/tests/test_01_basic.py b/test/tests/test_01_basic.py index cb6d293..a0697ec 100644 --- a/test/tests/test_01_basic.py +++ b/test/tests/test_01_basic.py @@ -55,17 +55,20 @@ class TestBasicFunctions(unittest.TestCase): It syncs all "OLItest* (specified in the default config) to our local Maildir at keeps it there.""" code, res = OLITestLib.run_OLI() - #logging.warn("%s %s "% (code, res)) self.assertEqual(res, "") - #TODO implement OLITestLib.countmails() - logging.warn("synced %d boxes, %d mails" % (0,0)) - def test_02_wipedir(self): - """Wipe OLItest* maildir, sync and see if it's still empty + boxes, mails = OLITestLib.count_maildir_mails('') + logging.warn("%d boxes and %d mails" % (boxes, mails)) - Wipes all "OLItest* (specified in the default config) to our - local Maildir at keeps it there.""" + def test_02_createdir(self): + """Create local OLItest 1 & OLItest "1" maildir, sync + Folder names with quotes used to fail and have been fixed, so + one is included here as a small challenge.""" + OLITestLib.create_maildir('INBOX.OLItest 1') + OLITestLib.create_maildir('INBOX.OLItest "1"') code, res = OLITestLib.run_OLI() #logging.warn("%s %s "% (code, res)) self.assertEqual(res, "") + boxes, mails = OLITestLib.count_maildir_mails('') + logging.warn("%d boxes and %d mails" % (boxes, mails))