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,48 +4,49 @@
from offlineimap import globals
import unittest
class Opt:
def __init__(self):
self.one = "baz"
self.two = 42
self.three = True
def __init__(self):
self.one = "baz"
self.two = 42
self.three = True
class TestOfflineimapGlobals(unittest.TestCase):
@classmethod
def setUpClass(klass):
klass.o = Opt()
globals.set_options (klass.o)
@classmethod
def setUpClass(klass):
klass.o = Opt()
globals.set_options(klass.o)
def test_initial_state(self):
for k in self.o.__dict__.keys():
self.assertTrue(getattr(self.o, k) ==
getattr(globals.options, k))
def test_initial_state(self):
for k in self.o.__dict__.keys():
self.assertTrue(getattr(self.o, k) ==
getattr(globals.options, k))
def test_object_changes(self):
self.o.one = "one"
self.o.two = 119
self.o.three = False
return self.test_initial_state()
def test_object_changes(self):
self.o.one = "one"
self.o.two = 119
self.o.three = False
return self.test_initial_state()
def test_modification(self):
with self.assertRaises(AttributeError):
globals.options.two = True
def test_modification(self):
with self.assertRaises(AttributeError):
globals.options.two = True
def test_deletion(self):
with self.assertRaises(RuntimeError):
del globals.options.three
def test_deletion(self):
with self.assertRaises(RuntimeError):
del globals.options.three
def test_nonexistent_key(self):
with self.assertRaises(AttributeError):
a = globals.options.nosuchoption
def test_nonexistent_key(self):
with self.assertRaises(AttributeError):
a = globals.options.nosuchoption
def test_double_init(self):
with self.assertRaises(ValueError):
globals.set_options (True)
def test_double_init(self):
with self.assertRaises(ValueError):
globals.set_options(True)
if __name__ == "__main__":
suite = unittest.TestLoader().loadTestsFromTestCase(TestOfflineimapGlobals)
unittest.TextTestRunner(verbosity=2).run(suite)
suite = unittest.TestLoader().loadTestsFromTestCase(TestOfflineimapGlobals)
unittest.TextTestRunner(verbosity=2).run(suite)

View File

@ -27,21 +27,24 @@ from test.OLItest import OLITestLib
if not OLITestLib.cred_file:
OLITestLib(cred_file='./test/credentials.conf', cmd='./offlineimap.py')
def setUpModule():
logging.info("Set Up test module %s" % __name__)
tdir = OLITestLib.create_test_dir(suffix=__name__)
def tearDownModule():
logging.info("Tear Down test module")
# comment out next line to keep testdir after test runs. TODO: make nicer
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
#self.assertRaises(TypeError, random.shuffle, (1,2,3))
#self.assertTrue(element in self.seq)
#self.assertFalse(element in self.seq)
# self.assertRaises(TypeError, random.shuffle, (1,2,3))
# self.assertTrue(element in self.seq)
# self.assertFalse(element in self.seq)
class TestInternalFunctions(unittest.TestCase):
"""While the other test files test OfflineImap as a program, these
@ -50,8 +53,8 @@ class TestInternalFunctions(unittest.TestCase):
@classmethod
def setUpClass(cls):
#This is run before all tests in this class
config= OLITestLib.get_default_config()
# This is run before all tests in this class
config = OLITestLib.get_default_config()
setglobalui(UI_LIST['quiet'](config))
def test_01_imapsplit(self):
@ -90,5 +93,5 @@ class TestInternalFunctions(unittest.TestCase):
def test_07_uid_sequence(self):
"""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')

View File

