Reformat offlineimap/test/tests/ all tests

Add some spaces, remove lines,... now format is better (lintian).
This commit is contained in:
Rodolfo García Peñas (kix) 2020-08-29 20:27:10 +02:00
parent d75cf8d80c
commit bcc497df16
5 changed files with 99 additions and 93 deletions

View File

@ -1 +0,0 @@

View File

@ -4,6 +4,7 @@
from offlineimap import globals from offlineimap import globals
import unittest import unittest
class Opt: class Opt:
def __init__(self): def __init__(self):
self.one = "baz" self.one = "baz"
@ -16,7 +17,7 @@ class TestOfflineimapGlobals(unittest.TestCase):
@classmethod @classmethod
def setUpClass(klass): def setUpClass(klass):
klass.o = Opt() klass.o = Opt()
globals.set_options (klass.o) globals.set_options(klass.o)
def test_initial_state(self): def test_initial_state(self):
for k in self.o.__dict__.keys(): for k in self.o.__dict__.keys():
@ -43,7 +44,7 @@ class TestOfflineimapGlobals(unittest.TestCase):
def test_double_init(self): def test_double_init(self):
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
globals.set_options (True) globals.set_options(True)
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -27,21 +27,24 @@ from test.OLItest import OLITestLib
if not OLITestLib.cred_file: if not OLITestLib.cred_file:
OLITestLib(cred_file='./test/credentials.conf', cmd='./offlineimap.py') OLITestLib(cred_file='./test/credentials.conf', cmd='./offlineimap.py')
def setUpModule(): def setUpModule():
logging.info("Set Up test module %s" % __name__) logging.info("Set Up test module %s" % __name__)
tdir = OLITestLib.create_test_dir(suffix=__name__) tdir = OLITestLib.create_test_dir(suffix=__name__)
def tearDownModule(): def tearDownModule():
logging.info("Tear Down test module") logging.info("Tear Down test module")
# comment out next line to keep testdir after test runs. TODO: make nicer # comment out next line to keep testdir after test runs. TODO: make nicer
OLITestLib.delete_test_dir() OLITestLib.delete_test_dir()
#Stuff that can be used
#self.assertEqual(self.seq, range(10)) # Stuff that can be used
# self.assertEqual(self.seq, range(10))
# should raise an exception for an immutable sequence # should raise an exception for an immutable sequence
#self.assertRaises(TypeError, random.shuffle, (1,2,3)) # self.assertRaises(TypeError, random.shuffle, (1,2,3))
#self.assertTrue(element in self.seq) # self.assertTrue(element in self.seq)
#self.assertFalse(element in self.seq) # self.assertFalse(element in self.seq)
class TestInternalFunctions(unittest.TestCase): class TestInternalFunctions(unittest.TestCase):
"""While the other test files test OfflineImap as a program, these """While the other test files test OfflineImap as a program, these
@ -50,8 +53,8 @@ class TestInternalFunctions(unittest.TestCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
#This is run before all tests in this class # This is run before all tests in this class
config= OLITestLib.get_default_config() config = OLITestLib.get_default_config()
setglobalui(UI_LIST['quiet'](config)) setglobalui(UI_LIST['quiet'](config))
def test_01_imapsplit(self): def test_01_imapsplit(self):
@ -90,5 +93,5 @@ class TestInternalFunctions(unittest.TestCase):
def test_07_uid_sequence(self): def test_07_uid_sequence(self):
"""Test imaputil.uid_sequence()""" """Test imaputil.uid_sequence()"""
res = imaputil.uid_sequence([1,2,3,4,5,10,12,13]) res = imaputil.uid_sequence([1, 2, 3, 4, 5, 10, 12, 13])
self.assertEqual(res, b'1:5,10,12:13') self.assertEqual(res, b'1:5,10,12:13')

View File

@ -29,16 +29,18 @@ def setUpModule():
logging.info("Set Up test module %s" % __name__) logging.info("Set Up test module %s" % __name__)
tdir = OLITestLib.create_test_dir(suffix=__name__) tdir = OLITestLib.create_test_dir(suffix=__name__)
def tearDownModule(): def tearDownModule():
logging.info("Tear Down test module") logging.info("Tear Down test module")
OLITestLib.delete_test_dir() OLITestLib.delete_test_dir()
#Stuff that can be used
#self.assertEqual(self.seq, range(10)) # Stuff that can be used
# self.assertEqual(self.seq, range(10))
# should raise an exception for an immutable sequence # should raise an exception for an immutable sequence
#self.assertRaises(TypeError, random.shuffle, (1,2,3)) # self.assertRaises(TypeError, random.shuffle, (1,2,3))
#self.assertTrue(element in self.seq) # self.assertTrue(element in self.seq)
#self.assertFalse(element in self.seq) # self.assertFalse(element in self.seq)
class TestBasicFunctions(unittest.TestCase): class TestBasicFunctions(unittest.TestCase):
def setUp(self): def setUp(self):
@ -56,18 +58,18 @@ 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 {0} folders and {1} mails".format( "mails, but sync led to {0} folders and {1} mails".format(
boxes, mails)) boxes, mails))
def test_02_createdir(self): def test_02_createdir(self):
"""Create local 'OLItest 1', sync""" """Create local 'OLItest 1', sync"""
OLITestLib.delete_maildir('') #Delete all local maildir folders OLITestLib.delete_maildir('') # Delete all local maildir folders
OLITestLib.create_maildir('INBOX.OLItest 1') OLITestLib.create_maildir('INBOX.OLItest 1')
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)==(1,0), msg="Expected 1 folders and 0 " self.assertTrue((boxes, mails) == (1, 0), msg="Expected 1 folders and 0 "
"mails, but sync led to {0} folders and {1} mails".format( "mails, but sync led to {0} folders and {1} mails".format(
boxes, mails)) boxes, mails))
@ -76,14 +78,14 @@ class TestBasicFunctions(unittest.TestCase):
Folder names with quotes used to fail and have been fixed, so Folder names with quotes used to fail and have been fixed, so
one is included here as a small challenge.""" one is included here as a small challenge."""
OLITestLib.delete_maildir('') #Delete all local maildir folders OLITestLib.delete_maildir('') # Delete all local maildir folders
OLITestLib.create_maildir('INBOX.OLItest "1"') OLITestLib.create_maildir('INBOX.OLItest "1"')
code, res = OLITestLib.run_OLI() code, res = OLITestLib.run_OLI()
if 'unallowed folder' in res: if 'unallowed folder' in res:
raise unittest.SkipTest("remote server doesn't handle quote") raise unittest.SkipTest("remote server doesn't handle quote")
self.assertEqual(res, "") self.assertEqual(res, "")
boxes, mails = OLITestLib.count_maildir_mails('') boxes, mails = OLITestLib.count_maildir_mails('')
self.assertTrue((boxes, mails)==(1,0), msg="Expected 1 folders and 0 " self.assertTrue((boxes, mails) == (1, 0), msg="Expected 1 folders and 0 "
"mails, but sync led to {0} folders and {1} mails".format( "mails, but sync led to {0} folders and {1} mails".format(
boxes, mails)) boxes, mails))
@ -93,12 +95,12 @@ class TestBasicFunctions(unittest.TestCase):
This should raise an error.""" This should raise an error."""
config = OLITestLib.get_default_config() config = OLITestLib.get_default_config()
config.set('Repository IMAP', 'nametrans', config.set('Repository IMAP', 'nametrans',
'lambda f: f' ) 'lambda f: f')
config.set('Repository Maildir', 'nametrans', config.set('Repository Maildir', 'nametrans',
'lambda f: f + "moo"' ) 'lambda f: f + "moo"')
OLITestLib.write_config_file(config) OLITestLib.write_config_file(config)
code, res = OLITestLib.run_OLI() code, res = OLITestLib.run_OLI()
#logging.warn("%s %s "% (code, res)) # logging.warn("%s %s "% (code, res))
# We expect an INFINITE FOLDER CREATION WARNING HERE.... # We expect an INFINITE FOLDER CREATION WARNING HERE....
mismatch = "ERROR: INFINITE FOLDER CREATION DETECTED!" in res mismatch = "ERROR: INFINITE FOLDER CREATION DETECTED!" in res
self.assertEqual(mismatch, True, msg="Mismatching nametrans rules did " self.assertEqual(mismatch, True, msg="Mismatching nametrans rules did "
@ -107,7 +109,6 @@ class TestBasicFunctions(unittest.TestCase):
# Write out default config file again # Write out default config file again
OLITestLib.write_config_file() OLITestLib.write_config_file()
def test_05_createmail(self): def test_05_createmail(self):
"""Create mail in OLItest 1, sync, wipe folder sync """Create mail in OLItest 1, sync, wipe folder sync
@ -115,21 +116,21 @@ class TestBasicFunctions(unittest.TestCase):
locally. At some point when remote folder deletion is locally. At some point when remote folder deletion is
implemented, this behavior will change.""" implemented, this behavior will change."""
OLITestLib.delete_remote_testfolders() OLITestLib.delete_remote_testfolders()
OLITestLib.delete_maildir('') #Delete all local maildir folders OLITestLib.delete_maildir('') # Delete all local maildir folders
OLITestLib.create_maildir('INBOX.OLItest') OLITestLib.create_maildir('INBOX.OLItest')
OLITestLib.create_mail('INBOX.OLItest') OLITestLib.create_mail('INBOX.OLItest')
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('') boxes, mails = OLITestLib.count_maildir_mails('')
self.assertTrue((boxes, mails)==(1,1), msg="Expected 1 folders and 1 " self.assertTrue((boxes, mails) == (1, 1), msg="Expected 1 folders and 1 "
"mails, but sync led to {0} folders and {1} mails".format( "mails, but sync led to {0} folders and {1} mails".format(
boxes, mails)) boxes, mails))
# The local Mail should have been assigned a proper UID now, check! # The local Mail should have been assigned a proper UID now, check!
uids = OLITestLib.get_maildir_uids('INBOX.OLItest') uids = OLITestLib.get_maildir_uids('INBOX.OLItest')
self.assertFalse (None in uids, msg = "All mails should have been "+ \ self.assertFalse(None in uids, msg="All mails should have been " + \
"assigned the IMAP's UID number, but {0} messages had no valid ID "\ "assigned the IMAP's UID number, but {0} messages had no valid ID " \
.format(len([None for x in uids if x==None]))) .format(len([None for x in uids if x == None])))
def test_06_createfolders(self): def test_06_createfolders(self):
"""Test if createfolders works as expected """Test if createfolders works as expected
@ -141,7 +142,7 @@ class TestBasicFunctions(unittest.TestCase):
been written""" been written"""
config = OLITestLib.get_default_config() config = OLITestLib.get_default_config()
config.set('Repository IMAP', 'createfolders', config.set('Repository IMAP', 'createfolders',
'False' ) 'False')
OLITestLib.write_config_file(config) OLITestLib.write_config_file(config)
# delete all remote and local testfolders # delete all remote and local testfolders
@ -149,12 +150,12 @@ class TestBasicFunctions(unittest.TestCase):
OLITestLib.delete_maildir('') OLITestLib.delete_maildir('')
OLITestLib.create_maildir('INBOX.OLItest') OLITestLib.create_maildir('INBOX.OLItest')
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, "")
OLITestLib.delete_maildir('INBOX.OLItest') OLITestLib.delete_maildir('INBOX.OLItest')
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))

View File

@ -29,30 +29,32 @@ def setUpModule():
logging.info("Set Up test module %s" % __name__) logging.info("Set Up test module %s" % __name__)
tdir = OLITestLib.create_test_dir(suffix=__name__) tdir = OLITestLib.create_test_dir(suffix=__name__)
def tearDownModule(): def tearDownModule():
logging.info("Tear Down test module") logging.info("Tear Down test module")
OLITestLib.delete_test_dir() OLITestLib.delete_test_dir()
#Stuff that can be used
#self.assertEqual(self.seq, range(10)) # Stuff that can be used
# self.assertEqual(self.seq, range(10))
# should raise an exception for an immutable sequence # should raise an exception for an immutable sequence
#self.assertRaises(TypeError, random.shuffle, (1,2,3)) # self.assertRaises(TypeError, random.shuffle, (1,2,3))
#self.assertTrue(element in self.seq) # self.assertTrue(element in self.seq)
#self.assertFalse(element in self.seq) # self.assertFalse(element in self.seq)
class TestBasicFunctions(unittest.TestCase): class TestBasicFunctions(unittest.TestCase):
#@classmethod # @classmethod
#def setUpClass(cls): # def setUpClass(cls):
#This is run before all tests in this class # This is run before all tests in this class
# cls._connection = createExpensiveConnectionObject() # cls._connection = createExpensiveConnectionObject()
#@classmethod # @classmethod
#This is run after all tests in this class # This is run after all tests in this class
#def tearDownClass(cls): # def tearDownClass(cls):
# cls._connection.destroy() # cls._connection.destroy()
# This will be run before each test # This will be run before each test
#def setUp(self): # def setUp(self):
# self.seq = range(10) # self.seq = range(10)
def test_01_MappedImap(self): def test_01_MappedImap(self):
@ -61,11 +63,11 @@ class TestBasicFunctions(unittest.TestCase):
Cleans existing remote test folders. Then syncs all "OLItest* Cleans existing remote test folders. Then syncs all "OLItest*
(specified in the default config) to our local IMAP (Gmail). The (specified in the default config) to our local IMAP (Gmail). The
result should be 0 folders and 0 mails.""" result should be 0 folders and 0 mails."""
pass #TODO pass # TODO
#OLITestLib.delete_remote_testfolders() # OLITestLib.delete_remote_testfolders()
#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))