From de21abe97b202882be6a0bb4ba5bd8d0b8c911c4 Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Thu, 12 Jun 2008 03:56:30 +0000 Subject: [PATCH] split off test initialization code --- test/test_sessions.py | 32 +++----------------------------- test/testlib.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 29 deletions(-) create mode 100644 test/testlib.py diff --git a/test/test_sessions.py b/test/test_sessions.py index e47d3759a..273143ae9 100644 --- a/test/test_sessions.py +++ b/test/test_sessions.py @@ -1,42 +1,16 @@ import unittest -import sys -import os.path - -gajim_root = os.path.join(os.path.abspath(os.path.dirname(__file__)), '..') - -sys.path.append(gajim_root + '/src') - -# a temporary version of ~/.gajim for testing -configdir = gajim_root + '/test/tmp' - -# define _ for i18n -import __builtin__ -__builtin__._ = lambda x: x - -# wipe config directory -import os -if os.path.isdir(configdir): - import shutil - shutil.rmtree(configdir) - -os.mkdir(configdir) - -import common.configpaths -common.configpaths.gajimpaths.init(configdir) -common.configpaths.gajimpaths.init_profile() - import time -# for some reason common.gajim needs to be imported before xmpppy? +import testlib +testlib.setup_env() + from common import gajim from common import xmpp from mock import Mock, expectParams from mocks import * -gajim.DATA_DIR = gajim_root + '/data' - from common.stanza_session import StanzaSession # name to use for the test account diff --git a/test/testlib.py b/test/testlib.py new file mode 100644 index 000000000..00363d971 --- /dev/null +++ b/test/testlib.py @@ -0,0 +1,32 @@ +import sys +import os.path + +gajim_root = os.path.join(os.path.abspath(os.path.dirname(__file__)), '..') + +sys.path.append(gajim_root + '/src') + +# a temporary version of ~/.gajim for testing +configdir = gajim_root + '/test/tmp' + +# define _ for i18n +import __builtin__ +__builtin__._ = lambda x: x + +import os + +def setup_env(): + # wipe config directory + if os.path.isdir(configdir): + import shutil + shutil.rmtree(configdir) + + os.mkdir(configdir) + + import common.configpaths + common.configpaths.gajimpaths.init(configdir) + common.configpaths.gajimpaths.init_profile() + + # for some reason common.gajim needs to be imported before xmpppy? + from common import gajim + + gajim.DATA_DIR = gajim_root + '/data'