@ -29,16 +29,18 @@ def setUpModule():
logging.info("Set Up test module %s" % __name__)
tdir = OLITestLib.create_test_dir(suffix=__name__)
def tearDownModule():
logging.info("Tear Down test module")
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
#self.assertRaises(TypeError, random.shuffle, (1,2,3))
#self.assertTrue(element in self.seq)
#self.assertFalse(element in self.seq)
# self.assertRaises(TypeError, random.shuffle, (1,2,3))
# self.assertTrue(element in self.seq)
# self.assertFalse(element in self.seq)
class TestBasicFunctions(unittest.TestCase):
def setUp(self):
@ -56,36 +58,36 @@ 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 "
"mails, but sync led to {0} folders and {1} mails".format(
boxes, mails))
self.assertTrue((boxes, mails) == (0, 0), msg="Expected 0 folders and 0 "
"mails, but sync led to {0} folders and {1} mails".format(
boxes, mails))
def test_02_createdir(self):
"""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')
code, res = OLITestLib.run_OLI()
self.assertEqual(res, "")
boxes, mails = OLITestLib.count_maildir_mails('')
self.assertTrue((boxes, mails)==(1,0), msg="Expected 1 folders and 0 "
"mails, but sync led to {0} folders and {1} mails".format(
boxes, mails))
self.assertTrue((boxes, mails) == (1, 0), msg="Expected 1 folders and 0 "
"mails, but sync led to {0} folders and {1} mails".format(
boxes, mails))
def test_03_createdir_quote(self):
"""Create local '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.delete_maildir('') #Delete all local maildir folders
OLITestLib.delete_maildir('') # Delete all local maildir folders
OLITestLib.create_maildir('INBOX.OLItest "1"')
code, res = OLITestLib.run_OLI()
if 'unallowed folder' in res:
raise unittest.SkipTest("remote server doesn't handle quote")
self.assertEqual(res, "")
boxes, mails = OLITestLib.count_maildir_mails('')
self.assertTrue((boxes, mails)==(1,0), msg="Expected 1 folders and 0 "
"mails, but sync led to {0} folders and {1} mails".format(
boxes, mails))
self.assertTrue((boxes, mails) == (1, 0), msg="Expected 1 folders and 0 "
"mails, but sync led to {0} folders and {1} mails".format(
boxes, mails))
def test_04_nametransmismatch(self):
"""Create mismatching remote and local nametrans rules
@ -93,21 +95,20 @@ class TestBasicFunctions(unittest.TestCase):
This should raise an error."""
config = OLITestLib.get_default_config()
config.set('Repository IMAP', 'nametrans',
'lambda f: f' )
'lambda f: f')
config.set('Repository Maildir', 'nametrans',
'lambda f: f + "moo"' )
'lambda f: f + "moo"')
OLITestLib.write_config_file(config)
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....
mismatch = "ERROR: INFINITE FOLDER CREATION DETECTED!" in res
self.assertEqual(mismatch, True, msg="Mismatching nametrans rules did "
"NOT trigger an 'infinite folder generation' error. Output was:\n"
"{0}".format(res))
"NOT trigger an 'infinite folder generation' error. Output was:\n"
"{0}".format(res))
# Write out default config file again
OLITestLib.write_config_file()
def test_05_createmail(self):
"""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
implemented, this behavior will change."""
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_mail('INBOX.OLItest')
code, res = OLITestLib.run_OLI()
#logging.warn("%s %s "% (code, res))
# logging.warn("%s %s "% (code, res))
self.assertEqual(res, "")
boxes, mails = OLITestLib.count_maildir_mails('')
self.assertTrue((boxes, mails)==(1,1), msg="Expected 1 folders and 1 "
"mails, but sync led to {0} folders and {1} mails".format(
boxes, mails))
self.assertTrue((boxes, mails) == (1, 1), msg="Expected 1 folders and 1 "
"mails, but sync led to {0} folders and {1} mails".format(
boxes, mails))
# The local Mail should have been assigned a proper UID now, check!
uids = OLITestLib.get_maildir_uids('INBOX.OLItest')
self.assertFalse (None in uids, msg = "All mails should have been "+ \
"assigned the IMAP's UID number, but {0} messages had no valid ID "\
.format(len([None for x in uids if x==None])))
self.assertFalse(None in uids, msg="All mails should have been " + \
"assigned the IMAP's UID number, but {0} messages had no valid ID " \
.format(len([None for x in uids if x == None])))
def test_06_createfolders(self):
"""Test if createfolders works as expected
@ -141,7 +142,7 @@ class TestBasicFunctions(unittest.TestCase):
been written"""
config = OLITestLib.get_default_config()
config.set('Repository IMAP', 'createfolders',
'False' )
'False')
OLITestLib.write_config_file(config)
# delete all remote and local testfolders
@ -149,12 +150,12 @@ class TestBasicFunctions(unittest.TestCase):
OLITestLib.delete_maildir('')
OLITestLib.create_maildir('INBOX.OLItest')
code, res = OLITestLib.run_OLI()
#logging.warn("%s %s "% (code, res))
# logging.warn("%s %s "% (code, res))
self.assertEqual(res, "")
OLITestLib.delete_maildir('INBOX.OLItest')
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 "
"mails, but sync led to {} folders and {} mails".format(
boxes, mails))
self.assertTrue((boxes, mails) == (0, 0), msg="Expected 0 folders and 0 "
"mails, but sync led to {} folders and {} mails".format(
boxes, mails))

View File

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