From 75ea403278ec080d110589914fb1cb63431836bd Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Thu, 16 Feb 2012 09:31:14 +0100 Subject: [PATCH] test: Split configuration generation so we can tweak values Use get_default_config and write_config_file (which can be handed an optional config object), so we can manipulate configuration options easily from within the test function. Signed-off-by: Sebastian Spaeth --- test/OLItest/TestRunner.py | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/test/OLItest/TestRunner.py b/test/OLItest/TestRunner.py index 742d118..3c21257 100644 --- a/test/OLItest/TestRunner.py +++ b/test/OLItest/TestRunner.py @@ -54,23 +54,36 @@ class OLITestLib(): cls.testdir = os.path.abspath( tempfile.mkdtemp(prefix='tmp_%s_'%suffix, dir=os.path.dirname(cls.cred_file))) - cls.create_config_file() + cls.write_config_file() return cls.testdir @classmethod - def create_config_file(cls): - """Creates a OLI configuration file + def get_default_config(cls): + """Creates a default ConfigParser file and returns it - It is created in testdir (so create_test_dir has to be called - earlier) using the credentials information given (so they had to - be set earlier). Failure to do either of them will raise an - AssertionException.""" + The returned config can be manipulated and then saved with + write_config_file()""" assert cls.cred_file != None assert cls.testdir != None config = SafeConfigParser() config.readfp(default_conf) + default_conf.seek(0) # rewind config_file to start config.read(cls.cred_file) config.set("general", "metadata", cls.testdir) + return config + + @classmethod + def write_config_file(cls, config=None): + """Creates a OLI configuration file + + It is created in testdir (so create_test_dir has to be called + earlier) using the credentials information given (so they had + to be set earlier). Failure to do either of them will raise an + AssertionException. If config is None, a default one will be + used via get_default_config, otherwise it needs to be a config + object derived from that.""" + if config is None: + config = cls.get_default_config() localfolders = os.path.join(cls.testdir, 'mail') config.set("Repository Maildir", "localfolders", localfolders) with open(os.path.join(cls.testdir, 'offlineimap.conf'), "wa") as f: