Updated to OpenStack Build stuff.

This commit is contained in:
Monty Taylor 2013-07-11 16:24:50 -04:00
parent 85fe71617f
commit a71799ea2c
48 changed files with 246 additions and 220 deletions

4
.gitignore vendored
View File

@ -1,3 +1,7 @@
AUTHORS
ChangeLog
.tox/*
.testrepository/*
*.pyc
*data/*
*build/*

8
.testr.conf Normal file
View File

@ -0,0 +1,8 @@
[DEFAULT]
test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \
OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} \
OS_TEST_TIMEOUT=${OS_TEST_TIMEOUT:-60} \
${PYTHON:-python} -m subunit.run discover -t ./ . $LISTOPT $IDOPTION
test_id_option=--load-list $IDFILE
test_list_option=--list

View File

@ -1,7 +1,8 @@
include AUTHORS
include ChangeLog
include README
recursive-include docs *
recursive-include migrate *
recursive-include tests *
global-exclude *pyc
exclude .hgtags
recursive-exclude docs/_build *

4
README
View File

@ -34,9 +34,9 @@ To run automated tests:
* Copy test_db.cfg.tmpl to test_db.cfg
* Edit test_db.cfg with database connection strings suitable for running tests.
(Use empty databases.)
* $ pip install -r test-req.pip
* $ pip install -r requirements.txt -r test-requirements.txt
* $ python setup.py develop
* $ nosetests
* $ testr run --parallel
Please report any issues with sqlalchemy-migrate to the issue tracker at
`code.google.com issues

1
TODO
View File

@ -26,7 +26,6 @@ Unknown milestone
- verbose output on migration failures
- interactive migration script resolution?
- backend for versioning management
- port to unittest2
Documentation updates in 0.6.1
- glossary

View File

@ -44,11 +44,11 @@ class TestAddDropColumn(fixture.DB):
self.refresh_table(self.table_name)
result = len(self.table.c)
self.assertEquals(result, num_of_expected_cols),
self.assertEqual(result, num_of_expected_cols),
if col_k.get('primary_key', None):
# new primary key: check its length too
result = len(self.table.primary_key)
self.assertEquals(result, num_of_expected_cols)
self.assertEqual(result, num_of_expected_cols)
# we have 1 columns and there is no data column
assert_numcols(1)
@ -485,7 +485,7 @@ class TestRename(fixture.DB):
"""
if not skip_object_check:
# Table object check
self.assertEquals(self.table.name,expected)
self.assertEqual(self.table.name,expected)
newname = self.table.name
else:
# we know the object's name isn't consistent: just assign it
@ -493,12 +493,12 @@ class TestRename(fixture.DB):
# Table DB check
self.meta.clear()
self.table = Table(newname, self.meta, autoload=True)
self.assertEquals(self.table.name, expected)
self.assertEqual(self.table.name, expected)
def assert_index_name(expected, skip_object_check=False):
if not skip_object_check:
# Index object check
self.assertEquals(self.index.name, expected)
self.assertEqual(self.index.name, expected)
else:
# object is inconsistent
self.index.name = expected
@ -583,7 +583,7 @@ class TestColumnChange(fixture.DB):
# Table content should be preserved in changed columns
content = "fgsfds"
self.engine.execute(self.table.insert(), data=content, id=42)
self.assertEquals(num_rows(self.table.c.data, content), 1)
self.assertEqual(num_rows(self.table.c.data, content), 1)
# ...as a function, given a column object and the new name
alter_column('data', name='data2', table=self.table)
@ -592,14 +592,14 @@ class TestColumnChange(fixture.DB):
self.refresh_table(self.table.name)
self.assert_('data' not in self.table.c.keys())
self.assert_('atad' in self.table.c.keys())
self.assertEquals(num_rows(self.table.c.atad, content), 1)
self.assertEqual(num_rows(self.table.c.atad, content), 1)
# ...as a method, given a new name
self.table.c.atad.alter(name='data')
self.refresh_table(self.table.name)
self.assert_('atad' not in self.table.c.keys())
self.table.c.data # Should not raise exception
self.assertEquals(num_rows(self.table.c.data, content), 1)
self.assertEqual(num_rows(self.table.c.data, content), 1)
# ...as a function, given a new object
alter_column(self.table.c.data,
@ -608,7 +608,7 @@ class TestColumnChange(fixture.DB):
self.refresh_table(self.table.name)
self.assert_('data' not in self.table.c.keys())
self.table.c.atad # Should not raise exception
self.assertEquals(num_rows(self.table.c.atad, content), 1)
self.assertEqual(num_rows(self.table.c.atad, content), 1)
# ...as a method, given a new object
self.table.c.atad.alter(
@ -618,7 +618,7 @@ class TestColumnChange(fixture.DB):
self.refresh_table(self.table.name)
self.assert_('atad' not in self.table.c.keys())
self.table.c.data # Should not raise exception
self.assertEquals(num_rows(self.table.c.data,content), 1)
self.assertEqual(num_rows(self.table.c.data,content), 1)
@fixture.usedb()
def test_type(self):
@ -628,15 +628,15 @@ class TestColumnChange(fixture.DB):
self.table.c.data.alter(type=String(43))
self.refresh_table(self.table.name)
self.assert_(isinstance(self.table.c.data.type, String))
self.assertEquals(self.table.c.data.type.length, 43)
self.assertEqual(self.table.c.data.type.length, 43)
# Different type
self.assert_(isinstance(self.table.c.id.type, Integer))
self.assertEquals(self.table.c.id.nullable, False)
self.assertEqual(self.table.c.id.nullable, False)
if not self.engine.name == 'firebird':
self.table.c.id.alter(type=String(20))
self.assertEquals(self.table.c.id.nullable, False)
self.assertEqual(self.table.c.id.nullable, False)
self.refresh_table(self.table.name)
self.assert_(isinstance(self.table.c.id.type, String))
@ -646,13 +646,13 @@ class TestColumnChange(fixture.DB):
Only DefaultClauses are changed here: others are managed by the
application / by SA
"""
self.assertEquals(self.table.c.data.server_default.arg, 'tluafed')
self.assertEqual(self.table.c.data.server_default.arg, 'tluafed')
# Just the new default
default = 'my_default'
self.table.c.data.alter(server_default=DefaultClause(default))
self.refresh_table(self.table.name)
#self.assertEquals(self.table.c.data.server_default.arg,default)
#self.assertEqual(self.table.c.data.server_default.arg,default)
# TextClause returned by autoload
self.assert_(default in str(self.table.c.data.server_default.arg))
self.engine.execute(self.table.insert(), id=12)
@ -679,18 +679,18 @@ class TestColumnChange(fixture.DB):
@fixture.usedb(not_supported='firebird')
def test_null(self):
"""Can change a column's null constraint"""
self.assertEquals(self.table.c.data.nullable, True)
self.assertEqual(self.table.c.data.nullable, True)
# Full column
self.table.c.data.alter(type=String(40), nullable=False)
self.table.nullable = None
self.refresh_table(self.table.name)
self.assertEquals(self.table.c.data.nullable, False)
self.assertEqual(self.table.c.data.nullable, False)
# Just the new status
self.table.c.data.alter(nullable=True)
self.refresh_table(self.table.name)
self.assertEquals(self.table.c.data.nullable, True)
self.assertEqual(self.table.c.data.nullable, True)
@fixture.usedb()
def test_alter_deprecated(self):
@ -793,7 +793,7 @@ class TestColumnDelta(fixture.DB):
self.delta = ColumnDelta(original, *p, **k)
result = self.delta.keys()
result.sort()
self.assertEquals(expected, result)
self.assertEqual(expected, result)
return self.delta
def test_deltas_two_columns(self):
@ -885,8 +885,8 @@ class TestColumnDelta(fixture.DB):
# Change name, given an up-to-date definition and the current name
delta = self.verify(['name'], col_orig, name='blah')
self.assertEquals(delta.get('name'), 'blah')
self.assertEquals(delta.current_name, 'id')
self.assertEqual(delta.get('name'), 'blah')
self.assertEqual(delta.current_name, 'id')
col_orig = self.mkcol(primary_key=True)
self.verify(['name', 'type'], col_orig, name='id12', type=Text, alter_metadata=True)

View File

@ -40,7 +40,7 @@ class CommonTestConstraint(fixture.DB):
self.table.create()
# make sure we start at zero
self.assertEquals(len(self.table.primary_key), 0)
self.assertEqual(len(self.table.primary_key), 0)
self.assert_(isinstance(self.table.primary_key,
schema.PrimaryKeyConstraint), self.table.primary_key.__class__)
@ -67,7 +67,7 @@ class TestConstraint(CommonTestConstraint):
# pk.name = self.table.primary_key.name
pk.drop()
self.refresh_table()
self.assertEquals(len(self.table.primary_key), 0)
self.assertEqual(len(self.table.primary_key), 0)
self.assert_(isinstance(self.table.primary_key, schema.PrimaryKeyConstraint))
return pk
@ -80,9 +80,9 @@ class TestConstraint(CommonTestConstraint):
# Add a FK by creating a FK constraint
if SQLA_07:
self.assertEquals(list(self.table.c.fkey.foreign_keys), [])
self.assertEqual(list(self.table.c.fkey.foreign_keys), [])
else:
self.assertEquals(self.table.c.fkey.foreign_keys._list, [])
self.assertEqual(self.table.c.fkey.foreign_keys._list, [])
fk = ForeignKeyConstraint([self.table.c.fkey],
[self.table.c.id],
name="fk_id_fkey",
@ -92,9 +92,9 @@ class TestConstraint(CommonTestConstraint):
else:
self.assert_(self.table.c.fkey.foreign_keys._list is not [])
for key in fk.columns:
self.assertEquals(key, self.table.c.fkey.name)
self.assertEquals([e.column for e in fk.elements], [self.table.c.id])
self.assertEquals(list(fk.referenced), [self.table.c.id])
self.assertEqual(key, self.table.c.fkey.name)
self.assertEqual([e.column for e in fk.elements], [self.table.c.id])
self.assertEqual(list(fk.referenced), [self.table.c.id])
if self.url.startswith('mysql'):
# MySQL FKs need an index
@ -107,7 +107,7 @@ class TestConstraint(CommonTestConstraint):
fkey = list(self.table.c.fkey.foreign_keys)[0]
else:
fkey = self.table.c.fkey.foreign_keys._list[0]
self.assertEquals(fkey.ondelete, "CASCADE")
self.assertEqual(fkey.ondelete, "CASCADE")
# TODO: test on real db if it was set
self.refresh_table()
@ -119,9 +119,9 @@ class TestConstraint(CommonTestConstraint):
fk.drop()
self.refresh_table()
if SQLA_07:
self.assertEquals(list(self.table.c.fkey.foreign_keys), [])
self.assertEqual(list(self.table.c.fkey.foreign_keys), [])
else:
self.assertEquals(self.table.c.fkey.foreign_keys._list, [])
self.assertEqual(self.table.c.fkey.foreign_keys._list, [])
@fixture.usedb()
def test_define_pk(self):
@ -203,7 +203,7 @@ class TestAutoname(CommonTestConstraint):
cons.name = None
cons.drop()
self.refresh_table()
self.assertEquals(list(), list(self.table.primary_key))
self.assertEqual(list(), list(self.table.primary_key))
# test string names
cons = PrimaryKeyConstraint('id', table=self.table)
@ -234,9 +234,9 @@ class TestAutoname(CommonTestConstraint):
cons.drop()
self.refresh_table()
if SQLA_07:
self.assertEquals(list(self.table.c.fkey.foreign_keys), list())
self.assertEqual(list(self.table.c.fkey.foreign_keys), list())
else:
self.assertEquals(self.table.c.fkey.foreign_keys._list, list())
self.assertEqual(self.table.c.fkey.foreign_keys._list, list())
# test string names
cons = ForeignKeyConstraint(['fkey'], ['%s.id' % self.tablename], table=self.table)

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import unittest2
import testtools
def main(imports=None):
if imports:
@ -10,7 +10,7 @@ def main(imports=None):
defaultTest='fixture.suite'
else:
defaultTest=None
return unittest2.TestProgram(defaultTest=defaultTest)
return testtools.TestProgram(defaultTest=defaultTest)
from base import Base
from migrate.tests.fixture.pathed import Pathed

View File

@ -2,17 +2,11 @@
# -*- coding: utf-8 -*-
import re
import unittest2
import testtools
class Base(unittest2.TestCase):
class Base(testtools.TestCase):
def setup_method(self,func=None):
self.setUp()
def teardown_method(self,func=None):
self.tearDown()
def assertEqualsIgnoreWhitespace(self, v1, v2):
def assertEqualIgnoreWhitespace(self, v1, v2):
"""Compares two strings that should be\
identical except for whitespace
"""

View File

@ -6,7 +6,7 @@ from migrate.tests import fixture
# Collect tests for all handwritten docs: doc/*.rst
dir = ('..','..','..','docs')
dir = ('..','..','..','doc','source')
absdir = (os.path.dirname(os.path.abspath(__file__)),)+dir
dirpath = os.path.join(*absdir)
files = [f for f in os.listdir(dirpath) if f.endswith('.rst')]

View File

@ -4,7 +4,6 @@ import os
import sqlalchemy
from sqlalchemy import *
from nose.tools import eq_
from migrate.versioning import genmodel, schemadiff
from migrate.changeset import schema
@ -45,7 +44,7 @@ class TestSchemaDiff(fixture.DB):
def assertDiff(isDiff, tablesMissingInDatabase, tablesMissingInModel, tablesWithDiff):
diff = schemadiff.getDiffOfModelAgainstDatabase(self.meta, self.engine, excludeTables=['migrate_version'])
eq_(
self.assertEqual(
(diff.tables_missing_from_B,
diff.tables_missing_from_A,
diff.tables_different.keys(),
@ -66,7 +65,7 @@ class TestSchemaDiff(fixture.DB):
# Feature test for a recent SQLa feature;
# expect different output in that case.
if repr(String()) == 'String()':
self.assertEqualsIgnoreWhitespace(decls, '''
self.assertEqualIgnoreWhitespace(decls, '''
from migrate.changeset import schema
pre_meta = MetaData()
post_meta = MetaData()
@ -77,7 +76,7 @@ class TestSchemaDiff(fixture.DB):
)
''')
else:
self.assertEqualsIgnoreWhitespace(decls, '''
self.assertEqualIgnoreWhitespace(decls, '''
from migrate.changeset import schema
pre_meta = MetaData()
post_meta = MetaData()
@ -157,8 +156,8 @@ class TestSchemaDiff(fixture.DB):
# Make sure data is still present.
result = self.engine.execute(self.table.select(self.table.c.id==dataId))
rows = result.fetchall()
eq_(len(rows), 1)
eq_(rows[0].name, 'mydata')
self.assertEqual(len(rows), 1)
self.assertEqual(rows[0].name, 'mydata')
# Add data, later we'll make sure it's still present.
result = self.engine.execute(self.table.insert(), id=2, name=u'mydata2', data2=123)
@ -185,9 +184,9 @@ class TestSchemaDiff(fixture.DB):
# Make sure data is still present.
result = self.engine.execute(self.table.select(self.table.c.id==dataId2))
rows = result.fetchall()
self.assertEquals(len(rows), 1)
self.assertEquals(rows[0].name, 'mydata2')
self.assertEquals(rows[0].data2, '123')
self.assertEqual(len(rows), 1)
self.assertEqual(rows[0].name, 'mydata2')
self.assertEqual(rows[0].data2, '123')
# Delete data, since we're about to make a required column.
# Not even using sqlalchemy.PassiveDefault helps because we're doing explicit column select.

View File

@ -35,7 +35,7 @@ class TestKeydInstance(fixture.Base):
self.assert_(a10 is a11)
# __init__ is called
self.assertEquals(a10.value,'a')
self.assertEqual(a10.value,'a')
# clear() causes us to forget all existing instances
Uniq1.clear()

View File

@ -7,7 +7,6 @@ import shutil
from migrate import exceptions
from migrate.versioning.repository import *
from migrate.versioning.script import *
from nose.tools import raises
from migrate.tests import fixture
from datetime import datetime
@ -76,7 +75,7 @@ class TestVersionedRepository(fixture.Pathed):
repos = Repository(self.path_repos)
# Get latest version, or detect if a specified version exists
self.assertEquals(repos.latest, 0)
self.assertEqual(repos.latest, 0)
# repos.latest isn't an integer, but a VerNum
# (so we can't just assume the following tests are correct)
self.assert_(repos.latest >= 0)
@ -84,14 +83,14 @@ class TestVersionedRepository(fixture.Pathed):
# Create a script and test again
repos.create_script('')
self.assertEquals(repos.latest, 1)
self.assertEqual(repos.latest, 1)
self.assert_(repos.latest >= 0)
self.assert_(repos.latest >= 1)
self.assert_(repos.latest < 2)
# Create a new script and test again
repos.create_script('')
self.assertEquals(repos.latest, 2)
self.assertEqual(repos.latest, 2)
self.assert_(repos.latest >= 0)
self.assert_(repos.latest >= 1)
self.assert_(repos.latest >= 2)
@ -103,7 +102,7 @@ class TestVersionedRepository(fixture.Pathed):
repos.config.set('db_settings', 'use_timestamp_numbering', 'True')
# Get latest version, or detect if a specified version exists
self.assertEquals(repos.latest, 0)
self.assertEqual(repos.latest, 0)
# repos.latest isn't an integer, but a VerNum
# (so we can't just assume the following tests are correct)
self.assert_(repos.latest >= 0)
@ -113,7 +112,7 @@ class TestVersionedRepository(fixture.Pathed):
now = int(datetime.utcnow().strftime('%Y%m%d%H%M%S'))
repos.create_script('')
print repos.latest
self.assertEquals(repos.latest, now)
self.assertEqual(repos.latest, now)
def test_source(self):
"""Get a script object by version number and view its source"""
@ -148,7 +147,7 @@ class TestVersionedRepository(fixture.Pathed):
def check_changeset(params, length):
"""Creates and verifies a changeset"""
changeset = repos.changeset('postgres', *params)
self.assertEquals(len(changeset), length)
self.assertEqual(len(changeset), length)
self.assertTrue(isinstance(changeset, Changeset))
uniq = list()
# Changesets are iterable
@ -161,10 +160,10 @@ class TestVersionedRepository(fixture.Pathed):
# Upgrade to a specified version...
cs = check_changeset((0, 10), 10)
self.assertEquals(cs.keys().pop(0),0 ) # 0 -> 1: index is starting version
self.assertEquals(cs.keys().pop(), 9) # 9 -> 10: index is starting version
self.assertEquals(cs.start, 0) # starting version
self.assertEquals(cs.end, 10) # ending version
self.assertEqual(cs.keys().pop(0),0 ) # 0 -> 1: index is starting version
self.assertEqual(cs.keys().pop(), 9) # 9 -> 10: index is starting version
self.assertEqual(cs.start, 0) # starting version
self.assertEqual(cs.end, 10) # ending version
check_changeset((0, 1), 1)
check_changeset((0, 5), 5)
check_changeset((0, 0), 0)
@ -178,10 +177,10 @@ class TestVersionedRepository(fixture.Pathed):
# Upgrade to the latest version...
cs = check_changeset((0,), 10)
self.assertEquals(cs.keys().pop(0), 0)
self.assertEquals(cs.keys().pop(), 9)
self.assertEquals(cs.start, 0)
self.assertEquals(cs.end, 10)
self.assertEqual(cs.keys().pop(0), 0)
self.assertEqual(cs.keys().pop(), 9)
self.assertEqual(cs.start, 0)
self.assertEqual(cs.end, 10)
check_changeset((1,), 9)
check_changeset((5,), 5)
check_changeset((9,), 1)
@ -196,10 +195,10 @@ class TestVersionedRepository(fixture.Pathed):
# Downgrade
cs = check_changeset((10, 0),10)
self.assertEquals(cs.keys().pop(0), 10) # 10 -> 9
self.assertEquals(cs.keys().pop(), 1) # 1 -> 0
self.assertEquals(cs.start, 10)
self.assertEquals(cs.end, 0)
self.assertEqual(cs.keys().pop(0), 10) # 10 -> 9
self.assertEqual(cs.keys().pop(), 1) # 1 -> 0
self.assertEqual(cs.start, 10)
self.assertEqual(cs.end, 0)
check_changeset((10, 5), 5)
check_changeset((5, 0), 5)

View File

@ -31,22 +31,22 @@ class TestRunChangeset(fixture.Pathed,fixture.DB):
# Scripts are empty; we'll check version # correctness.
# (Correct application of their content is checked elsewhere)
self.assertEquals(db.version,0)
self.assertEqual(db.version,0)
db.upgrade(1)
self.assertEquals(db.version,1)
self.assertEqual(db.version,1)
db.upgrade(5)
self.assertEquals(db.version,5)
self.assertEqual(db.version,5)
db.upgrade(5)
self.assertEquals(db.version,5)
self.assertEqual(db.version,5)
db.upgrade(None) # Latest is implied
self.assertEquals(db.version,10)
self.assertEqual(db.version,10)
self.assertRaises(Exception,db.upgrade,11)
self.assertEquals(db.version,10)
self.assertEqual(db.version,10)
db.upgrade(9)
self.assertEquals(db.version,9)
self.assertEqual(db.version,9)
db.upgrade(0)
self.assertEquals(db.version,0)
self.assertEqual(db.version,0)
self.assertRaises(Exception,db.upgrade,-1)
self.assertEquals(db.version,0)
self.assertEqual(db.version,0)
#changeset = repos.changeset(self.url,0)
db.drop()

View File

@ -56,16 +56,16 @@ class TestControlledSchema(fixture.Pathed, fixture.DB):
# We can load a controlled DB this way, too
dbcontrol0 = ControlledSchema(self.engine, self.repos)
self.assertEquals(dbcontrol, dbcontrol0)
self.assertEqual(dbcontrol, dbcontrol0)
# We can also use a repository path, instead of a repository
dbcontrol0 = ControlledSchema(self.engine, self.repos.path)
self.assertEquals(dbcontrol, dbcontrol0)
self.assertEqual(dbcontrol, dbcontrol0)
# We don't have to use the same connection
engine = create_engine(self.url)
dbcontrol0 = ControlledSchema(engine, self.repos.path)
self.assertEquals(dbcontrol, dbcontrol0)
self.assertEqual(dbcontrol, dbcontrol0)
# Clean up:
dbcontrol.drop()
@ -83,11 +83,11 @@ class TestControlledSchema(fixture.Pathed, fixture.DB):
# Establish version control on this database
version = 0
dbcontrol = ControlledSchema.create(self.engine, self.repos, version)
self.assertEquals(dbcontrol.version, version)
self.assertEqual(dbcontrol.version, version)
# Correct when we load it, too
dbcontrol = ControlledSchema(self.engine, self.repos)
self.assertEquals(dbcontrol.version, version)
self.assertEqual(dbcontrol.version, version)
dbcontrol.drop()
@ -95,16 +95,16 @@ class TestControlledSchema(fixture.Pathed, fixture.DB):
version = 10
for i in range(version):
self.repos.create_script('')
self.assertEquals(self.repos.latest, version)
self.assertEqual(self.repos.latest, version)
# Test with some mid-range value
dbcontrol = ControlledSchema.create(self.engine,self.repos, 5)
self.assertEquals(dbcontrol.version, 5)
self.assertEqual(dbcontrol.version, 5)
dbcontrol.drop()
# Test with max value
dbcontrol = ControlledSchema.create(self.engine, self.repos, version)
self.assertEquals(dbcontrol.version, version)
self.assertEqual(dbcontrol.version, version)
dbcontrol.drop()
@fixture.usedb()
@ -132,7 +132,7 @@ class TestControlledSchema(fixture.Pathed, fixture.DB):
for i in range(5):
self.repos.create_script('')
self.assertEquals(self.repos.latest, 5)
self.assertEqual(self.repos.latest, 5)
cs = dbschema.changeset(5)
self.assertEqual(len(cs), 5)
@ -147,7 +147,7 @@ class TestControlledSchema(fixture.Pathed, fixture.DB):
for i in range(10):
self.repos.create_script('')
self.assertEquals(self.repos.latest, 10)
self.assertEqual(self.repos.latest, 10)
dbschema.upgrade(10)

View File

@ -3,7 +3,6 @@
import os
from sqlalchemy import *
from nose.tools import eq_
from migrate.versioning import schemadiff
@ -27,12 +26,12 @@ class SchemaDiffBase(fixture.DB):
diff = self._run_diff()
# print diff
self.assertTrue(diff)
eq_(1,len(diff.tables_different))
self.assertEqual(1,len(diff.tables_different))
td = diff.tables_different.values()[0]
eq_(1,len(td.columns_different))
self.assertEqual(1,len(td.columns_different))
cd = td.columns_different.values()[0]
label_width = max(len(self.name1), len(self.name2))
eq_(('Schema diffs:\n'
self.assertEqual(('Schema diffs:\n'
' table with differences: xtable\n'
' column with differences: data\n'
' %*s: %r\n'
@ -59,7 +58,7 @@ class Test_getDiffOfModelAgainstDatabase(SchemaDiffBase):
self._make_table(create=False)
diff = self._run_diff()
self.assertTrue(diff)
eq_('Schema diffs:\n tables missing from %s: xtable' % self.name2,
self.assertEqual('Schema diffs:\n tables missing from %s: xtable' % self.name2,
str(diff))
@fixture.usedb()
@ -68,7 +67,7 @@ class Test_getDiffOfModelAgainstDatabase(SchemaDiffBase):
self.meta.clear()
diff = self._run_diff()
self.assertTrue(diff)
eq_('Schema diffs:\n tables missing from %s: xtable' % self.name1,
self.assertEqual('Schema diffs:\n tables missing from %s: xtable' % self.name1,
str(diff))
@fixture.usedb()
@ -86,7 +85,7 @@ class Test_getDiffOfModelAgainstDatabase(SchemaDiffBase):
# run diff
diff = self._run_diff()
self.assertTrue(diff)
eq_('Schema diffs:\n'
self.assertEqual('Schema diffs:\n'
' table with differences: xtable\n'
' %s missing these columns: xcol' % self.name2,
str(diff))
@ -105,7 +104,7 @@ class Test_getDiffOfModelAgainstDatabase(SchemaDiffBase):
# run diff
diff = self._run_diff()
self.assertTrue(diff)
eq_('Schema diffs:\n'
self.assertEqual('Schema diffs:\n'
' table with differences: xtable\n'
' %s missing these columns: xcol' % self.name1,
str(diff))
@ -134,14 +133,14 @@ class Test_getDiffOfModelAgainstDatabase(SchemaDiffBase):
# ztable identical on both
# ...so we expect no diff!
self.assertFalse(diff)
eq_('No schema diffs',str(diff))
self.assertEqual('No schema diffs',str(diff))
@fixture.usedb()
def test_identical_just_pk(self):
self._make_table()
diff = self._run_diff()
self.assertFalse(diff)
eq_('No schema diffs',str(diff))
self.assertEqual('No schema diffs',str(diff))
@fixture.usedb()
@ -192,7 +191,7 @@ class Test_getDiffOfModelAgainstDatabase(SchemaDiffBase):
Column('data', Integer()),
)
diff = self._run_diff()
eq_('No schema diffs',str(diff))
self.assertEqual('No schema diffs',str(diff))
self.assertFalse(diff)
@fixture.usedb()
@ -201,7 +200,7 @@ class Test_getDiffOfModelAgainstDatabase(SchemaDiffBase):
Column('data', String(10)),
)
diff = self._run_diff()
eq_('No schema diffs',str(diff))
self.assertEqual('No schema diffs',str(diff))
self.assertFalse(diff)
@fixture.usedb()
@ -210,7 +209,7 @@ class Test_getDiffOfModelAgainstDatabase(SchemaDiffBase):
Column('data', Text),
)
diff = self._run_diff()
eq_('No schema diffs',str(diff))
self.assertEqual('No schema diffs',str(diff))
self.assertFalse(diff)
class Test_getDiffOfModelAgainstModel(Test_getDiffOfModelAgainstDatabase):

View File

@ -126,7 +126,7 @@ def upgrade(migrate_engine):
pyscript = self.cls(path)
SQL = pyscript.preview_sql(self.url, 1)
self.assertEqualsIgnoreWhitespace("""
self.assertEqualIgnoreWhitespace("""
CREATE TABLE "Link"
("link1ID" INTEGER,
"link2ID" INTEGER,

View File

@ -7,7 +7,6 @@ import tempfile
from cStringIO import StringIO
from sqlalchemy import MetaData, Table
from nose.plugins.skip import SkipTest
from migrate.exceptions import *
from migrate.versioning.repository import Repository
@ -48,7 +47,7 @@ class TestShellCommands(Shell):
def test_main_with_runpy(self):
if sys.version_info[:2] == (2, 4):
raise SkipTest("runpy is not part of python2.4")
self.skipTest("runpy is not part of python2.4")
from runpy import run_module
try:
original = sys.argv
@ -271,50 +270,50 @@ class TestShellDatabase(Shell, DB):
repos_name = 'repos_name'
repos_path = self.tmp()
result = self.env.run('migrate create %(repos_path)s %(repos_name)s' % locals())
self.assertEquals(self.run_version(repos_path), 0)
self.assertEqual(self.run_version(repos_path), 0)
# Version the DB
result = self.env.run('migrate drop_version_control %s %s' % (self.url, repos_path), expect_error=True)
result = self.env.run('migrate version_control %s %s' % (self.url, repos_path))
# Upgrades with latest version == 0
self.assertEquals(self.run_db_version(self.url, repos_path), 0)
self.assertEqual(self.run_db_version(self.url, repos_path), 0)
result = self.env.run('migrate upgrade %s %s' % (self.url, repos_path))
self.assertEquals(self.run_db_version(self.url, repos_path), 0)
self.assertEqual(self.run_db_version(self.url, repos_path), 0)
result = self.env.run('migrate upgrade %s %s' % (self.url, repos_path))
self.assertEquals(self.run_db_version(self.url, repos_path), 0)
self.assertEqual(self.run_db_version(self.url, repos_path), 0)
result = self.env.run('migrate upgrade %s %s 1' % (self.url, repos_path), expect_error=True)
self.assertEquals(result.returncode, 1)
self.assertEqual(result.returncode, 1)
result = self.env.run('migrate upgrade %s %s -1' % (self.url, repos_path), expect_error=True)
self.assertEquals(result.returncode, 2)
self.assertEqual(result.returncode, 2)
# Add a script to the repository; upgrade the db
result = self.env.run('migrate script Desc --repository=%s' % (repos_path))
self.assertEquals(self.run_version(repos_path), 1)
self.assertEquals(self.run_db_version(self.url, repos_path), 0)
self.assertEqual(self.run_version(repos_path), 1)
self.assertEqual(self.run_db_version(self.url, repos_path), 0)
# Test preview
result = self.env.run('migrate upgrade %s %s 0 --preview_sql' % (self.url, repos_path))
result = self.env.run('migrate upgrade %s %s 0 --preview_py' % (self.url, repos_path))
result = self.env.run('migrate upgrade %s %s' % (self.url, repos_path))
self.assertEquals(self.run_db_version(self.url, repos_path), 1)
self.assertEqual(self.run_db_version(self.url, repos_path), 1)
# Downgrade must have a valid version specified
result = self.env.run('migrate downgrade %s %s' % (self.url, repos_path), expect_error=True)
self.assertEquals(result.returncode, 2)
self.assertEqual(result.returncode, 2)
result = self.env.run('migrate downgrade %s %s -1' % (self.url, repos_path), expect_error=True)
self.assertEquals(result.returncode, 2)
self.assertEqual(result.returncode, 2)
result = self.env.run('migrate downgrade %s %s 2' % (self.url, repos_path), expect_error=True)
self.assertEquals(result.returncode, 2)
self.assertEquals(self.run_db_version(self.url, repos_path), 1)
self.assertEqual(result.returncode, 2)
self.assertEqual(self.run_db_version(self.url, repos_path), 1)
result = self.env.run('migrate downgrade %s %s 0' % (self.url, repos_path))
self.assertEquals(self.run_db_version(self.url, repos_path), 0)
self.assertEqual(self.run_db_version(self.url, repos_path), 0)
result = self.env.run('migrate downgrade %s %s 1' % (self.url, repos_path), expect_error=True)
self.assertEquals(result.returncode, 2)
self.assertEquals(self.run_db_version(self.url, repos_path), 0)
self.assertEqual(result.returncode, 2)
self.assertEqual(self.run_db_version(self.url, repos_path), 0)
result = self.env.run('migrate drop_version_control %s %s' % (self.url, repos_path))
@ -326,26 +325,26 @@ class TestShellDatabase(Shell, DB):
result = self.env.run('migrate create %s %s' % (repos_path, repos_name))
result = self.env.run('migrate drop_version_control %s %s' % (self.url, repos_path), expect_error=True)
result = self.env.run('migrate version_control %s %s' % (self.url, repos_path))
self.assertEquals(self.run_version(repos_path), 0)
self.assertEquals(self.run_db_version(self.url, repos_path), 0)
self.assertEqual(self.run_version(repos_path), 0)
self.assertEqual(self.run_db_version(self.url, repos_path), 0)
beforeCount = len(os.listdir(os.path.join(repos_path, 'versions'))) # hmm, this number changes sometimes based on running from svn
result = self.env.run('migrate script_sql %s --repository=%s' % ('postgres', repos_path))
self.assertEquals(self.run_version(repos_path), 1)
self.assertEquals(len(os.listdir(os.path.join(repos_path, 'versions'))), beforeCount + 2)
self.assertEqual(self.run_version(repos_path), 1)
self.assertEqual(len(os.listdir(os.path.join(repos_path, 'versions'))), beforeCount + 2)
open('%s/versions/001_postgres_upgrade.sql' % repos_path, 'a').write(upgrade_script)
open('%s/versions/001_postgres_downgrade.sql' % repos_path, 'a').write(downgrade_script)
self.assertEquals(self.run_db_version(self.url, repos_path), 0)
self.assertEqual(self.run_db_version(self.url, repos_path), 0)
self.assertRaises(Exception, self.engine.text('select * from t_table').execute)
result = self.env.run('migrate upgrade %s %s' % (self.url, repos_path))
self.assertEquals(self.run_db_version(self.url, repos_path), 1)
self.assertEqual(self.run_db_version(self.url, repos_path), 1)
self.engine.text('select * from t_table').execute()
result = self.env.run('migrate downgrade %s %s 0' % (self.url, repos_path))
self.assertEquals(self.run_db_version(self.url, repos_path), 0)
self.assertEqual(self.run_db_version(self.url, repos_path), 0)
self.assertRaises(Exception, self.engine.text('select * from t_table').execute)
# The tests below are written with some postgres syntax, but the stuff
@ -387,14 +386,14 @@ class TestShellDatabase(Shell, DB):
result = self.env.run('migrate create repository_name --repository=%s' % repos_path)
result = self.env.run('migrate drop_version_control %s %s' % (self.url, repos_path), expect_error=True)
result = self.env.run('migrate version_control %s %s' % (self.url, repos_path))
self.assertEquals(self.run_version(repos_path), 0)
self.assertEquals(self.run_db_version(self.url, repos_path), 0)
self.assertEqual(self.run_version(repos_path), 0)
self.assertEqual(self.run_db_version(self.url, repos_path), 0)
# Empty script should succeed
result = self.env.run('migrate script Desc %s' % repos_path)
result = self.env.run('migrate test %s %s' % (self.url, repos_path))
self.assertEquals(self.run_version(repos_path), 1)
self.assertEquals(self.run_db_version(self.url, repos_path), 0)
self.assertEqual(self.run_version(repos_path), 1)
self.assertEqual(self.run_db_version(self.url, repos_path), 0)
# Error script should fail
script_path = self.tmp_py()
@ -416,8 +415,8 @@ class TestShellDatabase(Shell, DB):
result = self.env.run('migrate test %s %s bla' % (self.url, repos_path), expect_error=True)
self.assertEqual(result.returncode, 2)
self.assertEquals(self.run_version(repos_path), 1)
self.assertEquals(self.run_db_version(self.url, repos_path), 0)
self.assertEqual(self.run_version(repos_path), 1)
self.assertEqual(self.run_db_version(self.url, repos_path), 0)
# Nonempty script using migrate_engine should succeed
script_path = self.tmp_py()
@ -446,8 +445,8 @@ class TestShellDatabase(Shell, DB):
file.write(script_text)
file.close()
result = self.env.run('migrate test %s %s' % (self.url, repos_path))
self.assertEquals(self.run_version(repos_path), 1)
self.assertEquals(self.run_db_version(self.url, repos_path), 0)
self.assertEqual(self.run_version(repos_path), 1)
self.assertEqual(self.run_db_version(self.url, repos_path), 0)
@usedb()
def test_rundiffs_in_shell(self):
@ -468,8 +467,8 @@ class TestShellDatabase(Shell, DB):
result = self.env.run('migrate create %s %s' % (repos_path, repos_name))
result = self.env.run('migrate drop_version_control %s %s' % (self.url, repos_path), expect_error=True)
result = self.env.run('migrate version_control %s %s' % (self.url, repos_path))
self.assertEquals(self.run_version(repos_path), 0)
self.assertEquals(self.run_db_version(self.url, repos_path), 0)
self.assertEqual(self.run_version(repos_path), 0)
self.assertEqual(self.run_db_version(self.url, repos_path), 0)
# Setup helper script.
result = self.env.run('migrate manage %s --repository=%s --url=%s --model=%s'\
@ -491,8 +490,8 @@ class TestShellDatabase(Shell, DB):
# Update db to latest model.
result = self.env.run('migrate update_db_from_model %s %s %s'\
% (self.url, repos_path, model_module))
self.assertEquals(self.run_version(repos_path), 0)
self.assertEquals(self.run_db_version(self.url, repos_path), 0) # version did not get bumped yet because new version not yet created
self.assertEqual(self.run_version(repos_path), 0)
self.assertEqual(self.run_db_version(self.url, repos_path), 0) # version did not get bumped yet because new version not yet created
result = self.env.run('migrate compare_model_to_db %s %s %s'\
% (self.url, repos_path, model_module))
@ -520,7 +519,7 @@ class TestShellDatabase(Shell, DB):
#result_script = self.env.run('migrate make_update_script_for_model %s %s %s %s'\
#% (self.url, repos_path, old_model_module, model_module))
#self.assertEqualsIgnoreWhitespace(result_script.stdout,
#self.assertEqualIgnoreWhitespace(result_script.stdout,
#'''from sqlalchemy import *
#from migrate import *

View File

@ -24,11 +24,11 @@ class TestUtil(fixture.Pathed):
# keyword arg
engine = construct_engine(url, engine_arg_encoding='utf-8')
self.assertEquals(engine.dialect.encoding, 'utf-8')
self.assertEqual(engine.dialect.encoding, 'utf-8')
# dict
engine = construct_engine(url, engine_dict={'encoding': 'utf-8'})
self.assertEquals(engine.dialect.encoding, 'utf-8')
self.assertEqual(engine.dialect.encoding, 'utf-8')
# engine parameter
engine_orig = create_engine('sqlite://')
@ -38,7 +38,7 @@ class TestUtil(fixture.Pathed):
# test precedance
engine = construct_engine(url, engine_dict={'encoding': 'iso-8859-1'},
engine_arg_encoding='utf-8')
self.assertEquals(engine.dialect.encoding, 'utf-8')
self.assertEqual(engine.dialect.encoding, 'utf-8')
# deprecated echo=True parameter
try:

View File

@ -76,14 +76,14 @@ class TestVersion(fixture.Pathed):
super(TestVersion, self).setUp()
def test_str_to_filename(self):
self.assertEquals(str_to_filename(''), '')
self.assertEquals(str_to_filename('__'), '_')
self.assertEquals(str_to_filename('a'), 'a')
self.assertEquals(str_to_filename('Abc Def'), 'Abc_Def')
self.assertEquals(str_to_filename('Abc "D" Ef'), 'Abc_D_Ef')
self.assertEquals(str_to_filename("Abc's Stuff"), 'Abc_s_Stuff')
self.assertEquals(str_to_filename("a b"), 'a_b')
self.assertEquals(str_to_filename("a.b to c"), 'a_b_to_c')
self.assertEqual(str_to_filename(''), '')
self.assertEqual(str_to_filename('__'), '_')
self.assertEqual(str_to_filename('a'), 'a')
self.assertEqual(str_to_filename('Abc Def'), 'Abc_Def')
self.assertEqual(str_to_filename('Abc "D" Ef'), 'Abc_D_Ef')
self.assertEqual(str_to_filename("Abc's Stuff"), 'Abc_s_Stuff')
self.assertEqual(str_to_filename("a b"), 'a_b')
self.assertEqual(str_to_filename("a.b to c"), 'a_b_to_c')
def test_collection(self):
"""Let's see how we handle versions collection"""
@ -142,19 +142,19 @@ class TestVersion(fixture.Pathed):
open(filepath, 'w').close()
ver = Version(1, path, [sqlite_upgrade_file])
self.assertEquals(os.path.basename(ver.script('sqlite', 'upgrade').path), sqlite_upgrade_file)
self.assertEqual(os.path.basename(ver.script('sqlite', 'upgrade').path), sqlite_upgrade_file)
ver = Version(1, path, [default_upgrade_file])
self.assertEquals(os.path.basename(ver.script('default', 'upgrade').path), default_upgrade_file)
self.assertEqual(os.path.basename(ver.script('default', 'upgrade').path), default_upgrade_file)
ver = Version(1, path, [sqlite_upgrade_file, default_upgrade_file])
self.assertEquals(os.path.basename(ver.script('sqlite', 'upgrade').path), sqlite_upgrade_file)
self.assertEqual(os.path.basename(ver.script('sqlite', 'upgrade').path), sqlite_upgrade_file)
ver = Version(1, path, [sqlite_upgrade_file, default_upgrade_file, python_file])
self.assertEquals(os.path.basename(ver.script('postgres', 'upgrade').path), default_upgrade_file)
self.assertEqual(os.path.basename(ver.script('postgres', 'upgrade').path), default_upgrade_file)
ver = Version(1, path, [sqlite_upgrade_file, python_file])
self.assertEquals(os.path.basename(ver.script('postgres', 'upgrade').path), python_file)
self.assertEqual(os.path.basename(ver.script('postgres', 'upgrade').path), python_file)
def test_bad_version(self):
ver = Version(1, self.temp_usable_dir, [])

View File

@ -1,5 +1,6 @@
d2to1>=0.2.10,<0.3
pbr>=0.5,<0.6
SQLAlchemy >= 0.6
decorator
Tempita >= 0.4
Sphinx
sphinxcontrib_issuetracker

View File

@ -1,18 +1,40 @@
[metadata]
name = sqlalchemy-migrate
summary = Database schema migration for SQLAlchemy
description-file =
README
author = OpenStack
author-email = openstack-dev@lists.openstack.org
home-page = http://www.openstack.org/
classifier =
Environment :: OpenStack
Intended Audience :: Information Technology
Intended Audience :: System Administrators
License :: OSI Approved :: Apache Software License
Operating System :: POSIX :: Linux
Programming Language :: Python
Programming Language :: Python :: 2
Programming Language :: Python :: 2.7
Programming Language :: Python :: 2.6
[global]
setup-hooks =
pbr.hooks.setup_hook
[files]
packages =
migrate
[entry_points]
console_scripts =
migrate = migrate.versioning.shell:main
migrate-repository = migrate.versioning.migrate_repository:main
[build_sphinx]
source-dir = docs
build-dir = docs/_build
all_files = 1
build-dir = doc/build
source-dir = doc/source
[egg_info]
tag_svn_revision = 1
tag_build = .dev
[nosetests]
# uncomment these if you want tests to drop to pdb on first
# error or failure.
#nologcapture =
#pdb =
#pdb-failures =
#stop =
[aliases]
release = egg_info -RDb ''

View File

@ -1,34 +1,21 @@
#!/usr/bin/python
import os
#!/usr/bin/env python
# Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import setuptools
required_deps = ['SQLAlchemy >= 0.6', 'decorator', 'Tempita >= 0.4']
readme_file = open(os.path.join(os.path.dirname(os.path.abspath(__file__)),
'README'))
setuptools.setup(
name = "sqlalchemy-migrate",
version = "0.7.3",
packages = setuptools.find_packages(exclude=["migrate.tests*"]),
include_package_data = True,
description = "Database schema migration for SQLAlchemy",
long_description = readme_file.read(),
install_requires = required_deps,
extras_require = {
'docs' : ['sphinx >= 0.5'],
},
author = "Evan Rosson",
author_email = "evan.rosson@gmail.com",
url = "http://code.google.com/p/sqlalchemy-migrate/",
maintainer = "Jan Dittberner",
maintainer_email = "jan@dittberner.info",
license = "MIT",
entry_points = """
[console_scripts]
migrate = migrate.versioning.shell:main
migrate-repository = migrate.versioning.migrate_repository:main
""",
test_suite = "nose.collector",
)
setup_requires=['d2to1>=0.2.10,<0.3', 'pbr>=0.5.10,<0.6'],
d2to1=True)

View File

@ -1,11 +1,25 @@
coverage
nose
nosexcover
# Install bounded pep8/pyflakes first, then let flake8 install
pep8==1.4.5
pyflakes==0.7.2
flake8==2.0
hacking>=0.5.3,<0.6
coverage>=3.6
discover
feedparser
fixtures>=0.3.12
mox==0.5.3
MySQL-python
psycopg2
pylint==0.25.2
python-subunit
setuptools_git>=0.4
sphinx>=1.1.2
sphinxcontrib_issuetracker
testrepository>=0.0.13
testtools>=0.9.27
# NOTE: scripttest 1.0.1 removes base_path argument to ScriptTest
scripttest==1.0
pytz
psycopg2
pysqlite
mysql-python
virtualenv
unittest2

View File

@ -6,7 +6,7 @@ setenv = VIRTUAL_ENV={envdir}
deps = -r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt
commands =
nosetests {posargs}
python setup.py testr --slowest --testr-args='{posargs}'
[testenv:pep8]
commands = flake8
@ -17,7 +17,7 @@ commands = {posargs}
[testenv:cover]
setenv = VIRTUAL_ENV={envdir}
commands =
nosetests {posargs}
python setup.py testr --slowest --testr-args='{posargs}'
[flake8]
# F841 local variable 'json_template' is assigned to but never used