diff options
Diffstat (limited to 'migrate')
26 files changed, 123 insertions, 123 deletions
diff --git a/migrate/changeset/databases/firebird.py b/migrate/changeset/databases/firebird.py index 226728b..bbb4acd 100644 --- a/migrate/changeset/databases/firebird.py +++ b/migrate/changeset/databases/firebird.py @@ -31,7 +31,7 @@ class FBColumnDropper(ansisql.ANSIColumnDropper): if column.name in [col.name for col in index.columns]: index.drop() # TODO: recreate index if it references more than this column - + for cons in column.table.constraints: if isinstance(cons,PrimaryKeyConstraint): # will be deleted only when the column its on diff --git a/migrate/changeset/databases/sqlite.py b/migrate/changeset/databases/sqlite.py index 5ddd3f1..6453422 100644 --- a/migrate/changeset/databases/sqlite.py +++ b/migrate/changeset/databases/sqlite.py @@ -42,7 +42,7 @@ class SQLiteHelper(SQLiteCommon): self.execute() self.append('DROP TABLE migration_tmp') self.execute() - + def visit_column(self, delta): if isinstance(delta, DictMixin): column = delta.result_column @@ -52,7 +52,7 @@ class SQLiteHelper(SQLiteCommon): table = self._to_table(column.table) self.recreate_table(table,column,delta) -class SQLiteColumnGenerator(SQLiteSchemaGenerator, +class SQLiteColumnGenerator(SQLiteSchemaGenerator, ansisql.ANSIColumnGenerator, # at the end so we get the normal # visit_column by default @@ -78,7 +78,7 @@ class SQLiteColumnDropper(SQLiteHelper, ansisql.ANSIColumnDropper): """SQLite ColumnDropper""" def _modify_table(self, table, column, delta): - + columns = ' ,'.join(map(self.preparer.format_column, table.columns)) return 'INSERT INTO %(table_name)s SELECT ' + columns + \ ' from migration_tmp' diff --git a/migrate/tests/changeset/test_changeset.py b/migrate/tests/changeset/test_changeset.py index 8b4a6be..1ea7219 100644 --- a/migrate/tests/changeset/test_changeset.py +++ b/migrate/tests/changeset/test_changeset.py @@ -65,7 +65,7 @@ class TestAddDropColumn(fixture.DB): result = len(self.table.primary_key) self.assertEqual(result, num_of_expected_cols) - # we have 1 columns and there is no data column + # we have 1 columns and there is no data column assert_numcols(1) self.assertTrue(getattr(self.table.c, 'data', None) is None) if len(col_p) == 0: @@ -147,7 +147,7 @@ class TestAddDropColumn(fixture.DB): # Not necessarily bound to table return self.table.drop_column(col.name) return self.run_(add_func, drop_func) - + @fixture.usedb() def test_byname(self): """Add/drop columns via functions; by table object and column name""" @@ -302,7 +302,7 @@ class TestAddDropColumn(fixture.DB): if index.name=='ix_data': break self.assertEqual(expected,index.unique) - + @fixture.usedb() def test_index(self): col = Column('data', Integer) @@ -311,7 +311,7 @@ class TestAddDropColumn(fixture.DB): self._check_index(False) col.drop() - + @fixture.usedb() def test_index_unique(self): # shows how to create a unique index @@ -332,7 +332,7 @@ class TestAddDropColumn(fixture.DB): self._check_index(True) col.drop() - + @fixture.usedb() def test_server_defaults(self): """Can create columns with server_default values""" @@ -382,7 +382,7 @@ class TestAddDropColumn(fixture.DB): sorted([i.name for i in self.table.indexes]), [u'ix_tmp_adddropcol_d1', u'ix_tmp_adddropcol_d2'] ) - + # delete one self.table.c.d2.drop() @@ -392,7 +392,7 @@ class TestAddDropColumn(fixture.DB): sorted([i.name for i in self.table.indexes]), [u'ix_tmp_adddropcol_d1'] ) - + def _actual_foreign_keys(self): from sqlalchemy.schema import ForeignKeyConstraint result = [] @@ -406,12 +406,12 @@ class TestAddDropColumn(fixture.DB): result.append(col_names) result.sort() return result - + @fixture.usedb() def test_drop_with_foreign_keys(self): self.table.drop() self.meta.clear() - + # create FK's target reftable = Table('tmp_ref', self.meta, Column('id', Integer, primary_key=True), @@ -419,7 +419,7 @@ class TestAddDropColumn(fixture.DB): if self.engine.has_table(reftable.name): reftable.drop() reftable.create() - + # add a table with two foreign key columns self.table = Table( self.table_name, self.meta, @@ -432,13 +432,13 @@ class TestAddDropColumn(fixture.DB): # paranoid check self.assertEqual([['r1'],['r2']], self._actual_foreign_keys()) - + # delete one if self.engine.name == 'mysql': constraint.ForeignKeyConstraint([self.table.c.r2], [reftable.c.id], name='test_fk2').drop() self.table.c.r2.drop() - + # check remaining foreign key is there self.assertEqual([['r1']], self._actual_foreign_keys()) @@ -447,7 +447,7 @@ class TestAddDropColumn(fixture.DB): def test_drop_with_complex_foreign_keys(self): from sqlalchemy.schema import ForeignKeyConstraint from sqlalchemy.schema import UniqueConstraint - + self.table.drop() self.meta.clear() @@ -465,7 +465,7 @@ class TestAddDropColumn(fixture.DB): if self.engine.has_table(reftable.name): reftable.drop() reftable.create() - + # add a table with a complex foreign key constraint self.table = Table( self.table_name, self.meta, @@ -481,21 +481,21 @@ class TestAddDropColumn(fixture.DB): # paranoid check self.assertEqual([['r1','r2']], self._actual_foreign_keys()) - + # delete one if self.engine.name == 'mysql': constraint.ForeignKeyConstraint([self.table.c.r1, self.table.c.r2], [reftable.c.id, reftable.c.jd], name='test_fk').drop() self.table.c.r2.drop() - + # check the constraint is gone, since part of it # is no longer there - if people hit this, # they may be confused, maybe we should raise an error # and insist that the constraint is deleted first, separately? self.assertEqual([], self._actual_foreign_keys()) - + class TestRename(fixture.DB): """Tests for table and index rename methods""" level = fixture.DB.CONNECT @@ -575,7 +575,7 @@ class TestRename(fixture.DB): # test by just the string rename_table(table_name1, table_name2, engine=self.engine) assert_table_name(table_name2, True) # object not updated - + # Index renames if self.url.startswith('sqlite') or self.url.startswith('mysql'): self.assertRaises(exceptions.NotSupportedError, @@ -671,7 +671,7 @@ class TestColumnChange(fixture.DB): self.assert_('atad' not in self.table.c.keys()) self.table.c.data # Should not raise exception self.assertEqual(num_rows(self.table.c.data,content), 1) - + @fixture.usedb() def test_type(self): # Test we can change a column's type @@ -695,12 +695,12 @@ class TestColumnChange(fixture.DB): @fixture.usedb() def test_default(self): """Can change a column's server_default value (DefaultClauses only) - Only DefaultClauses are changed here: others are managed by the + Only DefaultClauses are changed here: others are managed by the application / by SA """ self.assertEqual(self.table.c.data.server_default.arg, 'tluafed') - # Just the new default + # Just the new default default = 'my_default' self.table.c.data.alter(server_default=DefaultClause(default)) self.refresh_table(self.table.name) @@ -750,7 +750,7 @@ class TestColumnChange(fixture.DB): # py 2.4 compatability :-/ cw = catch_warnings(record=True) w = cw.__enter__() - + warnings.simplefilter("always") self.table.c.data.alter(Column('data', String(100))) @@ -763,7 +763,7 @@ class TestColumnChange(fixture.DB): str(w[-1].message)) finally: cw.__exit__() - + @fixture.usedb() def test_alter_returns_delta(self): """Test if alter constructs return delta""" @@ -791,7 +791,7 @@ class TestColumnChange(fixture.DB): if self.engine.name == 'firebird': del kw['nullable'] self.table.c.data.alter(**kw) - + # test altered objects self.assertEqual(self.table.c.data.server_default.arg, 'foobar') if not self.engine.name == 'firebird': diff --git a/migrate/tests/changeset/test_constraint.py b/migrate/tests/changeset/test_constraint.py index 5527559..941030a 100644 --- a/migrate/tests/changeset/test_constraint.py +++ b/migrate/tests/changeset/test_constraint.py @@ -13,7 +13,7 @@ from migrate.tests import fixture class CommonTestConstraint(fixture.DB): """helper functions to test constraints. - + we just create a fresh new table and make sure everything is as required. """ @@ -257,7 +257,7 @@ class TestAutoname(CommonTestConstraint): cons = CheckConstraint('id > 3', columns=[self.table.c.id]) cons.create() self.refresh_table() - + if not self.engine.name == 'mysql': self.table.insert(values={'id': 4, 'fkey': 1}).execute() try: @@ -280,7 +280,7 @@ class TestAutoname(CommonTestConstraint): cons = UniqueConstraint(self.table.c.fkey) cons.create() self.refresh_table() - + self.table.insert(values={'fkey': 4, 'id': 1}).execute() try: self.table.insert(values={'fkey': 4, 'id': 2}).execute() diff --git a/migrate/tests/fixture/database.py b/migrate/tests/fixture/database.py index e000d60..90b25d5 100644 --- a/migrate/tests/fixture/database.py +++ b/migrate/tests/fixture/database.py @@ -65,7 +65,7 @@ def usedb(supported=None, not_supported=None): @param supported: run tests for ONLY these databases @param not_supported: run tests for all databases EXCEPT these - If both supported and not_supported are empty, all dbs are assumed + If both supported and not_supported are empty, all dbs are assumed to be supported """ if supported is not None and not_supported is not None: @@ -126,7 +126,7 @@ class DB(Base): level = TXN def _engineInfo(self, url=None): - if url is None: + if url is None: url = self.url return url @@ -151,7 +151,7 @@ class DB(Base): if self.level < self.CONNECT: return #self.session = create_session(bind=self.engine) - if self.level < self.TXN: + if self.level < self.TXN: return #self.txn = self.session.begin() diff --git a/migrate/tests/fixture/pathed.py b/migrate/tests/fixture/pathed.py index b36aa08..78cf4cd 100644 --- a/migrate/tests/fixture/pathed.py +++ b/migrate/tests/fixture/pathed.py @@ -30,10 +30,10 @@ class Pathed(base.Base): @classmethod def _tmp(cls, prefix='', suffix=''): """Generate a temporary file name that doesn't exist - All filenames are generated inside a temporary directory created by - tempfile.mkdtemp(); only the creating user has access to this directory. - It should be secure to return a nonexistant temp filename in this - directory, unless the user is messing with their own files. + All filenames are generated inside a temporary directory created by + tempfile.mkdtemp(); only the creating user has access to this directory. + It should be secure to return a nonexistant temp filename in this + directory, unless the user is messing with their own files. """ file, ret = tempfile.mkstemp(suffix,prefix,cls._tmpdir) os.close(file) @@ -43,7 +43,7 @@ class Pathed(base.Base): @classmethod def tmp(cls, *p, **k): return cls._tmp(*p, **k) - + @classmethod def tmp_py(cls, *p, **k): return cls._tmp(suffix='.py', *p, **k) @@ -63,7 +63,7 @@ class Pathed(base.Base): @classmethod def purge(cls, path): """Removes this path if it exists, in preparation for tests - Careful - all tests should take place in /tmp. + Careful - all tests should take place in /tmp. We don't want to accidentally wipe stuff out... """ if os.path.exists(path): diff --git a/migrate/tests/versioning/test_cfgparse.py b/migrate/tests/versioning/test_cfgparse.py index 27f52cd..1d0d7e8 100644 --- a/migrate/tests/versioning/test_cfgparse.py +++ b/migrate/tests/versioning/test_cfgparse.py @@ -17,7 +17,7 @@ class TestConfigParser(fixture.Base): parser.set('section','option','value') self.assertEqual(parser.get('section', 'option'), 'value') self.assertEqual(parser.to_dict()['section']['option'], 'value') - + def test_table_config(self): """We should be able to specify the table to be used with a repository""" default_text = Repository.prepare_config(Template().get_repository(), diff --git a/migrate/tests/versioning/test_keyedinstance.py b/migrate/tests/versioning/test_keyedinstance.py index 28f3b2b..d5e6ba2 100644 --- a/migrate/tests/versioning/test_keyedinstance.py +++ b/migrate/tests/versioning/test_keyedinstance.py @@ -19,7 +19,7 @@ class TestKeydInstance(fixture.Base): return str(key) def __init__(self,value): self.value=value - + a10 = Uniq1('a') # Different key: different instance diff --git a/migrate/tests/versioning/test_pathed.py b/migrate/tests/versioning/test_pathed.py index 7616e9d..2798067 100644 --- a/migrate/tests/versioning/test_pathed.py +++ b/migrate/tests/versioning/test_pathed.py @@ -12,7 +12,7 @@ class TestPathed(fixture.Base): self.assert_(result==Pathed._parent_path(filepath)) self.assert_(result==Pathed._parent_path(dirpath)) self.assert_(result==Pathed._parent_path(sdirpath)) - + def test_new(self): """Pathed(path) shouldn't create duplicate objects of the same path""" path='/fgsfds' @@ -34,7 +34,7 @@ class TestPathed(fixture.Base): parent=None children=0 def _init_child(self,child,path): - """Keep a tally of children. + """Keep a tally of children. (A real class might do something more interesting here) """ self.__class__.children+=1 diff --git a/migrate/tests/versioning/test_repository.py b/migrate/tests/versioning/test_repository.py index 7065368..37bb5e7 100644 --- a/migrate/tests/versioning/test_repository.py +++ b/migrate/tests/versioning/test_repository.py @@ -32,7 +32,7 @@ class TestRepository(fixture.Pathed): # Can't create it again: it already exists self.assertRaises(exceptions.PathFoundError, Repository.create, path, name) return path - + def test_load(self): """We should be able to load information about an existing repository""" # Create a repository to load @@ -45,7 +45,7 @@ class TestRepository(fixture.Pathed): # version_table's default isn't none self.assertNotEquals(repos.config.get('db_settings', 'version_table'), 'None') - + def test_load_notfound(self): """Nonexistant repositories shouldn't be loaded""" path = self.tmp_repos() @@ -54,7 +54,7 @@ class TestRepository(fixture.Pathed): def test_load_invalid(self): """Invalid repos shouldn't be loaded""" - # Here, invalid=empty directory. There may be other conditions too, + # Here, invalid=empty directory. There may be other conditions too, # but we shouldn't need to test all of them path = self.tmp_repos() os.mkdir(path) @@ -136,7 +136,7 @@ class TestVersionedRepository(fixture.Pathed): repos.create_script('') self.assert_(repos.version(repos.latest) is repos.version()) self.assert_(repos.version() is not None) - + def test_changeset(self): """Repositories can create changesets properly""" # Create a nonzero-version repository of empty scripts @@ -201,17 +201,17 @@ class TestVersionedRepository(fixture.Pathed): self.assertEqual(cs.end, 0) check_changeset((10, 5), 5) check_changeset((5, 0), 5) - + def test_many_versions(self): """Test what happens when lots of versions are created""" repos = Repository(self.path_repos) - for i in range(1001): + for i in range(1001): repos.create_script('') # since we normally create 3 digit ones, let's see if we blow up self.assert_(os.path.exists('%s/versions/1000.py' % self.path_repos)) self.assert_(os.path.exists('%s/versions/1001.py' % self.path_repos)) - + # TODO: test manage file # TODO: test changeset diff --git a/migrate/tests/versioning/test_schema.py b/migrate/tests/versioning/test_schema.py index 7502783..0089c38 100644 --- a/migrate/tests/versioning/test_schema.py +++ b/migrate/tests/versioning/test_schema.py @@ -53,7 +53,7 @@ class TestControlledSchema(fixture.Pathed, fixture.DB): # Trying to create another DB this way fails: table exists self.assertRaises(exceptions.DatabaseAlreadyControlledError, ControlledSchema.create, self.engine, self.repos) - + # We can load a controlled DB this way, too dbcontrol0 = ControlledSchema(self.engine, self.repos) self.assertEqual(dbcontrol, dbcontrol0) @@ -67,7 +67,7 @@ class TestControlledSchema(fixture.Pathed, fixture.DB): dbcontrol0 = ControlledSchema(engine, self.repos.path) self.assertEqual(dbcontrol, dbcontrol0) - # Clean up: + # Clean up: dbcontrol.drop() # Attempting to drop vc from a db without it should fail @@ -84,7 +84,7 @@ class TestControlledSchema(fixture.Pathed, fixture.DB): version = 0 dbcontrol = ControlledSchema.create(self.engine, self.repos, version) self.assertEqual(dbcontrol.version, version) - + # Correct when we load it, too dbcontrol = ControlledSchema(self.engine, self.repos) self.assertEqual(dbcontrol.version, version) @@ -125,7 +125,7 @@ class TestControlledSchema(fixture.Pathed, fixture.DB): def test_changeset(self): """Create changeset from controlled schema""" dbschema = ControlledSchema.create(self.engine, self.repos) - + # empty schema doesn't have changesets cs = dbschema.changeset() self.assertEqual(cs, {}) @@ -143,7 +143,7 @@ class TestControlledSchema(fixture.Pathed, fixture.DB): @fixture.usedb() def test_upgrade_runchange(self): dbschema = ControlledSchema.create(self.engine, self.repos) - + for i in range(10): self.repos.create_script('') @@ -184,7 +184,7 @@ class TestControlledSchema(fixture.Pathed, fixture.DB): dbschema = ControlledSchema.create(self.engine, self.repos) meta = self.construct_model() - + dbschema.update_db_from_model(meta) # TODO: test for table version in db diff --git a/migrate/tests/versioning/test_schemadiff.py b/migrate/tests/versioning/test_schemadiff.py index 1ff353f..ec6d1dc 100644 --- a/migrate/tests/versioning/test_schemadiff.py +++ b/migrate/tests/versioning/test_schemadiff.py @@ -18,7 +18,7 @@ class SchemaDiffBase(fixture.DB): ) if kw.get('create',True): self.table.create() - + def _assert_diff(self,col_A,col_B): self._make_table(col_A) self.meta.clear() @@ -43,16 +43,16 @@ class SchemaDiffBase(fixture.DB): self.name2, cd.col_B ),str(diff)) - + class Test_getDiffOfModelAgainstDatabase(SchemaDiffBase): name1 = 'model' name2 = 'database' - + def _run_diff(self,**kw): return schemadiff.getDiffOfModelAgainstDatabase( self.meta, self.engine, **kw ) - + @fixture.usedb() def test_table_missing_in_db(self): self._make_table(create=False) @@ -187,7 +187,7 @@ class Test_getDiffOfModelAgainstDatabase(SchemaDiffBase): Column('data', String(10)), Column('data', String(20)), ) - + @fixture.usedb() def test_integer_identical(self): self._make_table( @@ -196,7 +196,7 @@ class Test_getDiffOfModelAgainstDatabase(SchemaDiffBase): diff = self._run_diff() self.assertEqual('No schema diffs',str(diff)) self.assertFalse(diff) - + @fixture.usedb() def test_string_identical(self): self._make_table( diff --git a/migrate/tests/versioning/test_script.py b/migrate/tests/versioning/test_script.py index b52ddaa..95ee58c 100644 --- a/migrate/tests/versioning/test_script.py +++ b/migrate/tests/versioning/test_script.py @@ -223,7 +223,7 @@ User = Table('User', meta, f = open(path, 'w') f.write(contents) f.close() - + class TestSqlScript(fixture.Pathed, fixture.DB): diff --git a/migrate/tests/versioning/test_shell.py b/migrate/tests/versioning/test_shell.py index 0bf5e22..4ba6bce 100644 --- a/migrate/tests/versioning/test_shell.py +++ b/migrate/tests/versioning/test_shell.py @@ -52,7 +52,7 @@ class TestShellCommands(Shell): try: original = sys.argv sys.argv=['X','--help'] - + run_module('migrate.versioning.shell', run_name='__main__') finally: @@ -73,7 +73,7 @@ class TestShellCommands(Shell): sys.stderr = original actual = actual.getvalue() self.assertTrue(expected in actual,'%r not in:\n"""\n%s\n"""'%(expected,actual)) - + def test_main(self): """Test main() function""" repos = self.tmp_repos() @@ -106,7 +106,7 @@ class TestShellCommands(Shell): result = self.env.run('migrate create %s repository_name' % repos, expect_error=True) self.assertEqual(result.returncode, 2) - + def test_script(self): """We can create a migration script via the command line""" repos = self.tmp_repos() @@ -202,7 +202,7 @@ class TestShellDatabase(Shell, DB): # we need to connect to the DB to see if things worked level = DB.CONNECT - + @usedb() def test_version_control(self): """Ensure we can set version control on a database""" @@ -298,7 +298,7 @@ class TestShellDatabase(Shell, DB): result = self.env.run('migrate upgrade %s %s' % (self.url, repos_path)) 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.assertEqual(result.returncode, 2) @@ -307,10 +307,10 @@ class TestShellDatabase(Shell, DB): result = self.env.run('migrate downgrade %s %s 2' % (self.url, repos_path), expect_error=True) 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.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.assertEqual(result.returncode, 2) self.assertEqual(self.run_db_version(self.url, repos_path), 0) @@ -348,7 +348,7 @@ class TestShellDatabase(Shell, DB): self.assertRaises(Exception, self.engine.text('select * from t_table').execute) # The tests below are written with some postgres syntax, but the stuff - # being tested (.sql files) ought to work with any db. + # being tested (.sql files) ought to work with any db. @usedb(supported='postgres') def test_sqlfile(self): upgrade_script = """ @@ -362,7 +362,7 @@ class TestShellDatabase(Shell, DB): """ self.meta.drop_all() self._run_test_sqlfile(upgrade_script, downgrade_script) - + @usedb(supported='postgres') def test_sqlfile_comment(self): upgrade_script = """ @@ -400,11 +400,11 @@ class TestShellDatabase(Shell, DB): script_text=''' from sqlalchemy import * from migrate import * - + def upgrade(): print 'fgsfds' raise Exception() - + def downgrade(): print 'sdfsgf' raise Exception() @@ -425,7 +425,7 @@ class TestShellDatabase(Shell, DB): from migrate import * from migrate.changeset import schema - + meta = MetaData(migrate_engine) account = Table('account', meta, Column('id', Integer, primary_key=True), @@ -436,7 +436,7 @@ class TestShellDatabase(Shell, DB): # Upgrade operations go here. Don't create your own engine; use the engine # named 'migrate_engine' imported from migrate. meta.create_all() - + def downgrade(): # Operations to reverse the above upgrade go here. meta.drop_all() @@ -447,7 +447,7 @@ class TestShellDatabase(Shell, DB): result = self.env.run('migrate test %s %s' % (self.url, repos_path)) 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): # This is a variant of the test_schemadiff tests but run through the shell level. @@ -542,7 +542,7 @@ class TestShellDatabase(Shell, DB): ## Operations to reverse the above upgrade go here. #meta.bind = migrate_engine #tmp_account_rundiffs.drop()''') - + ## Save the upgrade script. #result = self.env.run('migrate script Desc %s' % repos_path) #upgrade_script_path = '%s/versions/001_Desc.py' % repos_path diff --git a/migrate/tests/versioning/test_util.py b/migrate/tests/versioning/test_util.py index b6b1490..db4ea26 100644 --- a/migrate/tests/versioning/test_util.py +++ b/migrate/tests/versioning/test_util.py @@ -45,7 +45,7 @@ class TestUtil(fixture.Pathed): # py 2.4 compatability :-/ cw = catch_warnings(record=True) w = cw.__enter__() - + warnings.simplefilter("always") engine = construct_engine(url, echo='True') self.assertTrue(engine.echo) @@ -69,7 +69,7 @@ class TestUtil(fixture.Pathed): api.create(repo, 'temp') api.script('First Version', repo) engine = construct_engine('sqlite:///:memory:') - + api.version_control(engine, repo) api.upgrade(engine, repo) @@ -103,7 +103,7 @@ class TestUtil(fixture.Pathed): # py 2.4 compatability :-/ cw = catch_warnings(record=True) w = cw.__enter__() - + warnings.simplefilter("always") # deprecated spelling @@ -117,7 +117,7 @@ class TestUtil(fixture.Pathed): 'model should be in form of module.model:User ' 'and not module.model.User', str(w[-1].message)) - + finally: cw.__exit__() diff --git a/migrate/tests/versioning/test_version.py b/migrate/tests/versioning/test_version.py index f521659..25ab2b1 100644 --- a/migrate/tests/versioning/test_version.py +++ b/migrate/tests/versioning/test_version.py @@ -68,7 +68,7 @@ class TestVerNum(fixture.Base): self.assert_(VerNum(1) >= 1) self.assert_(VerNum(2) >= 1) self.assertFalse(VerNum(1) >= 2) - + class TestVersion(fixture.Pathed): @@ -128,11 +128,11 @@ class TestVersion(fixture.Pathed): def test_selection(self): """Verify right sql script is selected""" - + # Create empty directory. path = self.tmp_repos() os.mkdir(path) - + # Create files -- files must be present or you'll get an exception later. python_file = '001_initial_.py' sqlite_upgrade_file = '001_sqlite_upgrade.sql' @@ -143,13 +143,13 @@ class TestVersion(fixture.Pathed): ver = Version(1, 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.assertEqual(os.path.basename(ver.script('default', 'upgrade').path), default_upgrade_file) - + ver = Version(1, path, [sqlite_upgrade_file, default_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.assertEqual(os.path.basename(ver.script('postgres', 'upgrade').path), default_upgrade_file) diff --git a/migrate/versioning/repository.py b/migrate/versioning/repository.py index 6e2f678..82aa271 100644 --- a/migrate/versioning/repository.py +++ b/migrate/versioning/repository.py @@ -153,7 +153,7 @@ class Repository(pathed.Pathed): def create_script(self, description, **k): """API to :meth:`migrate.versioning.version.Collection.create_new_python_version`""" - + k['use_timestamp_numbering'] = self.use_timestamp_numbering self.versions.create_new_python_version(description, **k) @@ -229,7 +229,7 @@ class Repository(pathed.Pathed): @classmethod def create_manage_file(cls, file_, **opts): """Create a project management script (manage.py) - + :param file_: Destination file to be written :param opts: Options that are passed to :func:`migrate.versioning.shell.main` """ diff --git a/migrate/versioning/script/base.py b/migrate/versioning/script/base.py index 4287235..22ca7b4 100644 --- a/migrate/versioning/script/base.py +++ b/migrate/versioning/script/base.py @@ -28,7 +28,7 @@ class BaseScript(pathed.Pathed): self.verify(path) super(BaseScript, self).__init__(path) log.debug('Script %s loaded successfully' % path) - + @classmethod def verify(cls, path): """Ensure this is a valid script diff --git a/migrate/versioning/script/sql.py b/migrate/versioning/script/sql.py index ed80764..fdc9e2b 100644 --- a/migrate/versioning/script/sql.py +++ b/migrate/versioning/script/sql.py @@ -15,7 +15,7 @@ class SqlScript(base.BaseScript): @classmethod def create(cls, path, **opts): """Create an empty migration script at specified path - + :returns: :class:`SqlScript instance <migrate.versioning.script.sql.SqlScript>`""" cls.require_notfound(path) diff --git a/migrate/versioning/template.py b/migrate/versioning/template.py index 182898a..8182e6b 100644 --- a/migrate/versioning/template.py +++ b/migrate/versioning/template.py @@ -33,7 +33,7 @@ class SQLScriptCollection(Collection): class Template(pathed.Pathed): """Finds the paths/packages of various Migrate templates. - + :param path: Templates are loaded from migrate package if `path` is not provided. """ @@ -65,7 +65,7 @@ class Template(pathed.Pathed): def _get_item(self, collection, theme=None): """Locates and returns collection. - + :param collection: name of collection to locate :param type_: type of subfolder in collection (defaults to "_default") :returns: (package, source) @@ -79,7 +79,7 @@ class Template(pathed.Pathed): def get_repository(self, *a, **kw): """Calls self._get_item('repository', *a, **kw)""" return self._get_item('repository', *a, **kw) - + def get_script(self, *a, **kw): """Calls self._get_item('script', *a, **kw)""" return self._get_item('script', *a, **kw) diff --git a/migrate/versioning/templates/repository/default/migrate.cfg b/migrate/versioning/templates/repository/default/migrate.cfg index dae0612..bcc33a7 100644 --- a/migrate/versioning/templates/repository/default/migrate.cfg +++ b/migrate/versioning/templates/repository/default/migrate.cfg @@ -5,16 +5,16 @@ repository_id={{ locals().pop('repository_id') }} # The name of the database table used to track the schema version. # This name shouldn't already be used by your project. -# If this is changed once a database is under version control, you'll need to -# change the table name in each database too. +# If this is changed once a database is under version control, you'll need to +# change the table name in each database too. version_table={{ locals().pop('version_table') }} -# When committing a change script, Migrate will attempt to generate the +# When committing a change script, Migrate will attempt to generate the # sql for all supported databases; normally, if one of them fails - probably -# because you don't have that database installed - it is ignored and the -# commit continues, perhaps ending successfully. -# Databases in this list MUST compile successfully during a commit, or the -# entire commit will fail. List the databases your application will actually +# because you don't have that database installed - it is ignored and the +# commit continues, perhaps ending successfully. +# Databases in this list MUST compile successfully during a commit, or the +# entire commit will fail. List the databases your application will actually # be using to ensure your updates to that database work properly. # This must be a list; example: ['postgres','sqlite'] required_dbs={{ locals().pop('required_dbs') }} diff --git a/migrate/versioning/templates/repository/pylons/migrate.cfg b/migrate/versioning/templates/repository/pylons/migrate.cfg index dae0612..bcc33a7 100644 --- a/migrate/versioning/templates/repository/pylons/migrate.cfg +++ b/migrate/versioning/templates/repository/pylons/migrate.cfg @@ -5,16 +5,16 @@ repository_id={{ locals().pop('repository_id') }} # The name of the database table used to track the schema version. # This name shouldn't already be used by your project. -# If this is changed once a database is under version control, you'll need to -# change the table name in each database too. +# If this is changed once a database is under version control, you'll need to +# change the table name in each database too. version_table={{ locals().pop('version_table') }} -# When committing a change script, Migrate will attempt to generate the +# When committing a change script, Migrate will attempt to generate the # sql for all supported databases; normally, if one of them fails - probably -# because you don't have that database installed - it is ignored and the -# commit continues, perhaps ending successfully. -# Databases in this list MUST compile successfully during a commit, or the -# entire commit will fail. List the databases your application will actually +# because you don't have that database installed - it is ignored and the +# commit continues, perhaps ending successfully. +# Databases in this list MUST compile successfully during a commit, or the +# entire commit will fail. List the databases your application will actually # be using to ensure your updates to that database work properly. # This must be a list; example: ['postgres','sqlite'] required_dbs={{ locals().pop('required_dbs') }} diff --git a/migrate/versioning/util/__init__.py b/migrate/versioning/util/__init__.py index 0928644..34ec5b2 100644 --- a/migrate/versioning/util/__init__.py +++ b/migrate/versioning/util/__init__.py @@ -22,7 +22,7 @@ def load_model(dotted_name): """Import module and use module-level variable". :param dotted_name: path to model in form of string: ``some.python.module:Class`` - + .. versionchanged:: 0.5.4 """ @@ -54,9 +54,9 @@ def asbool(obj): def guess_obj_type(obj): """Do everything to guess object type from string - + Tries to convert to `int`, `bool` and finally returns if not succeded. - + .. versionadded: 0.5.4 """ @@ -81,7 +81,7 @@ def guess_obj_type(obj): @decorator def catch_known_errors(f, *a, **kw): """Decorator that catches known api errors - + .. versionadded: 0.5.4 """ diff --git a/migrate/versioning/util/importpath.py b/migrate/versioning/util/importpath.py index 59b57f1..0b398e1 100644 --- a/migrate/versioning/util/importpath.py +++ b/migrate/versioning/util/importpath.py @@ -3,7 +3,7 @@ import sys def import_path(fullpath): """ Import a file with full path specification. Allows one to - import from anywhere, something __import__ does not do. + import from anywhere, something __import__ does not do. """ # http://zephyrfalcon.org/weblog/arch_d7_2002_08_31.html path, filename = os.path.split(fullpath) diff --git a/migrate/versioning/util/keyedinstance.py b/migrate/versioning/util/keyedinstance.py index 3f6cb91..a692e08 100644 --- a/migrate/versioning/util/keyedinstance.py +++ b/migrate/versioning/util/keyedinstance.py @@ -4,7 +4,7 @@ class KeyedInstance(object): """A class whose instances have a unique identifier of some sort No two instances with the same unique ID should exist - if we try to create - a second instance, the first should be returned. + a second instance, the first should be returned. """ _instances = dict() @@ -24,7 +24,7 @@ class KeyedInstance(object): @classmethod def _key(cls, *p, **k): """Given a unique identifier, return a dictionary key - This should be overridden by child classes, to specify which parameters + This should be overridden by child classes, to specify which parameters should determine an object's uniqueness """ raise NotImplementedError() diff --git a/migrate/versioning/version.py b/migrate/versioning/version.py index 0f92dd8..37dfbb9 100644 --- a/migrate/versioning/version.py +++ b/migrate/versioning/version.py @@ -75,7 +75,7 @@ class Collection(pathed.Pathed): and store them in self.versions """ super(Collection, self).__init__(path) - + # Create temporary list of files, allowing skipped version numbers. files = os.listdir(path) if '1' in files: @@ -126,7 +126,7 @@ class Collection(pathed.Pathed): script.PythonScript.create(filepath, **k) self.versions[ver] = Version(ver, self.path, [filename]) - + def create_new_sql_version(self, database, description, **k): """Create SQL files for new version""" ver = self._next_ver_num(k.pop('use_timestamp_numbering', False)) @@ -146,7 +146,7 @@ class Collection(pathed.Pathed): filepath = self._version_path(filename) script.SqlScript.create(filepath, **k) self.versions[ver].add_script(filepath) - + def version(self, vernum=None): """Returns latest Version if vernum is not given. Otherwise, returns wanted version""" @@ -165,7 +165,7 @@ class Collection(pathed.Pathed): class Version(object): """A single version in a collection - :param vernum: Version Number + :param vernum: Version Number :param path: Path to script files :param filelist: List of scripts :type vernum: int, VerNum @@ -182,7 +182,7 @@ class Version(object): for script in filelist: self.add_script(os.path.join(path, script)) - + def script(self, database=None, operation=None): """Returns SQL or Python Script""" for db in (database, 'default'): @@ -211,7 +211,7 @@ class Version(object): def _add_script_sql(self, path): basename = os.path.basename(path) match = self.SQL_FILENAME.match(basename) - + if match: basename = basename.replace('.sql', '') parts = basename.split('_') |