From aa939ca2bd1fc92ccab0be5ab73bec94f91256b7 Mon Sep 17 00:00:00 2001 From: Laurent Bachelier Date: Sun, 1 May 2011 23:50:40 +0200 Subject: [PATCH] Support testing with multiple backend instances This is useful for testing backends with different configurations (different sites, being anonymous or not, etc.) The previous behavior was to chose a random backend instance. --- weboob/applications/pastoob/pastoob.py | 3 ++- weboob/tools/test.py | 26 +++++++++++++++++++++----- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/weboob/applications/pastoob/pastoob.py b/weboob/applications/pastoob/pastoob.py index fb788d78..b352a1a2 100644 --- a/weboob/applications/pastoob/pastoob.py +++ b/weboob/applications/pastoob/pastoob.py @@ -42,12 +42,13 @@ class Pastoob(ReplApplication): self.load_config() return ReplApplication.main(self, argv) - def do_get(self, _id): + def do_get(self, _id, *args): """ get ID Get a paste contents. """ + print args if not _id: print >>sys.stderr, 'This command takes an argument: %s' % self.get_command_help('get', short=True) return 1 diff --git a/weboob/tools/test.py b/weboob/tools/test.py index 808c0b0e..3733894c 100644 --- a/weboob/tools/test.py +++ b/weboob/tools/test.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright(C) 2010-2011 Romain Bignon +# Copyright(C) 2010-2011 Romain Bignon, Laurent Bachelier # # This file is part of weboob. # @@ -20,7 +20,6 @@ from unittest import TestCase from nose.plugins.skip import SkipTest from weboob.core import Weboob -from random import choice __all__ = ['TestCase', 'BackendTest'] @@ -32,18 +31,35 @@ class BackendTest(TestCase): TestCase.__init__(self, *args, **kwargs) self.backend = None + self.backend_instance = None self.weboob = Weboob() if self.weboob.load_backends(modules=[self.BACKEND]): - self.backend = choice(self.weboob.backend_instances.values()) + self.backends = self.weboob.backend_instances + else: + self.backends = {} def run(self, result): + """ + Call the parent run() for each backend instance. + Skip the test if we have no backends. + """ try: - if not self.backend: + if not len(self.backends): result.startTest(self) result.stopTest(self) raise SkipTest() - return TestCase.run(self, result) + for backend_instance, backend in self.backends.iteritems(): + self.backend = backend + self.backend_instance = backend_instance + TestCase.run(self, result) finally: self.weboob.deinit() + + def shortDescription(self): + """ + Generate a description with the backend instance name. + """ + # do not use TestCase.shortDescription as it returns None + return '%s [%s]' % (str(self), self.backend_instance)