From 976df5bf96adc16ea8c97e822cf7e773b0525f78 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 17 Oct 2010 15:23:14 -0400 Subject: - the NoseSQLAlchemyPlugin has been moved to a new package "sqlalchemy_nose" which installs along with "sqlalchemy". This so that the "nosetests" script works as always but also allows the --with-coverage option to turn on coverage before SQLAlchemy modules are imported, allowing coverage to work correctly. - added some new ignores --- .hgignore | 3 + CHANGES | 11 ++- lib/sqlalchemy/test/__init__.py | 3 +- lib/sqlalchemy/test/config.py | 173 -------------------------------------- lib/sqlalchemy/test/engines.py | 2 +- lib/sqlalchemy/test/noseplugin.py | 162 ----------------------------------- lib/sqlalchemy/test/profiling.py | 2 +- lib/sqlalchemy/test/testing.py | 3 +- lib/sqlalchemy_nose/__init__.py | 0 lib/sqlalchemy_nose/config.py | 173 ++++++++++++++++++++++++++++++++++++++ lib/sqlalchemy_nose/noseplugin.py | 166 ++++++++++++++++++++++++++++++++++++ setup.py | 12 +-- test/__init__.py | 1 - 13 files changed, 364 insertions(+), 347 deletions(-) delete mode 100644 lib/sqlalchemy/test/config.py delete mode 100644 lib/sqlalchemy/test/noseplugin.py create mode 100644 lib/sqlalchemy_nose/__init__.py create mode 100644 lib/sqlalchemy_nose/config.py create mode 100644 lib/sqlalchemy_nose/noseplugin.py diff --git a/.hgignore b/.hgignore index ef7855fae..a4a0ce2bc 100755 --- a/.hgignore +++ b/.hgignore @@ -4,4 +4,7 @@ syntax:regexp .pyc$ .orig$ .egg-info +.*,cover +\.coverage +\.DS_Store test.cfg diff --git a/CHANGES b/CHANGES index a2e864bda..7f055ea7a 100644 --- a/CHANGES +++ b/CHANGES @@ -202,7 +202,16 @@ CHANGES - *Major* cleanup / modernization of the Informix dialect for 0.6, courtesy Florian Apolloner. [ticket:1906] - + +- tests + - the NoseSQLAlchemyPlugin has been moved to a + new package "sqlalchemy_nose" which installs + along with "sqlalchemy". This so that the "nosetests" + script works as always but also allows the + --with-coverage option to turn on coverage before + SQLAlchemy modules are imported, allowing coverage + to work correctly. + - misc - CircularDependencyError now has .cycles and .edges members, which are the set of elements involved in diff --git a/lib/sqlalchemy/test/__init__.py b/lib/sqlalchemy/test/__init__.py index d69cedefd..7356945d2 100644 --- a/lib/sqlalchemy/test/__init__.py +++ b/lib/sqlalchemy/test/__init__.py @@ -6,7 +6,8 @@ by noseplugin.NoseSQLAlchemy. """ -from sqlalchemy.test import testing, engines, requires, profiling, pickleable, config +from sqlalchemy_nose import config +from sqlalchemy.test import testing, engines, requires, profiling, pickleable from sqlalchemy.test.schema import Column, Table from sqlalchemy.test.testing import \ AssertsCompiledSQL, \ diff --git a/lib/sqlalchemy/test/config.py b/lib/sqlalchemy/test/config.py deleted file mode 100644 index 7d528a04b..000000000 --- a/lib/sqlalchemy/test/config.py +++ /dev/null @@ -1,173 +0,0 @@ -import optparse, os, sys, re, ConfigParser, time, warnings - -# 2to3 -import StringIO - -logging = None - -__all__ = 'parser', 'configure', 'options', - -db = None -db_label, db_url, db_opts = None, None, {} - -options = None -file_config = None - -base_config = """ -[db] -sqlite=sqlite:///:memory: -sqlite_file=sqlite:///querytest.db -postgresql=postgresql://scott:tiger@127.0.0.1:5432/test -postgres=postgresql://scott:tiger@127.0.0.1:5432/test -pg8000=postgresql+pg8000://scott:tiger@127.0.0.1:5432/test -postgresql_jython=postgresql+zxjdbc://scott:tiger@127.0.0.1:5432/test -mysql_jython=mysql+zxjdbc://scott:tiger@127.0.0.1:5432/test -mysql=mysql://scott:tiger@127.0.0.1:3306/test -oracle=oracle://scott:tiger@127.0.0.1:1521 -oracle8=oracle://scott:tiger@127.0.0.1:1521/?use_ansi=0 -mssql=mssql://scott:tiger@SQUAWK\\SQLEXPRESS/test -firebird=firebird://sysdba:masterkey@localhost//tmp/test.fdb -maxdb=maxdb://MONA:RED@/maxdb1 -""" - -def _log(option, opt_str, value, parser): - global logging - if not logging: - import logging - logging.basicConfig() - - if opt_str.endswith('-info'): - logging.getLogger(value).setLevel(logging.INFO) - elif opt_str.endswith('-debug'): - logging.getLogger(value).setLevel(logging.DEBUG) - - -def _list_dbs(*args): - print "Available --db options (use --dburi to override)" - for macro in sorted(file_config.options('db')): - print "%20s\t%s" % (macro, file_config.get('db', macro)) - sys.exit(0) - -def _server_side_cursors(options, opt_str, value, parser): - db_opts['server_side_cursors'] = True - -def _engine_strategy(options, opt_str, value, parser): - if value: - db_opts['strategy'] = value - -class _ordered_map(object): - def __init__(self): - self._keys = list() - self._data = dict() - - def __setitem__(self, key, value): - if key not in self._keys: - self._keys.append(key) - self._data[key] = value - - def __iter__(self): - for key in self._keys: - yield self._data[key] - -# at one point in refactoring, modules were injecting into the config -# process. this could probably just become a list now. -post_configure = _ordered_map() - -def _engine_uri(options, file_config): - global db_label, db_url - db_label = 'sqlite' - if options.dburi: - db_url = options.dburi - db_label = db_url[:db_url.index(':')] - elif options.db: - db_label = options.db - db_url = None - - if db_url is None: - if db_label not in file_config.options('db'): - raise RuntimeError( - "Unknown engine. Specify --dbs for known engines.") - db_url = file_config.get('db', db_label) -post_configure['engine_uri'] = _engine_uri - -def _require(options, file_config): - if not(options.require or - (file_config.has_section('require') and - file_config.items('require'))): - return - - try: - import pkg_resources - except ImportError: - raise RuntimeError("setuptools is required for version requirements") - - cmdline = [] - for requirement in options.require: - pkg_resources.require(requirement) - cmdline.append(re.split('\s*(=)', requirement, 1)[0]) - - if file_config.has_section('require'): - for label, requirement in file_config.items('require'): - if not label == db_label or label.startswith('%s.' % db_label): - continue - seen = [c for c in cmdline if requirement.startswith(c)] - if seen: - continue - pkg_resources.require(requirement) -post_configure['require'] = _require - -def _engine_pool(options, file_config): - if options.mockpool: - from sqlalchemy import pool - db_opts['poolclass'] = pool.AssertionPool -post_configure['engine_pool'] = _engine_pool - -def _create_testing_engine(options, file_config): - from sqlalchemy.test import engines, testing - global db - db = engines.testing_engine(db_url, db_opts) - testing.db = db -post_configure['create_engine'] = _create_testing_engine - -def _prep_testing_database(options, file_config): - from sqlalchemy.test import engines - from sqlalchemy import schema - - # also create alt schemas etc. here? - if options.dropfirst: - e = engines.utf8_engine() - existing = e.table_names() - if existing: - print "Dropping existing tables in database: " + db_url - try: - print "Tables: %s" % ', '.join(existing) - except: - pass - print "Abort within 5 seconds..." - time.sleep(5) - md = schema.MetaData(e, reflect=True) - md.drop_all() - e.dispose() - -post_configure['prep_db'] = _prep_testing_database - -def _set_table_options(options, file_config): - from sqlalchemy.test import schema - - table_options = schema.table_options - for spec in options.tableopts: - key, value = spec.split('=') - table_options[key] = value - - if options.mysql_engine: - table_options['mysql_engine'] = options.mysql_engine -post_configure['table_options'] = _set_table_options - -def _reverse_topological(options, file_config): - if options.reversetop: - from sqlalchemy.orm import unitofwork, session, mapper, dependency - from sqlalchemy import topological - from sqlalchemy.test.util import RandomSet - topological.set = unitofwork.set = session.set = mapper.set = dependency.set = RandomSet -post_configure['topological'] = _reverse_topological - diff --git a/lib/sqlalchemy/test/engines.py b/lib/sqlalchemy/test/engines.py index 9e77f38d7..870f984ec 100644 --- a/lib/sqlalchemy/test/engines.py +++ b/lib/sqlalchemy/test/engines.py @@ -1,6 +1,6 @@ import sys, types, weakref from collections import deque -import config +from sqlalchemy_nose import config from sqlalchemy.util import function_named, callable import re import warnings diff --git a/lib/sqlalchemy/test/noseplugin.py b/lib/sqlalchemy/test/noseplugin.py deleted file mode 100644 index 6a3106e69..000000000 --- a/lib/sqlalchemy/test/noseplugin.py +++ /dev/null @@ -1,162 +0,0 @@ -import logging -import os -import re -import sys -import time -import warnings -import ConfigParser -import StringIO - -import nose.case -from nose.plugins import Plugin - -from sqlalchemy import util, log as sqla_log -from sqlalchemy.test import testing, config, requires -from sqlalchemy.test.config import ( - _create_testing_engine, _engine_pool, _engine_strategy, _engine_uri, _list_dbs, _log, - _prep_testing_database, _require, _reverse_topological, _server_side_cursors, - _set_table_options, base_config, db, db_label, db_url, file_config, post_configure) - -log = logging.getLogger('nose.plugins.sqlalchemy') - -class NoseSQLAlchemy(Plugin): - """ - Handles the setup and extra properties required for testing SQLAlchemy - """ - enabled = True - name = 'sqlalchemy' - score = 100 - - def options(self, parser, env=os.environ): - Plugin.options(self, parser, env) - opt = parser.add_option - opt("--log-info", action="callback", type="string", callback=_log, - help="turn on info logging for (multiple OK)") - opt("--log-debug", action="callback", type="string", callback=_log, - help="turn on debug logging for (multiple OK)") - opt("--require", action="append", dest="require", default=[], - help="require a particular driver or module version (multiple OK)") - opt("--db", action="store", dest="db", default="sqlite", - help="Use prefab database uri") - opt('--dbs', action='callback', callback=_list_dbs, - help="List available prefab dbs") - opt("--dburi", action="store", dest="dburi", - help="Database uri (overrides --db)") - opt("--dropfirst", action="store_true", dest="dropfirst", - help="Drop all tables in the target database first (use with caution on Oracle, " - "MS-SQL)") - opt("--mockpool", action="store_true", dest="mockpool", - help="Use mock pool (asserts only one connection used)") - opt("--enginestrategy", action="callback", type="string", - callback=_engine_strategy, - help="Engine strategy (plain or threadlocal, defaults to plain)") - opt("--reversetop", action="store_true", dest="reversetop", default=False, - help="Use a random-ordering set implementation in the ORM (helps " - "reveal dependency issues)") - opt("--unhashable", action="store_true", dest="unhashable", default=False, - help="Disallow SQLAlchemy from performing a hash() on mapped test objects.") - opt("--noncomparable", action="store_true", dest="noncomparable", default=False, - help="Disallow SQLAlchemy from performing == on mapped test objects.") - opt("--truthless", action="store_true", dest="truthless", default=False, - help="Disallow SQLAlchemy from truth-evaluating mapped test objects.") - opt("--serverside", action="callback", callback=_server_side_cursors, - help="Turn on server side cursors for PG") - opt("--mysql-engine", action="store", dest="mysql_engine", default=None, - help="Use the specified MySQL storage engine for all tables, default is " - "a db-default/InnoDB combo.") - opt("--table-option", action="append", dest="tableopts", default=[], - help="Add a dialect-specific table option, key=value") - - global file_config - file_config = ConfigParser.ConfigParser() - file_config.readfp(StringIO.StringIO(base_config)) - file_config.read(['test.cfg', os.path.expanduser('~/.satest.cfg')]) - config.file_config = file_config - - def configure(self, options, conf): - Plugin.configure(self, options, conf) - self.options = options - - def begin(self): - testing.db = db - testing.requires = requires - - # Lazy setup of other options (post coverage) - for fn in post_configure: - fn(self.options, file_config) - - def describeTest(self, test): - return "" - - def wantClass(self, cls): - """Return true if you want the main test selector to collect - tests from this class, false if you don't, and None if you don't - care. - - :Parameters: - cls : class - The class being examined by the selector - - """ - - if not issubclass(cls, testing.TestBase): - return False - else: - if (hasattr(cls, '__whitelist__') and testing.db.name in cls.__whitelist__): - return True - else: - return not self.__should_skip_for(cls) - - def __should_skip_for(self, cls): - if hasattr(cls, '__requires__'): - def test_suite(): return 'ok' - test_suite.__name__ = cls.__name__ - for requirement in cls.__requires__: - check = getattr(requires, requirement) - if check(test_suite)() != 'ok': - # The requirement will perform messaging. - return True - - if cls.__unsupported_on__: - spec = testing.db_spec(*cls.__unsupported_on__) - if spec(testing.db): - print "'%s' unsupported on DB implementation '%s'" % ( - cls.__class__.__name__, testing.db.name) - return True - - if getattr(cls, '__only_on__', None): - spec = testing.db_spec(*util.to_list(cls.__only_on__)) - if not spec(testing.db): - print "'%s' unsupported on DB implementation '%s'" % ( - cls.__class__.__name__, testing.db.name) - return True - - if getattr(cls, '__skip_if__', False): - for c in getattr(cls, '__skip_if__'): - if c(): - print "'%s' skipped by %s" % ( - cls.__class__.__name__, c.__name__) - return True - - for rule in getattr(cls, '__excluded_on__', ()): - if testing._is_excluded(*rule): - print "'%s' unsupported on DB %s version %s" % ( - cls.__class__.__name__, testing.db.name, - _server_version()) - return True - return False - - def beforeTest(self, test): - testing.resetwarnings() - - def afterTest(self, test): - testing.resetwarnings() - - def afterContext(self): - testing.global_cleanup_assertions() - - #def handleError(self, test, err): - #pass - - #def finalize(self, result=None): - #pass diff --git a/lib/sqlalchemy/test/profiling.py b/lib/sqlalchemy/test/profiling.py index c5256affa..835253a3a 100644 --- a/lib/sqlalchemy/test/profiling.py +++ b/lib/sqlalchemy/test/profiling.py @@ -6,7 +6,7 @@ in a more fine-grained way than nose's profiling plugin. """ import os, sys -from sqlalchemy.test import config +from sqlalchemy_nose import config from sqlalchemy.test.util import function_named, gc_collect from nose import SkipTest diff --git a/lib/sqlalchemy/test/testing.py b/lib/sqlalchemy/test/testing.py index 41ba3038f..471044742 100644 --- a/lib/sqlalchemy/test/testing.py +++ b/lib/sqlalchemy/test/testing.py @@ -8,7 +8,8 @@ import types import warnings from cStringIO import StringIO -from sqlalchemy.test import config, assertsql, util as testutil +from sqlalchemy_nose import config +from sqlalchemy.test import assertsql, util as testutil from sqlalchemy.util import function_named, py3k from engines import drop_all_tables diff --git a/lib/sqlalchemy_nose/__init__.py b/lib/sqlalchemy_nose/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/lib/sqlalchemy_nose/config.py b/lib/sqlalchemy_nose/config.py new file mode 100644 index 000000000..7d528a04b --- /dev/null +++ b/lib/sqlalchemy_nose/config.py @@ -0,0 +1,173 @@ +import optparse, os, sys, re, ConfigParser, time, warnings + +# 2to3 +import StringIO + +logging = None + +__all__ = 'parser', 'configure', 'options', + +db = None +db_label, db_url, db_opts = None, None, {} + +options = None +file_config = None + +base_config = """ +[db] +sqlite=sqlite:///:memory: +sqlite_file=sqlite:///querytest.db +postgresql=postgresql://scott:tiger@127.0.0.1:5432/test +postgres=postgresql://scott:tiger@127.0.0.1:5432/test +pg8000=postgresql+pg8000://scott:tiger@127.0.0.1:5432/test +postgresql_jython=postgresql+zxjdbc://scott:tiger@127.0.0.1:5432/test +mysql_jython=mysql+zxjdbc://scott:tiger@127.0.0.1:5432/test +mysql=mysql://scott:tiger@127.0.0.1:3306/test +oracle=oracle://scott:tiger@127.0.0.1:1521 +oracle8=oracle://scott:tiger@127.0.0.1:1521/?use_ansi=0 +mssql=mssql://scott:tiger@SQUAWK\\SQLEXPRESS/test +firebird=firebird://sysdba:masterkey@localhost//tmp/test.fdb +maxdb=maxdb://MONA:RED@/maxdb1 +""" + +def _log(option, opt_str, value, parser): + global logging + if not logging: + import logging + logging.basicConfig() + + if opt_str.endswith('-info'): + logging.getLogger(value).setLevel(logging.INFO) + elif opt_str.endswith('-debug'): + logging.getLogger(value).setLevel(logging.DEBUG) + + +def _list_dbs(*args): + print "Available --db options (use --dburi to override)" + for macro in sorted(file_config.options('db')): + print "%20s\t%s" % (macro, file_config.get('db', macro)) + sys.exit(0) + +def _server_side_cursors(options, opt_str, value, parser): + db_opts['server_side_cursors'] = True + +def _engine_strategy(options, opt_str, value, parser): + if value: + db_opts['strategy'] = value + +class _ordered_map(object): + def __init__(self): + self._keys = list() + self._data = dict() + + def __setitem__(self, key, value): + if key not in self._keys: + self._keys.append(key) + self._data[key] = value + + def __iter__(self): + for key in self._keys: + yield self._data[key] + +# at one point in refactoring, modules were injecting into the config +# process. this could probably just become a list now. +post_configure = _ordered_map() + +def _engine_uri(options, file_config): + global db_label, db_url + db_label = 'sqlite' + if options.dburi: + db_url = options.dburi + db_label = db_url[:db_url.index(':')] + elif options.db: + db_label = options.db + db_url = None + + if db_url is None: + if db_label not in file_config.options('db'): + raise RuntimeError( + "Unknown engine. Specify --dbs for known engines.") + db_url = file_config.get('db', db_label) +post_configure['engine_uri'] = _engine_uri + +def _require(options, file_config): + if not(options.require or + (file_config.has_section('require') and + file_config.items('require'))): + return + + try: + import pkg_resources + except ImportError: + raise RuntimeError("setuptools is required for version requirements") + + cmdline = [] + for requirement in options.require: + pkg_resources.require(requirement) + cmdline.append(re.split('\s*(=)', requirement, 1)[0]) + + if file_config.has_section('require'): + for label, requirement in file_config.items('require'): + if not label == db_label or label.startswith('%s.' % db_label): + continue + seen = [c for c in cmdline if requirement.startswith(c)] + if seen: + continue + pkg_resources.require(requirement) +post_configure['require'] = _require + +def _engine_pool(options, file_config): + if options.mockpool: + from sqlalchemy import pool + db_opts['poolclass'] = pool.AssertionPool +post_configure['engine_pool'] = _engine_pool + +def _create_testing_engine(options, file_config): + from sqlalchemy.test import engines, testing + global db + db = engines.testing_engine(db_url, db_opts) + testing.db = db +post_configure['create_engine'] = _create_testing_engine + +def _prep_testing_database(options, file_config): + from sqlalchemy.test import engines + from sqlalchemy import schema + + # also create alt schemas etc. here? + if options.dropfirst: + e = engines.utf8_engine() + existing = e.table_names() + if existing: + print "Dropping existing tables in database: " + db_url + try: + print "Tables: %s" % ', '.join(existing) + except: + pass + print "Abort within 5 seconds..." + time.sleep(5) + md = schema.MetaData(e, reflect=True) + md.drop_all() + e.dispose() + +post_configure['prep_db'] = _prep_testing_database + +def _set_table_options(options, file_config): + from sqlalchemy.test import schema + + table_options = schema.table_options + for spec in options.tableopts: + key, value = spec.split('=') + table_options[key] = value + + if options.mysql_engine: + table_options['mysql_engine'] = options.mysql_engine +post_configure['table_options'] = _set_table_options + +def _reverse_topological(options, file_config): + if options.reversetop: + from sqlalchemy.orm import unitofwork, session, mapper, dependency + from sqlalchemy import topological + from sqlalchemy.test.util import RandomSet + topological.set = unitofwork.set = session.set = mapper.set = dependency.set = RandomSet +post_configure['topological'] = _reverse_topological + diff --git a/lib/sqlalchemy_nose/noseplugin.py b/lib/sqlalchemy_nose/noseplugin.py new file mode 100644 index 000000000..8732142f7 --- /dev/null +++ b/lib/sqlalchemy_nose/noseplugin.py @@ -0,0 +1,166 @@ +import logging +import os +import re +import sys +import time +import warnings +import ConfigParser +import StringIO + +import nose.case +from nose.plugins import Plugin + +from sqlalchemy_nose import config + +from sqlalchemy_nose.config import ( + _create_testing_engine, _engine_pool, _engine_strategy, _engine_uri, _list_dbs, _log, + _prep_testing_database, _require, _reverse_topological, _server_side_cursors, + _set_table_options, base_config, db, db_label, db_url, file_config, post_configure) + +log = logging.getLogger('nose.plugins.sqlalchemy') + +class NoseSQLAlchemy(Plugin): + """ + Handles the setup and extra properties required for testing SQLAlchemy + """ + enabled = True + name = 'sqlalchemy' + score = 100 + + def options(self, parser, env=os.environ): + Plugin.options(self, parser, env) + opt = parser.add_option + opt("--log-info", action="callback", type="string", callback=_log, + help="turn on info logging for (multiple OK)") + opt("--log-debug", action="callback", type="string", callback=_log, + help="turn on debug logging for (multiple OK)") + opt("--require", action="append", dest="require", default=[], + help="require a particular driver or module version (multiple OK)") + opt("--db", action="store", dest="db", default="sqlite", + help="Use prefab database uri") + opt('--dbs', action='callback', callback=_list_dbs, + help="List available prefab dbs") + opt("--dburi", action="store", dest="dburi", + help="Database uri (overrides --db)") + opt("--dropfirst", action="store_true", dest="dropfirst", + help="Drop all tables in the target database first (use with caution on Oracle, " + "MS-SQL)") + opt("--mockpool", action="store_true", dest="mockpool", + help="Use mock pool (asserts only one connection used)") + opt("--enginestrategy", action="callback", type="string", + callback=_engine_strategy, + help="Engine strategy (plain or threadlocal, defaults to plain)") + opt("--reversetop", action="store_true", dest="reversetop", default=False, + help="Use a random-ordering set implementation in the ORM (helps " + "reveal dependency issues)") + opt("--unhashable", action="store_true", dest="unhashable", default=False, + help="Disallow SQLAlchemy from performing a hash() on mapped test objects.") + opt("--noncomparable", action="store_true", dest="noncomparable", default=False, + help="Disallow SQLAlchemy from performing == on mapped test objects.") + opt("--truthless", action="store_true", dest="truthless", default=False, + help="Disallow SQLAlchemy from truth-evaluating mapped test objects.") + opt("--serverside", action="callback", callback=_server_side_cursors, + help="Turn on server side cursors for PG") + opt("--mysql-engine", action="store", dest="mysql_engine", default=None, + help="Use the specified MySQL storage engine for all tables, default is " + "a db-default/InnoDB combo.") + opt("--table-option", action="append", dest="tableopts", default=[], + help="Add a dialect-specific table option, key=value") + + global file_config + file_config = ConfigParser.ConfigParser() + file_config.readfp(StringIO.StringIO(base_config)) + file_config.read(['test.cfg', os.path.expanduser('~/.satest.cfg')]) + config.file_config = file_config + + def configure(self, options, conf): + Plugin.configure(self, options, conf) + self.options = options + + def begin(self): + global testing, requires, util + from sqlalchemy.test import testing, requires + from sqlalchemy import util + + testing.db = db + testing.requires = requires + + # Lazy setup of other options (post coverage) + for fn in post_configure: + fn(self.options, file_config) + + def describeTest(self, test): + return "" + + def wantClass(self, cls): + """Return true if you want the main test selector to collect + tests from this class, false if you don't, and None if you don't + care. + + :Parameters: + cls : class + The class being examined by the selector + + """ + + if not issubclass(cls, testing.TestBase): + return False + else: + if (hasattr(cls, '__whitelist__') and testing.db.name in cls.__whitelist__): + return True + else: + return not self.__should_skip_for(cls) + + def __should_skip_for(self, cls): + if hasattr(cls, '__requires__'): + def test_suite(): return 'ok' + test_suite.__name__ = cls.__name__ + for requirement in cls.__requires__: + check = getattr(requires, requirement) + if check(test_suite)() != 'ok': + # The requirement will perform messaging. + return True + + if cls.__unsupported_on__: + spec = testing.db_spec(*cls.__unsupported_on__) + if spec(testing.db): + print "'%s' unsupported on DB implementation '%s'" % ( + cls.__class__.__name__, testing.db.name) + return True + + if getattr(cls, '__only_on__', None): + spec = testing.db_spec(*util.to_list(cls.__only_on__)) + if not spec(testing.db): + print "'%s' unsupported on DB implementation '%s'" % ( + cls.__class__.__name__, testing.db.name) + return True + + if getattr(cls, '__skip_if__', False): + for c in getattr(cls, '__skip_if__'): + if c(): + print "'%s' skipped by %s" % ( + cls.__class__.__name__, c.__name__) + return True + + for rule in getattr(cls, '__excluded_on__', ()): + if testing._is_excluded(*rule): + print "'%s' unsupported on DB %s version %s" % ( + cls.__class__.__name__, testing.db.name, + _server_version()) + return True + return False + + def beforeTest(self, test): + testing.resetwarnings() + + def afterTest(self, test): + testing.resetwarnings() + + def afterContext(self): + testing.global_cleanup_assertions() + + #def handleError(self, test, err): + #pass + + #def finalize(self, result=None): + #pass diff --git a/setup.py b/setup.py index 76cba0584..7a8a0f3f2 100644 --- a/setup.py +++ b/setup.py @@ -56,11 +56,11 @@ elif BUILD_CEXTENSIONS: def find_packages(dir_): packages = [] - for _dir, subdirectories, files in os.walk(os.path.join(dir_, - 'sqlalchemy')): - if '__init__.py' in files: - lib, fragment = _dir.split(os.sep, 1) - packages.append(fragment.replace(os.sep, '.')) + for pkg in ['sqlalchemy', 'sqlalchemy_nose']: + for _dir, subdirectories, files in os.walk(os.path.join(dir_, pkg)): + if '__init__.py' in files: + lib, fragment = _dir.split(os.sep, 1) + packages.append(fragment.replace(os.sep, '.')) return packages if sys.version_info < (2, 4): @@ -90,7 +90,7 @@ setup(name = "SQLAlchemy", test_suite = "nose.collector", entry_points = { 'nose.plugins.0.10': [ - 'sqlalchemy = sqlalchemy.test.noseplugin:NoseSQLAlchemy', + 'sqlalchemy = sqlalchemy_nose.noseplugin:NoseSQLAlchemy', ] }, diff --git a/test/__init__.py b/test/__init__.py index 8b1378917..e69de29bb 100644 --- a/test/__init__.py +++ b/test/__init__.py @@ -1 +0,0 @@ - -- cgit v1.2.1