summaryrefslogtreecommitdiff
path: root/alembic/testing
diff options
context:
space:
mode:
Diffstat (limited to 'alembic/testing')
-rw-r--r--alembic/testing/assertions.py55
-rw-r--r--alembic/testing/fixtures.py45
-rw-r--r--alembic/testing/plugin/bootstrap.py5
-rw-r--r--alembic/testing/plugin/noseplugin.py106
-rw-r--r--alembic/testing/plugin/plugin_base.py21
-rw-r--r--alembic/testing/requirements.py79
-rw-r--r--alembic/testing/runner.py49
-rw-r--r--alembic/testing/warnings.py5
8 files changed, 19 insertions, 346 deletions
diff --git a/alembic/testing/assertions.py b/alembic/testing/assertions.py
index 8654083..2ad9dba 100644
--- a/alembic/testing/assertions.py
+++ b/alembic/testing/assertions.py
@@ -6,6 +6,12 @@ import warnings
from sqlalchemy import exc as sa_exc
from sqlalchemy.engine import default
+from sqlalchemy.testing.assertions import assert_raises # noqa
+from sqlalchemy.testing.assertions import assert_raises_message # noqa
+from sqlalchemy.testing.assertions import eq_ # noqa
+from sqlalchemy.testing.assertions import is_ # noqa
+from sqlalchemy.testing.assertions import is_not_ # noqa
+from sqlalchemy.testing.assertions import ne_ # noqa
from sqlalchemy.util import decorator
from . import config
@@ -16,55 +22,6 @@ from ..util.compat import py3k
from ..util.compat import text_type
-if not util.sqla_094:
-
- def eq_(a, b, msg=None):
- """Assert a == b, with repr messaging on failure."""
- assert a == b, msg or "%r != %r" % (a, b)
-
- def ne_(a, b, msg=None):
- """Assert a != b, with repr messaging on failure."""
- assert a != b, msg or "%r == %r" % (a, b)
-
- def is_(a, b, msg=None):
- """Assert a is b, with repr messaging on failure."""
- assert a is b, msg or "%r is not %r" % (a, b)
-
- def is_not_(a, b, msg=None):
- """Assert a is not b, with repr messaging on failure."""
- assert a is not b, msg or "%r is %r" % (a, b)
-
- def assert_raises(except_cls, callable_, *args, **kw):
- try:
- callable_(*args, **kw)
- success = False
- except except_cls:
- success = True
-
- # assert outside the block so it works for AssertionError too !
- assert success, "Callable did not raise an exception"
-
- def assert_raises_message(except_cls, msg, callable_, *args, **kwargs):
- try:
- callable_(*args, **kwargs)
- assert False, "Callable did not raise an exception"
- except except_cls as e:
- assert re.search(msg, text_type(e), re.UNICODE), "%r !~ %s" % (
- msg,
- e,
- )
- print(text_type(e).encode("utf-8"))
-
-
-else:
- from sqlalchemy.testing.assertions import assert_raises # noqa
- from sqlalchemy.testing.assertions import assert_raises_message # noqa
- from sqlalchemy.testing.assertions import eq_ # noqa
- from sqlalchemy.testing.assertions import is_ # noqa
- from sqlalchemy.testing.assertions import is_not_ # noqa
- from sqlalchemy.testing.assertions import ne_ # noqa
-
-
def eq_ignore_whitespace(a, b, msg=None):
a = re.sub(r"^\s+?|\n", "", a)
a = re.sub(r" {2,}", " ", a)
diff --git a/alembic/testing/fixtures.py b/alembic/testing/fixtures.py
index 6243467..46a77ca 100644
--- a/alembic/testing/fixtures.py
+++ b/alembic/testing/fixtures.py
@@ -10,14 +10,13 @@ from sqlalchemy import MetaData
from sqlalchemy import String
from sqlalchemy import Table
from sqlalchemy import text
+from sqlalchemy.testing.fixtures import TestBase # noqa
import alembic
from . import config
from . import mock
from .assertions import _get_dialect
from .assertions import eq_
-from .plugin.plugin_base import SkipTest
-from .. import util
from ..environment import EnvironmentContext
from ..migration import MigrationContext
from ..operations import Operations
@@ -29,44 +28,6 @@ testing_config = configparser.ConfigParser()
testing_config.read(["test.cfg"])
-if not util.sqla_094:
-
- class TestBase(object):
- # A sequence of database names to always run, regardless of the
- # constraints below.
- __whitelist__ = ()
-
- # A sequence of requirement names matching testing.requires decorators
- __requires__ = ()
-
- # A sequence of dialect names to exclude from the test class.
- __unsupported_on__ = ()
-
- # If present, test class is only runnable for the *single* specified
- # dialect. If you need multiple, use __unsupported_on__ and invert.
- __only_on__ = None
-
- # A sequence of no-arg callables. If any are True, the entire
- # testcase is skipped.
- __skip_if__ = None
-
- def assert_(self, val, msg=None):
- assert val, msg
-
- # apparently a handful of tests are doing this....OK
- def setup(self):
- if hasattr(self, "setUp"):
- self.setUp()
-
- def teardown(self):
- if hasattr(self, "tearDown"):
- self.tearDown()
-
-
-else:
- from sqlalchemy.testing.fixtures import TestBase # noqa
-
-
def capture_db():
buf = []
@@ -108,10 +69,6 @@ def op_fixture(
opts = {}
if naming_convention:
- if not util.sqla_092:
- raise SkipTest(
- "naming_convention feature requires " "sqla 0.9.2 or greater"
- )
opts["target_metadata"] = MetaData(naming_convention=naming_convention)
class buffer_(object):
diff --git a/alembic/testing/plugin/bootstrap.py b/alembic/testing/plugin/bootstrap.py
index 4bd415d..ed8fa82 100644
--- a/alembic/testing/plugin/bootstrap.py
+++ b/alembic/testing/plugin/bootstrap.py
@@ -1,5 +1,5 @@
"""
-Bootstrapper for nose/pytest plugins.
+Bootstrapper for test framework 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
@@ -40,8 +40,5 @@ def load_file_as_module(name):
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
diff --git a/alembic/testing/plugin/noseplugin.py b/alembic/testing/plugin/noseplugin.py
deleted file mode 100644
index fafb9e1..0000000
--- a/alembic/testing/plugin/noseplugin.py
+++ /dev/null
@@ -1,106 +0,0 @@
-# plugin/noseplugin.py
-# Copyright (C) 2005-2017 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
-
-"""
-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
-
-from nose.plugins import Plugin
-
-fixtures = None
-
-py3k = sys.version_info.major >= 3
-
-
-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
-
- 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()
-
- def configure(self, options, conf):
- super(NoseSQLAlchemy, self).configure(options, conf)
- plugin_base.pre_begin(options)
-
- plugin_base.set_coverage_flag(options.enable_plugin_coverage)
-
- def begin(self):
- global fixtures
- from alembic.testing import fixtures # noqa
-
- plugin_base.post_begin()
-
- def describeTest(self, test):
- return ""
-
- def wantFunction(self, fn):
- return False
-
- def wantMethod(self, fn):
- if py3k:
- if not hasattr(fn.__self__, "cls"):
- return False
- cls = fn.__self__.cls
- else:
- cls = fn.im_class
- return plugin_base.want_method(cls, fn)
-
- def wantClass(self, cls):
- return plugin_base.want_class(cls)
-
- def beforeTest(self, test):
- plugin_base.before_test(
- test,
- test.test.cls.__module__,
- test.test.cls,
- test.test.method.__name__,
- )
-
- def afterTest(self, test):
- plugin_base.after_test(test)
-
- def startContext(self, ctx):
- if not isinstance(ctx, type) or not issubclass(ctx, fixtures.TestBase):
- return
- plugin_base.start_test_class(ctx)
-
- def stopContext(self, ctx):
- if not isinstance(ctx, type) or not issubclass(ctx, fixtures.TestBase):
- return
- plugin_base.stop_test_class(ctx)
diff --git a/alembic/testing/plugin/plugin_base.py b/alembic/testing/plugin/plugin_base.py
index 44930c8..20aa34e 100644
--- a/alembic/testing/plugin/plugin_base.py
+++ b/alembic/testing/plugin/plugin_base.py
@@ -7,11 +7,7 @@
"""Testing extensions.
this module is designed to work as a testing-framework-agnostic library,
-so that we can continue to support nose and also begin adding new
-functionality via py.test.
-
-NOTE: copied/adapted from SQLAlchemy master for backwards compatibility;
-this should be removable when Alembic targets SQLAlchemy 1.0.0
+however it currenty targets only py.test.
"""
@@ -21,14 +17,9 @@ from __future__ import absolute_import
import re
import sys
-try:
- # unitttest has a SkipTest also but pytest doesn't
- # honor it unless nose is imported too...
- from nose import SkipTest
-except ImportError:
- from pytest import skip
+from pytest import skip
- SkipTest = skip.Exception
+SkipTest = skip.Exception
py3k = sys.version_info.major >= 3
@@ -234,8 +225,6 @@ def post_begin():
for fn in post_configure:
fn(options, file_config)
- # late imports, has to happen after config as well
- # as nose plugins like coverage
global util, fixtures, engines, exclusions, assertions
global warnings, profiling, config, testing
from alembic.testing import config, warnings, exclusions # noqa
@@ -373,8 +362,6 @@ def _prep_testing_database(options, file_config):
from alembic.testing import config
from alembic.testing.exclusions import against
from sqlalchemy import schema
- from alembic import util
-
from sqlalchemy import inspect
if options.dropfirst:
@@ -431,7 +418,7 @@ def _prep_testing_database(options, file_config):
)
)
- if against(cfg, "postgresql") and util.sqla_100:
+ if against(cfg, "postgresql"):
from sqlalchemy.dialects import postgresql
for enum in inspector.get_enums("*"):
diff --git a/alembic/testing/requirements.py b/alembic/testing/requirements.py
index b4c147b..bbb2ca2 100644
--- a/alembic/testing/requirements.py
+++ b/alembic/testing/requirements.py
@@ -1,16 +1,11 @@
import sys
+from sqlalchemy.testing.requirements import Requirements
+
from alembic import util
from alembic.util import sqla_compat
from . import exclusions
-if util.sqla_094:
- from sqlalchemy.testing.requirements import Requirements
-else:
-
- class Requirements(object):
- pass
-
class SuiteRequirements(Requirements):
@property
@@ -77,76 +72,6 @@ class SuiteRequirements(Requirements):
)
@property
- def sqlalchemy_10(self):
- return exclusions.skip_if(
- lambda config: not util.sqla_100,
- "SQLAlchemy 1.0.0 or greater required",
- )
-
- @property
- def fail_before_sqla_100(self):
- return exclusions.fails_if(
- lambda config: not util.sqla_100,
- "SQLAlchemy 1.0.0 or greater required",
- )
-
- @property
- def fail_before_sqla_1010(self):
- return exclusions.fails_if(
- lambda config: not util.sqla_1010,
- "SQLAlchemy 1.0.10 or greater required",
- )
-
- @property
- def fail_before_sqla_099(self):
- return exclusions.fails_if(
- lambda config: not util.sqla_099,
- "SQLAlchemy 0.9.9 or greater required",
- )
-
- @property
- def fail_before_sqla_110(self):
- return exclusions.fails_if(
- lambda config: not util.sqla_110,
- "SQLAlchemy 1.1.0 or greater required",
- )
-
- @property
- def sqlalchemy_092(self):
- return exclusions.skip_if(
- lambda config: not util.sqla_092,
- "SQLAlchemy 0.9.2 or greater required",
- )
-
- @property
- def sqlalchemy_094(self):
- return exclusions.skip_if(
- lambda config: not util.sqla_094,
- "SQLAlchemy 0.9.4 or greater required",
- )
-
- @property
- def sqlalchemy_099(self):
- return exclusions.skip_if(
- lambda config: not util.sqla_099,
- "SQLAlchemy 0.9.9 or greater required",
- )
-
- @property
- def sqlalchemy_100(self):
- return exclusions.skip_if(
- lambda config: not util.sqla_100,
- "SQLAlchemy 1.0.0 or greater required",
- )
-
- @property
- def sqlalchemy_1014(self):
- return exclusions.skip_if(
- lambda config: not util.sqla_1014,
- "SQLAlchemy 1.0.14 or greater required",
- )
-
- @property
def sqlalchemy_1115(self):
return exclusions.skip_if(
lambda config: not util.sqla_1115,
diff --git a/alembic/testing/runner.py b/alembic/testing/runner.py
deleted file mode 100644
index da5e0f4..0000000
--- a/alembic/testing/runner.py
+++ /dev/null
@@ -1,49 +0,0 @@
-#!/usr/bin/env python
-# testing/runner.py
-# Copyright (C) 2005-2017 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
-"""
-Nose test runner module.
-
-This script is a front-end to "nosetests" which
-installs SQLAlchemy's testing plugin into the local environment.
-
-The script is intended to be used by third-party dialects and extensions
-that run within SQLAlchemy's testing framework. The runner can
-be invoked via::
-
- python -m alembic.testing.runner
-
-The script is then essentially the same as the "nosetests" script, including
-all of the usual Nose options. The test environment requires that a
-setup.cfg is locally present including various required options.
-
-Note that when using this runner, Nose's "coverage" plugin will not be
-able to provide coverage for SQLAlchemy itself, since SQLAlchemy is
-imported into sys.modules before coverage is started. The special
-script sqla_nose.py is provided as a top-level script which loads the
-plugin in a special (somewhat hacky) way so that coverage against
-SQLAlchemy itself is possible.
-
-"""
-import nose
-
-from .plugin.noseplugin import NoseSQLAlchemy
-
-
-def main():
- nose.main(addplugins=[NoseSQLAlchemy()])
-
-
-def setup_py_test():
- """Runner to use for the 'test_suite' entry of your setup.py.
-
- Prevents any name clash shenanigans from the command line
- argument "test" that the "setup.py test" command sends
- to nose.
-
- """
- nose.main(addplugins=[NoseSQLAlchemy()], argv=["runner"])
diff --git a/alembic/testing/warnings.py b/alembic/testing/warnings.py
index 27ba706..7689e17 100644
--- a/alembic/testing/warnings.py
+++ b/alembic/testing/warnings.py
@@ -25,6 +25,11 @@ def setup_filters():
warnings.filterwarnings("error", category=sa_exc.SAWarning)
warnings.filterwarnings("error", category=DeprecationWarning)
+ # temporary to allow SQLAlchemy 1.1 to pass under python 3
+ warnings.filterwarnings(
+ "ignore", category=DeprecationWarning, message=".*formatargspec"
+ )
+
def assert_warnings(fn, warning_msgs, regex=False):
"""Assert that each of the given warnings are emitted by fn."""