]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
- add workaround to setup.py to avoid setuptools issue regarding multiprocessing
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 5 Jan 2013 17:13:28 +0000 (12:13 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 5 Jan 2013 17:13:28 +0000 (12:13 -0500)
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

README.unittests [new file with mode: 0644]
alembic/util.py
docs/build/changelog.rst
setup.py
tests/__init__.py
tests/test_autogenerate.py

diff --git a/README.unittests b/README.unittests
new file mode 100644 (file)
index 0000000..61796b6
--- /dev/null
@@ -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".
index 0fe480047bc64a03ccd1f1cbf1a2515027cd8407..bf2c89d10605540625eb39367ee31836cd53d428 100644 (file)
@@ -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. "
index c857c01d4632397920fca6daeb13649d36fa40e6..046b9d29dcf4f961ac1002fb81d89ef8de20130f 100644 (file)
@@ -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
 
index 4b2664b3a5991bb769d3dd3db3fa4b64b39d3c20..4991d137da1f59d519b79c7769626124abd03cba 100644 (file)
--- 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:
index 2b128362e705f213080bec57ad31c406d617fdea..0f3c9c7c352451eddeaaf2efde2381476daed845 100644 (file)
@@ -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':
index 63e60afe5893c842bb953a51099dbc9257e6b2e6..6675aa538e226eab5fedc6bc68b02dd5fb79ffd1 100644 (file)
@@ -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')"