diff --git a/test/OLItest/TestRunner.py b/test/OLItest/TestRunner.py index e6277f2..7a2bb51 100644 --- a/test/OLItest/TestRunner.py +++ b/test/OLItest/TestRunner.py @@ -22,7 +22,10 @@ import sys import shutil import subprocess import tempfile -from ConfigParser import SafeConfigParser +try: + from configparser import SafeConfigParser +except ImportError: # python 2 + from ConfigParser import SafeConfigParser from . import default_conf class OLITestLib(): @@ -90,7 +93,7 @@ class OLITestLib(): config = cls.get_default_config() localfolders = os.path.join(cls.testdir, 'mail') config.set("Repository Maildir", "localfolders", localfolders) - with open(os.path.join(cls.testdir, 'offlineimap.conf'), "wa") as f: + with open(os.path.join(cls.testdir, 'offlineimap.conf'), "wt") as f: config.write(f) @classmethod @@ -105,7 +108,7 @@ class OLITestLib(): def run_OLI(cls): """Runs OfflineImap - :returns: (rescode, stdout) + :returns: (rescode, stdout (as unicode)) """ try: output = subprocess.check_output( @@ -113,8 +116,8 @@ class OLITestLib(): "-c%s" % os.path.join(cls.testdir, 'offlineimap.conf')], shell=False) except subprocess.CalledProcessError as e: - return (e.returncode, e.output) - return (0, output) + return (e.returncode, e.output.decode('utf-8')) + return (0, output.decode('utf-8')) @classmethod def delete_remote_testfolders(cls, reponame=None): @@ -128,7 +131,7 @@ class OLITestLib(): sections = [r for r in config.sections() \ if r.startswith('Repository')] sections = filter(lambda s: \ - config.get(s, 'Type', None).lower() == 'imap', + config.get(s, 'Type').lower() == 'imap', sections) for sec in sections: # Connect to each IMAP repo and delete all folders @@ -144,21 +147,22 @@ class OLITestLib(): assert res_t == 'OK' dirs = [] for d in data: - m = re.search(r''' # Find last quote + m = re.search(br''' # Find last quote "((?: # Non-tripple quoted can contain... [^"] | # a non-quote \\" # a backslashded quote )*)" # closing quote [^"]*$ # followed by no more quotes ''', d, flags=re.VERBOSE) - folder = m.group(1) - folder = folder.replace(r'\"', '"') # remove quoting + folder = bytearray(m.group(1)) + folder = folder.replace(br'\"', b'"') # remove quoting dirs.append(folder) # 2) filter out those not starting with INBOX.OLItest and del... - dirs = [d for d in dirs if d.startswith('INBOX.OLItest')] + dirs = [d for d in dirs if d.startswith(b'INBOX.OLItest')] for folder in dirs: - res_t, data = imapobj.delete(folder) - assert res_t == 'OK' + res_t, data = imapobj.delete(str(folder)) + assert res_t == 'OK', "Folder deletion of {} failed with error"\ + ":\n{} {}".format(folder.decode('utf-8'), res_t, data) imapobj.logout() @classmethod diff --git a/test/OLItest/__init__.py b/test/OLItest/__init__.py index 6fcd52f..ca6ef61 100644 --- a/test/OLItest/__init__.py +++ b/test/OLItest/__init__.py @@ -31,4 +31,4 @@ banner = """%(__productname__)s %(__version__)s import unittest from unittest import TestLoader, TextTestRunner from .globals import default_conf -from TestRunner import OLITestLib +from .TestRunner import OLITestLib diff --git a/test/OLItest/globals.py b/test/OLItest/globals.py index 88806f2..8e69ee8 100644 --- a/test/OLItest/globals.py +++ b/test/OLItest/globals.py @@ -14,7 +14,10 @@ # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -from cStringIO import StringIO +try: + from cStringIO import StringIO +except ImportError: #python3 + from io import StringIO default_conf=StringIO("""[general] #will be set automatically diff --git a/test/tests/test_01_basic.py b/test/tests/test_01_basic.py index 0967d9d..6cda54e 100644 --- a/test/tests/test_01_basic.py +++ b/test/tests/test_01_basic.py @@ -65,7 +65,7 @@ class TestBasicFunctions(unittest.TestCase): code, res = OLITestLib.run_OLI() self.assertEqual(res, "") boxes, mails = OLITestLib.count_maildir_mails('') - self.assertTrue((boxes, mails)==(0,0), msg="Expected 0 folders and 0" + self.assertTrue((boxes, mails)==(0,0), msg="Expected 0 folders and 0 " "mails, but sync led to {} folders and {} mails".format( boxes, mails))