--- /dev/null
+[run]
+include=alembic/*
+
+[report]
+omit=alembic/testing/*
\ No newline at end of file
-from . import postgresql, mysql, sqlite, mssql, oracle
-from .impl import DefaultImpl
+from . import postgresql, mysql, sqlite, mssql, oracle # pragma: no cover
+from .impl import DefaultImpl # pragma: no cover
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
"""NOTE: copied/adapted from SQLAlchemy master for backwards compatibility;
- this should be removable when Alembic targets SQLAlchemy 0.9.4.
+ this should be removable when Alembic targets SQLAlchemy 1.0.0
"""
import collections
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
"""NOTE: copied/adapted from SQLAlchemy master for backwards compatibility;
- this should be removable when Alembic targets SQLAlchemy 0.9.4.
+ this should be removable when Alembic targets SQLAlchemy 1.0.0.
"""
from __future__ import absolute_import
from alembic.script import Script, ScriptDirectory
from alembic import util
from . import engines
-from alembic.testing.plugin import plugin_base
+from . import provision
def _get_staging_directory():
- if plugin_base.FOLLOWER_IDENT:
- return "scratch_%s" % plugin_base.FOLLOWER_IDENT
+ if provision.FOLLOWER_IDENT:
+ return "scratch_%s" % provision.FOLLOWER_IDENT
else:
return 'scratch'
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
"""NOTE: copied/adapted from SQLAlchemy master for backwards compatibility;
- this should be removable when Alembic targets SQLAlchemy 0.9.4.
+ this should be removable when Alembic targets SQLAlchemy 1.0.0
"""
"""Import stub for mock library.
NOTE: copied/adapted from SQLAlchemy master for backwards compatibility;
- this should be removable when Alembic targets SQLAlchemy 0.9.4.
+ this should be removable when Alembic targets SQLAlchemy 1.0.0
"""
from __future__ import absolute_import
from unittest.mock import MagicMock, Mock, call, patch
else:
try:
- from mock import MagicMock, Mock, call, patch
+ from mock import MagicMock, Mock, call, patch # noqa
except ImportError:
raise ImportError(
"SQLAlchemy's test suite requires the "
"""NOTE: copied/adapted from SQLAlchemy master for backwards compatibility;
- this should be removable when Alembic targets SQLAlchemy 0.9.4.
+ this should be removable when Alembic targets SQLAlchemy 1.0.0
"""
--- /dev/null
+"""
+Bootstrapper for nose/pytest plugins.
+
+The entire rationale for this system is to get the modules in plugin/
+imported without importing all of the supporting library, so that we can
+set up things for testing before coverage starts.
+
+The rationale for all of plugin/ being *in* the supporting library in the
+first place is so that the testing and plugin suite is available to other
+libraries, mainly external SQLAlchemy and Alembic dialects, to make use
+of the same test environment and standard suites available to
+SQLAlchemy/Alembic themselves without the need to ship/install a separate
+package outside of SQLAlchemy.
+
+NOTE: copied/adapted from SQLAlchemy master for backwards compatibility;
+this should be removable when Alembic targets SQLAlchemy 1.0.0.
+
+"""
+
+import os
+import sys
+
+bootstrap_file = locals()['bootstrap_file']
+to_bootstrap = locals()['to_bootstrap']
+
+
+def load_file_as_module(name):
+ path = os.path.join(os.path.dirname(bootstrap_file), "%s.py" % name)
+ if sys.version_info >= (3, 3):
+ from importlib import machinery
+ mod = machinery.SourceFileLoader(name, path).load_module()
+ else:
+ import imp
+ mod = imp.load_source(name, path)
+ return mod
+
+if to_bootstrap == "pytest":
+ sys.modules["alembic_plugin_base"] = load_file_as_module("plugin_base")
+ sys.modules["alembic_pytestplugin"] = load_file_as_module("pytestplugin")
+elif to_bootstrap == "nose":
+ sys.modules["alembic_plugin_base"] = load_file_as_module("plugin_base")
+ sys.modules["alembic_noseplugin"] = load_file_as_module("noseplugin")
+else:
+ raise Exception("unknown bootstrap: %s" % to_bootstrap) # noqa
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
-"""NOTE: copied/adapted from SQLAlchemy master for backwards compatibility;
- this should be removable when Alembic targets SQLAlchemy 0.9.4.
"""
+Enhance nose with extra options and behaviors for running SQLAlchemy tests.
-"""Enhance nose with extra options and behaviors for running SQLAlchemy tests.
+NOTE: copied/adapted from SQLAlchemy master for backwards compatibility;
+this should be removable when Alembic targets SQLAlchemy 1.0.0.
"""
+try:
+ # installed by bootstrap.py
+ import alembic_plugin_base as plugin_base
+except ImportError:
+ # assume we're a package, use traditional import
+ from . import plugin_base
+
import os
import sys
fixtures = None
py3k = sys.version_info >= (3, 0)
-# no package imports yet! this prevents us from tripping coverage
-# too soon.
-path = os.path.join(os.path.dirname(__file__), "plugin_base.py")
-if sys.version_info >= (3, 3):
- from importlib import machinery
- plugin_base = machinery.SourceFileLoader(
- "plugin_base", path).load_module()
-else:
- import imp
- plugin_base = imp.load_source("plugin_base", path)
class NoseSQLAlchemy(Plugin):
plugin_base.set_coverage_flag(options.enable_plugin_coverage)
+ def begin(self):
global fixtures
from alembic.testing import fixtures # noqa
- def begin(self):
plugin_base.post_begin()
def describeTest(self, test):
cls = fn.__self__.cls
else:
cls = fn.im_class
- print "METH:", fn, "CLS:", cls
return plugin_base.want_method(cls, fn)
def wantClass(self, cls):
functionality via py.test.
NOTE: copied/adapted from SQLAlchemy master for backwards compatibility;
- this should be removable when Alembic targets SQLAlchemy 0.9.4.
+this should be removable when Alembic targets SQLAlchemy 1.0.0
"""
else:
import ConfigParser as configparser
-FOLLOWER_IDENT = None
-
# late imports
fixtures = None
engines = None
+provision = None
exclusions = None
warnings = None
assertions = None
database creation.
"""
- global FOLLOWER_IDENT
- FOLLOWER_IDENT = follower_ident
+ from alembic.testing import provision
+ provision.FOLLOWER_IDENT = follower_ident
def memoize_important_follower_config(dict_):
def post_begin():
"""things to set up later, once we know coverage is running."""
+
# Lazy setup of other options (post coverage)
for fn in post_configure:
fn(options, file_config)
@post
def _engine_uri(options, file_config):
from alembic.testing import config
- from alembic.testing.plugin import provision
+ from alembic.testing import provision
if options.dburi:
db_urls = list(options.dburi)
for db_url in db_urls:
cfg = provision.setup_config(
- db_url, db_opts, options, file_config, FOLLOWER_IDENT)
+ db_url, db_opts, options, file_config, provision.FOLLOWER_IDENT)
if not config._current:
cfg.set_as_current(cfg)
"""NOTE: copied/adapted from SQLAlchemy master for backwards compatibility;
- this should be removable when Alembic targets SQLAlchemy 0.9.4.
+ this should be removable when Alembic targets SQLAlchemy 1.0.0.
"""
+
+try:
+ # installed by bootstrap.py
+ import alembic_plugin_base as plugin_base
+except ImportError:
+ # assume we're a package, use traditional import
+ from . import plugin_base
+
+import sys
+
+py3k = sys.version_info >= (3, 0)
+
import pytest
import argparse
import inspect
-from . import plugin_base
import collections
import itertools
plugin_base.pre_begin(config.option)
- plugin_base.set_coverage_flag(bool(getattr(config.option,
- "cov_source", False)))
+ coverage = bool(getattr(config.option, "cov_source", False))
+ plugin_base.set_coverage_flag(coverage)
+
+def pytest_sessionstart(session):
plugin_base.post_begin()
if has_xdist:
plugin_base.memoize_important_follower_config(node.slaveinput)
node.slaveinput["follower_ident"] = "test_%s" % next(_follower_count)
- from . import provision
+ from alembic.testing import provision
provision.create_follower_db(node.slaveinput["follower_ident"])
def pytest_testnodedown(node, error):
- from . import provision
+ from alembic.testing import provision
provision.drop_follower_db(node.slaveinput["follower_ident"])
_current_class = None
+
def pytest_runtest_setup(item):
# here we seem to get called only based on what we collected
# in pytest_collection_modifyitems. So to do class-based stuff
"""NOTE: copied/adapted from SQLAlchemy master for backwards compatibility;
- this should be removable when Alembic targets SQLAlchemy 0.9.4.
+ this should be removable when Alembic targets SQLAlchemy 1.0.0
"""
from sqlalchemy.engine import url as sa_url
from sqlalchemy import text
from alembic.testing import config, engines
from alembic.testing.compat import get_url_backend_name
+FOLLOWER_IDENT = None
+
class register(object):
def __init__(self):
SQLAlchemy itself is possible.
"""
-
-from alembic.testing.plugin.noseplugin import NoseSQLAlchemy
-
+from .plugin.noseplugin import NoseSQLAlchemy
import nose
-from alembic.testing import runner
+import os
+# use bootstrapping so that test plugins are loaded
+# without touching the main library before coverage starts
+bootstrap_file = os.path.join(
+ os.path.dirname(__file__), "alembic",
+ "testing", "plugin", "bootstrap.py"
+)
-runner.main()
+with open(bootstrap_file) as f:
+ code = compile(f.read(), "bootstrap.py", 'exec')
+ to_bootstrap = "nose"
+ exec(code, globals(), locals())
+
+
+from noseplugin import NoseSQLAlchemy
+import nose
+nose.main(addplugins=[NoseSQLAlchemy()])
installs SQLAlchemy's testing plugin into the local environment.
"""
-import sys
+import os
-from os import path
-for pth in ['../lib']:
- sys.path.insert(0, path.join(path.dirname(path.abspath(__file__)), pth))
+# use bootstrapping so that test plugins are loaded
+# without touching the main library before coverage starts
+bootstrap_file = os.path.join(
+ os.path.dirname(__file__), "..", "alembic",
+ "testing", "plugin", "bootstrap.py"
+)
-from alembic.testing.plugin.pytestplugin import *
+with open(bootstrap_file) as f:
+ code = compile(f.read(), "bootstrap.py", 'exec')
+ to_bootstrap = "pytest"
+ exec(code, globals(), locals())
+ from pytestplugin import * # noqa
recreate=True
[testenv:coverage]
+# see also .coveragerc
deps=coverage
commands=
- python -m pytest --cov=alembic {posargs}
- python -m coverage xml --include=alembic/*
+ python -m pytest --cov=alembic --cov-report term --cov-report xml {posargs}
[testenv:pep8]
deps=flake8