Commits

Mike Bayer committed 44a6117

- 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

  • Participants
  • Parent commits b708c3e

Comments (0)

Files changed (6)

File README.unittests

+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".

File alembic/util.py

     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. "

File docs/build/changelog.rst

 
 
 .. 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
 
 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 = [
     '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:

File tests/__init__.py

         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:
         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':

File tests/test_autogenerate.py

 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, )
         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')"