diff --git a/tests/__init__.py b/migrate/tests/__init__.py similarity index 100% rename from tests/__init__.py rename to migrate/tests/__init__.py diff --git a/tests/changeset/__init__.py b/migrate/tests/changeset/__init__.py similarity index 100% rename from tests/changeset/__init__.py rename to migrate/tests/changeset/__init__.py diff --git a/tests/changeset/test_changeset.py b/migrate/tests/changeset/test_changeset.py similarity index 99% rename from tests/changeset/test_changeset.py rename to migrate/tests/changeset/test_changeset.py index 97db212..beeb509 100644 --- a/tests/changeset/test_changeset.py +++ b/migrate/tests/changeset/test_changeset.py @@ -6,7 +6,7 @@ from sqlalchemy import * from migrate import changeset from migrate.changeset import * from migrate.changeset.schema import ColumnDelta -from tests import fixture +from migrate.tests import fixture class TestAddDropColumn(fixture.DB): diff --git a/tests/changeset/test_constraint.py b/migrate/tests/changeset/test_constraint.py similarity index 99% rename from tests/changeset/test_constraint.py rename to migrate/tests/changeset/test_constraint.py index 19e32ec..e5717f2 100644 --- a/tests/changeset/test_constraint.py +++ b/migrate/tests/changeset/test_constraint.py @@ -8,7 +8,7 @@ from sqlalchemy.exc import * from migrate.changeset import * from migrate.changeset.exceptions import * -from tests import fixture +from migrate.tests import fixture class CommonTestConstraint(fixture.DB): diff --git a/tests/fixture/__init__.py b/migrate/tests/fixture/__init__.py similarity index 97% rename from tests/fixture/__init__.py rename to migrate/tests/fixture/__init__.py index 4f06680..2a40355 100644 --- a/tests/fixture/__init__.py +++ b/migrate/tests/fixture/__init__.py @@ -61,6 +61,6 @@ def main(imports=None): testRunner=Runner(verbosity=1)) from base import Base -from pathed import Pathed +from migrate.tests.fixture.pathed import Pathed from shell import Shell from database import DB,usedb diff --git a/tests/fixture/base.py b/migrate/tests/fixture/base.py similarity index 95% rename from tests/fixture/base.py rename to migrate/tests/fixture/base.py index c64df7b..10e8f13 100644 --- a/tests/fixture/base.py +++ b/migrate/tests/fixture/base.py @@ -4,9 +4,6 @@ import re import unittest -from nose.tools import raises, eq_ - - class Base(unittest.TestCase): def setup_method(self,func=None): diff --git a/tests/fixture/database.py b/migrate/tests/fixture/database.py similarity index 98% rename from tests/fixture/database.py rename to migrate/tests/fixture/database.py index 89ae109..7155b26 100644 --- a/tests/fixture/database.py +++ b/migrate/tests/fixture/database.py @@ -12,8 +12,8 @@ from migrate.changeset import SQLA_06 from migrate.changeset.schema import ColumnDelta from migrate.versioning.util import Memoize -from tests.fixture.base import Base -from tests.fixture.pathed import Pathed +from migrate.tests.fixture.base import Base +from migrate.tests.fixture.pathed import Pathed @Memoize diff --git a/tests/fixture/models.py b/migrate/tests/fixture/models.py similarity index 100% rename from tests/fixture/models.py rename to migrate/tests/fixture/models.py diff --git a/tests/fixture/pathed.py b/migrate/tests/fixture/pathed.py similarity index 98% rename from tests/fixture/pathed.py rename to migrate/tests/fixture/pathed.py index 3f670de..b36aa08 100644 --- a/tests/fixture/pathed.py +++ b/migrate/tests/fixture/pathed.py @@ -6,7 +6,7 @@ import sys import shutil import tempfile -from tests.fixture import base +from migrate.tests.fixture import base class Pathed(base.Base): diff --git a/migrate/tests/fixture/shell.py b/migrate/tests/fixture/shell.py new file mode 100644 index 0000000..92f9e33 --- /dev/null +++ b/migrate/tests/fixture/shell.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import os +import sys + +from scripttest import TestFileEnvironment + +from migrate.tests.fixture.pathed import * + + +class Shell(Pathed): + """Base class for command line tests""" + + def setUp(self): + super(Shell, self).setUp() + self.env = TestFileEnvironment( + base_path=os.path.join(self.temp_usable_dir, 'env'), + script_path=[os.path.dirname(sys.executable)], # PATH to migrate development script folder + environ={'PYTHONPATH': + os.path.join(os.getcwd(), 'migrate', 'tests')}, + ) + self.env.run("virtualenv %s" % self.env.base_path) + self.env.run("%s/bin/python setup.py install" % (self.env.base_path,), cwd=os.getcwd()) + + def run_version(self, repos_path): + result = self.env.run('bin/migrate version %s' % repos_path) + return int(result.stdout.strip()) + + def run_db_version(self, url, repos_path): + result = self.env.run('bin/migrate db_version %s %s' % (url, repos_path)) + return int(result.stdout.strip()) diff --git a/tests/integrated/__init__.py b/migrate/tests/integrated/__init__.py similarity index 100% rename from tests/integrated/__init__.py rename to migrate/tests/integrated/__init__.py diff --git a/tests/integrated/test_docs.py b/migrate/tests/integrated/test_docs.py similarity index 85% rename from tests/integrated/test_docs.py rename to migrate/tests/integrated/test_docs.py index 71c97a7..6aed071 100644 --- a/tests/integrated/test_docs.py +++ b/migrate/tests/integrated/test_docs.py @@ -2,11 +2,11 @@ import doctest import os -from tests import fixture +from migrate.tests import fixture # Collect tests for all handwritten docs: doc/*.rst -dir = ('..','..','docs') +dir = ('..','..','..','docs') 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')] diff --git a/tests/versioning/__init__.py b/migrate/tests/versioning/__init__.py similarity index 100% rename from tests/versioning/__init__.py rename to migrate/tests/versioning/__init__.py diff --git a/tests/versioning/test_api.py b/migrate/tests/versioning/test_api.py similarity index 97% rename from tests/versioning/test_api.py rename to migrate/tests/versioning/test_api.py index f4ea73c..41152b0 100644 --- a/tests/versioning/test_api.py +++ b/migrate/tests/versioning/test_api.py @@ -4,9 +4,9 @@ from migrate.versioning import api from migrate.versioning.exceptions import * -from tests.fixture.pathed import * -from tests.fixture import models -from tests import fixture +from migrate.tests.fixture.pathed import * +from migrate.tests.fixture import models +from migrate.tests import fixture class TestAPI(Pathed): diff --git a/tests/versioning/test_cfgparse.py b/migrate/tests/versioning/test_cfgparse.py similarity index 96% rename from tests/versioning/test_cfgparse.py rename to migrate/tests/versioning/test_cfgparse.py index f424162..27f52cd 100644 --- a/tests/versioning/test_cfgparse.py +++ b/migrate/tests/versioning/test_cfgparse.py @@ -4,7 +4,7 @@ from migrate.versioning import cfgparse from migrate.versioning.repository import * from migrate.versioning.template import Template -from tests import fixture +from migrate.tests import fixture class TestConfigParser(fixture.Base): diff --git a/tests/versioning/test_database.py b/migrate/tests/versioning/test_database.py similarity index 90% rename from tests/versioning/test_database.py rename to migrate/tests/versioning/test_database.py index 090c086..525385f 100644 --- a/tests/versioning/test_database.py +++ b/migrate/tests/versioning/test_database.py @@ -1,5 +1,5 @@ from sqlalchemy import select -from tests import fixture +from migrate.tests import fixture class TestConnect(fixture.DB): level=fixture.DB.TXN diff --git a/tests/versioning/test_genmodel.py b/migrate/tests/versioning/test_genmodel.py similarity index 87% rename from tests/versioning/test_genmodel.py rename to migrate/tests/versioning/test_genmodel.py index 0fb7aed..61610a1 100644 --- a/tests/versioning/test_genmodel.py +++ b/migrate/tests/versioning/test_genmodel.py @@ -6,7 +6,7 @@ import os from migrate.versioning.genmodel import * from migrate.versioning.exceptions import * -from tests import fixture +from migrate.tests import fixture class TestModelGenerator(fixture.Pathed, fixture.DB): diff --git a/tests/versioning/test_keyedinstance.py b/migrate/tests/versioning/test_keyedinstance.py similarity index 97% rename from tests/versioning/test_keyedinstance.py rename to migrate/tests/versioning/test_keyedinstance.py index 6e4f5dc..b2f87ac 100644 --- a/tests/versioning/test_keyedinstance.py +++ b/migrate/tests/versioning/test_keyedinstance.py @@ -1,7 +1,7 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -from tests import fixture +from migrate.tests import fixture from migrate.versioning.util.keyedinstance import * class TestKeydInstance(fixture.Base): diff --git a/tests/versioning/test_pathed.py b/migrate/tests/versioning/test_pathed.py similarity index 97% rename from tests/versioning/test_pathed.py rename to migrate/tests/versioning/test_pathed.py index a2dfc24..7616e9d 100644 --- a/tests/versioning/test_pathed.py +++ b/migrate/tests/versioning/test_pathed.py @@ -1,4 +1,4 @@ -from tests import fixture +from migrate.tests import fixture from migrate.versioning.pathed import * class TestPathed(fixture.Base): diff --git a/tests/versioning/test_repository.py b/migrate/tests/versioning/test_repository.py similarity index 99% rename from tests/versioning/test_repository.py rename to migrate/tests/versioning/test_repository.py index a650d91..a23cd45 100644 --- a/tests/versioning/test_repository.py +++ b/migrate/tests/versioning/test_repository.py @@ -9,7 +9,7 @@ from migrate.versioning.repository import * from migrate.versioning.script import * from nose.tools import raises -from tests import fixture +from migrate.tests import fixture class TestRepository(fixture.Pathed): diff --git a/tests/versioning/test_runchangeset.py b/migrate/tests/versioning/test_runchangeset.py similarity index 98% rename from tests/versioning/test_runchangeset.py rename to migrate/tests/versioning/test_runchangeset.py index 1b79b15..52b0215 100644 --- a/tests/versioning/test_runchangeset.py +++ b/migrate/tests/versioning/test_runchangeset.py @@ -3,7 +3,7 @@ import os,shutil -from tests import fixture +from migrate.tests import fixture from migrate.versioning.schema import * from migrate.versioning import script diff --git a/tests/versioning/test_schema.py b/migrate/tests/versioning/test_schema.py similarity index 99% rename from tests/versioning/test_schema.py rename to migrate/tests/versioning/test_schema.py index 3d14809..d4b4861 100644 --- a/tests/versioning/test_schema.py +++ b/migrate/tests/versioning/test_schema.py @@ -9,7 +9,7 @@ from migrate.versioning import script, exceptions, schemadiff from sqlalchemy import * -from tests import fixture +from migrate.tests import fixture class TestControlledSchema(fixture.Pathed, fixture.DB): diff --git a/tests/versioning/test_schemadiff.py b/migrate/tests/versioning/test_schemadiff.py similarity index 99% rename from tests/versioning/test_schemadiff.py rename to migrate/tests/versioning/test_schemadiff.py index 4f2ae1f..6df6463 100644 --- a/tests/versioning/test_schemadiff.py +++ b/migrate/tests/versioning/test_schemadiff.py @@ -9,7 +9,7 @@ from nose.tools import eq_ from migrate.versioning import genmodel, schemadiff from migrate.changeset import schema -from tests import fixture +from migrate.tests import fixture class TestSchemaDiff(fixture.DB): diff --git a/tests/versioning/test_script.py b/migrate/tests/versioning/test_script.py similarity index 97% rename from tests/versioning/test_script.py rename to migrate/tests/versioning/test_script.py index f806bc8..51eeef8 100644 --- a/tests/versioning/test_script.py +++ b/migrate/tests/versioning/test_script.py @@ -9,8 +9,8 @@ from migrate.versioning import exceptions, version, repository from migrate.versioning.script import * from migrate.versioning.util import * -from tests import fixture -from tests.fixture.models import tmp_sql_table +from migrate.tests import fixture +from migrate.tests.fixture.models import tmp_sql_table class TestBaseScript(fixture.Pathed): @@ -226,7 +226,7 @@ class TestSqlScript(fixture.Pathed, fixture.DB): # populate python script contents = open(script_path, 'r').read() contents = contents.replace("pass", "tmp_sql_table.create(migrate_engine)") - contents = 'from tests.fixture.models import tmp_sql_table\n' + contents + contents = 'from migrate.tests.fixture.models import tmp_sql_table\n' + contents f = open(script_path, 'w') f.write(contents) f.close() diff --git a/tests/versioning/test_shell.py b/migrate/tests/versioning/test_shell.py similarity index 68% rename from tests/versioning/test_shell.py rename to migrate/tests/versioning/test_shell.py index 6a7de7f..1ce6dae 100644 --- a/tests/versioning/test_shell.py +++ b/migrate/tests/versioning/test_shell.py @@ -15,8 +15,8 @@ from nose.plugins.skip import SkipTest from migrate.versioning.repository import Repository from migrate.versioning import genmodel, shell, api from migrate.versioning.exceptions import * -from tests.fixture import Shell, DB, usedb -from tests.fixture import models +from migrate.tests.fixture import Shell, DB, usedb +from migrate.tests.fixture import models class TestShellCommands(Shell): @@ -24,15 +24,15 @@ class TestShellCommands(Shell): def test_help(self): """Displays default help dialog""" - self.assertEqual(self.env.run('migrate -h').returncode, 0) - self.assertEqual(self.env.run('migrate --help').returncode, 0) - self.assertEqual(self.env.run('migrate help').returncode, 0) + self.assertEqual(self.env.run('bin/migrate -h').returncode, 0) + self.assertEqual(self.env.run('bin/migrate --help').returncode, 0) + self.assertEqual(self.env.run('bin/migrate help').returncode, 0) def test_help_commands(self): """Display help on a specific command""" # we can only test that we get some output for cmd in api.__all__: - result = self.env.run('migrate help %s' % cmd) + result = self.env.run('bin/migrate help %s' % cmd) self.assertTrue(isinstance(result.stdout, basestring)) self.assertTrue(result.stdout) self.assertFalse(result.stderr) @@ -40,10 +40,10 @@ class TestShellCommands(Shell): def test_shutdown_logging(self): """Try to shutdown logging output""" repos = self.tmp_repos() - result = self.env.run('migrate create %s repository_name' % repos) - result = self.env.run('migrate version %s --disable_logging' % repos) + result = self.env.run('bin/migrate create %s repository_name' % repos) + result = self.env.run('bin/migrate version %s --disable_logging' % repos) self.assertEqual(result.stdout, '') - result = self.env.run('migrate version %s -q' % repos) + result = self.env.run('bin/migrate version %s -q' % repos) self.assertEqual(result.stdout, '') # TODO: assert logging messages to 0 @@ -88,7 +88,7 @@ class TestShellCommands(Shell): repos = self.tmp_repos() # Creating a file that doesn't exist should succeed - result = self.env.run('migrate create %s repository_name' % repos) + result = self.env.run('bin/migrate create %s repository_name' % repos) # Files should actually be created self.assert_(os.path.exists(repos)) @@ -98,35 +98,35 @@ class TestShellCommands(Shell): self.assertNotEquals(repos_.config.get('db_settings', 'version_table'), 'None') # Can't create it again: it already exists - result = self.env.run('migrate create %s repository_name' % repos, + result = self.env.run('bin/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() - result = self.env.run('migrate create %s repository_name' % repos) + result = self.env.run('bin/migrate create %s repository_name' % repos) - result = self.env.run('migrate script --repository=%s Desc' % repos) + result = self.env.run('bin/migrate script --repository=%s Desc' % repos) self.assert_(os.path.exists('%s/versions/001_Desc.py' % repos)) - result = self.env.run('migrate script More %s' % repos) + result = self.env.run('bin/migrate script More %s' % repos) self.assert_(os.path.exists('%s/versions/002_More.py' % repos)) - result = self.env.run('migrate script "Some Random name" %s' % repos) + result = self.env.run('bin/migrate script "Some Random name" %s' % repos) self.assert_(os.path.exists('%s/versions/003_Some_Random_name.py' % repos)) def test_script_sql(self): """We can create a migration sql script via the command line""" repos = self.tmp_repos() - result = self.env.run('migrate create %s repository_name' % repos) + result = self.env.run('bin/migrate create %s repository_name' % repos) - result = self.env.run('migrate script_sql mydb %s' % repos) + result = self.env.run('bin/migrate script_sql mydb %s' % repos) self.assert_(os.path.exists('%s/versions/001_mydb_upgrade.sql' % repos)) self.assert_(os.path.exists('%s/versions/001_mydb_downgrade.sql' % repos)) # Test creating a second - result = self.env.run('migrate script_sql postgres --repository=%s' % repos) + result = self.env.run('bin/migrate script_sql postgres --repository=%s' % repos) self.assert_(os.path.exists('%s/versions/002_postgres_upgrade.sql' % repos)) self.assert_(os.path.exists('%s/versions/002_postgres_downgrade.sql' % repos)) @@ -138,7 +138,7 @@ class TestShellCommands(Shell): self.assert_(not os.path.exists(script)) # No attempt is made to verify correctness of the repository path here - result = self.env.run('migrate manage %s --repository=/bla/' % script) + result = self.env.run('bin/migrate manage %s --repository=/bla/' % script) self.assert_(os.path.exists(script)) @@ -149,41 +149,41 @@ class TestShellRepository(Shell): """Create repository, python change script""" super(TestShellRepository, self).setUp() self.path_repos = self.tmp_repos() - result = self.env.run('migrate create %s repository_name' % self.path_repos) + result = self.env.run('bin/migrate create %s repository_name' % self.path_repos) def test_version(self): """Correctly detect repository version""" # Version: 0 (no scripts yet); successful execution - result = self.env.run('migrate version --repository=%s' % self.path_repos) + result = self.env.run('bin/migrate version --repository=%s' % self.path_repos) self.assertEqual(result.stdout.strip(), "0") # Also works as a positional param - result = self.env.run('migrate version %s' % self.path_repos) + result = self.env.run('bin/migrate version %s' % self.path_repos) self.assertEqual(result.stdout.strip(), "0") # Create a script and version should increment - result = self.env.run('migrate script Desc %s' % self.path_repos) - result = self.env.run('migrate version %s' % self.path_repos) + result = self.env.run('bin/migrate script Desc %s' % self.path_repos) + result = self.env.run('bin/migrate version %s' % self.path_repos) self.assertEqual(result.stdout.strip(), "1") def test_source(self): """Correctly fetch a script's source""" - result = self.env.run('migrate script Desc --repository=%s' % self.path_repos) + result = self.env.run('bin/migrate script Desc --repository=%s' % self.path_repos) filename = '%s/versions/001_Desc.py' % self.path_repos source = open(filename).read() self.assert_(source.find('def upgrade') >= 0) # Version is now 1 - result = self.env.run('migrate version %s' % self.path_repos) + result = self.env.run('bin/migrate version %s' % self.path_repos) self.assertEqual(result.stdout.strip(), "1") # Output/verify the source of version 1 - result = self.env.run('migrate source 1 --repository=%s' % self.path_repos) + result = self.env.run('bin/migrate source 1 --repository=%s' % self.path_repos) self.assertEqual(result.stdout.strip(), source.strip()) # We can also send the source to a file... test that too - result = self.env.run('migrate source 1 %s --repository=%s' % + result = self.env.run('bin/migrate source 1 %s --repository=%s' % (filename, self.path_repos)) self.assert_(os.path.exists(filename)) fd = open(filename) @@ -203,17 +203,17 @@ class TestShellDatabase(Shell, DB): """Ensure we can set version control on a database""" path_repos = repos = self.tmp_repos() url = self.url - result = self.env.run('migrate create %s repository_name' % repos) + result = self.env.run('bin/migrate create %s repository_name' % repos) - result = self.env.run('migrate drop_version_control %(url)s %(repos)s'\ + result = self.env.run('bin/migrate drop_version_control %(url)s %(repos)s'\ % locals(), expect_error=True) self.assertEqual(result.returncode, 1) - result = self.env.run('migrate version_control %(url)s %(repos)s' % locals()) + result = self.env.run('bin/migrate version_control %(url)s %(repos)s' % locals()) # Clean up - result = self.env.run('migrate drop_version_control %(url)s %(repos)s' % locals()) + result = self.env.run('bin/migrate drop_version_control %(url)s %(repos)s' % locals()) # Attempting to drop vc from a database without it should fail - result = self.env.run('migrate drop_version_control %(url)s %(repos)s'\ + result = self.env.run('bin/migrate drop_version_control %(url)s %(repos)s'\ % locals(), expect_error=True) self.assertEqual(result.returncode, 1) @@ -222,41 +222,41 @@ class TestShellDatabase(Shell, DB): """Commands with default arguments set by manage.py""" path_repos = repos = self.tmp_repos() url = self.url - result = self.env.run('migrate create --name=repository_name %s' % repos) - result = self.env.run('migrate drop_version_control %(url)s %(repos)s' % locals(), expect_error=True) + result = self.env.run('bin/migrate create --name=repository_name %s' % repos) + result = self.env.run('bin/migrate drop_version_control %(url)s %(repos)s' % locals(), expect_error=True) self.assertEqual(result.returncode, 1) - result = self.env.run('migrate version_control %(url)s %(repos)s' % locals()) + result = self.env.run('bin/migrate version_control %(url)s %(repos)s' % locals()) - result = self.env.run('migrate drop_version_control %(url)s %(repos)s' % locals()) + result = self.env.run('bin/migrate drop_version_control %(url)s %(repos)s' % locals()) @usedb() def test_version_control_specified(self): """Ensure we can set version control to a particular version""" path_repos = self.tmp_repos() url = self.url - result = self.env.run('migrate create --name=repository_name %s' % path_repos) - result = self.env.run('migrate drop_version_control %(url)s %(path_repos)s' % locals(), expect_error=True) + result = self.env.run('bin/migrate create --name=repository_name %s' % path_repos) + result = self.env.run('bin/migrate drop_version_control %(url)s %(path_repos)s' % locals(), expect_error=True) self.assertEqual(result.returncode, 1) # Fill the repository path_script = self.tmp_py() version = 2 for i in range(version): - result = self.env.run('migrate script Desc --repository=%s' % path_repos) + result = self.env.run('bin/migrate script Desc --repository=%s' % path_repos) # Repository version is correct - result = self.env.run('migrate version %s' % path_repos) + result = self.env.run('bin/migrate version %s' % path_repos) self.assertEqual(result.stdout.strip(), str(version)) # Apply versioning to DB - result = self.env.run('migrate version_control %(url)s %(path_repos)s %(version)s' % locals()) + result = self.env.run('bin/migrate version_control %(url)s %(path_repos)s %(version)s' % locals()) # Test db version number (should start at 2) - result = self.env.run('migrate db_version %(url)s %(path_repos)s' % locals()) + result = self.env.run('bin/migrate db_version %(url)s %(path_repos)s' % locals()) self.assertEqual(result.stdout.strip(), str(version)) # Clean up - result = self.env.run('migrate drop_version_control %(url)s %(path_repos)s' % locals()) + result = self.env.run('bin/migrate drop_version_control %(url)s %(path_repos)s' % locals()) @usedb() def test_upgrade(self): @@ -264,67 +264,67 @@ class TestShellDatabase(Shell, DB): # Create a repository repos_name = 'repos_name' repos_path = self.tmp() - result = self.env.run('migrate create %(repos_path)s %(repos_name)s' % locals()) + result = self.env.run('bin/migrate create %(repos_path)s %(repos_name)s' % locals()) self.assertEquals(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)) + result = self.env.run('bin/migrate drop_version_control %s %s' % (self.url, repos_path), expect_error=True) + result = self.env.run('bin/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) - result = self.env.run('migrate upgrade %s %s' % (self.url, repos_path)) + result = self.env.run('bin/migrate upgrade %s %s' % (self.url, repos_path)) self.assertEquals(self.run_db_version(self.url, repos_path), 0) - result = self.env.run('migrate upgrade %s %s' % (self.url, repos_path)) + result = self.env.run('bin/migrate upgrade %s %s' % (self.url, repos_path)) self.assertEquals(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) + result = self.env.run('bin/migrate upgrade %s %s 1' % (self.url, repos_path), expect_error=True) self.assertEquals(result.returncode, 1) - result = self.env.run('migrate upgrade %s %s -1' % (self.url, repos_path), expect_error=True) + result = self.env.run('bin/migrate upgrade %s %s -1' % (self.url, repos_path), expect_error=True) self.assertEquals(result.returncode, 2) # Add a script to the repository; upgrade the db - result = self.env.run('migrate script Desc --repository=%s' % (repos_path)) + result = self.env.run('bin/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) # 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('bin/migrate upgrade %s %s 0 --preview_sql' % (self.url, repos_path)) + result = self.env.run('bin/migrate upgrade %s %s 0 --preview_py' % (self.url, repos_path)) - result = self.env.run('migrate upgrade %s %s' % (self.url, repos_path)) + result = self.env.run('bin/migrate upgrade %s %s' % (self.url, repos_path)) self.assertEquals(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) + result = self.env.run('bin/migrate downgrade %s %s' % (self.url, repos_path), expect_error=True) self.assertEquals(result.returncode, 2) - result = self.env.run('migrate downgrade %s %s -1' % (self.url, repos_path), expect_error=True) + result = self.env.run('bin/migrate downgrade %s %s -1' % (self.url, repos_path), expect_error=True) self.assertEquals(result.returncode, 2) - result = self.env.run('migrate downgrade %s %s 2' % (self.url, repos_path), expect_error=True) + result = self.env.run('bin/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) - result = self.env.run('migrate downgrade %s %s 0' % (self.url, repos_path)) + result = self.env.run('bin/migrate downgrade %s %s 0' % (self.url, repos_path)) self.assertEquals(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) + result = self.env.run('bin/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) - result = self.env.run('migrate drop_version_control %s %s' % (self.url, repos_path)) + result = self.env.run('bin/migrate drop_version_control %s %s' % (self.url, repos_path)) def _run_test_sqlfile(self, upgrade_script, downgrade_script): # TODO: add test script that checks if db really changed repos_path = self.tmp() repos_name = 'repos' - 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)) + result = self.env.run('bin/migrate create %s %s' % (repos_path, repos_name)) + result = self.env.run('bin/migrate drop_version_control %s %s' % (self.url, repos_path), expect_error=True) + result = self.env.run('bin/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) 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)) + result = self.env.run('bin/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) @@ -334,11 +334,11 @@ class TestShellDatabase(Shell, DB): self.assertEquals(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)) + result = self.env.run('bin/migrate upgrade %s %s' % (self.url, repos_path)) self.assertEquals(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)) + result = self.env.run('bin/migrate downgrade %s %s 0' % (self.url, repos_path)) self.assertEquals(self.run_db_version(self.url, repos_path), 0) self.assertRaises(Exception, self.engine.text('select * from t_table').execute) @@ -378,15 +378,15 @@ class TestShellDatabase(Shell, DB): repos_name = 'repos_name' repos_path = self.tmp() - 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)) + result = self.env.run('bin/migrate create repository_name --repository=%s' % repos_path) + result = self.env.run('bin/migrate drop_version_control %s %s' % (self.url, repos_path), expect_error=True) + result = self.env.run('bin/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) # 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)) + result = self.env.run('bin/migrate script Desc %s' % repos_path) + result = self.env.run('bin/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) @@ -408,7 +408,7 @@ class TestShellDatabase(Shell, DB): file.write(script_text) file.close() - result = self.env.run('migrate test %s %s bla' % (self.url, repos_path), expect_error=True) + result = self.env.run('bin/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) @@ -439,7 +439,7 @@ class TestShellDatabase(Shell, DB): file = open(script_path, 'w') file.write(script_text) file.close() - result = self.env.run('migrate test %s %s' % (self.url, repos_path)) + result = self.env.run('bin/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) @@ -450,51 +450,51 @@ class TestShellDatabase(Shell, DB): repos_name = 'repos_name' repos_path = self.tmp() script_path = self.tmp_py() - model_module = 'tests.fixture.models:meta_rundiffs' - old_model_module = 'tests.fixture.models:meta_old_rundiffs' + model_module = 'migrate.tests.fixture.models:meta_rundiffs' + old_model_module = 'migrate.tests.fixture.models:meta_old_rundiffs' # Create empty repository. self.meta = MetaData(self.engine, reflect=True) self.meta.reflect() self.meta.drop_all() # in case junk tables are lying around in the test database - 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)) + result = self.env.run('bin/migrate create %s %s' % (repos_path, repos_name)) + result = self.env.run('bin/migrate drop_version_control %s %s' % (self.url, repos_path), expect_error=True) + result = self.env.run('bin/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) # Setup helper script. - result = self.env.run('migrate manage %s --repository=%s --url=%s --model=%s'\ + result = self.env.run('bin/migrate manage %s --repository=%s --url=%s --model=%s'\ % (script_path, repos_path, self.url, model_module)) self.assert_(os.path.exists(script_path)) # Model is defined but database is empty. - result = self.env.run('migrate compare_model_to_db %s %s --model=%s' \ + result = self.env.run('bin/migrate compare_model_to_db %s %s --model=%s' \ % (self.url, repos_path, model_module)) self.assert_("tables missing in database: tmp_account_rundiffs" in result.stdout) # Test Deprecation - result = self.env.run('migrate compare_model_to_db %s %s --model=%s' \ + result = self.env.run('bin/migrate compare_model_to_db %s %s --model=%s' \ % (self.url, repos_path, model_module.replace(":", ".")), expect_error=True) self.assertEqual(result.returncode, 0) self.assertTrue("DeprecationWarning" in result.stderr) self.assert_("tables missing in database: tmp_account_rundiffs" in result.stdout) # Update db to latest model. - result = self.env.run('migrate update_db_from_model %s %s %s'\ + result = self.env.run('bin/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 - result = self.env.run('migrate compare_model_to_db %s %s %s'\ + result = self.env.run('bin/migrate compare_model_to_db %s %s %s'\ % (self.url, repos_path, model_module)) self.assert_("No schema diffs" in result.stdout) - 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)) + result = self.env.run('bin/migrate drop_version_control %s %s' % (self.url, repos_path), expect_error=True) + result = self.env.run('bin/migrate version_control %s %s' % (self.url, repos_path)) - result = self.env.run('migrate create_model %s %s' % (self.url, repos_path)) + result = self.env.run('bin/migrate create_model %s %s' % (self.url, repos_path)) temp_dict = dict() exec result.stdout in temp_dict @@ -506,10 +506,10 @@ class TestShellDatabase(Shell, DB): #Column('passwd', String(length=None, convert_unicode=False, assert_unicode=None))""" in result.stdout) # We're happy with db changes, make first db upgrade script to go from version 0 -> 1. - result = self.env.run('migrate make_update_script_for_model', expect_error=True) + result = self.env.run('bin/migrate make_update_script_for_model', expect_error=True) self.assertTrue('Not enough arguments' in result.stderr) - result_script = self.env.run('migrate make_update_script_for_model %s %s %s %s'\ + result_script = self.env.run('bin/migrate make_update_script_for_model %s %s %s %s'\ % (self.url, repos_path, old_model_module, model_module)) self.assertEqualsIgnoreWhitespace(result_script.stdout, '''from sqlalchemy import * @@ -536,11 +536,11 @@ class TestShellDatabase(Shell, DB): tmp_account_rundiffs.drop()''') # Save the upgrade script. - result = self.env.run('migrate script Desc %s' % repos_path) + result = self.env.run('bin/migrate script Desc %s' % repos_path) upgrade_script_path = '%s/versions/001_Desc.py' % repos_path open(upgrade_script_path, 'w').write(result_script.stdout) - result = self.env.run('migrate compare_model_to_db %s %s %s'\ + result = self.env.run('bin/migrate compare_model_to_db %s %s %s'\ % (self.url, repos_path, model_module)) self.assert_("No schema diffs" in result.stdout) diff --git a/tests/versioning/test_template.py b/migrate/tests/versioning/test_template.py similarity index 98% rename from tests/versioning/test_template.py rename to migrate/tests/versioning/test_template.py index 18303ab..c6a45a6 100644 --- a/tests/versioning/test_template.py +++ b/migrate/tests/versioning/test_template.py @@ -8,7 +8,7 @@ import migrate.versioning.templates from migrate.versioning.template import * from migrate.versioning import api -from tests import fixture +from migrate.tests import fixture class TestTemplate(fixture.Pathed): diff --git a/tests/versioning/test_util.py b/migrate/tests/versioning/test_util.py similarity index 98% rename from tests/versioning/test_util.py rename to migrate/tests/versioning/test_util.py index 0ccb6de..76bd1fd 100644 --- a/tests/versioning/test_util.py +++ b/migrate/tests/versioning/test_util.py @@ -5,7 +5,7 @@ import os from sqlalchemy import * -from tests import fixture +from migrate.tests import fixture from migrate.versioning.util import * diff --git a/tests/versioning/test_version.py b/migrate/tests/versioning/test_version.py similarity index 99% rename from tests/versioning/test_version.py rename to migrate/tests/versioning/test_version.py index 5840612..0be192f 100644 --- a/tests/versioning/test_version.py +++ b/migrate/tests/versioning/test_version.py @@ -4,7 +4,7 @@ from migrate.versioning.version import * from migrate.versioning.exceptions import * -from tests import fixture +from migrate.tests import fixture class TestVerNum(fixture.Base): diff --git a/migrate/versioning/migrate_repository.py b/migrate/versioning/migrate_repository.py index 27c4d35..53833bb 100644 --- a/migrate/versioning/migrate_repository.py +++ b/migrate/versioning/migrate_repository.py @@ -6,6 +6,9 @@ import os import sys +import logging + +log = logging.getLogger(__name__) def usage(): @@ -22,13 +25,13 @@ def usage(): def delete_file(filepath): """Deletes a file and prints a message.""" - print ' Deleting file: %s' % filepath + log.info('Deleting file: %s' % filepath) os.remove(filepath) def move_file(src, tgt): """Moves a file and prints a message.""" - print ' Moving file %s to %s' % (src, tgt) + log.info('Moving file %s to %s' % (src, tgt)) if os.path.exists(tgt): raise Exception( 'Cannot move file %s because target %s already exists' % \ @@ -38,13 +41,13 @@ def move_file(src, tgt): def delete_directory(dirpath): """Delete a directory and print a message.""" - print ' Deleting directory: %s' % dirpath + log.info('Deleting directory: %s' % dirpath) os.rmdir(dirpath) def migrate_repository(repos): """Does the actual migration to the new repository format.""" - print 'Migrating repository at: %s to new format' % repos + log.info('Migrating repository at: %s to new format' % repos) versions = '%s/versions' % repos dirs = os.listdir(versions) # Only use int's in list. @@ -52,7 +55,7 @@ def migrate_repository(repos): numdirs.sort() # Sort list. for dirname in numdirs: origdir = '%s/%s' % (versions, dirname) - print ' Working on directory: %s' % origdir + log.info('Working on directory: %s' % origdir) files = os.listdir(origdir) files.sort() for filename in files: diff --git a/setup.cfg b/setup.cfg index 1229d67..d3a6074 100644 --- a/setup.cfg +++ b/setup.cfg @@ -7,8 +7,8 @@ tag_svn_revision = 1 tag_build = .dev [nosetests] -pdb = true -pdb-failures = true +pdb = 0 +pdb-failures = 0 #stop = true [aliases] diff --git a/tests/fixture/shell.py b/tests/fixture/shell.py deleted file mode 100644 index a996b5c..0000000 --- a/tests/fixture/shell.py +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -import os -import sys - -from scripttest import TestFileEnvironment - -from tests.fixture.pathed import * - - -class Shell(Pathed): - """Base class for command line tests""" - - def setUp(self): - super(Shell, self).setUp() - self.env = TestFileEnvironment( - base_path=os.path.join(self.temp_usable_dir, 'env'), - script_path=[os.path.dirname(sys.executable)] # PATH to migrate development script folder - ) - - def run_version(self, repos_path): - result = self.env.run('migrate version %s' % repos_path) - return int(result.stdout.strip()) - - def run_db_version(self, url, repos_path): - result = self.env.run('migrate db_version %s %s' % (url, repos_path)) - return int(result.stdout.strip())