From c708e36ff7900e93b46af8f25541c6c349c02b97 Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Tue, 3 Apr 2012 01:13:27 +0200 Subject: [PATCH 1/3] Don't fail if no dry-run setting has been specified Somehow we failed if no dry-run setting had been specified in the config file. This got caught thanks to extending the test suite with a stock configuration. Signed-off-by: Sebastian Spaeth --- Changelog.rst | 3 +++ offlineimap/ui/UIBase.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Changelog.rst b/Changelog.rst index f8bdfaa..53a9797 100644 --- a/Changelog.rst +++ b/Changelog.rst @@ -17,6 +17,9 @@ Changes Bug Fixes --------- +* Don't fail if no dry-run setting exists in offlineimap.conf + (introduced in 6.5.3) + OfflineIMAP v6.5.3 (2012-04-02) =============================== diff --git a/offlineimap/ui/UIBase.py b/offlineimap/ui/UIBase.py index 4bf4423..eea929d 100644 --- a/offlineimap/ui/UIBase.py +++ b/offlineimap/ui/UIBase.py @@ -49,7 +49,7 @@ class UIBase(object): def __init__(self, config, loglevel = logging.INFO): self.config = config # Is this a 'dryrun'? - self.dryrun = config.getboolean('general', 'dry-run') + self.dryrun = config.getdefaultboolean('general', 'dry-run', False) self.debuglist = [] """list of debugtypes we are supposed to log""" self.debugmessages = {} From f67278b2a82acd72c196c5a9fe08431521555ebd Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Tue, 3 Apr 2012 01:34:59 +0200 Subject: [PATCH 2/3] tests: Add tests for imaputil.* functions Add one test for each of the functions in offlineimap.imaputil, to make sure they keep working. These functions tests the internal innards of the offlineimap module rather than invoking offlineimap as a program. Signed-off-by: Sebastian Spaeth --- test/OLItest/TestRunner.py | 8 ++- test/tests/__init__.py | 1 + test/tests/test_00_imaputil.py | 96 ++++++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+), 5 deletions(-) create mode 100644 test/tests/test_00_imaputil.py diff --git a/test/OLItest/TestRunner.py b/test/OLItest/TestRunner.py index fc06a87..3535b61 100644 --- a/test/OLItest/TestRunner.py +++ b/test/OLItest/TestRunner.py @@ -24,10 +24,8 @@ import subprocess import tempfile import random random.seed() -try: - from configparser import SafeConfigParser -except ImportError: # python 2 - from ConfigParser import SafeConfigParser + +from offlineimap.CustomConfig import CustomConfigParser from . import default_conf @@ -75,7 +73,7 @@ class OLITestLib(): #TODO, only do first time and cache then for subsequent calls? assert cls.cred_file != None assert cls.testdir != None - config = SafeConfigParser() + config = CustomConfigParser() config.readfp(default_conf) default_conf.seek(0) # rewind config_file to start config.read(cls.cred_file) diff --git a/test/tests/__init__.py b/test/tests/__init__.py index e69de29..8b13789 100644 --- a/test/tests/__init__.py +++ b/test/tests/__init__.py @@ -0,0 +1 @@ + diff --git a/test/tests/test_00_imaputil.py b/test/tests/test_00_imaputil.py new file mode 100644 index 0000000..c97d5c9 --- /dev/null +++ b/test/tests/test_00_imaputil.py @@ -0,0 +1,96 @@ +# Copyright (C) 2012- Sebastian Spaeth & contributors +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# 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 +import unittest +import logging + +from offlineimap import imaputil +from offlineimap.ui import UI_LIST, setglobalui +from offlineimap.CustomConfig import CustomConfigParser + +from test.OLItest import OLITestLib + +# Things need to be setup first, usually setup.py initializes everything. +# but if e.g. called from command line, we take care of default values here: +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)) +# 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) + +class TestInternalFunctions(unittest.TestCase): + """While the other test files test OfflineImap as a program, these + tests directly invoke internal helper functions to guarantee that + they deliver results as expected""" + + @classmethod + def setUpClass(cls): + #This is run before all tests in this class + config= OLITestLib.get_default_config() + setglobalui(UI_LIST['quiet'](config)) + + def test_01_imapsplit(self): + """Test imaputil.imapsplit()""" + res = imaputil.imapsplit(b'(\\HasNoChildren) "." "INBOX.Sent"') + self.assertEqual(res, [b'(\\HasNoChildren)', b'"."', b'"INBOX.Sent"']) + + def test_02_flagsplit(self): + """Test imaputil.flagsplit()""" + res = imaputil.flagsplit(b'(\\Draft \\Deleted)') + self.assertEqual(res, [b'\\Draft', b'\\Deleted']) + + res = imaputil.flagsplit(b'(FLAGS (\\Seen Old) UID 4807)') + self.assertEqual(res, [b'FLAGS', b'(\\Seen Old)', b'UID', b'4807']) + + def test_03_options2hash(self): + """Test imaputil.options2hash()""" + res = imaputil.options2hash([1,2,3,4,5,6]) + self.assertEqual(res, {1:2, 3:4, 5:6}) + + def test_04_flags2hash(self): + """Test imaputil.flags2hash()""" + res = imaputil.flags2hash(b'(FLAGS (\\Seen Old) UID 4807)') + self.assertEqual(res, {b'FLAGS': b'(\\Seen Old)', b'UID': b'4807'}) + + def test_05_flagsimap2maildir(self): + """Test imaputil.flagsimap2maildir()""" + res = imaputil.flagsimap2maildir(b'(\\Draft \\Deleted)') + self.assertEqual(res, set(b'DT')) + + def test_06_flagsmaildir2imap(self): + """Test imaputil.flagsmaildir2imap()""" + res = imaputil.flagsmaildir2imap(set(b'DR')) + self.assertEqual(res, b'(\\Answered \\Draft)') + # test all possible flags + res = imaputil.flagsmaildir2imap(set(b'SRFTD')) + self.assertEqual(res, b'(\\Answered \\Deleted \\Draft \\Flagged \\Seen)') + + def test_07_uid_sequence(self): + """Test imaputil.uid_sequence()""" + res = imaputil.uid_sequence([1,2,3,4,5,10,12,13]) + self.assertEqual(res, b'1:5,10,12:13') From 679c491c56c981961e18aa43b31955900491d7a3 Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Tue, 3 Apr 2012 01:39:28 +0200 Subject: [PATCH 3/3] bugfix release v6.5.3.1 a single bugfix when no dry-run option was given in the config file. Signed-off-by: Sebastian Spaeth --- Changelog.rst | 3 +++ offlineimap/__init__.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Changelog.rst b/Changelog.rst index 53a9797..4e803b8 100644 --- a/Changelog.rst +++ b/Changelog.rst @@ -17,6 +17,9 @@ Changes Bug Fixes --------- +OfflineIMAP v6.5.3.1 (2012-04-03) +================================= + * Don't fail if no dry-run setting exists in offlineimap.conf (introduced in 6.5.3) diff --git a/offlineimap/__init__.py b/offlineimap/__init__.py index 5673a89..81dcbac 100644 --- a/offlineimap/__init__.py +++ b/offlineimap/__init__.py @@ -1,7 +1,7 @@ __all__ = ['OfflineImap'] __productname__ = 'OfflineIMAP' -__version__ = "6.5.3" +__version__ = "6.5.3.1" __copyright__ = "Copyright 2002-2012 John Goerzen & contributors" __author__ = "John Goerzen" __author_email__= "john@complete.org"