tests: make tests (nearly) work with python3
Tests work now with python 3 with the exception of the deletion of remote testfolders which fails for some reasons. Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
This commit is contained in:
parent
d0723fb8a2
commit
d1e6e1f09e
@ -22,7 +22,10 @@ import sys
|
|||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import tempfile
|
import tempfile
|
||||||
from ConfigParser import SafeConfigParser
|
try:
|
||||||
|
from configparser import SafeConfigParser
|
||||||
|
except ImportError: # python 2
|
||||||
|
from ConfigParser import SafeConfigParser
|
||||||
from . import default_conf
|
from . import default_conf
|
||||||
|
|
||||||
class OLITestLib():
|
class OLITestLib():
|
||||||
@ -90,7 +93,7 @@ class OLITestLib():
|
|||||||
config = cls.get_default_config()
|
config = cls.get_default_config()
|
||||||
localfolders = os.path.join(cls.testdir, 'mail')
|
localfolders = os.path.join(cls.testdir, 'mail')
|
||||||
config.set("Repository Maildir", "localfolders", localfolders)
|
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)
|
config.write(f)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -105,7 +108,7 @@ class OLITestLib():
|
|||||||
def run_OLI(cls):
|
def run_OLI(cls):
|
||||||
"""Runs OfflineImap
|
"""Runs OfflineImap
|
||||||
|
|
||||||
:returns: (rescode, stdout)
|
:returns: (rescode, stdout (as unicode))
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
output = subprocess.check_output(
|
output = subprocess.check_output(
|
||||||
@ -113,8 +116,8 @@ class OLITestLib():
|
|||||||
"-c%s" % os.path.join(cls.testdir, 'offlineimap.conf')],
|
"-c%s" % os.path.join(cls.testdir, 'offlineimap.conf')],
|
||||||
shell=False)
|
shell=False)
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
return (e.returncode, e.output)
|
return (e.returncode, e.output.decode('utf-8'))
|
||||||
return (0, output)
|
return (0, output.decode('utf-8'))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def delete_remote_testfolders(cls, reponame=None):
|
def delete_remote_testfolders(cls, reponame=None):
|
||||||
@ -128,7 +131,7 @@ class OLITestLib():
|
|||||||
sections = [r for r in config.sections() \
|
sections = [r for r in config.sections() \
|
||||||
if r.startswith('Repository')]
|
if r.startswith('Repository')]
|
||||||
sections = filter(lambda s: \
|
sections = filter(lambda s: \
|
||||||
config.get(s, 'Type', None).lower() == 'imap',
|
config.get(s, 'Type').lower() == 'imap',
|
||||||
sections)
|
sections)
|
||||||
for sec in sections:
|
for sec in sections:
|
||||||
# Connect to each IMAP repo and delete all folders
|
# Connect to each IMAP repo and delete all folders
|
||||||
@ -144,21 +147,22 @@ class OLITestLib():
|
|||||||
assert res_t == 'OK'
|
assert res_t == 'OK'
|
||||||
dirs = []
|
dirs = []
|
||||||
for d in data:
|
for d in data:
|
||||||
m = re.search(r''' # Find last quote
|
m = re.search(br''' # Find last quote
|
||||||
"((?: # Non-tripple quoted can contain...
|
"((?: # Non-tripple quoted can contain...
|
||||||
[^"] | # a non-quote
|
[^"] | # a non-quote
|
||||||
\\" # a backslashded quote
|
\\" # a backslashded quote
|
||||||
)*)" # closing quote
|
)*)" # closing quote
|
||||||
[^"]*$ # followed by no more quotes
|
[^"]*$ # followed by no more quotes
|
||||||
''', d, flags=re.VERBOSE)
|
''', d, flags=re.VERBOSE)
|
||||||
folder = m.group(1)
|
folder = bytearray(m.group(1))
|
||||||
folder = folder.replace(r'\"', '"') # remove quoting
|
folder = folder.replace(br'\"', b'"') # remove quoting
|
||||||
dirs.append(folder)
|
dirs.append(folder)
|
||||||
# 2) filter out those not starting with INBOX.OLItest and del...
|
# 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:
|
for folder in dirs:
|
||||||
res_t, data = imapobj.delete(folder)
|
res_t, data = imapobj.delete(str(folder))
|
||||||
assert res_t == 'OK'
|
assert res_t == 'OK', "Folder deletion of {} failed with error"\
|
||||||
|
":\n{} {}".format(folder.decode('utf-8'), res_t, data)
|
||||||
imapobj.logout()
|
imapobj.logout()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -31,4 +31,4 @@ banner = """%(__productname__)s %(__version__)s
|
|||||||
import unittest
|
import unittest
|
||||||
from unittest import TestLoader, TextTestRunner
|
from unittest import TestLoader, TextTestRunner
|
||||||
from .globals import default_conf
|
from .globals import default_conf
|
||||||
from TestRunner import OLITestLib
|
from .TestRunner import OLITestLib
|
||||||
|
@ -14,7 +14,10 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# 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
|
||||||
from cStringIO import StringIO
|
try:
|
||||||
|
from cStringIO import StringIO
|
||||||
|
except ImportError: #python3
|
||||||
|
from io import StringIO
|
||||||
|
|
||||||
default_conf=StringIO("""[general]
|
default_conf=StringIO("""[general]
|
||||||
#will be set automatically
|
#will be set automatically
|
||||||
|
@ -65,7 +65,7 @@ class TestBasicFunctions(unittest.TestCase):
|
|||||||
code, res = OLITestLib.run_OLI()
|
code, res = OLITestLib.run_OLI()
|
||||||
self.assertEqual(res, "")
|
self.assertEqual(res, "")
|
||||||
boxes, mails = OLITestLib.count_maildir_mails('')
|
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(
|
"mails, but sync led to {} folders and {} mails".format(
|
||||||
boxes, mails))
|
boxes, mails))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user