Reformat offlineimap/test/OLItest/TestRunner.py
Add some spaces, remove lines,... now format is better (lintian).
This commit is contained in:
parent
6d4298dca7
commit
d75cf8d80c
@ -23,6 +23,7 @@ import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
import random
|
||||
|
||||
random.seed()
|
||||
|
||||
from offlineimap.CustomConfig import CustomConfigParser
|
||||
@ -36,7 +37,7 @@ class OLITestLib():
|
||||
cmd = None
|
||||
"""command that will be executed to invoke offlineimap"""
|
||||
|
||||
def __init__(self, cred_file = None, cmd='offlineimap'):
|
||||
def __init__(self, cred_file=None, cmd='offlineimap'):
|
||||
"""
|
||||
|
||||
:param cred_file: file of the configuration
|
||||
@ -59,7 +60,7 @@ class OLITestLib():
|
||||
assert cls.cred_file != None
|
||||
# creating temporary dir for testing in same dir as credentials.conf
|
||||
cls.testdir = os.path.abspath(
|
||||
tempfile.mkdtemp(prefix='tmp_%s_'%suffix,
|
||||
tempfile.mkdtemp(prefix='tmp_%s_' % suffix,
|
||||
dir=os.path.dirname(cls.cred_file)))
|
||||
cls.write_config_file()
|
||||
return cls.testdir
|
||||
@ -70,7 +71,7 @@ class OLITestLib():
|
||||
|
||||
The returned config can be manipulated and then saved with
|
||||
write_config_file()"""
|
||||
#TODO, only do first time and cache then for subsequent calls?
|
||||
# TODO, only do first time and cache then for subsequent calls?
|
||||
assert cls.cred_file != None
|
||||
assert cls.testdir != None
|
||||
config = CustomConfigParser()
|
||||
@ -162,13 +163,13 @@ class OLITestLib():
|
||||
folder = bytearray(m.group('dir'))
|
||||
if not m.group('quote'):
|
||||
folder = '"%s"' % folder
|
||||
#folder = folder.replace(br'\"', b'"') # remove quoting
|
||||
# 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(b'"INBOX.OLItest') or d.startswith(b'"INBOX/OLItest')]
|
||||
for folder in dirs:
|
||||
res_t, data = imapobj.delete(folder)
|
||||
assert res_t == 'OK', "Folder deletion of {0} failed with error"\
|
||||
assert res_t == 'OK', "Folder deletion of {0} failed with error" \
|
||||
":\n{1} {2}".format(folder.decode('utf-8'), res_t, data)
|
||||
imapobj.logout()
|
||||
|
||||
@ -179,7 +180,7 @@ class OLITestLib():
|
||||
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'):
|
||||
for subdir in ('', 'tmp', 'cur', 'new'):
|
||||
try:
|
||||
os.makedirs(os.path.join(maildir, subdir))
|
||||
except OSError as e:
|
||||
@ -203,12 +204,12 @@ class OLITestLib():
|
||||
Use some default content if not given"""
|
||||
assert cls.testdir != None
|
||||
while True: # Loop till we found a unique filename
|
||||
mailfile = '{0}:2,'.format(random.randint(0,999999999))
|
||||
mailfile = '{0}:2,'.format(random.randint(0, 999999999))
|
||||
mailfilepath = os.path.join(cls.testdir, 'mail',
|
||||
folder, 'new', mailfile)
|
||||
if not os.path.isfile(mailfilepath):
|
||||
break
|
||||
with open(mailfilepath,"wb") as mailf:
|
||||
with open(mailfilepath, "wb") as mailf:
|
||||
mailf.write(b'''From: test <test@offlineimap.org>
|
||||
Subject: Boo
|
||||
Date: 1 Jan 1980
|
||||
@ -229,7 +230,7 @@ Content here.''')
|
||||
if set(dirs) == set(['cur', 'new', 'tmp']):
|
||||
# New maildir folder
|
||||
boxes += 1
|
||||
#raise RuntimeError("%s is not Maildir" % maildir)
|
||||
# raise RuntimeError("%s is not Maildir" % maildir)
|
||||
if dirpath.endswith(('/cur', '/new')):
|
||||
mails += len(files)
|
||||
return boxes, mails
|
||||
|
Loading…
Reference in New Issue
Block a user