From: Mike Bayer Date: Sat, 5 Jan 2013 17:13:28 +0000 (-0500) Subject: - add workaround to setup.py to avoid setuptools issue regarding multiprocessing X-Git-Tag: rel_0_4_2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=44a611700f76410d07d527059391dac689b897b4;p=thirdparty%2Fsqlalchemy%2Falembic.git - add workaround to setup.py to avoid setuptools issue regarding multiprocessing when "setup.py test" is run, #96 - add version detection for 0.8, apply this version detection to test_autogenerate:AutogenRenderTest.test_render_fk_constraint_kwarg and emit explicit append_constraint() for each FK if not on 0.8 as FKs do not auto-attach in 0.7, #96 - add a README containing instructions for running tests and setting up optional database backens, #96 --- diff --git a/README.unittests b/README.unittests new file mode 100644 index 00000000..61796b61 --- /dev/null +++ b/README.unittests @@ -0,0 +1,31 @@ +Running Unit Tests +================== + +Tests can be run using the nosetests runner: + + nosetests -v + +Or via the setup.py script: + + python setup.py test + + +Setting up Optional Databases +------------------------------ + +The test suite will attempt to run a subset of tests against various +database backends, including Postgresql and MySQL. It uses the database +URLs in the file test.cfg to locate a URL for particular backend types. +If the URL cannot be loaded, either because the requisite DBAPI is +not present, or if the target database is found to be not accessible, +the test is skipped. + +To run tests for these backends, replace URLs with working ones +inside the test.cfg file. Setting a URL here requires that the +corresponding DBAPI is installed as well as that the target database +is running. A connection to the database should provide access +to a *blank* schema, where tables will be created and dropped. It +is critical that this schema have no tables in it already. + +For Postgresql, it is also necessary that the target database contain +a user-accessible schema called "test_schema". diff --git a/alembic/util.py b/alembic/util.py index 0fe48004..bf2c89d1 100644 --- a/alembic/util.py +++ b/alembic/util.py @@ -22,10 +22,11 @@ def _safe_int(value): try: return int(value) except: - return 0 -_vers = tuple([_safe_int(x) for x in __version__.split(".")]) + return value +_vers = tuple([_safe_int(x) for x in re.findall(r'(\d+|[abc]\d)', __version__)]) sqla_06 = _vers > (0, 6) sqla_07 = _vers > (0, 7) +sqla_08 = _vers >= (0, 8, 0, 'b2') if not sqla_06: raise CommandError( "SQLAlchemy 0.6 or greater is required. " diff --git a/docs/build/changelog.rst b/docs/build/changelog.rst index c857c01d..046b9d29 100644 --- a/docs/build/changelog.rst +++ b/docs/build/changelog.rst @@ -6,6 +6,33 @@ Changelog .. changelog:: + :version: 0.4.2 + + .. change:: + :tags: bug + :tickets: 96 + + Added a workaround to setup.py to prevent + "NoneType" error from occuring when + "setup.py test" is run. + + .. change:: + :tags: bug + :tickets: 96 + + Added an append_constraint() step to each + condition within + test_autogenerate:AutogenRenderTest.test_render_fk_constraint_kwarg + if the SQLAlchemy version is less than 0.8, as ForeignKeyConstraint + does not auto-append prior to 0.8. + + .. change:: + :tags: feature + :tickets: 96 + + Added a README.unittests with instructions for running the test + suite fully. + :version: 0.4.1 :released: Sun Dec 9 2012 diff --git a/setup.py b/setup.py index 4b2664b3..4991d137 100644 --- a/setup.py +++ b/setup.py @@ -13,6 +13,7 @@ v = open(os.path.join(os.path.dirname(__file__), 'alembic', '__init__.py')) VERSION = re.compile(r".*__version__ = '(.*?)'", re.S).match(v.read()).group(1) v.close() + readme = os.path.join(os.path.dirname(__file__), 'README.rst') requires = [ @@ -20,6 +21,15 @@ requires = [ 'Mako', ] +# Hack to prevent "TypeError: 'NoneType' object is not callable" error +# in multiprocessing/util.py _exit_function when running `python +# setup.py test` (see +# http://www.eby-sarna.com/pipermail/peak/2010-May/003357.html) +try: + import multiprocessing +except ImportError: + pass + try: import argparse except ImportError: diff --git a/tests/__init__.py b/tests/__init__.py index 2b128362..0f3c9c7c 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -52,7 +52,7 @@ def db_for_dialect(name): except ConfigParser.NoOptionError: raise SkipTest("No dialect %r in test.cfg" % name) try: - eng = create_engine(cfg) #, echo=True) + eng = create_engine(cfg, echo=True) except ImportError, er1: raise SkipTest("Can't import DBAPI: %s" % er1) try: @@ -68,6 +68,12 @@ def requires_07(fn, *arg, **kw): raise SkipTest("SQLAlchemy 0.7 required") return fn(*arg, **kw) +@decorator +def requires_08(fn, *arg, **kw): + if not util.sqla_08: + raise SkipTest("SQLAlchemy 0.8.0b2 or greater required") + return fn(*arg, **kw) + _dialects = {} def _get_dialect(name): if name is None or name == 'default': diff --git a/tests/test_autogenerate.py b/tests/test_autogenerate.py index 63e60afe..6675aa53 100644 --- a/tests/test_autogenerate.py +++ b/tests/test_autogenerate.py @@ -11,6 +11,7 @@ from alembic.migration import MigrationContext from unittest import TestCase from tests import staging_env, sqlite_db, clear_staging_env, eq_, \ eq_ignore_whitespace, requires_07, db_for_dialect +from alembic import util import re import sys py3k = sys.version_info >= (3, ) @@ -960,24 +961,34 @@ class AutogenRenderTest(TestCase): t2 = Table('t2', m, Column('c_rem', Integer)) fk = ForeignKeyConstraint([t1.c.c], [t2.c.c_rem], onupdate="CASCADE") + if not util.sqla_08: + t1.append_constraint(fk) + eq_ignore_whitespace( autogenerate._render_constraint(fk, self.autogen_context), "sa.ForeignKeyConstraint(['c'], ['t2.c_rem'], onupdate='CASCADE')" ) fk = ForeignKeyConstraint([t1.c.c], [t2.c.c_rem], ondelete="CASCADE") + if not util.sqla_08: + t1.append_constraint(fk) + eq_ignore_whitespace( autogenerate._render_constraint(fk, self.autogen_context), "sa.ForeignKeyConstraint(['c'], ['t2.c_rem'], ondelete='CASCADE')" ) fk = ForeignKeyConstraint([t1.c.c], [t2.c.c_rem], deferrable=True) + if not util.sqla_08: + t1.append_constraint(fk) eq_ignore_whitespace( autogenerate._render_constraint(fk, self.autogen_context), "sa.ForeignKeyConstraint(['c'], ['t2.c_rem'], deferrable=True)" ) fk = ForeignKeyConstraint([t1.c.c], [t2.c.c_rem], initially="XYZ") + if not util.sqla_08: + t1.append_constraint(fk) eq_ignore_whitespace( autogenerate._render_constraint(fk, self.autogen_context), "sa.ForeignKeyConstraint(['c'], ['t2.c_rem'], initially='XYZ')"