SickGear/lib/sqlalchemy/testing/plugin/noseplugin.py

90 lines
2.5 KiB
Python
Raw Normal View History

2014-05-05 04:05:43 +00:00
# plugin/noseplugin.py
# Copyright (C) 2005-2014 the SQLAlchemy authors and contributors <see AUTHORS file>
#
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
2014-05-05 03:25:51 +00:00
2014-05-05 04:05:43 +00:00
"""Enhance nose with extra options and behaviors for running SQLAlchemy tests.
2014-05-05 04:05:43 +00:00
Must be run via ./sqla_nose.py so that it is imported in the expected
way (e.g. as a package-less import).
2014-05-05 03:25:51 +00:00
"""
import os
from nose.plugins import Plugin
fixtures = None
2014-05-05 04:05:43 +00:00
# no package imports yet! this prevents us from tripping coverage
# too soon.
import imp
path = os.path.join(os.path.dirname(__file__), "plugin_base.py")
plugin_base = imp.load_source("plugin_base", path)
2014-05-05 03:25:51 +00:00
class NoseSQLAlchemy(Plugin):
enabled = True
name = 'sqla_testing'
score = 100
def options(self, parser, env=os.environ):
Plugin.options(self, parser, env)
opt = parser.add_option
2014-05-05 04:05:43 +00:00
def make_option(name, **kw):
callback_ = kw.pop("callback", None)
if callback_:
def wrap_(option, opt_str, value, parser):
callback_(opt_str, value, parser)
kw["callback"] = wrap_
opt(name, **kw)
plugin_base.setup_options(make_option)
plugin_base.read_config()
2014-05-05 03:25:51 +00:00
def configure(self, options, conf):
2014-05-05 04:05:43 +00:00
super(NoseSQLAlchemy, self).configure(options, conf)
plugin_base.pre_begin(options)
2014-05-05 03:25:51 +00:00
2014-05-05 04:05:43 +00:00
plugin_base.set_coverage_flag(options.enable_plugin_coverage)
global fixtures
from sqlalchemy.testing import fixtures
2014-05-05 04:05:43 +00:00
def begin(self):
plugin_base.post_begin()
2014-05-05 03:25:51 +00:00
def describeTest(self, test):
return ""
def wantFunction(self, fn):
2014-05-05 04:05:43 +00:00
if fn.__module__ is None:
return False
2014-05-05 03:25:51 +00:00
if fn.__module__.startswith('sqlalchemy.testing'):
return False
def wantClass(self, cls):
2014-05-05 04:05:43 +00:00
return plugin_base.want_class(cls)
2014-05-05 03:25:51 +00:00
def beforeTest(self, test):
2014-05-05 04:05:43 +00:00
plugin_base.before_test(test,
test.test.cls.__module__,
test.test.cls, test.test.method.__name__)
2014-05-05 03:25:51 +00:00
def afterTest(self, test):
2014-05-05 04:05:43 +00:00
plugin_base.after_test(test)
2014-05-05 03:25:51 +00:00
def startContext(self, ctx):
if not isinstance(ctx, type) \
or not issubclass(ctx, fixtures.TestBase):
return
2014-05-05 04:05:43 +00:00
plugin_base.start_test_class(ctx)
2014-05-05 03:25:51 +00:00
def stopContext(self, ctx):
if not isinstance(ctx, type) \
or not issubclass(ctx, fixtures.TestBase):
return
2014-05-05 04:05:43 +00:00
plugin_base.stop_test_class(ctx)