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:
parent
58450fb22e
commit
314a4e3b2c
4
setup.py
4
setup.py
@ -25,7 +25,7 @@ import os
|
|||||||
from distutils.core import setup, Command
|
from distutils.core import setup, Command
|
||||||
import offlineimap
|
import offlineimap
|
||||||
import logging
|
import logging
|
||||||
from test.OLItest import OLITextTestRunner, TestLoader, OLITestLib
|
from test.OLItest import TextTestRunner, TestLoader, OLITestLib
|
||||||
|
|
||||||
class TestCommand(Command):
|
class TestCommand(Command):
|
||||||
"""runs the OLI testsuite"""
|
"""runs the OLI testsuite"""
|
||||||
@ -44,7 +44,7 @@ class TestCommand(Command):
|
|||||||
OLITestLib(cred_file='./test/credentials.conf', cmd='./offlineimap.py')
|
OLITestLib(cred_file='./test/credentials.conf', cmd='./offlineimap.py')
|
||||||
suite = TestLoader().discover('./test/tests')
|
suite = TestLoader().discover('./test/tests')
|
||||||
#TODO: failfast does not seem to exist in python2.6?
|
#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",
|
setup(name = "offlineimap",
|
||||||
|
@ -99,8 +99,34 @@ class OLITestLib():
|
|||||||
return (e.returncode, e.output)
|
return (e.returncode, e.output)
|
||||||
return (0, 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):
|
Does not fail if it already exists"""
|
||||||
logging.warning("OfflineImap testsuite")
|
assert cls.testdir != None
|
||||||
return super(OLITextTestRunner, self).__init__(*args, **kwargs)
|
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
|
||||||
|
@ -15,7 +15,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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
__all__ = ['OLITestLib', 'OLITextTestRunner','TestLoader']
|
__all__ = ['OLITestLib', 'TextTestRunner','TestLoader']
|
||||||
|
|
||||||
__productname__ = 'OfflineIMAP Test suite'
|
__productname__ = 'OfflineIMAP Test suite'
|
||||||
__version__ = '0'
|
__version__ = '0'
|
||||||
@ -29,6 +29,6 @@ banner = """%(__productname__)s %(__version__)s
|
|||||||
%(__license__)s""" % locals()
|
%(__license__)s""" % locals()
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
from unittest import TestLoader
|
from unittest import TestLoader, TextTestRunner
|
||||||
from globals import default_conf
|
from globals import default_conf
|
||||||
from TestRunner import OLITestLib, OLITextTestRunner
|
from TestRunner import OLITestLib
|
||||||
|
@ -33,5 +33,5 @@ localfolders =
|
|||||||
|
|
||||||
[Repository IMAP]
|
[Repository IMAP]
|
||||||
type=IMAP
|
type=IMAP
|
||||||
folderfilter= lambda f: f.startswith('OLItest')
|
folderfilter= lambda f: f.startswith('INBOX.OLItest')
|
||||||
""")
|
""")
|
||||||
|
@ -55,17 +55,20 @@ class TestBasicFunctions(unittest.TestCase):
|
|||||||
It syncs all "OLItest* (specified in the default config) to our
|
It syncs all "OLItest* (specified in the default config) to our
|
||||||
local Maildir at keeps it there."""
|
local Maildir at keeps it there."""
|
||||||
code, res = OLITestLib.run_OLI()
|
code, res = OLITestLib.run_OLI()
|
||||||
#logging.warn("%s %s "% (code, res))
|
|
||||||
self.assertEqual(res, "")
|
self.assertEqual(res, "")
|
||||||
#TODO implement OLITestLib.countmails()
|
|
||||||
logging.warn("synced %d boxes, %d mails" % (0,0))
|
|
||||||
|
|
||||||
def test_02_wipedir(self):
|
boxes, mails = OLITestLib.count_maildir_mails('')
|
||||||
"""Wipe OLItest* maildir, sync and see if it's still empty
|
logging.warn("%d boxes and %d mails" % (boxes, mails))
|
||||||
|
|
||||||
Wipes all "OLItest* (specified in the default config) to our
|
def test_02_createdir(self):
|
||||||
local Maildir at keeps it there."""
|
"""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()
|
code, res = OLITestLib.run_OLI()
|
||||||
#logging.warn("%s %s "% (code, res))
|
#logging.warn("%s %s "% (code, res))
|
||||||
self.assertEqual(res, "")
|
self.assertEqual(res, "")
|
||||||
|
boxes, mails = OLITestLib.count_maildir_mails('')
|
||||||
|
logging.warn("%d boxes and %d mails" % (boxes, mails))
|
||||||
|
Loading…
Reference in New Issue
Block a user