Improve test suite and add test

1) Add helper functions to create and count maildirs and mails.

2) Add a second test that creates 2 maildirs, one of the including a
quotation sign " in its folder name and sync.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
This commit is contained in:
Sebastian Spaeth 2012-01-20 15:55:44 +01:00
parent 58450fb22e
commit 314a4e3b2c
5 changed files with 46 additions and 17 deletions

View File

@ -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",

View File

@ -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

View File

@ -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

View File

@ -33,5 +33,5 @@ localfolders =
[Repository IMAP]
type=IMAP
folderfilter= lambda f: f.startswith('OLItest')
folderfilter= lambda f: f.startswith('INBOX.OLItest')
""")

View File

@ -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))