new tests architecture

This commit is contained in:
Romain Bignon 2010-08-13 17:27:22 +02:00
commit 9c7f585753
6 changed files with 25 additions and 79 deletions

View file

@ -18,3 +18,5 @@
from .browser import DLFP
from .backend import DLFPBackend
__all__ = ['DLFP', 'DLFPBackend']

View file

@ -17,3 +17,6 @@
from .bcall import CallErrors
from .ouiboube import Weboob
__all__ = ['CallErrors', 'Weboob']

View file

@ -82,13 +82,15 @@ class Weboob(object):
self.backend_instances[backend_name] = loaded[backend_name] = backend_instance
return loaded
def load_configured_backends(self, caps=None, names=None, storage=None):
def load_configured_backends(self, caps=None, names=None, modules=None, storage=None):
loaded = {}
if storage is None:
storage = self.storage
for instance_name, backend_name, params in self.backends_config.iter_backends():
if '_enabled' in params and not params['_enabled']:
if '_enabled' in params and not params['_enabled'] or \
names is not None and instance_name not in names or \
modules is not None and backend_name not in modules:
continue
backend = self.backends_loader.get_or_load_backend(backend_name)
if backend is None:
@ -96,8 +98,7 @@ class Weboob(object):
'configuration file, but was not found. '
'Hint: is it installed?' % backend_name)
continue
if caps is not None and not backend.has_caps(caps) or \
names is not None and instance_name not in names:
if caps is not None and not backend.has_caps(caps):
continue
backend_instance = backend.create_instance(self, instance_name, params, storage)
self.backend_instances[instance_name] = loaded[instance_name] = backend_instance

View file

@ -77,8 +77,6 @@ class BaseBackend(object):
STORAGE = {}
# Browser class
BROWSER = None
# Test class
TEST = None
# Supported objects to fill
# The key is the class and the value the method to call to fill
# Method prototype: method(object, fields)
@ -194,11 +192,6 @@ class BaseBackend(object):
return True
return False
def get_test(self):
if not self.TEST:
return None
return self.TEST(self)
def fillobj(self, obj, fields):
missing_fields = []
for field in fields:

View file

@ -15,31 +15,21 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
from nose import run
from weboob.tools.application.console import ConsoleApplication
__all__ = ['WeboobTests']
from unittest import TestCase
from weboob.core import Weboob
class WeboobTests(ConsoleApplication):
APPNAME = 'weboobtests'
VERSION = '0.1'
COPYRIGHT = 'Copyright(C) 2010 Romain Bignon'
__all__ = ['TestCase', 'BackendTest']
def main(self, argv):
return self.process_command(*argv[1:])
@ConsoleApplication.command('Run tests')
def command_run(self):
self.load_backends()
self.load_configured_backends()
class BackendTest(TestCase):
BACKEND = None
suite = []
for backend in self.weboob.iter_backends():
test = backend.get_test()
if test:
suite.append(test)
def __init__(self, *args, **kwargs):
TestCase.__init__(self, *args, **kwargs)
return run(suite=suite)
self.weboob = Weboob()
if not self.weboob.load_configured_backends(modules=[self.BACKEND]):
return None
self.backend = self.weboob.backend_instances.values()[0]